diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-05-23 12:53:57 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-05-23 12:53:57 +0000 |
commit | 9ba2d6e08c35300deb8ba98fe67964bc7477c9c6 (patch) | |
tree | 4e69c345d70210e8b9a4426b7fd18d6d2dd5a310 /NxWidgets/nxwm | |
parent | ba69f7e7611d2998d783f8224d2d5f8aa10dde58 (diff) | |
download | nuttx-9ba2d6e08c35300deb8ba98fe67964bc7477c9c6.tar.gz nuttx-9ba2d6e08c35300deb8ba98fe67964bc7477c9c6.tar.bz2 nuttx-9ba2d6e08c35300deb8ba98fe67964bc7477c9c6.zip |
Various improvements to NxWM hex calculator display
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4767 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'NxWidgets/nxwm')
-rw-r--r-- | NxWidgets/nxwm/include/chexcalculator.hxx | 3 | ||||
-rw-r--r-- | NxWidgets/nxwm/include/nxwmconfig.hxx | 6 | ||||
-rw-r--r-- | NxWidgets/nxwm/src/chexcalculator.cxx | 63 |
3 files changed, 67 insertions, 5 deletions
diff --git a/NxWidgets/nxwm/include/chexcalculator.hxx b/NxWidgets/nxwm/include/chexcalculator.hxx index 9f9b61a9b..69ee37624 100644 --- a/NxWidgets/nxwm/include/chexcalculator.hxx +++ b/NxWidgets/nxwm/include/chexcalculator.hxx @@ -48,6 +48,7 @@ #include "cbuttonarray.hxx" #include "clabel.hxx" +#include "cnxfont.hxx" #include "iapplication.hxx" #include "capplicationwindow.hxx" @@ -104,6 +105,7 @@ namespace NxWM NXWidgets::CButtonArray *m_keypad; /**< The calculator keyboard */ NXWidgets::CLabel *m_text; /**< The accumulator text display */ + NXWidgets::CNxFont *m_font; /**< The font used in the calculator */ /** * Calculator geometry. This stuff does not really have to be retained @@ -132,6 +134,7 @@ namespace NxWM struct SPendingOperation m_low; /**< Low precedence pending operation */ struct SPendingOperation m_high; /**< Hight precedence pending operation */ bool m_hexMode; /**< True if in hex mode */ + bool m_result ; /**< True if the accumulator holds a previoius result */ /** * Select the geometry of the calculator given the current window size. diff --git a/NxWidgets/nxwm/include/nxwmconfig.hxx b/NxWidgets/nxwm/include/nxwmconfig.hxx index 46cfa7410..578fc5be8 100644 --- a/NxWidgets/nxwm/include/nxwmconfig.hxx +++ b/NxWidgets/nxwm/include/nxwmconfig.hxx @@ -517,6 +517,8 @@ * calculator display. Default: Same as CONFIG_NXWM_DEFAULT_BACKGROUNDCOLOR * CONFIG_NXWM_HEXCALCULATOR_ICON - The ICON to use for the hex calculator * application. Default: NxWM::g_calculatorBitmap + * CONFIG_NXWM_HEXCALCULATOR_FONTID - The font used with the calculator. + * Default: CONFIG_NXWM_DEFAULT_FONTID */ #ifndef CONFIG_NXWM_HEXCALCULATOR_BACKGROUNDCOLOR @@ -527,6 +529,10 @@ # define CONFIG_NXWM_HEXCALCULATOR_ICON NxWM::g_calculatorBitmap #endif +#ifndef CONFIG_NXWM_HEXCALCULATOR_FONTID +# define CONFIG_NXWM_HEXCALCULATOR_FONTID CONFIG_NXWM_DEFAULT_FONTID +#endif + /**************************************************************************** * Global Function Prototypes ****************************************************************************/ diff --git a/NxWidgets/nxwm/src/chexcalculator.cxx b/NxWidgets/nxwm/src/chexcalculator.cxx index d865817b9..167c114b7 100644 --- a/NxWidgets/nxwm/src/chexcalculator.cxx +++ b/NxWidgets/nxwm/src/chexcalculator.cxx @@ -210,6 +210,7 @@ CHexCalculator::CHexCalculator(CTaskbar *taskbar, CApplicationWindow *window) m_keypad = (NXWidgets::CButtonArray *)0; m_text = (NXWidgets::CLabel *)0; + m_font = (NXWidgets::CNxFont *)0; // Reset other values @@ -219,7 +220,8 @@ CHexCalculator::CHexCalculator(CTaskbar *taskbar, CApplicationWindow *window) m_high.value = 0; m_low.operation = (uint8_t)KEY_NONE; // No pending high precedence operation m_low.value = 0; - m_hexMode = 0; // Decimal mode + m_hexMode = false; // Decimal mode + m_result = false; // Accumulator does not hot a result // Add our personalized window label @@ -255,6 +257,11 @@ CHexCalculator::~CHexCalculator(void) delete m_keypad; } + if (m_font) + { + delete m_font; + } + // Although we didn't create it, we are responsible for deleting the // application window @@ -489,6 +496,17 @@ void CHexCalculator::setGeometry(void) bool CHexCalculator::createCalculator(void) { + // Select a font for the calculator + + m_font = new NXWidgets::CNxFont((nx_fontid_e)CONFIG_NXWM_HEXCALCULATOR_FONTID, + CONFIG_NXWM_DEFAULT_FONTCOLOR, + CONFIG_NXWM_TRANSPARENT_COLOR); + if (!m_font) + { + gdbg("ERROR failed to create font\n"); + return false; + } + // Get the widget control associated with the application window NXWidgets::CWidgetControl *control = m_window->getWidgetControl(); @@ -511,6 +529,10 @@ bool CHexCalculator::createCalculator(void) m_keypad->disableDrawing(); m_keypad->setRaisesEvents(false); + // Select the font + + m_keypad->setFont(m_font); + // Register to receive events from the keypad m_keypad->addWidgetEventHandler(this); @@ -536,6 +558,10 @@ bool CHexCalculator::createCalculator(void) m_text->disableDrawing(); m_text->setRaisesEvents(false); + + // Select the font + + m_text->setFont(m_font); return true; } @@ -645,7 +671,7 @@ void CHexCalculator::updateText(void) if (m_hexMode) { - std::snprintf(buffer, 24, "%16llx", m_accum); + std::snprintf(buffer, 24, "%16llX", m_accum); } else { @@ -707,13 +733,25 @@ void CHexCalculator::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) // Process the keypress + bool result = false; switch (g_keyDesc[index].keyType) { // Values: {0-9, A-F} case KEY_VALUE: // Key is a value { - if (m_hexMode) + // If the accumulator current holds the result of a previous + // operation, then start fresh + + if (m_result) + { + m_accum = (uint64_t)g_keyDesc[index].value; + } + + // Otherwise, add the new value to the accumulator. The way + // in which it is added depends on the mode + + else if (m_hexMode) { m_accum <<= 4; m_accum |= (uint64_t)g_keyDesc[index].value; @@ -770,9 +808,12 @@ void CHexCalculator::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) m_low.operation = (uint8_t) g_keyDesc[index].keyType; m_low.value = m_accum; - m_accum = 0; + + // Update the display with the value in the accumulator, but + // then clear the accumulator in preparation for the next input updateText(); + m_accum = 0; } break; @@ -795,9 +836,12 @@ void CHexCalculator::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) m_high.operation = (uint8_t) g_keyDesc[index].keyType; m_high.value = m_accum; - m_accum = 0; + + // Update the display with the value in the accumulator, but + // then clear the accumulator in preparation for the next input updateText(); + m_accum = 0; } break; @@ -823,7 +867,12 @@ void CHexCalculator::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) m_low.value = 0; } + // Update the display with the value in the accumulator. Flag that + // this is a result meaning that (1) it can be used as an accumulator + // for the next operation, but new input values cannot be appended to it. + updateText(); + result = true; } break; @@ -897,6 +946,10 @@ void CHexCalculator::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) gdbg("ERROR: Invalid key type %d\n", g_keyDesc[index].keyType); break; } + + // Remember if the accumulator contains a special reault + + m_result = result; } } |