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-2024 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
24/* =========================================================================
25 * included modules
26 * ======================================================================= */
27#include <config.h>
28
29#include "MFXSevenSegment.h"
30#include "MFXLCDLabel.h"
31#include "MFXBaseObject.h"
32
33
34// ===========================================================================
35// FOX callback mapping
36// ===========================================================================
37
38FXDEFMAP(MFXLCDLabel) MFXLCDLabelMap[] = {
39 FXMAPFUNC(SEL_PAINT, 0, MFXLCDLabel::onPaint),
40 FXMAPFUNC(SEL_ENTER, 0, MFXLCDLabel::onEnter),
41 FXMAPFUNC(SEL_LEAVE, 0, MFXLCDLabel::onLeave),
42 FXMAPFUNC(SEL_MOTION, 0, MFXLCDLabel::onMotion),
43 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_SETVALUE, MFXLCDLabel::onCmdSetValue),
44 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_SETINTVALUE, MFXLCDLabel::onCmdSetIntValue),
45 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_SETREALVALUE, MFXLCDLabel::onCmdSetRealValue),
46 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_SETSTRINGVALUE, MFXLCDLabel::onCmdSetStringValue),
47 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_GETINTVALUE, MFXLCDLabel::onCmdGetIntValue),
48 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_GETREALVALUE, MFXLCDLabel::onCmdGetRealValue),
49 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_GETSTRINGVALUE, MFXLCDLabel::onCmdGetStringValue),
50 //FXMAPFUNC(SEL_UPDATE, FXWindow::ID_QUERY_TIP, MFXLCDLabel::onQueryTip),
51 //FXMAPFUNC(SEL_UPDATE, FXWindow::ID_QUERY_HELP, MFXLCDLabel::onQueryHelp),
52 // map key
54};
55
56// Object implementation
57FXIMPLEMENT(MFXLCDLabel, FXHorizontalFrame, MFXLCDLabelMap, ARRAYNUMBER(MFXLCDLabelMap))
58
59
60// ===========================================================================
61// method definitions
62// ===========================================================================
63
64MFXLCDLabel::MFXLCDLabel(FXComposite* p, MFXStaticToolTip* staticToolTip, FXuint nfig, FXObject* tgt, FXSelector sel, FXuint opts, FXint pl, FXint pr, FXint pt, FXint pb, FXint hs) :
65 FXHorizontalFrame(p, opts, 0, 0, 0, 0, pl, pr, pt, pb, hs, 0),
66 myNFigures(nfig),
67 myStaticToolTip(staticToolTip) {
68 if (nfig == 0) {
69 fxerror("%s: must have at least one figure.\n", getClassName());
70 }
71 setTarget(tgt);
72 setSelector(sel);
73 enable();
74 for (FXint i = 0; i < myNFigures; i++) {
75 new MFXSevenSegment(this, this, ID_SEVENSEGMENT, 0, 0, 0, 0);
76 }
77}
78
79
81 /*
82 for (MFXSevenSegment *child=(MFXSevenSegment*)getFirst(); child; child=(MFXSevenSegment*)child->getNext()){
83 delete child;
84 }
85 */
86}
87
88
89void
91 FXHorizontalFrame::create();
92 for (FXWindow* child = getFirst(); child; child = child->getNext()) {
93 child->create();
94 }
95}
96
97
98void
100 for (FXWindow* child = getFirst(); child; child = child->getNext()) {
101 child->detach();
102 }
103 FXHorizontalFrame::detach();
104}
105
106
107void
109 for (FXWindow* child = getFirst(); child; child = child->getNext()) {
110 child->destroy();
111 }
112 FXHorizontalFrame::destroy();
113}
114
115
116FXColor
118 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
119 return child->getFgColor();
120}
121
122
123void
125 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
126 if (clr != child->getFgColor()) {
127 for (child = (MFXSevenSegment*)getFirst(); child; child = (MFXSevenSegment*)child->getNext()) {
128 child->setFgColor(clr);
129 }
130 }
131}
132
133
134FXColor
136 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
137 return child->getBgColor();
138}
139
140
141void
143 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
144 if (clr != child->getBgColor()) {
145 for (child = (MFXSevenSegment*)getFirst(); child; child = (MFXSevenSegment*)child->getNext()) {
146 child->setBgColor(clr);
147 }
148 }
149}
150
151
152void
153MFXLCDLabel::setText(FXString lbl) {
154 if (lbl != myLabel) {
155 myLabel = lbl;
156 recalc();
157 update();
158 }
159}
160
161
162FXString
164 return myLabel;
165}
166
167
168FXint
170 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
171 return child->getHorizontal();
172}
173
174
175void
177 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
178 if (len != child->getHorizontal()) {
179 for (child = (MFXSevenSegment*)getFirst(); child; child = (MFXSevenSegment*)child->getNext()) {
180 child->setHorizontal(len);
181 }
182 recalc();
183 update();
184 }
185}
186
187
188FXint
190 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
191 return child->getVertical();
192}
193
194
195void
196MFXLCDLabel::setVertical(const FXint len) {
197 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
198 if (len != child->getVertical()) {
199 for (child = (MFXSevenSegment*)getFirst(); child; child = (MFXSevenSegment*)child->getNext()) {
200 child->setVertical(len);
201 }
202 recalc();
203 update();
204 }
205}
206
207
208FXint
210 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
211 return child->getThickness();
212}
213
214
215void
217 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
218 if (w != child->getThickness()) {
219 for (child = (MFXSevenSegment*)getFirst(); child; child = (MFXSevenSegment*)child->getNext()) {
220 child->setThickness(w);
221 }
222 recalc();
223 update();
224 }
225}
226
227
228FXint
230 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
231 return child->getGroove();
232}
233
234
235void
237 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
238 if (w != child->getGroove()) {
239 for (child = (MFXSevenSegment*)getFirst(); child; child = (MFXSevenSegment*)child->getNext()) {
240 child->setGroove(w);
241 }
242 recalc();
243 update();
244 }
245}
246
247
248long
249MFXLCDLabel::onCmdSetValue(FXObject*, FXSelector, void* ptr) {
250 setText((const FXchar*)ptr);
251 return 1;
252}
253
254
255long
256MFXLCDLabel::onCmdSetIntValue(FXObject*, FXSelector, void* ptr) {
257 setText(FXStringVal(*((FXint*)ptr)));
258 return 1;
259}
260
261
262long
263MFXLCDLabel::onCmdSetRealValue(FXObject*, FXSelector, void* ptr) {
264 setText(FXStringVal(*((FXdouble*)ptr)));
265 return 1;
266}
267
268
269long
270MFXLCDLabel::onCmdSetStringValue(FXObject*, FXSelector, void* ptr) {
271 setText(*((FXString*)ptr));
272 return 1;
273}
274
275
276long
277MFXLCDLabel::onCmdGetIntValue(FXObject*, FXSelector, void* ptr) {
278 *((FXint*)ptr) = FXIntVal(getText());
279 return 1;
280}
281
282
283long
284MFXLCDLabel::onCmdGetRealValue(FXObject*, FXSelector, void* ptr) {
285 *((FXdouble*)ptr) = FXDoubleVal(getText());
286 return 1;
287}
288
289
290long
291MFXLCDLabel::onCmdGetStringValue(FXObject*, FXSelector, void* ptr) {
292 *((FXString*)ptr) = getText();
293 return 1;
294}
295
296
297long
298MFXLCDLabel::onPaint(FXObject*, FXSelector, void* ptr) {
299 FXEvent* event = (FXEvent*) ptr;
300 FXDCWindow dc(this, event);
301 drawFrame(dc, 0, 0, width, height);
302 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
303 // Fill the background
304 dc.setForeground(child->getBgColor());
305 dc.fillRectangle(border, border, width - (border << 1), height - (border << 1));
306 // Draw the current string
307 dc.setForeground(child->getFgColor());
309 return 1;
310}
311
312
313long
314MFXLCDLabel::onEnter(FXObject* obj, FXSelector sel, void* ptr) {
315 // show static toolTip depending of myToolTipText
316 if (!myToolTipText.empty()) {
317 // show tip show
319 } else {
321 }
322 return FXHorizontalFrame::onEnter(obj, sel, ptr);
323}
324
325
326long
327MFXLCDLabel::onLeave(FXObject* obj, FXSelector sel, void* ptr) {
328 // hide static toolTip
330 return FXHorizontalFrame::onLeave(obj, sel, ptr);
331}
332
333
334long
335MFXLCDLabel::onMotion(FXObject* sender, FXSelector sel, void* ptr) {
336 // update static tooltip
337 myStaticToolTip->onUpdate(sender, sel, ptr);
338 return FXHorizontalFrame::onMotion(sender, sel, ptr);
339}
340
341
342long
343MFXLCDLabel::onRedirectEvent(FXObject*, FXSelector sel, void* ptr) {
344 FXuint seltype = FXSELTYPE(sel);
345 if (isEnabled()) {
346 if (target) {
347 target->handle(this, FXSEL(seltype, message), ptr);
348 }
349 }
350 return 1;
351}
352
353
354FXint
356 return padleft + getFirst()->getDefaultWidth() * myNFigures + hspacing * (myNFigures - 1) + padright + (border << 1);
357}
358
359
360FXint
362 return padtop + getFirst()->getDefaultHeight() + padbottom + (border << 1);
363}
364
365
366void
367MFXLCDLabel::setToolTipText(const FXString& text) {
368 myToolTipText = text;
369}
370
371
372void
373MFXLCDLabel::save(FXStream& store) const {
374 FXHorizontalFrame::save(store);
375 store << myLabel;
376 store << myNFigures;
377}
378
379
380void
381MFXLCDLabel::load(FXStream& store) {
382 FXHorizontalFrame::load(store);
383 store >> myLabel;
384 store >> myNFigures;
385}
386
387
388long
389MFXLCDLabel::onQueryTip(FXObject* sender, FXSelector sel, void* ptr) {
390 if (getParent()) {
391 return getParent()->handle(sender, sel, ptr);
392 }
393 return 0;
394}
395
396
397long
398MFXLCDLabel::onQueryHelp(FXObject* sender, FXSelector sel, void* ptr) {
399 if (getParent()) {
400 return getParent()->handle(sender, sel, ptr);
401 }
402 return 0;
403}
404
405
406void
407MFXLCDLabel::drawString(const FXString& lbl) {
408 FXint i = 0;
409 FXString displayString(' ', myNFigures);
410 if (options & LCDLABEL_LEADING_ZEROS && (FXIntVal(lbl) || lbl == "0")) {
411 FXString txt = lbl;
412 if (txt[0] == '-') {
413 displayString.replace(0, '-');
414 txt.erase(0);
415 i = 1;
416 }
417 for (; (i + txt.length()) < myNFigures; i++) {
418 displayString.replace(i, '0');
419 }
420 displayString.insert(i, txt);
421 } else if (options & JUSTIFY_RIGHT) {
422 for (; (i + lbl.length()) < myNFigures; i++) {}
423 displayString.insert(i, lbl);
424 } else {
425 displayString.insert(0, lbl);
426 }
427 displayString.trunc(myNFigures);
428 i = 0;
429
430 // FIXME: at the moment, if we resize the parent widget, we must use integer multiples
431 // of the SevenSegment width. The problem is that it makes the padding on the
432 // RHS look wrong. What we need to do is to extend the horizontal segment width
433 // for the last sevensegment, so as to fill the remaining space.
434 MFXSevenSegment* child = (MFXSevenSegment*)getFirst();
435 if (options & LAYOUT_FILL) {
436 const FXint w = this->width - padleft - padright - (border << 1);
437 const FXint h = this->height - padtop - padbottom - (border << 1);
438 hspacing = FXMAX(w, h) / 50;
439 if (hspacing < 1) {
440 hspacing = 1;
441 }
442 FXint hsl = (w - (myNFigures - 1) * hspacing) / myNFigures;
443 if (hsl < 5) {
444 hsl = 5;
445 }
446 FXint vsl = h >> 1;
447 if (vsl < 5) {
448 vsl = 5;
449 }
450 FXint st = FXMIN(hsl, vsl) / 4;
451 if (st < 1) {
452 st = 1;
453 }
454 FXint groove = st / 4;
455 if (groove < 1) {
456 groove = 1;
457 }
458 if (options & LAYOUT_FILL_X) {
459 hsl -= groove << 1;
460 for (; child; child = (MFXSevenSegment*)child->getNext()) {
461 child->setHorizontal(hsl);
462 }
463 child = (MFXSevenSegment*)getFirst();
464 }
465 if (options & LAYOUT_FILL_Y) {
466 vsl -= groove << 1;
467 for (; child; child = (MFXSevenSegment*)child->getNext()) {
468 child->setVertical(vsl);
469 }
470 child = (MFXSevenSegment*)getFirst();
471 }
472 for (; child; child = (MFXSevenSegment*)child->getNext()) {
473 child->setText(displayString[i++]);
474 child->setGroove(groove);
475 child->setThickness(st);
476 }
477 } else {
478 for (; child; child = (MFXSevenSegment*)child->getNext()) {
479 child->setText(displayString[i++]);
480 }
481 }
482}
#define FXMAPKEY(key, func)
FXDEFMAP(MFXLCDLabel) MFXLCDLabelMap[]
A widget which has the seven-segment display used as the drawing object for each letter in the label....
Definition MFXLCDLabel.h:34
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:42
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