-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitmap_btn_panel.cc
73 lines (63 loc) · 2.16 KB
/
bitmap_btn_panel.cc
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "bitmap_btn_panel.h"
#include "preference.h"
#include <iostream>
#include "home_frame.h"
BEGIN_EVENT_TABLE(BitmapBtnPanel, wxPanel)
// some useful events
/*
EVT_MOTION(wxImagePanel::mouseMoved)
EVT_LEFT_DOWN(wxImagePanel::mouseDown)
EVT_LEFT_UP(wxImagePanel::mouseReleased)
EVT_RIGHT_DOWN(wxImagePanel::rightClick)
EVT_LEAVE_WINDOW(wxImagePanel::mouseLeftWindow)
EVT_KEY_DOWN(wxImagePanel::keyPressed)
EVT_KEY_UP(wxImagePanel::keyReleased)
EVT_MOUSEWHEEL(wxImagePanel::mouseWheelMoved)
*/
// catch paint events
EVT_LEFT_DOWN(BitmapBtnPanel::MouseDown)
EVT_PAINT(BitmapBtnPanel::PaintEvent)
END_EVENT_TABLE()
BitmapBtnPanel::BitmapBtnPanel(wxFrame* parent, wxString file, wxBitmapType format, wxSize size, wxString text,SideTabSwitcher::Section section)
: wxPanel(parent, wxID_ANY,wxDefaultPosition,wxSize(100,size.GetHeight() + 20)),
size_(size),
text_(text),
parent_(parent),
section_(section) {
image_.LoadFile(file, format);
wxImage tmp = image_.ConvertToImage();
tmp.Rescale(size.GetWidth(), size.GetHeight(),wxIMAGE_QUALITY_BICUBIC);
image_ = wxBitmap(tmp);
if(static_cast<HomeFrame*>(parent_)->GetController()->GetModel()
->GetSideTabSwitcher()->GetSection() == section_){
SetBackgroundColour(wxColour("#000000"));
}else{
SetBackgroundColour(wxColour("#181818"));
}
}
void BitmapBtnPanel::PaintEvent(wxPaintEvent &evt)
{
wxPaintDC dc(this);
Render(dc);
}
void BitmapBtnPanel::PaintNow(){
wxClientDC dc(this);
HomeFrame* parent = static_cast<HomeFrame*>(parent_);
if(parent->GetController()->GetModel()
->GetSideTabSwitcher()->GetSection() == section_){
SetBackgroundColour(wxColour("#000000"));
}else{
SetBackgroundColour(wxColour("#181818"));
}
Render(dc);
}
void BitmapBtnPanel::Render(wxDC& dc){
dc.DrawBitmap( image_, 16, 8, false );
dc.DrawText(text_,wxPoint(size_.GetWidth() + 20,13));
}
void BitmapBtnPanel::MouseDown(wxMouseEvent& event) {
HomeFrame* parent = static_cast<HomeFrame*>(parent_);
parent->GetController()->GetModel()
->GetSideTabSwitcher()->SetSection(section_);
parent->RefreshSectionStatus();
}