~ubuntu-branches/ubuntu/intrepid/tcm/intrepid

« back to all changes in this revision

Viewing changes to src/tb/simplelabel.h

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2003-07-03 20:08:21 UTC
  • Revision ID: james.westby@ubuntu.com-20030703200821-se4xtqx25e5miczi
Tags: upstream-2.20
ImportĀ upstreamĀ versionĀ 2.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//------------------------------------------------------------------------------
 
2
// 
 
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
 
4
// (c) copyright 1996, Vrije Universiteit Amsterdam.
 
5
// Author: Frank Dehne (frank@cs.vu.nl).
 
6
//
 
7
// TCM is free software; you can redistribute it and/or modify
 
8
// it under the terms of the GNU General Public License as published by
 
9
// the Free Software Foundation; either version 2 of the License, or
 
10
// (at your option) any later version.
 
11
//
 
12
// TCM is distributed in the hope that it will be useful,
 
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
// GNU General Public License for more details.
 
16
//
 
17
// You should have received a copy of the GNU General Public License
 
18
// along with TCM; if not, write to the Free Software
 
19
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
20
// 02111-1307, USA.
 
21
//-----------------------------------------------------------------------------
 
22
#ifndef _SIMPLELABEL_H
 
23
#define _SIMPLELABEL_H
 
24
 
 
25
#include "point.h"
 
26
#include "lstring.h"
 
27
#include "xfont.h"
 
28
class Grafport;
 
29
 
 
30
/// abstract (simple) text label class.
 
31
class SimpleLabel {
 
32
/*@Doc: {\large {\bf scope:} table} */
 
33
public:
 
34
        ///
 
35
        SimpleLabel(Grafport *g, XFont *font);
 
36
        ///
 
37
        SimpleLabel(const SimpleLabel &text);   
 
38
        ///
 
39
        virtual ~SimpleLabel();                 
 
40
 
 
41
        ///
 
42
        friend int operator==(const SimpleLabel &t1, const SimpleLabel &t2);
 
43
        ///
 
44
        friend int Compare(SimpleLabel *r1, SimpleLabel *r2) {return *r1==*r2;}
 
45
 
 
46
        /// draw label.
 
47
        virtual void Draw() = 0;                
 
48
 
 
49
        /// erase label.
 
50
        virtual void Undraw();          
 
51
 
 
52
        /// when label is dragged only a dotted box (outline) is drawn
 
53
        void DrawOutLine(const Point *c);
 
54
 
 
55
        /// update position and redraw.
 
56
        virtual void UpdatePosition(const Point *);
 
57
 
 
58
        /// update label and redraw.
 
59
        virtual void UpdateText(const string *);        
 
60
 
 
61
        /// set position.
 
62
        void SetPosition(const Point *pt);      
 
63
 
 
64
        /// set label text
 
65
        void SetText(const string *s);  
 
66
 
 
67
        /// set grafport
 
68
        void SetGrafport(Grafport *g) {grafport = g;}
 
69
 
 
70
        /// calculate text size.
 
71
        void CalcSize();                
 
72
 
 
73
        /// true iff (x,y) is in text.
 
74
        bool HitText(int x, int y);     
 
75
 
 
76
        /// simple 'get' actions.
 
77
        const Point *GetPosition() const {return &position;} 
 
78
 
 
79
        ///
 
80
        const Point *GetTopLeft() const {return &topLeft;}
 
81
        ///
 
82
        const string *GetText() const {return &text;}
 
83
 
 
84
        ///
 
85
        int GetWidth() const {return width;}
 
86
        ///
 
87
        int GetHeight() const {return height;}
 
88
 
 
89
        ///
 
90
        XFont *GetFont() const {return font;}
 
91
        ///
 
92
        void SetFont(XFont *f);
 
93
 
 
94
        ///
 
95
        virtual void UpdateFont(XFont *font);
 
96
 
 
97
        ///
 
98
        int FontHeight() const {return font->GetHeight();}
 
99
 
 
100
        /// minimal width of cell text outline.
 
101
        static const int MIN_TEXT_WIDTH; 
 
102
 
 
103
        /// minimal height of cell text outline.
 
104
        static const int MIN_TEXT_HEIGHT;
 
105
protected:
 
106
        ///
 
107
        Grafport *GetGrafport() const {return grafport;}
 
108
private:
 
109
        /// center position of text.
 
110
        Point position;
 
111
 
 
112
        /// topleft position of text.
 
113
        Point topLeft;
 
114
 
 
115
        /// text width (depends on number of characters and point size + font).
 
116
        int width;
 
117
 
 
118
        /// text height (depends on font).
 
119
        int height;
 
120
 
 
121
        /// text string
 
122
        string text;
 
123
 
 
124
        /// 
 
125
        Grafport *grafport;
 
126
        ///
 
127
        XFont *font;
 
128
        /// set size
 
129
        void SetSize(int wd, int ht);
 
130
 
 
131
        /// make sure text has positive coordinates.
 
132
        void PositiveCoord();   
 
133
};
 
134
#endif