BREW Cartoon - 3 / 6 -
Events
Cartoon Class
Define all variables which will be referred to from anywhere in the application.
SFMTYPEDEFCLASS(Cartoon) class Cartoon : public SFRApplication { SFMSEALCOPY(Cartoon) private: // Retain size of the device display SFXSize m_devsize; // Variable to manage picture numbers to be displayed. // (0 = beginning, 1-4 = picture number, 5 = finish ) SIntN m_pict_index; // Retain bitmaps to be displayed SFBBitmapSmp m_bitmap; // Enlargement factor "2" when the device is QVGA, otherwise "1". SIntN m_qvga_ratio; // Member functions };
Drawing Handler
Draw the image at the beginning of the application, or when the "Back" "Next" buttons are pushed.
// Declair draw handler SFMTYPEDEFCLASS(Cartoon) class Cartoon : public SFRApplication { ... private: HANDLER_DECLARE_VOIDRENDER(OnRenderContent) ... } // Define draw handler HANDLER_IMPLEMENT_VOIDRENDER(Cartoon, OnRenderContent, graphics) { // Clear display with background color graphics->FillRectangle(GetContentWorld(), SFXRGBColor(0, 192, 192, 255)); // Calculations to get the coordinates of the uper right corner SIntN blank1 = (m_devsize.GetWidth() - PICTSIZE) / 2; // Calculate pixel numbers between bitmap and navigation SIntN blank2 = (m_devsize.GetHeight() - blank1 - PICTSIZE) / 4; // Draw rectangle to draw images graphics->SetForeColor(SFXRGBColor(0, 0, 0, 255)); graphics->DrawRectangle(SFXRectangle(blank1 - 1, blank1 - 1, PICTSIZE + 2, PICTSIZE + 2)); // Draw nacigation area ("Back" "Enlarge" "Next") graphics->SetFillColor(SFXRGBColor(128, 128, 128, 255)); graphics->DrawRoundRectangle(SFXRectangle(blank1, blank1 + blank2 + PICTSIZE, NAVI_WIDTH, NAVI_HEIGHT ),SFXSize(3, 3)); graphics->DrawRoundRectangle(SFXRectangle(blank1 + NAVI_X_POS_2, blank1 + blank2 + PICTSIZE, NAVI_WIDTH, NAVI_HEIGHT ), SFXSize(3, 3)); graphics->DrawRoundRectangle(SFXRectangle(blank1 + NAVI_X_POS_3, blank1 + blank2 + PICTSIZE, NAVI_WIDTH, NAVI_HEIGHT ), SFXSize(3, 3)); graphics->SetForeColor(SFXRGBColor(0, 0, 0, 255)); if (m_pict_index >= 1) { graphics->DrawText("Back", SFXRectangle(blank1, blank1 + blank2 + PICTSIZE, NAVI_WIDTH, NAVI_HEIGHT ) ); } if (1 <= m_pict_index && m_pict_index <= 4) { graphics->DrawText("Enlarge", SFXRectangle(blank1 + NAVI_X_POS_2, blank1 + blank2 + PICTSIZE, NAVI_WIDTH, NAVI_HEIGHT ) ); } if (m_pict_index <= 4) { graphics->DrawText("Next", SFXRectangle(blank1 + NAVI_X_POS_3, blank1 + blank2 + PICTSIZE, NAVI_WIDTH, NAVI_HEIGHT ) ); } // Draw image (The rest is omitted ) }
Key handler
Process when the left or right key is pressed.
// Declare key handler SFMTYPEDEFCLASS(Cartoon) class Cartoon : public SFRApplication { ... private: HANDLER_DECLARE_BOOLEVENT(OnKey) ... } // Define key handler HANDLER_IMPLEMENT_BOOLEVENT(Cartoon, OnKey, event) { UInt16 key = event.GetP16(); switch (key) { case AVK_RIGHT: //When right key is pressed if (m_pict_index <= 4) { m_pict_index++; // Next picture m_bitmap = LoadBitmap(m_pict_index); // Load bitmap InvalidateContent(); // Redraw } return true; case AVK_LEFT: // When left key is pushed if (m_pict_index >= 1) { m_pict_index--; // Prior picture m_bitmap = LoadBitmap(m_pict_index); // Load bitmap InvalidateContent(); // redraw } return true; case AVK_SELECT: // When select key is pushed if (1 <= m_pict_index && m_pict_index <= 4) { new ImageWindow(this, GetContentWorld(), m_bitmap); //Generate ImageWindow } return true; } return false; }
Constructor
// Constructor Cartoon::Cartoon(Void) { // Register draw handler if (static_try()) { // Error handling static_throw( RegisterHandler(SREVT_RESPONDER_RENDER, SRP16_RENDER_CONTENT, HANDLER_BEFORE, HANDLER_FUNCTION(OnRenderContent))); } // Register key handler if (static_try()) { static_throw( RegisterHandler(SFEVT_KEY, HANDLER_AFTER, HANDLER_FUNCTION(OnKey))); } // }