1
////////////////////////////////////////////////////////////////////////////////
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).
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.
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.
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
21
////////////////////////////////////////////////////////////////////////////////
22
#include "rectangle.h"
24
#include "simplelabel.h"
26
const int SimpleLabel::MIN_TEXT_WIDTH = 20;
27
const int SimpleLabel::MIN_TEXT_HEIGHT = 20;
29
SimpleLabel::SimpleLabel(Grafport *g, XFont *ft) {
37
SimpleLabel::SimpleLabel(const SimpleLabel &t) {
40
position = t.position;
43
grafport = t.grafport;
47
SimpleLabel::~SimpleLabel() { }
49
int operator==(const SimpleLabel &t1, const SimpleLabel &t2) {
50
return strcmp((t1.text).getstr(),(t2.text).getstr());
53
void SimpleLabel::Undraw() {
57
void SimpleLabel::DrawOutLine(const Point *center) {
58
int x = center->x - width / 2;
59
int y = center->y - height / 2;
60
int wd = max(width, MIN_TEXT_WIDTH);
61
int ht = max(height, MIN_TEXT_HEIGHT);
62
GetGrafport()->SetLineWidth(1);
63
GetGrafport()->SetLineStyle(LineStyle::DOTTED);
64
grafport->DrawRectangle(x, y, wd, ht);
68
void SimpleLabel::UpdatePosition(const Point *pt) {
74
void SimpleLabel::UpdateText(const string *s) {
80
void SimpleLabel::UpdateFont(XFont *ft) {
86
void SimpleLabel::SetPosition(const Point *pos) {
89
topLeft.x = position.x - width / 2;
90
topLeft.y = position.y - height / 2;
94
void SimpleLabel::SetFont(XFont *ft) {
99
void SimpleLabel::SetText(const string *s) {
104
void SimpleLabel::CalcSize() {
106
font->Box(&text, w, h);
110
bool SimpleLabel::HitText(int x, int y) {
111
if (text.length() == 0)
115
int tx = topLeft.x - dist;
116
int ty = topLeft.y - dist;
117
int w = max(width, MIN_TEXT_WIDTH) + 2*dist;
118
int h = max(height, MIN_TEXT_HEIGHT) + 2*dist;
119
Rectangle rect(tx, ty, w, h);
120
return rect.Inside(x, y);
124
void SimpleLabel::SetSize(int w, int h) {
128
topLeft.x = position.x - width/2;
129
topLeft.y = position.y - height/2;
132
void SimpleLabel::PositiveCoord() {