Commit 17f5ee5e authored by claes's avatar claes

Tooltip text added

parent 06191506
This diff is collapsed.
/*
* Proview $Id: flow.h,v 1.13 2007-07-18 09:26:43 claes Exp $
* Proview $Id: flow.h,v 1.14 2008-01-18 13:55:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -260,6 +260,7 @@ typedef enum {
flow_eEvent_Resized,
flow_eEvent_ScrollUp,
flow_eEvent_ScrollDown,
flow_eEvent_TipText,
flow_eEvent__
} flow_eEvent;
......
/*
* Proview $Id: flow_api.cpp,v 1.13 2008-01-17 14:18:55 claes Exp $
* Proview $Id: flow_api.cpp,v 1.14 2008-01-18 13:55:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -40,6 +40,7 @@
#include "flow_conpoint.h"
#include "flow_annot.h"
#include "flow_draw.h"
#include "flow_tiptext.h"
#include "flow_api.h"
int flow_Save( flow_tCtx ctx, char *filename)
......@@ -723,3 +724,9 @@ int flow_LoadNodeClass( flow_tCtx ctx, char *fname, flow_tNodeClass *nodeclass)
return sts;
}
void flow_SetTipText( flow_tCtx ctx, flow_tObject object, char *text, int x, int y)
{
ctx->tiptext->draw_text( (FlowArrayElem *)object, text, x, y);
}
/*
* Proview $Id: flow_api.h,v 1.13 2008-01-17 14:18:55 claes Exp $
* Proview $Id: flow_api.h,v 1.14 2008-01-18 13:55:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -241,6 +241,7 @@ int flow_GetNextObject( flow_tCtx ctx, flow_tNode object, flow_eDirection dir,
flow_tNode *next);
int flow_IsVisible( flow_tCtx ctx, flow_tObject object, flow_eVisible type);
int flow_LoadNodeClass( flow_tCtx ctx, char *fname, flow_tNodeClass *nodeclass);
void flow_SetTipText( flow_tCtx ctx, flow_tObject object, char *text, int x, int y);
#if defined __cplusplus
}
......
/*
* Proview $Id: flow_ctx.cpp,v 1.12 2007-09-25 13:11:00 claes Exp $
* Proview $Id: flow_ctx.cpp,v 1.13 2008-01-18 13:55:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -41,6 +41,7 @@
#include "flow_pushbutton.h"
#include "flow_draw.h"
#include "flow_browctx.h"
#include "flow_tiptext.h"
#include "flow_msg.h"
class NextElem {
......@@ -51,8 +52,46 @@ class NextElem {
double rank;
};
FlowCtx::FlowCtx( char *ctx_name, double zoom_fact, int offs_x, int offs_y)
: ctx_type(flow_eCtxType_Flow), zoom_factor(zoom_fact), base_zoom_factor(zoom_fact),
offset_x(offs_x), offset_y(offs_y), nav_zoom_factor(zoom_fact),
print_zoom_factor(100),
x_right(0), x_left(0), y_high(0), y_low(0),
window_width(0), window_height(0),
nav_window_width(0), nav_window_height(0),
nav_rect_ll_x(0), nav_rect_ll_y(0), nav_rect_ur_x(0), nav_rect_ur_y(0),
node_movement_active(0),
node_movement_paste_active(0), node_movement_paste_pending(0),
nav_rect_movement_active(0), nav_rect_zoom_active(0),
select_rect_active(0),
con_create_active(0), auto_scrolling_active(0), defered_redraw_active(0),
a(50,50), a_sel(20,20), a_paste(20,20),
a_move(20,20), a_nc(20,20), a_cc(20,20),
event_region_select(flow_eEvent_Null),
event_region_add_select(flow_eEvent_Null),
event_create_con(flow_eEvent_Null), event_create_node(flow_eEvent_Null),
event_move_node(flow_eEvent_Null),
callback_object(0), callback_object_type(flow_eObjectType_NoObject),
cursor_present(0), cursor_x(0), cursor_y(0), user_highlight(0),
application_paste(0),
grid_size_x(2), grid_size_y(1), grid_on(1),
draw_delta(0.3),
grafcet_con_delta(2), refcon_cnt(0), refcon_width(1.5),
refcon_height(0.8), refcon_textsize(3), refcon_linewidth(2),
trace_connect_func(0), trace_scan_func(0), trace_started(0),
unobscured(1), nodraw(0), no_nav(1), widget_cnt(0),
select_policy(flow_eSelectPolicy_Partial), tiptext(0),
display_level(flow_mDisplayLevel_1), scroll_size(0),
scroll_callback(0), scroll_data(NULL)
{
strcpy(name, ctx_name);
memset( event_callback, 0, sizeof(event_callback));
tiptext = new FlowTipText( this);
}
FlowCtx::~FlowCtx()
{
delete tiptext;
set_nodraw();
a_sel.clear();
move_clear();
......@@ -444,6 +483,7 @@ void FlowCtx::draw( int ll_x, int ll_y, int ur_x, int ur_y)
select_rect_ur_x - select_rect_ll_x,
select_rect_ur_y - select_rect_ll_y, flow_eDrawType_Line, 0, 0);
}
tiptext->draw();
}
void FlowCtx::clear()
......@@ -799,6 +839,7 @@ int FlowCtx::event_handler( flow_eEvent event, int x, int y, int w, int h)
switch ( event)
{
case flow_eEvent_MB1Click:
tiptext->remove();
if ( node_movement_paste_active)
{
if ( auto_scrolling_active)
......@@ -849,6 +890,7 @@ int FlowCtx::event_handler( flow_eEvent event, int x, int y, int w, int h)
case flow_eEvent_MB2DoubleClickShiftCtrl:
case flow_eEvent_MB3Click:
case flow_eEvent_MB3Press:
tiptext->remove();
sts = 0;
for ( i = 0; i < a.a_size; i++)
{
......@@ -904,6 +946,7 @@ int FlowCtx::event_handler( flow_eEvent event, int x, int y, int w, int h)
}
break;
case flow_eEvent_ButtonMotion:
tiptext->remove();
if ( node_movement_active)
{
set_defered_redraw();
......@@ -1093,6 +1136,7 @@ int FlowCtx::event_handler( flow_eEvent event, int x, int y, int w, int h)
}
else if ( x < 0 || x > ctx->window_width || y < 0 || y > window_height)
a.set_hot( 0);
tiptext->remove();
break;
case flow_eEvent_VisibilityUnobscured:
unobscured = 1;
......@@ -1343,6 +1387,26 @@ void FlowCtx::disable_event_all()
event_callback[i] = 0;
}
void FlowCtx::tiptext_event( FlowArrayElem *object, int x, int y)
{
if ( event_callback[flow_eEvent_TipText] )
{
/* Send an tiptext callback */
static flow_sEvent e;
e.event = flow_eEvent_TipText;
e.any.type = flow_eEventType_Object;
e.any.x_pixel = x;
e.any.y_pixel = y;
e.any.x = 0;
e.any.y = 0;
e.object.object_type = object->type();
e.object.object = object;
event_callback[flow_eEvent_TipText]( this, &e);
}
}
FlowArrayElem *FlowCtx::get_node_from_name( char *name)
{
int i;
......
/*
* Proview $Id: flow_ctx.h,v 1.8 2007-09-25 13:11:00 claes Exp $
* Proview $Id: flow_ctx.h,v 1.9 2008-01-18 13:55:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -28,6 +28,7 @@
#include "flow_array.h"
class FlowDraw;
class FlowTipText;
typedef struct {
void *scroll_data;
......@@ -41,39 +42,8 @@ typedef struct {
class FlowCtx {
public:
FlowCtx( char *ctx_name, double zoom_fact = 100, int offs_x = 0, int offs_y = 0)
: ctx_type(flow_eCtxType_Flow), zoom_factor(zoom_fact), base_zoom_factor(zoom_fact),
offset_x(offs_x), offset_y(offs_y), nav_zoom_factor(zoom_fact),
print_zoom_factor(100),
x_right(0), x_left(0), y_high(0), y_low(0),
window_width(0), window_height(0),
nav_window_width(0), nav_window_height(0),
nav_rect_ll_x(0), nav_rect_ll_y(0), nav_rect_ur_x(0), nav_rect_ur_y(0),
node_movement_active(0),
node_movement_paste_active(0), node_movement_paste_pending(0),
nav_rect_movement_active(0), nav_rect_zoom_active(0),
select_rect_active(0),
con_create_active(0), auto_scrolling_active(0), defered_redraw_active(0),
a(50,50), a_sel(20,20), a_paste(20,20),
a_move(20,20), a_nc(20,20), a_cc(20,20),
event_region_select(flow_eEvent_Null),
event_region_add_select(flow_eEvent_Null),
event_create_con(flow_eEvent_Null), event_create_node(flow_eEvent_Null),
event_move_node(flow_eEvent_Null),
callback_object(0), callback_object_type(flow_eObjectType_NoObject),
cursor_present(0), cursor_x(0), cursor_y(0), user_highlight(0),
application_paste(0),
grid_size_x(2), grid_size_y(1), grid_on(1),
draw_delta(0.3),
grafcet_con_delta(2), refcon_cnt(0), refcon_width(1.5),
refcon_height(0.8), refcon_textsize(3), refcon_linewidth(2),
trace_connect_func(0), trace_scan_func(0), trace_started(0),
unobscured(1), nodraw(0), no_nav(1), widget_cnt(0),
select_policy(flow_eSelectPolicy_Partial),
display_level(flow_mDisplayLevel_1), scroll_size(0),
scroll_callback(0), scroll_data(NULL)
{ strcpy(name, ctx_name);
memset( event_callback, 0, sizeof(event_callback));};
FlowCtx( char *ctx_name, double zoom_fact = 100, int offs_x = 0, int offs_y = 0);
flow_eCtxType ctx_type;
double zoom_factor;
double base_zoom_factor;
......@@ -209,6 +179,7 @@ class FlowCtx {
int (*event_cb)( FlowCtx *ctx, flow_tEvent event));
void disable_event( flow_eEvent event);
void disable_event_all();
void tiptext_event( FlowArrayElem *object, int x, int y);
void redraw_node_cons( void *node);
void delete_node_cons( void *node);
void set_defered_redraw();
......@@ -300,6 +271,8 @@ class FlowCtx {
int no_nav;
int widget_cnt;
flow_eSelectPolicy select_policy;
FlowTipText *tiptext;
void set_nodraw() { nodraw++; };
void reset_nodraw() { if ( nodraw) nodraw--; };
void reconfigure();
......
/*
* Proview $Id: flow_node.cpp,v 1.9 2007-05-11 15:07:21 claes Exp $
* Proview $Id: flow_node.cpp,v 1.10 2008-01-18 13:55:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -28,6 +28,7 @@
#include "flow_draw.h"
#include "flow_conpoint.h"
#include "flow_browctx.h"
#include "flow_tiptext.h"
#include "flow_msg.h"
FlowNode::FlowNode( FlowCtx *flow_ctx, char *name, FlowNodeClass *node_class,
......@@ -810,6 +811,7 @@ int FlowNode::event_handler( flow_eEvent event, int x, int y)
ctx->fdraw->set_cursor( ctx, draw_eCursor_CrossHair);
hot = 1;
redraw = 1;
ctx->tiptext_event( this, x, y);
}
if ( !sts && hot)
{
......@@ -817,6 +819,7 @@ int FlowNode::event_handler( flow_eEvent event, int x, int y)
erase();
hot = 0;
redraw = 1;
ctx->tiptext->remove_text( this);
}
if ( redraw)
{
......
/*
* Proview $Id: flow_tiptext.cpp,v 1.1 2008-01-18 13:55:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include "flow_std.h"
#include "flow_tiptext.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <math.h>
#include "flow_ctx.h"
#include "flow_draw.h"
static void tiptext_timer_cb( FlowCtx *ctx)
{
ctx->tiptext->timer_id = 0;
ctx->tiptext->active = true;
ctx->tiptext->draw();
}
FlowTipText::~FlowTipText()
{
if ( timer_id)
ctx->fdraw->cancel_timer( ctx, timer_id);
}
void FlowTipText::draw_text( FlowArrayElem *e, char *text, int x, int y)
{
int z_width, z_height;
int row;
char *s, *t;
if ( active)
remove_text( text_object);
if ( timer_id) {
ctx->fdraw->cancel_timer( ctx, timer_id);
timer_id = 0;
}
row = 0;
for ( s = text, t = tiptext[0]; *s; s++) {
if ( *s == 10) {
*t = 0;
row++;
if ( row >= TIPTEXT_ROWS)
break;
t = tiptext[row];
}
else {
*t = *s;
t++;
if ( t - tiptext[0] >= (int)sizeof(tiptext))
break;
}
}
*t = 0;
tiptext_rows = row + 1;
for ( int i = row + 1; i < TIPTEXT_ROWS; i++)
tiptext[i][0] = 0;
text_width = 0;
text_height = 0;
for ( int i = 0; i < tiptext_rows; i++) {
ctx->fdraw->get_text_extent( ctx, tiptext[i], strlen(tiptext[i]), flow_eDrawType_TextHelvetica, 2,
&z_width, &z_height);
if ( z_width > text_width)
text_width = z_width;
text_height += z_height + 3;
}
text_x = x;
text_y = y;
text_width += 8;
text_height += 4;
text_descent = 4;
text_object = e;
if ( text_x + text_width > ctx->window_width)
text_x = ctx->window_width - text_width;
if ( text_x < 0)
text_x = 0;
if ( text_y + text_height > ctx->window_height)
text_y = ctx->window_height - text_height;
if ( text_y < 0)
text_y = 0;
ctx->fdraw->set_timer( ctx, 1000, tiptext_timer_cb, &timer_id);
}
void FlowTipText::draw()
{
if ( !active || !tiptext_rows)
return;
ctx->fdraw->fill_rect( ctx, text_x, text_y, text_width, text_height,
flow_eDrawType_LineErase);
ctx->fdraw->rect( ctx, text_x, text_y, text_width, text_height,
flow_eDrawType_Line, 0, 0);
int y = text_y + 4 + (text_height-4)/tiptext_rows;
for ( int i = 0; i < tiptext_rows; i++) {
ctx->fdraw->text( ctx, text_x + 6, y - text_descent - 2,
tiptext[i], strlen(tiptext[i]), flow_eDrawType_TextHelvetica, 2,
0, 0);
y += (text_height-3)/tiptext_rows;
}
}
void FlowTipText::remove_text( FlowArrayElem *e)
{
if ( e != text_object)
return;
if ( timer_id) {
ctx->fdraw->cancel_timer( ctx, timer_id);
timer_id = 0;
return;
}
if ( active) {
active = false;
ctx->fdraw->fill_rect( ctx, text_x, text_y, text_width + 1, text_height + 1,
flow_eDrawType_LineErase);
ctx->draw( text_x, text_y, text_x + text_width + 1, text_y + text_height + 1);
}
}
void FlowTipText::remove()
{
if ( timer_id) {
ctx->fdraw->cancel_timer( ctx, timer_id);
timer_id = 0;
}
if ( active)
remove_text( text_object);
}
/*
* Proview $Id: flow_tiptext.h,v 1.1 2008-01-18 13:55:06 claes Exp $
* Copyright (C) 2005 SSAB Oxelösund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#ifndef flow_tiptext_h
#define flow_tiptext_h
#include <iostream.h>
#include <fstream.h>
#include "flow.h"
#define TIPTEXT_ROWS 3
class FlowCtx;
class FlowArrayElem;
/*! \file flow_tiptext.h
\brief Contains the FlowTipText class. */
/*! \addtogroup Flow */
/*@{*/
//! Draw tooltip text.
/*! A tooltip text is a text frame that becomes visible some time after the cursor has visited an object, it
the cursor still rest on that object. When the object is hit by the cursor, draw_text() should be called.
The text will be displayed within 1 second if not the remove_text() or remove() function are called.
The text is visible until the remove_text() or remove() function are called.
*/
class FlowTipText {
public:
//! Constructor
/*!
\param gctx Flow context.
*/
FlowTipText( FlowCtx *gctx) : ctx(gctx), tiptext_rows(0), active(false), timer_id(0) {}
//! Destructor
/*! Removes the timer if it is set.
*/
~FlowTipText();
FlowCtx *ctx; //!< Flow context.
int text_x; //!< x coordinate in pixels for text.
int text_y; //!< y coordinate in pixels for text.
int text_width; //!< Text width in pixels.
int text_height; //!< Text height in pixels.
int text_descent; //!< Text descent in pixels.
FlowArrayElem *text_object; //!< Object that activated the current tip text.
int tiptext_rows; //!< Number of rows in current tiptext.
char tiptext[TIPTEXT_ROWS][512]; //!< Current tip text.
bool active; //!< Tip text is active, i.e. timer is running or text is displayed.
void *timer_id; //!< Timer id.
//! Activate tooltip.
/*!
\param e Object that owns the tiptext.
\param text The tooltip text.
\param x x coordinate in pixel for the text.
\param y y coordinate in pixel for the text.
This function is called when the cursor hits an object. It starts a timer, and if
no remove function is called, the text will be displayed within 1 second, and remain until
a remove function is called.
*/
void draw_text( FlowArrayElem *e, char *text, int x, int y);
//! Remove or inactivate the text for the specified object.
/*!
\param e Object which the text should be removed for.
*/
void remove_text( FlowArrayElem *e);
//! Remove or inactivate texts for any object.
/*! If the timer is running, it is stopped. If the text is diplayed, it is erased.
*/
void remove();
//! Draw the current tooltip text.
/*! Function to draw the text and rectangle of the tooltip.
*/
void draw();
};
/*@}*/
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment