Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MFXLCDLabel.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2004-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20//
21/****************************************************************************/
22
23#include "MFXStaticToolTip.h"
24#include "MFXSevenSegment.h"
25#include "MFXBaseObject.h"
26#include "MFXLCDLabel.h"
27
28// ===========================================================================
29// FOX callback mapping
30// ===========================================================================
31
32FXDEFMAP(MFXLCDLabel) MFXLCDLabelMap[] = {
33 FXMAPFUNC(SEL_PAINT, 0, MFXLCDLabel::onPaint),
34 FXMAPFUNC(SEL_ENTER, 0, MFXLCDLabel::onEnter),
35 FXMAPFUNC(SEL_LEAVE, 0, MFXLCDLabel::onLeave),
36 FXMAPFUNC(SEL_MOTION, 0, MFXLCDLabel::onMotion),
37 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_SETVALUE, MFXLCDLabel::onCmdSetValue),
38 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_SETINTVALUE, MFXLCDLabel::onCmdSetIntValue),
39 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_SETREALVALUE, MFXLCDLabel::onCmdSetRealValue),
40 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_SETSTRINGVALUE, MFXLCDLabel::onCmdSetStringValue),
41 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_GETINTVALUE, MFXLCDLabel::onCmdGetIntValue),
42 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_GETREALVALUE, MFXLCDLabel::onCmdGetRealValue),
43 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_GETSTRINGVALUE, MFXLCDLabel::onCmdGetStringValue),
44 //FXMAPFUNC(SEL_UPDATE, FXWindow::ID_QUERY_TIP, MFXLCDLabel::onQueryTip),
45 //FXMAPFUNC(SEL_UPDATE, FXWindow::ID_QUERY_HELP, MFXLCDLabel::onQueryHelp),
46 // map key
48};
49
50// Object implementation
51FXIMPLEMENT(MFXLCDLabel, FXHorizontalFrame, MFXLCDLabelMap, ARRAYNUMBER(MFXLCDLabelMap))
52
53// ===========================================================================
54// method definitions
55// ===========================================================================
56
57MFXLCDLabel::MFXLCDLabel(FXComposite* p, MFXStaticToolTip* staticToolTip, FXuint nfig, FXObject* tgt, FXSelector sel, FXuint opts, FXint pl, FXint pr, FXint pt, FXint pb, FXint hs) :
58 FXHorizontalFrame(p, opts, 0, 0, 0, 0, pl, pr, pt, pb, hs, 0),
59 myNFigures(nfig),
60 myStaticToolTip(staticToolTip) {
61 if (nfig == 0) {
62 fxerror("%s: must have at least one figure.\n", getClassName());
63 }
64 setTarget(tgt);
65 setSelector(sel);
66 enable();
67 for (FXint i = 0; i < myNFigures; i++) {
68 new MFXSevenSegment(this, this, ID_SEVENSEGMENT, 0, 0, 0, 0);
69 }
70}
71
72
74 /*
75 for (MFXSevenSegment *child=(MFXSevenSegment*)getFirst(); child; child=(MFXSevenSegment*)child->getNext()){
76 delete child;
77 }
78 */
79}
80
81
82void
84 FXHorizontalFrame::create();
85 for (FXWindow* child = getFirst(); child; child = child->getNext()) {
86 child->create();
87 }
88}
89
90
91void
93 for (FXWindow* child = getFirst(); child; child = child->getNext()) {
94 child->detach();
95 }
96 FXHorizontalFrame::detach();
97}
98
99
100void
102 for (FXWindow* child = getFirst(); child; child = child->getNext()) {
103 child->destroy();
104 }
105 FXHorizontalFrame::destroy();
106}
107
108
109FXColor
111 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
112 return child->getFgColor();
113}
114
115
116void
118 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
119 if (clr != child->getFgColor()) {
120 for (child = (MFXSevenSegment*)getFirst(); child; child = (MFXSevenSegment*)child->getNext()) {
121 child->setFgColor(clr);
122 }
123 }
124}
125
126
127FXColor
129 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
130 return child->getBgColor();
131}
132
133
134void
136 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
137 if (clr != child->getBgColor()) {
138 for (child = (MFXSevenSegment*)getFirst(); child; child = (MFXSevenSegment*)child->getNext()) {
139 child->setBgColor(clr);
140 }
141 }
142}
143
144
145void
146MFXLCDLabel::setText(FXString lbl) {
147 if (lbl != myLabel) {
148 myLabel = lbl;
149 recalc();
150 update();
151 }
152}
153
154
155FXString
157 return myLabel;
158}
159
160
161FXint
163 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
164 return child->getHorizontal();
165}
166
167
168void
170 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
171 if (len != child->getHorizontal()) {
172 for (child = (MFXSevenSegment*)getFirst(); child; child = (MFXSevenSegment*)child->getNext()) {
173 child->setHorizontal(len);
174 }
175 recalc();
176 update();
177 }
178}
179
180
181FXint
183 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
184 return child->getVertical();
185}
186
187
188void
189MFXLCDLabel::setVertical(const FXint len) {
190 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
191 if (len != child->getVertical()) {
192 for (child = (MFXSevenSegment*)getFirst(); child; child = (MFXSevenSegment*)child->getNext()) {
193 child->setVertical(len);
194 }
195 recalc();
196 update();
197 }
198}
199
200
201FXint
203 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
204 return child->getThickness();
205}
206
207
208void
210 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
211 if (w != child->getThickness()) {
212 for (child = (MFXSevenSegment*)getFirst(); child; child = (MFXSevenSegment*)child->getNext()) {
213 child->setThickness(w);
214 }
215 recalc();
216 update();
217 }
218}
219
220
221FXint
223 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
224 return child->getGroove();
225}
226
227
228void
230 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
231 if (w != child->getGroove()) {
232 for (child = (MFXSevenSegment*)getFirst(); child; child = (MFXSevenSegment*)child->getNext()) {
233 child->setGroove(w);
234 }
235 recalc();
236 update();
237 }
238}
239
240
241long
242MFXLCDLabel::onCmdSetValue(FXObject*, FXSelector, void* ptr) {
243 setText((const FXchar*)ptr);
244 return 1;
245}
246
247
248long
249MFXLCDLabel::onCmdSetIntValue(FXObject*, FXSelector, void* ptr) {
250 setText(FXStringVal(*((FXint*)ptr)));
251 return 1;
252}
253
254
255long
256MFXLCDLabel::onCmdSetRealValue(FXObject*, FXSelector, void* ptr) {
257 setText(FXStringVal(*((FXdouble*)ptr)));
258 return 1;
259}
260
261
262long
263MFXLCDLabel::onCmdSetStringValue(FXObject*, FXSelector, void* ptr) {
264 setText(*((FXString*)ptr));
265 return 1;
266}
267
268
269long
270MFXLCDLabel::onCmdGetIntValue(FXObject*, FXSelector, void* ptr) {
271 *((FXint*)ptr) = FXIntVal(getText());
272 return 1;
273}
274
275
276long
277MFXLCDLabel::onCmdGetRealValue(FXObject*, FXSelector, void* ptr) {
278 *((FXdouble*)ptr) = FXDoubleVal(getText());
279 return 1;
280}
281
282
283long
284MFXLCDLabel::onCmdGetStringValue(FXObject*, FXSelector, void* ptr) {
285 *((FXString*)ptr) = getText();
286 return 1;
287}
288
289
290long
291MFXLCDLabel::onPaint(FXObject*, FXSelector, void* ptr) {
292 FXEvent* event = (FXEvent*) ptr;
293 FXDCWindow dc(this, event);
294 drawFrame(dc, 0, 0, width, height);
295 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
296 // Fill the background
297 dc.setForeground(child->getBgColor());
298 dc.fillRectangle(border, border, width - (border << 1), height - (border << 1));
299 // Draw the current string
300 dc.setForeground(child->getFgColor());
302 return 1;
303}
304
305
306long
307MFXLCDLabel::onEnter(FXObject* obj, FXSelector sel, void* ptr) {
308 // show static toolTip depending of myToolTipText
309 if (!myToolTipText.empty()) {
310 // show tip show
312 } else {
314 }
315 return FXHorizontalFrame::onEnter(obj, sel, ptr);
316}
317
318
319long
320MFXLCDLabel::onLeave(FXObject* obj, FXSelector sel, void* ptr) {
321 // hide static toolTip
323 return FXHorizontalFrame::onLeave(obj, sel, ptr);
324}
325
326
327long
328MFXLCDLabel::onMotion(FXObject* sender, FXSelector sel, void* ptr) {
329 // update static tooltip
330 myStaticToolTip->onUpdate(sender, sel, ptr);
331 return FXHorizontalFrame::onMotion(sender, sel, ptr);
332}
333
334
335long
336MFXLCDLabel::onRedirectEvent(FXObject*, FXSelector sel, void* ptr) {
337 FXuint seltype = FXSELTYPE(sel);
338 if (isEnabled()) {
339 if (target) {
340 target->handle(this, FXSEL(seltype, message), ptr);
341 }
342 }
343 return 1;
344}
345
346
347FXint
349 return padleft + getFirst()->getDefaultWidth() * myNFigures + hspacing * (myNFigures - 1) + padright + (border << 1);
350}
351
352
353FXint
355 return padtop + getFirst()->getDefaultHeight() + padbottom + (border << 1);
356}
357
358
359void
360MFXLCDLabel::setToolTipText(const FXString& text) {
361 myToolTipText = text;
362}
363
364
365void
366MFXLCDLabel::save(FXStream& store) const {
367 FXHorizontalFrame::save(store);
368 store << myLabel;
369 store << myNFigures;
370}
371
372
373void
374MFXLCDLabel::load(FXStream& store) {
375 FXHorizontalFrame::load(store);
376 store >> myLabel;
377 store >> myNFigures;
378}
379
380
381long
382MFXLCDLabel::onQueryTip(FXObject* sender, FXSelector sel, void* ptr) {
383 if (getParent()) {
384 return getParent()->handle(sender, sel, ptr);
385 }
386 return 0;
387}
388
389
390long
391MFXLCDLabel::onQueryHelp(FXObject* sender, FXSelector sel, void* ptr) {
392 if (getParent()) {
393 return getParent()->handle(sender, sel, ptr);
394 }
395 return 0;
396}
397
398
399void
400MFXLCDLabel::drawString(const FXString& lbl) {
401 FXint i = 0;
402 FXString displayString(' ', myNFigures);
403 if (options & LCDLABEL_LEADING_ZEROS && (FXIntVal(lbl) || lbl == "0")) {
404 FXString txt = lbl;
405 if (txt[0] == '-') {
406 displayString.replace(0, '-');
407 txt.erase(0);
408 i = 1;
409 }
410 for (; (i + txt.length()) < myNFigures; i++) {
411 displayString.replace(i, '0');
412 }
413 displayString.insert(i, txt);
414 } else if (options & JUSTIFY_RIGHT) {
415 for (; (i + lbl.length()) < myNFigures; i++) {}
416 displayString.insert(i, lbl);
417 } else {
418 displayString.insert(0, lbl);
419 }
420 displayString.trunc(myNFigures);
421 i = 0;
422
423 // FIXME: at the moment, if we resize the parent widget, we must use integer multiples
424 // of the SevenSegment width. The problem is that it makes the padding on the
425 // RHS look wrong. What we need to do is to extend the horizontal segment width
426 // for the last sevensegment, so as to fill the remaining space.
427 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
428 if (options & LAYOUT_FILL) {
429 const FXint w = this->width - padleft - padright - (border << 1);
430 const FXint h = this->height - padtop - padbottom - (border << 1);
431 hspacing = FXMAX(w, h) / 50;
432 if (hspacing < 1) {
433 hspacing = 1;
434 }
435 FXint hsl = (w - (myNFigures - 1) * hspacing) / myNFigures;
436 if (hsl < 5) {
437 hsl = 5;
438 }
439 FXint vsl = h >> 1;
440 if (vsl < 5) {
441 vsl = 5;
442 }
443 FXint st = FXMIN(hsl, vsl) / 4;
444 if (st < 1) {
445 st = 1;
446 }
447 FXint groove = st / 4;
448 if (groove < 1) {
449 groove = 1;
450 }
451 if (options & LAYOUT_FILL_X) {
452 hsl -= groove << 1;
453 for (; child; child = (MFXSevenSegment*)child->getNext()) {
454 child->setHorizontal(hsl);
455 }
456 child = (MFXSevenSegment*)getFirst();
457 }
458 if (options & LAYOUT_FILL_Y) {
459 vsl -= groove << 1;
460 for (; child; child = (MFXSevenSegment*)child->getNext()) {
461 child->setVertical(vsl);
462 }
463 child = (MFXSevenSegment*)getFirst();
464 }
465 for (; child; child = (MFXSevenSegment*)child->getNext()) {
466 child->setText(displayString[i++]);
467 child->setGroove(groove);
468 child->setThickness(st);
469 }
470 } else {
471 for (; child; child = (MFXSevenSegment*)child->getNext()) {
472 child->setText(displayString[i++]);
473 }
474 }
475}
#define FXMAPKEY(key, func)
FXDEFMAP(MFXLCDLabel) MFXLCDLabelMap[]
virtual FXint getDefaultHeight()
return minimum height
void drawString(const FXString &lbl)
Draw a string.
long onQueryHelp(FXObject *, FXSelector, void *ptr)
let parent show help if appropriate
virtual void save(FXStream &store) const
save resources
long onPaint(FXObject *, FXSelector, void *)
handle paint event
void setVertical(const FXint len)
set segment vertical length - must be more than twice the segment width
long onCmdSetRealValue(FXObject *, FXSelector, void *ptr)
Update real value from a message.
void setGroove(const FXint w)
set groove width - must be less than segment width
@ LCDLABEL_LEADING_ZEROS
Definition MFXLCDLabel.h:46
FXString myToolTipText
toolTip text
virtual void create()
create resrouces
long onRedirectEvent(FXObject *, FXSelector, void *ptr)
redirect events to main window
FXint getVertical() const
get segment vertical length - must be more than twice the segment width
virtual FXint getDefaultWidth()
return minimum width
long onCmdGetStringValue(FXObject *, FXSelector, void *ptr)
Obtain string value from text field.
FXString getText() const
get text
FXint myNFigures
The number of shown figuresi, greater than zero.
long onCmdSetStringValue(FXObject *, FXSelector, void *ptr)
Update string value from a message.
virtual void load(FXStream &store)
load resources
long onEnter(FXObject *obj, FXSelector sel, void *ptr)
called when mouse enter in MFXMenuButtonTooltip
void setThickness(const FXint w)
set segment width - must be less than half the segment length
long onLeave(FXObject *obj, FXSelector sel, void *ptr)
called when mouse leaves in MFXMenuButtonTooltip
FXint getThickness() const
get segment width - must be less than half the segment length
void setToolTipText(const FXString &text)
set tooltip text
long onCmdSetIntValue(FXObject *, FXSelector, void *ptr)
Update int value from a message.
MFXStaticToolTip * myStaticToolTip
pointer to staticToolTip
virtual ~MFXLCDLabel()
destructor
FXint getHorizontal() const
get segment horizontal length - must be more than twice the segment width
FXint getGroove() const
get groove width - must be less than segment width
void setText(FXString lbl)
manipulate text in LCD label
virtual void destroy()
destroy resources
FXColor getFgColor() const
get forground color
void setHorizontal(const FXint len)
set segment horizontal length - must be more than twice the segment width
long onQueryTip(FXObject *, FXSelector, void *ptr)
let parent show tip if appropriate
void setFgColor(FXColor clr)
set forground color
void setBgColor(FXColor clr)
set background color
long onCmdGetIntValue(FXObject *, FXSelector, void *ptr)
Obtain int value from text field.
virtual void detach()
detach resources
long onMotion(FXObject *obj, FXSelector sel, void *ptr)
called when mouse motion in MFXMenuButtonTooltip
FXString myLabel
FOX constructor.
FXColor getBgColor() const
get background color
long onCmdSetValue(FXObject *, FXSelector, void *ptr)
Update value from a message.
long onCmdGetRealValue(FXObject *, FXSelector, void *ptr)
Obtain real value from text field.
Seven-segment (eg LCD/watch style) widget.
void setText(const FXchar val)
set the text on the display
void setThickness(const FXint w)
get/set segment thickness
void setHorizontal(const FXint len)
get/set horizontal segment length
FXint getThickness() const
void setVertical(const FXint len)
get/set vertical segment length
FXColor getFgColor() const
void setBgColor(const FXColor clr)
get/set background color
FXint getVertical() const
FXint getHorizontal() const
void setFgColor(const FXColor clr)
get/set foreground color
FXColor getBgColor() const
void setGroove(const FXint w)
get/set myGroove thickness
FXint getGroove() const
MFXStaticToolTip (based on FXToolTip)
long onUpdate(FXObject *sender, FXSelector sel, void *ptr)
called when tooltip is updated
void showStaticToolTip(const FXString &toolTipText)
show static toolTip
void hideStaticToolTip()
hide static toolTip