40 #include <nuttx/config.h> 126 static FAR
const char *
g_labels[NXWM_HEXCALCULATOR_NCOLUMNS*NXWM_HEXCALCULATOR_NROWS] =
128 "MR",
"M+",
"M-",
"MC",
"CE",
"C",
129 "A",
"B",
"C",
"D",
"E",
"F",
130 "NOT",
"XOR",
"7",
"8",
"9",
"/",
131 "RSH",
"LSH",
"4",
"5",
"6",
"*",
132 "AND",
"OR",
"1",
"2",
"3",
"-",
133 "DEC",
"HEX",
"+/-",
"0",
"=",
"+" 196 using namespace NxWM;
221 m_high.operation = (uint8_t)
KEY_NONE;
223 m_low.operation = (uint8_t)
KEY_NONE;
324 if (!createCalculator())
326 gerr(
"ERROR: Failed to create widgets\n");
346 m_keypad->disableDrawing();
347 m_keypad->setRaisesEvents(
false);
349 m_text->disableDrawing();
369 m_window->block(
this);
403 CONFIG_NXWM_HEXCALCULATOR_BACKGROUNDCOLOR);
407 m_keypad->enableDrawing();
409 m_keypad->setRaisesEvents(
true);
411 m_text->enableDrawing();
425 return m_window->isFullScreen();
440 (void)window->
getSize(&m_windowSize);
446 m_buttonSize.w = m_windowSize.w / NXWM_HEXCALCULATOR_NCOLUMNS;
447 m_buttonSize.h = (m_windowSize.h << 1) / (2 * NXWM_HEXCALCULATOR_NROWS + 3);
452 if (m_buttonSize.h > m_buttonSize.w)
454 m_buttonSize.h = m_buttonSize.w;
456 else if (m_buttonSize.w > (m_buttonSize.h << 1))
458 m_buttonSize.w = (m_buttonSize.h << 1);
463 m_keypadSize.w = NXWM_HEXCALCULATOR_NCOLUMNS * m_buttonSize.w;
464 m_keypadSize.h = NXWM_HEXCALCULATOR_NROWS * m_buttonSize.h;
468 m_textSize.w = m_keypadSize.w;
469 m_textSize.h = m_windowSize.h - m_keypadSize.h;
473 if (m_textSize.h > (m_buttonSize.h << 1))
475 m_textSize.h = (m_buttonSize.h << 1);
481 struct nxgl_point_s calculatorPos;
482 calculatorPos.x = (m_windowSize.w - m_keypadSize.w) >> 1;
483 calculatorPos.y = (m_windowSize.h - m_textSize.h - m_keypadSize.h) >> 1;
487 m_textPos.x = calculatorPos.x;
488 m_textPos.y = calculatorPos.y;
490 m_keypadPos.x = calculatorPos.x;
491 m_keypadPos.y = calculatorPos.y + m_textSize.h;
504 CONFIG_NXWM_DEFAULT_FONTCOLOR,
505 CONFIG_NXWM_TRANSPARENT_COLOR);
508 gerr(
"ERROR failed to create font\n");
519 m_keypadPos.x, m_keypadPos.y,
520 NXWM_HEXCALCULATOR_NCOLUMNS,
521 NXWM_HEXCALCULATOR_NROWS,
522 m_buttonSize.w, m_buttonSize.h);
525 gerr(
"ERROR: Failed to create CButtonArray\n");
531 m_keypad->disableDrawing();
532 m_keypad->setRaisesEvents(
false);
536 m_keypad->setFont(m_font);
540 m_keypad->addWidgetEventHandler(
this);
546 m_textPos.x, m_textPos.y,
547 m_textSize.w, m_textSize.h,
551 gerr(
"ERROR: Failed to create CLabel\n");
561 m_text->disableDrawing();
562 m_text->setRaisesEvents(
false);
566 m_text->setFont(m_font);
578 bool isEnabled = m_keypad->isDrawingEnabled();
579 m_keypad->disableDrawing();
583 for (
int j = 0; j < NXWM_HEXCALCULATOR_NROWS; j++)
585 for (
int i = 0; i < NXWM_HEXCALCULATOR_NCOLUMNS; i++)
587 int index = j * NXWM_HEXCALCULATOR_NCOLUMNS + i;
591 FAR
const char *label;
604 m_keypad->setText(i, j, label);
612 m_keypad->enableDrawing();
634 return value1 ^ value2;
637 return value1 / value2;
640 return value1 >> value2;
643 return value1 << value2;
646 return value1 * value2;
649 return value1 & value2;
652 return value1 | value2;
655 return value1 - value2;
658 return value1 + value2;
661 gerr(
"ERROR: Unexpected pending operation %d\n", operation);
676 std::snprintf(buffer, 24,
"%16llX", m_accum);
680 std::snprintf(buffer, 24,
"%lld", m_accum);
685 m_text->setText(buffer);
694 m_taskbar->minimizeApplication(static_cast<IApplication*>(
this));
703 m_taskbar->stopApplication(static_cast<IApplication*>(
this));
720 if (m_keypad->isButtonClicked(column, row))
724 int index = row * NXWM_HEXCALCULATOR_NCOLUMNS + column;
795 if (m_high.operation != (uint8_t)
KEY_NONE)
797 m_accum = evaluateBinaryOperation(m_high.operation, m_high.value, m_accum);
798 m_high.operation = (uint8_t)KEY_NONE;
804 if (m_low.operation != (uint8_t)
KEY_NONE)
806 m_accum = evaluateBinaryOperation(m_low.operation, m_low.value, m_accum);
811 m_low.operation = (uint8_t)
g_keyDesc[index].keyType;
812 m_low.
value = m_accum;
832 if (m_high.operation != (uint8_t)
KEY_NONE)
834 m_accum = evaluateBinaryOperation(m_high.operation, m_high.value, m_accum);
839 m_high.operation = (uint8_t)
g_keyDesc[index].keyType;
840 m_high.
value = m_accum;
856 if (m_high.operation != (uint8_t)
KEY_NONE)
858 m_accum = evaluateBinaryOperation(m_high.operation, m_high.value, m_accum);
859 m_high.operation = (uint8_t)KEY_NONE;
865 if (m_low.operation != (uint8_t)
KEY_NONE)
867 m_accum = evaluateBinaryOperation(m_low.operation, m_low.value, m_accum);
868 m_low.operation = (uint8_t)KEY_NONE;
938 m_high.operation = (uint8_t)
KEY_NONE;
940 m_low.operation = (uint8_t)
KEY_NONE;
948 gerr(
"ERROR: Invalid key type %d\n",
g_keyDesc[index].keyType);
981 gerr(
"ERROR: Failed to create CApplicationWindow\n");
989 gerr(
"ERROR: Failed to open CApplicationWindow\n");
1000 gerr(
"ERROR: Failed to instantiate CHexCalculator\n");
CGraphicsPort * getGraphicsPort(void)
static FAR const char * g_labels[NXWM_HEXCALCULATOR_NCOLUMNS *NXWM_HEXCALCULATOR_NROWS]
bool createCalculator(void)
IApplicationWindow * getWindow(void) const
IApplication * create(void)
int64_t evaluateBinaryOperation(uint8_t operation, int64_t value1, int64_t value2)
void setWindowLabel(NXWidgets::CNxString &appname)
NXWidgets::IBitmap * getIcon(void)
virtual bool getSize(FAR struct nxgl_size_s *pSize)=0
void drawFilledRect(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, nxgl_mxpixel_t color)
NXWidgets::CNxString getName(void)
void registerCallbacks(IApplicationCallback *callback)
bool isFullScreen(void) const
static struct SKeyDesc g_keyDesc[NXWM_HEXCALCULATOR_NCOLUMNS *NXWM_HEXCALCULATOR_NROWS]
CHexCalculatorFactory(CTaskbar *taskbar)
static const NXWidgets::SRlePaletteBitmapEntry bitmap[]
CHexCalculator(CTaskbar *taskbar, CApplicationWindow *window)
void handleActionEvent(const NXWidgets::CWidgetEventArgs &e)
NXWidgets::IBitmap * getIcon(void)