Menu

[r22]: / src / mytoolbar.cpp  Maximize  Restore  History

Download this file

94 lines (77 with data), 2.8 kB

 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//mytoolbar.cpp
#include "mytoolbar.h"
BEGIN_EVENT_TABLE ( MyToolBar, wxToolBar )
EVT_ERASE_BACKGROUND ( MyToolBar::OnEraseBG )
END_EVENT_TABLE()
// taken from wxStyledNotebook (c) Eran Ifrah <eranif@bezeqint.net>
static wxColor LightColour ( const wxColour& color, int percent )
{
int rd, gd, bd, high = 0;
wxColor end_color = wxT ( "WHITE" );
rd = end_color.Red() - color.Red();
gd = end_color.Green() - color.Green();
bd = end_color.Blue() - color.Blue();
high = 100;
// We take the percent way of the color from color --> white
int i = percent;
int r = color.Red() + ( ( i*rd*100 ) /high ) /100;
int g = color.Green() + ( ( i*gd*100 ) /high ) /100;
int b = color.Blue() + ( ( i*bd*100 ) /high ) /100;
return wxColor ( r, g, b );
}
MyToolBar::MyToolBar (
wxFrame *parent,
int id,
const wxPoint& pos,
const wxSize& size,
long style ) :
wxToolBar ( parent, id, pos, size, style )
{
/// Override colors
m_colorTo = LightColour ( wxSystemSettings::GetColour ( wxSYS_COLOUR_3DFACE ), 0 );
m_colorFrom = LightColour ( wxSystemSettings::GetColour ( wxSYS_COLOUR_3DFACE ), 80 );//60);
//m_colorFrom = LightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENU), 0);
}
void MyToolBar::OnEraseBG ( wxEraseEvent& event )
{
wxDC* DC = event.GetDC();
wxWindow *Window = dynamic_cast<wxWindow *> ( event.GetEventObject() );
assert ( Window );
int x, y, w, h;
x = y = 0;
Window->GetSize ( &w, &h );
wxRect rect ( x, y, w, h );
PaintStraightGradientBox ( DC, rect, m_colorFrom, m_colorTo );
}
// adapted from wxFlatNotebook (c) Eran Ifrah
void MyToolBar::PaintStraightGradientBox ( wxDC *dc, const wxRect& rect, const wxColour& startColor, const wxColour& endColor, bool vertical )
{
int rd, gd, bd, high = 0;
rd = endColor.Red() - startColor.Red();
gd = endColor.Green() - startColor.Green();
bd = endColor.Blue() - startColor.Blue();
/// Save the current pen and brush
wxPen savedPen = dc->GetPen();
wxBrush savedBrush = dc->GetBrush();
if ( vertical )
high = rect.GetHeight()-1;
else
high = rect.GetWidth()-1;
if ( high < 1 )
return;
for ( int i = 0; i <= high; ++i )
{
int r = startColor.Red() + ( ( i*rd*100 ) /high ) /100;
int g = startColor.Green() + ( ( i*gd*100 ) /high ) /100;
int b = startColor.Blue() + ( ( i*bd*100 ) /high ) /100;
wxPen p ( wxColor ( r, g, b ) );
dc->SetPen ( p );
if ( vertical )
dc->DrawLine ( rect.x, rect.y+i, rect.x+rect.width, rect.y+i );
else
dc->DrawLine ( rect.x+i, rect.y, rect.x+i, rect.y+rect.height );
}
/// Restore the pen and brush
dc->SetPen ( savedPen );
dc->SetBrush ( savedBrush );
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.