-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewWidget.cpp
174 lines (138 loc) · 3.87 KB
/
NewWidget.cpp
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// DRN: Unused in current Testdc Demo application (replaced by kwxNewWidget ?)
/////////////////////////////////////////////////////////////////////////////
// Name: NewWidget.cpp
// Purpose:
// Author:
// Modified by:
// Created:
// RCS-ID:
// Copyright: (C)2003
// Licence: wxWindows
/////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include <wx/image.h>
#include <wx/log.h>
#include "NewWidget.h"
#include <wx/event.h>
//IMPLEMENT_DYNAMIC_CLASS(kwxNewWidget, wxWindow)
BEGIN_EVENT_TABLE(kwxNewWidget,wxWindow)
EVT_PAINT(kwxNewWidget::OnPaint)
EVT_MOUSE_EVENTS(kwxNewWidget::OnMouse)
EVT_ERASE_BACKGROUND(kwxNewWidget::OnEraseBackGround)
//EVT_MOTION(kwxNewWidget::OnMouse)
END_EVENT_TABLE()
kwxNewWidget::kwxNewWidget(wxWindow* parent,
const wxWindowID id,
const wxString& label,
wxBitmap& defaultBitmap,
wxBitmap& MoveMouseBitmap,
wxBitmap& PressMouseBitmap,
const wxPoint& pos,
const wxSize& size,
const long int style)
: wxWindow(parent, id, pos, size, 0)
{
if (parent)
SetBackgroundColour(parent->GetBackgroundColour());
else
SetBackgroundColour(*wxLIGHT_GREY);
mDefaultBitmap = &defaultBitmap;
mMoveMouseBitmap = &MoveMouseBitmap;
mPressMouseBitmap = &PressMouseBitmap;
int total_width = 0, total_height = 0 ;
// se c'e' un bitmap ne uso le dimensioni
if (mDefaultBitmap)
{
total_width = mDefaultBitmap->GetWidth(); // NB! Should use largest bm
total_height = mDefaultBitmap->GetHeight(); // NB! Should use largest bm
}
SetSize(total_width, total_height);
//SetSize(size);
SetAutoLayout(TRUE);
Refresh();
m_stato=0;
m_oldstato=0;
}
void kwxNewWidget::SetLabel(wxString label)
{
mLabelStr = label;
}
void kwxNewWidget::OnPaint(wxPaintEvent& event)
{
wxPaintDC dc(this);
dc.SetBackground(*wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(),wxSOLID));
dc.Clear();
int w,h;
GetClientSize(&w,&h);
// se impostato n bitmap lo disegno
//if (mDefaultBitmap)
if(m_stato==0)
{
dc.DrawBitmap(*mDefaultBitmap, 0, 0, TRUE);
}
else if(m_stato==1)
{
dc.DrawBitmap(*mMoveMouseBitmap, 0, 0, TRUE);
}
else if(m_stato==2)
{
dc.DrawBitmap(*mPressMouseBitmap, 0, 0, TRUE);
}
// Cornice intorno
dc.SetPen(*wxThePenList->FindOrCreatePen(*wxRED, 1, wxSOLID));
dc.DrawLine(0,0,0,h-1);
dc.DrawLine(0,0,w,0);
dc.DrawLine(0,h-1,w,h-1);
dc.DrawLine(w-1,0,w-1,h-1);
}
void kwxNewWidget::OnMouse(wxMouseEvent& event)
{
if(MouseIsOnButton())
{
if (event.LeftIsDown())
{
m_stato=2;
}
else
{
m_stato=1;
}
}
if(event.Leaving())
{
m_stato=0;
}
if(m_oldstato!=m_stato)
{
Refresh();
}
m_oldstato=m_stato;
//event.Skip();
}
bool kwxNewWidget::MouseIsOnButton()
{
int cx=0,cy=0;
int wbit,hbit;
ClientToScreen(&cx,&cy);
int cw=0,ch=0;
this->GetClientSize(&cw,&ch);
//wxLogTrace("ClientSize cw=%d ch=%d", cw, ch) ;
GetSize(&cw,&ch);
//wxLogTrace("Size cw=%d ch=%d", cw, ch) ;
int mpx,mpy;
::wxGetMousePosition(&mpx,&mpy);
wbit = mDefaultBitmap->GetWidth(); // NB! Should use largest bm
hbit = mDefaultBitmap->GetHeight(); // NB! Should use largest bm
return(mpx >= cx && mpx <= cx + wbit &&
mpy >= cy && mpy <= cy + hbit);
}
void kwxNewWidget::OnEraseBackGround(wxEraseEvent& event)
{
wxLogTrace(wxTRACE_Messages/*DRN*/,"erase background") ;
}