BREW Cartoon - 4 / 6 -
Drawing Bitmaps
Resource file
Generate resource file containing images.
Load image
Function to load a image, and throw back pointer.
// Load the corresponding bitmap from the resource // index stands for picture numbers ( 1 to 4) SFBBitmapSmp Cartoon::LoadBitmap(SIntN index) { if (1 <= index && index <= 4) { SFBShellSmp shell = SFBShell::GetInstance(); // Load image and throw back pointer return shell->LoadResBitmap(CARTOON_RES_FILE, IDR_PICT1 + index - 1); } else { return SFBBitmapSmp(NULL); } }
Using this function :
// Declare member variable class Cartoon : public SFRApplication { // Retain bitmap to display SFBBitmapSmp m_bitmap; ... } // Key handler HANDLER_IMPLEMENT_BOOLEVENT(Cartoon, OnKey, event) { ... m_bitmap = LoadBitmap(m_pict_index); // Load bitmap ... }
Display bitmap
Use SFXGraphics::DrawBitmap function to display the loaded bitmap.
// Drawing handler HANDLER_IMPLEMENT_VOIDRENDER(Cartoon, OnRenderContent, graphics) { ... graphics->DrawBitmap(m_bitmap, SFXGrid(10, 10)); // SFXGrid is a shape class for declaring coordinates ... }
Resource File
The resource file includes images and strings used in the application.
Using the Resource Editor
To handle resources, use the "BREW resource editor" attached to BREW SDK.
-
- Boot up BREW Resource Editor, [Resource] -> [New Object]
- Input the image to use as resource in the [Image file path]
- Input name of the resource.
(This name is used as a macro to refer this resource from the application, the first name is IDR_PICT1) - Repeat 2 and 3, until all 4 images are registered
- Save this resource file as "Cartoon" by going [File] -> [Save as]
- [Generate] -> [Compile Resource Script] to generate cartoon.bar and cartoon.brh file.]
- Include cartoon.brh file in the source code.
// cartoon.brh #ifndef CARTOON_BRH #define CARTOON_BRH // WARNING: DO NOT MODIFY THIS FILE // AUTO-GENERATED BY BREW Resource Editor #define CARTOON_RES_FILE "cartoon.bar" #define IDI_PICT1 5001 #define IDI_PICT2 5002 #define IDI_PICT3 5003 #define IDI_PICT4 5004 #endif // CARTOON_BRH