1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include "clBitmapOverlayCtrl.h"
#include "bitmap_loader.h"
#include "globals.h"
#include "imanager.h"
clBitmapOverlayCtrl::clBitmapOverlayCtrl(wxWindow* win, const wxString& bitmapname, size_t flags)
: m_win(win)
, m_name(bitmapname)
, m_flags(flags)
, m_bmpWindow(NULL)
{
BitmapLoader* bmpLoader = clGetManager()->GetStdIcons();
m_bmp = bmpLoader->LoadBitmap(bitmapname);
DoPosition();
m_win->Bind(wxEVT_SIZE, &clBitmapOverlayCtrl::OnSize, this);
}
clBitmapOverlayCtrl::~clBitmapOverlayCtrl()
{
if(m_bmpWindow) {
m_win->RemoveChild(m_bmpWindow);
m_bmpWindow->Destroy();
}
m_win->Unbind(wxEVT_SIZE, &clBitmapOverlayCtrl::OnSize, this);
}
void clBitmapOverlayCtrl::DoPosition()
{
if(m_bmp.IsOk() && m_win) {
wxRect rect = m_win->GetRect();
int xx = 0;
int yy = 0;
int spacer = 5;
if(m_flags & wxRIGHT) {
xx = rect.GetWidth() - m_bmp.GetScaledWidth() - spacer;
} else {
xx = spacer;
}
if(m_flags & wxCENTER) {
yy = (rect.GetHeight() - m_bmp.GetScaledHeight()) / 2;
} else if(m_flags & wxBOTTOM) {
yy = (rect.GetHeight() - m_bmp.GetScaledHeight());
} else {
// Top
yy = 0;
}
if(!m_bmpWindow) {
m_bmpWindow = new wxStaticBitmap(m_win, wxID_ANY, m_bmp, wxPoint(xx, yy));
}
m_bmpWindow->Move(wxPoint(xx, yy));
}
}
void clBitmapOverlayCtrl::OnSize(wxSizeEvent& event)
{
event.Skip();
DoPosition();
}
|