49 #ifdef CHECK_MEMORY_LEAKS
51 #endif // CHECK_MEMORY_LEAKS
60 FXMAPFUNC(SEL_PAINT, 0, FXSevenSegment::onPaint),
61 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_SETVALUE, FXSevenSegment::onCmdSetValue),
62 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_SETINTVALUE, FXSevenSegment::onCmdSetIntValue),
63 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_GETINTVALUE, FXSevenSegment::onCmdGetIntValue),
64 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_SETSTRINGVALUE, FXSevenSegment::onCmdSetStringValue),
65 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_GETSTRINGVALUE, FXSevenSegment::onCmdGetStringValue),
72 FXSevenSegment::
FXSevenSegment(FXComposite* p,
FXObject* tgt, FXSelector sel, FXuint opts, FXint pl, FXint pr, FXint pt, FXint pb) :
FXFrame(p, opts, 0, 0, 0, 0, pl, pr, pt, pb), value(' '), fgcolor(FXRGB(0, 255, 0)), bgcolor(FXRGB(0, 0, 0)), hsl(8), vsl(8), st(3), groove(1) {
79 FXint FXSevenSegment::getDefaultWidth() {
80 return padleft + (groove << 1) + hsl + padright + (border << 1);
84 FXint FXSevenSegment::getDefaultHeight() {
85 return padtop + (groove << 2) + (vsl << 1) + padbottom + (border << 1);
89 void FXSevenSegment::setText(FXchar val) {
90 if (FXString(val, 1).upper() != FXString(value, 1).upper()) {
98 void FXSevenSegment::setFgColor(
const FXColor clr) {
107 void FXSevenSegment::setBgColor(
const FXColor clr) {
108 if (bgcolor != clr) {
116 void FXSevenSegment::setHorizontal(
const FXint len) {
126 void FXSevenSegment::setVertical(
const FXint len) {
136 void FXSevenSegment::setThickness(
const FXint width) {
146 void FXSevenSegment::setGroove(
const FXint width) {
147 if (width != groove) {
156 long FXSevenSegment::onPaint(
FXObject*, FXSelector,
void* ptr) {
157 FXEvent*
event = (FXEvent*) ptr;
158 FXDCWindow dc(
this, event);
159 drawFrame(dc, 0, 0, width, height);
160 dc.setForeground(bgcolor);
161 dc.fillRectangle(border, border, width - (border << 1), height - (border << 1));
162 dc.setForeground(fgcolor);
163 drawFigure(dc, value);
168 long FXSevenSegment::onCmdSetValue(
FXObject*, FXSelector,
void* ptr) {
169 FXchar* c = (FXchar*)ptr;
177 long FXSevenSegment::onCmdGetIntValue(
FXObject* sender, FXSelector,
void*) {
185 sender->handle(
this, FXSEL(SEL_COMMAND, ID_SETINTVALUE), (
void*)&i);
190 long FXSevenSegment::onCmdSetIntValue(
FXObject*, FXSelector,
void* ptr) {
191 FXint i = *((FXint*)ptr);
203 long FXSevenSegment::onCmdGetStringValue(
FXObject* sender, FXSelector,
void*) {
204 FXString s(value, 1);
205 sender->handle(
this, FXSEL(SEL_COMMAND, ID_SETSTRINGVALUE), (
void*)&s);
210 long FXSevenSegment::onCmdSetStringValue(
FXObject*, FXSelector,
void* ptr) {
211 FXString* s = (FXString*)ptr;
219 void FXSevenSegment::drawFigure(FXDCWindow& dc, FXchar figure) {
222 drawSegments(dc, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE);
225 drawSegments(dc, TRUE , TRUE , FALSE, FALSE, TRUE , FALSE, TRUE);
228 drawSegments(dc, TRUE , FALSE, TRUE , FALSE, FALSE, TRUE , TRUE);
231 drawSegments(dc, TRUE , TRUE , FALSE, FALSE, TRUE , FALSE, TRUE);
234 drawSegments(dc, TRUE , FALSE, TRUE , FALSE, FALSE, TRUE , TRUE);
237 drawSegments(dc, FALSE, FALSE, FALSE, TRUE , FALSE, FALSE, TRUE);
241 drawSegments(dc, FALSE, FALSE, FALSE, TRUE , FALSE, FALSE, FALSE);
245 drawSegments(dc, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE);
248 drawSegments(dc, TRUE , TRUE , TRUE , FALSE, TRUE , TRUE , TRUE);
251 drawSegments(dc, FALSE, FALSE, TRUE , FALSE, FALSE, TRUE , FALSE);
254 drawSegments(dc, TRUE , FALSE, TRUE , TRUE , TRUE , FALSE, TRUE);
257 drawSegments(dc, TRUE , FALSE, TRUE , TRUE , FALSE, TRUE , TRUE);
260 drawSegments(dc, FALSE, TRUE , TRUE , TRUE , FALSE, TRUE , FALSE);
263 drawSegments(dc, TRUE , TRUE , FALSE, TRUE , FALSE, TRUE , TRUE);
266 drawSegments(dc, TRUE , TRUE , FALSE, TRUE , TRUE , TRUE , TRUE);
269 drawSegments(dc, TRUE , FALSE, TRUE , FALSE, FALSE, TRUE , FALSE);
272 drawSegments(dc, TRUE , TRUE , TRUE , TRUE , TRUE , TRUE , TRUE);
275 drawSegments(dc, TRUE , TRUE , TRUE , TRUE , FALSE, TRUE , TRUE);
279 drawSegments(dc, TRUE , TRUE , TRUE , TRUE , TRUE , TRUE , FALSE);
283 drawSegments(dc, FALSE, TRUE , FALSE, TRUE , TRUE , TRUE , TRUE);
287 drawSegments(dc, TRUE , TRUE , FALSE, FALSE, TRUE , FALSE, TRUE);
291 drawSegments(dc, FALSE, FALSE, TRUE , TRUE , TRUE , TRUE , TRUE);
295 drawSegments(dc, TRUE , TRUE , FALSE, TRUE , TRUE , FALSE, TRUE);
299 drawSegments(dc, TRUE , TRUE , FALSE, TRUE , TRUE , FALSE, FALSE);
303 drawSegments(dc, TRUE , TRUE , FALSE, FALSE, TRUE , TRUE , TRUE);
307 drawSegments(dc, FALSE, TRUE , FALSE, TRUE , TRUE , TRUE , FALSE);
311 drawSegments(dc, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE , FALSE);
315 drawSegments(dc, FALSE, FALSE, TRUE , FALSE, TRUE , TRUE , TRUE);
321 drawSegments(dc, FALSE, TRUE , FALSE, FALSE, TRUE , FALSE, TRUE);
327 drawSegments(dc, FALSE, FALSE, FALSE, TRUE , TRUE , TRUE , FALSE);
331 drawSegments(dc, TRUE , TRUE , TRUE , FALSE, TRUE , TRUE , TRUE);
335 drawSegments(dc, TRUE , TRUE , TRUE , TRUE , TRUE , FALSE, FALSE);
339 drawSegments(dc, TRUE , TRUE , TRUE , TRUE , FALSE, TRUE , FALSE);
343 drawSegments(dc, FALSE, FALSE, FALSE, TRUE , TRUE , FALSE, FALSE);
347 drawSegments(dc, TRUE , TRUE , FALSE, TRUE , FALSE, TRUE , TRUE);
351 drawSegments(dc, FALSE, TRUE , FALSE, TRUE , TRUE , FALSE, FALSE);
355 drawSegments(dc, FALSE, TRUE , TRUE , FALSE, TRUE , TRUE , TRUE);
363 drawSegments(dc, FALSE, TRUE , TRUE , TRUE , TRUE , TRUE , FALSE);
367 drawSegments(dc, FALSE, TRUE , TRUE , TRUE , FALSE, TRUE , TRUE);
372 fxerror(
"FXSevenSegment doesnt support: %c\n", figure);
377 void FXSevenSegment::checkSize() {
389 if (hsl < (st << 1)) {
392 if (vsl < (st << 1)) {
395 if (hsl < 8 || vsl < 8) {
398 if (hsl < 1 || vsl < 3 || st < 3) {
408 void FXSevenSegment::drawSegments(FXDCWindow& dc, FXbool s1, FXbool s2, FXbool s3, FXbool s4, FXbool s5, FXbool s6, FXbool s7) {
409 FXint sx = border + padleft, sy = border + padtop;
411 if (options & LAYOUT_FILL) {
412 if (options & LAYOUT_FILL_X) {
413 hsl = width - padleft - padright - (border << 1);
418 if (options & LAYOUT_FILL_Y) {
419 vsl = (height - padtop - padbottom - (border << 1)) >> 1;
424 st = FXMIN(hsl, vsl) / 4;
432 if (options & LAYOUT_FILL_X) {
435 if (options & LAYOUT_FILL_Y) {
442 drawTopSegment(dc, x, y);
447 drawLeftTopSegment(dc, x, y);
450 x = sx + groove + hsl - st + groove;
452 drawRightTopSegment(dc, x, y);
456 y = sy + groove + vsl - (st >> 1) + groove;
457 drawMiddleSegment(dc, x, y);
461 y = sy + (groove << 1) + vsl + groove;
462 drawLeftBottomSegment(dc, x, y);
465 x = sx + groove + hsl - st + groove;
466 y = sy + (groove << 1) + vsl + groove;
467 drawRightBottomSegment(dc, x, y);
471 y = sy + (groove << 1) + vsl + groove + vsl + groove - st;
472 drawBottomSegment(dc, x, y);
476 void FXSevenSegment::drawTopSegment(FXDCWindow& dc, FXshort x, FXshort y) {
480 points[1].x = x + hsl;
482 points[2].x = x + hsl - st;
483 points[2].y = y + st;
484 points[3].x = x + st;
485 points[3].y = y + st;
486 dc.fillPolygon(points, 4);
489 void FXSevenSegment::drawLeftTopSegment(FXDCWindow& dc, FXshort x, FXshort y) {
493 points[1].x = x + st;
494 points[1].y = y + st;
495 points[2].x = x + st;
496 points[2].y = y + vsl - (st >> 1);
498 points[3].y = y + vsl;
499 dc.fillPolygon(points, 4);
502 void FXSevenSegment::drawRightTopSegment(FXDCWindow& dc, FXshort x, FXshort y) {
504 points[0].x = x + st;
506 points[1].x = x + st;
507 points[1].y = y + vsl;
509 points[2].y = y + vsl - (st >> 1);
511 points[3].y = y + st;
512 dc.fillPolygon(points, 4);
515 void FXSevenSegment::drawMiddleSegment(FXDCWindow& dc, FXshort x, FXshort y) {
517 points[0].x = x + st;
519 points[1].x = x + hsl - st;
521 points[2].x = x + hsl;
522 points[2].y = y + (st >> 1);
523 points[3].x = x + hsl - st;
524 points[3].y = y + st;
525 points[4].x = x + st;
526 points[4].y = y + st;
528 points[5].y = y + (st >> 1);
529 dc.fillPolygon(points, 6);
532 void FXSevenSegment::drawLeftBottomSegment(FXDCWindow& dc, FXshort x, FXshort y) {
536 points[1].x = x + st;
537 points[1].y = y + (st >> 1);
538 points[2].x = x + st;
539 points[2].y = y + vsl - st;
541 points[3].y = y + vsl;
542 dc.fillPolygon(points, 4);
545 void FXSevenSegment::drawRightBottomSegment(FXDCWindow& dc, FXshort x, FXshort y) {
547 points[0].x = x + st;
549 points[1].x = x + st;
550 points[1].y = y + vsl;
552 points[2].y = y + vsl - st;
554 points[3].y = y + (st >> 1);
555 dc.fillPolygon(points, 4);
558 void FXSevenSegment::drawBottomSegment(FXDCWindow& dc, FXshort x, FXshort y) {
560 points[0].x = x + st;
562 points[1].x = x + hsl - st;
564 points[2].x = x + hsl;
565 points[2].y = y + st;
567 points[3].y = y + st;
568 dc.fillPolygon(points, 4);
571 void FXSevenSegment::save(FXStream& store)
const {
572 FXFrame::save(store);
594 long FXSevenSegment::onQueryTip(
FXObject* sender, FXSelector sel,
void* ptr) {
596 return getParent()->handle(sender, sel, ptr);
602 long FXSevenSegment::onQueryHelp(
FXObject* sender, FXSelector sel,
void* ptr) {
604 return getParent()->handle(sender, sel, ptr);