BREW Cartoon - 5 / 6 -
Generate / Cancel windows
ImageWindow class
SFMTYPEDEFCLASS(ImageWindow) class ImageWindow : public SFRPlainWindow { private: //Bitmap to display SFXBrewPointer<SFBBitmap> m_bitmap; //Coordinate of the left top corner to be transferred SFXGrid m_transfered_point; //Display size of the device SFXSize m_devsize; //The original bitmap size before enlarging SFXSize m_bitmap_size; //Scale ratio of the bitmap Float64 m_scale_ratio; public: ... }
Generate window
This code is for generating a window
// Key handler for Cartoon class HANDLER_IMPLEMENT_BOOLEVENT(Cartoon, OnKey, event) ... //Generate ImageWindow new ImageWindow(this, GetContentWorld(), m_bitmap); }
Cancel window
This code is for deleting a window.
Windows can not be canceled by delete operator.
However, if an error occurs in the constructor when generating window, it must be canceled by the delete operator.
// Image handler for ImageWindow class HANDLER_IMPLEMENT_BOOLEVENT(ImageWindow, OnKey, event) { UInt16 key = event.GetP16(); switch (key) { case AVK_SELECT: // Select key case AVK_CLR: // Clear ket // Delete window Invoke(SFXEvent(SREVT_RESPONDER_TERMINATE, SRP16_TERMINATE_INVOKE, true)); return true; } return false; }
Draw handler
Draw handler is for displaying enlarged image.
// Draw handler HANDLER_IMPLEMENT_VOIDRENDER(ImageWindow, OnDraw, graphic) { SFBShellSmp shell = SFBShell::GetInstance(); SFBBitmapSmp pSourceBitmap; SFBTransformSmp pTransform; AEETransformMatrix matrix; //Paint whole window with white graphic->DrawRectangle(GetContentWorld(), SFXRGBColor(255, 255, 255, 255)); //Matrix for modification matrix.A = static_cast<SIntN>(m_scale_ratio * 256.0); matrix.B = 0; matrix.C = 0; matrix.D = static_cast<SIntN>(m_scale_ratio * 256.0); //Enlarge bitmap and display it pSourceBitmap = graphic->CreateBitmap(m_bitmap_size); pSourceBitmap->BltIn(SFXRectangle(0, 0, m_bitmap_size), m_bitmap, SFXGrid(0, 0)); pTransform = SFBTransform::NewInstance(graphic->GetDestination()); pTransform->TransformBltComplex( SFXGrid(m_transfered_point.GetX(), m_transfered_point.GetY()), pSourceBitmap, SFXRectangle(0, 0, m_bitmap_size), matrix); }
Constructor
// Constructor ImageWindow::ImageWindow(SFRApplicationPtr papp, SFXRectangleConstRef rect, SFBBitmapSmpConstRef bmp) : SFRPlainWindow(papp, rect) { //Register event handler RegisterHandler( SREVT_RESPONDER_RENDER, SRP16_RENDER_CONTENT, HANDLER_BEFORE, HANDLER_FUNCTION(OnDraw)); RegisterHandler(SFEVT_KEY, HANDLER_AFTER, HANDLER_FUNCTION(OnKey)); //Initialize the bitmap to be displayed m_bitmap = bmp; //Choose scale ratio of the bitmap Float64 bmp_aspect_ratio; Float64 dev_aspect_ratio; AEEDeviceInfo devinfo; AEEBitmapInfo bmpinfo; SFBShellSmp shell = SFBShell::GetInstance(); m_bitmap->GetInfo(&bmpinfo); m_bitmap_size.SetWidth(static_cast<SInt16>(bmpinfo.cx)); m_bitmap_size.SetHeight(static_cast<SInt16>(bmpinfo.cy)); shell->GetDeviceInfo(&devinfo); m_devsize.SetWidth(devinfo.cxScreen); m_devsize.SetHeight(devinfo.cyScreen); bmp_aspect_ratio = static_cast<Float64>(m_bitmap_size.GetWidth()) / static_cast<Float64>(m_bitmap_size.GetHeight()); dev_aspect_ratio = static_cast<Float64>(m_devsize.GetWidth()) / static_cast<Float64>(m_devsize.GetHeight()); Bool isheight_fit; if (dev_aspect_ratio >= bmp_aspect_ratio) { m_scale_ratio = static_cast<Float64>( m_devsize.GetHeight() / m_bitmap_size.GetHeight()); isheight_fit = TRUE; } else { m_scale_ratio = static_cast<Float64>( m_devsize.GetWidth()) / static_cast<Float64> (m_bitmap_size.GetWidth());isheight_fit = FALSE; } //Assign the coordinate to transfer m_transfered_point.SetX(static_cast<SInt16>( m_bitmap_size.GetWidth() * (m_scale_ratio - 1.0) / 2.0)); m_transfered_point.SetY(static_cast<SInt16>( m_bitmap_size.GetHeight() * (m_scale_ratio - 1.0) / 2.0)); if (isheight_fit) { m_transfered_point.AddX(static_cast<SInt16>( (m_devsize.GetWidth() - m_bitmap_size.GetWidth() * m_scale_ratio) / 2.0)); } else { m_transfered_point.AddY(static_cast<SInt16>( (m_devsize.GetHeight() - m_bitmap_size.GetHeight() * m_scale_ratio) / 2.0)); } } // Destructor ImageWindow::~ImageWindow() { return; }
Types of windows
There are 3 kinds of window classes in SophiaFramework UNIVERSE.
- SFRPlainWindow ... Window without border
- SFRFrameWindow ... Window with border
- SFRTitleWindow ... Window with border and title bar
When using a window in an application, one of these window classes are to be inherited.
Special Notice
This application may not work properly on the emulator, since the bitmaps have been specially configured for the actual device.