comparison src/custom.cpp @ 0:2f5584f0d127

first commit.
author pyon@macmini
date Sat, 08 Jun 2019 16:21:40 +0900
parents
children f40a65687079
comparison
equal deleted inserted replaced
-1:000000000000 0:2f5584f0d127
1 // Filename : custom.cpp
2 // Last Change: 2019-06-07 金 17:36:31.
3 //
4
5 #include "id.h"
6 #include "appconf.h"
7 #include "custom.h"
8
9 /*** LookWindow Class ***/
10 LookWindow::LookWindow( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
11 : wxWindow( parent, id, pos, size, style )
12 {
13 }
14
15 LookWindow::~LookWindow()
16 {
17 }
18
19 // Event Table
20 BEGIN_EVENT_TABLE( LookWindow, wxWindow )
21 EVT_PAINT( LookWindow::OnPaint )
22 EVT_LEFT_DOWN( LookWindow::OnLeftDown )
23 EVT_RIGHT_DOWN( LookWindow::OnRightDown )
24 EVT_MOTION( LookWindow::OnMotion )
25 END_EVENT_TABLE()
26
27 /* Event Handlers & Functions */
28 // Event Handlers
29 void LookWindow::OnPaint( wxPaintEvent &event )
30 {
31 LoadImage();
32 }
33
34 void LookWindow::OnMotion( wxMouseEvent &event )
35 {
36 if ( event.Dragging() && event.LeftIsDown() ) {
37 event.GetPosition( &m_x2, &m_y2 );
38 //m_spnx->SetValue( m_x1 ); // **seg fault
39 DoMask1();
40 } else if ( event.Dragging() && event.RightIsDown() && m_masknum == 2 ) {
41 event.GetPosition( &m_s2, &m_t2 );
42 DoMask2();
43 }
44 }
45
46 void LookWindow::OnLeftDown( wxMouseEvent &event )
47 {
48 event.GetPosition( &m_x1, &m_y1 );
49 ReloadImage();
50 if ( m_masknum == 2 ) DoMask2();
51 }
52
53 void LookWindow::OnLeftUp( wxMouseEvent &event )
54 {
55 event.GetPosition( &m_x2, &m_y2 );
56 }
57
58 void LookWindow::OnRightDown( wxMouseEvent &event )
59 {
60 if ( m_masknum == 1 ) return;
61
62 event.GetPosition( &m_s1, &m_t1 );
63 ReloadImage();
64 DoMask1();
65 }
66
67 void LookWindow::OnRightUp( wxMouseEvent &event )
68 {
69 event.GetPosition( &m_s2, &m_t2 );
70 }
71
72 // Functions
73 void LookWindow::SetDefaultParams( int i, int w, int h, int dcw, int dch )
74 {
75 AppConf appconf;
76 wxRect r = appconf.LoadMask( i );
77
78 m_w = w; m_h = h;
79 m_dcw = dcw; m_dch = dch;
80
81 m_scalex = m_w / m_dcw;
82 m_scaley = m_h / m_dch;
83
84 m_x0 = r.x / m_scalex;
85 m_y0 = r.y / m_scaley;
86 m_w0 = r.width / m_scalex;
87 m_h0 = r.height / m_scaley;
88 }
89
90 void LookWindow::AddMask( void )
91 {
92 AppConf appconf;
93 wxRect r = appconf.LoadMask( 4 );
94
95 m_s0 = r.x / m_scalex;
96 m_t0 = r.y / m_scaley;
97 m_u0 = r.width / m_scalex;
98 m_v0 = r.height / m_scaley;
99
100 m_masknum = 2;
101 }
102
103 void LookWindow::ResetMask1( void )
104 {
105 m_x1 = m_x0;
106 m_y1 = m_y0;
107 m_x2 = m_x0 + m_w0;
108 m_y2 = m_y0 + m_h0;
109 DoMask1();
110 if ( m_masknum == 2 ) DoMask2();
111 }
112
113 void LookWindow::ResetMask2( void )
114 {
115 m_s1 = m_s0;
116 m_t1 = m_t0;
117 m_s2 = m_s0 + m_u0;
118 m_t2 = m_t0 + m_v0;
119 DoMask2();
120 DoMask1();
121 }
122
123 void LookWindow::LoadImage( void )
124 {
125 wxImage image( m_file, wxBITMAP_TYPE_JPEG );
126 wxRect rect( 0, 0, m_w, m_h );
127
128 image = image.GetSubImage( rect );
129 m_bitmap = wxBitmap( image.Scale( m_dcw, m_dch, wxIMAGE_QUALITY_HIGH ) );
130
131 wxPaintDC dc( this );
132 dc.DrawBitmap( m_bitmap, 0, 0 );
133 }
134
135 void LookWindow::ReloadImage( void )
136 {
137 wxClientDC dc( this );
138 dc.DrawBitmap( m_bitmap, 0, 0 );
139 }
140
141 void LookWindow::DoMask1()
142 {
143 wxClientDC dc( this );
144 wxPen pen( *wxRED, 10 );
145 dc.SetPen( pen );
146
147 int sx, sy, ex, ey;
148 int dx = 3, dy = 3;
149
150 if ( m_x1 < m_x2 ) {
151 sx = m_x1; ex = m_x2;
152 } else {
153 sx = m_x2; ex = m_x1; // **not perform
154 }
155 if ( m_y1 < m_y2 ) {
156 sy = m_y1; ey = m_y2;
157 } else {
158 sy = m_y2; ey = m_y1;
159 }
160
161 for ( int i = m_x1; i < m_x2; i += dx ) {
162 for ( int j = m_y1; j < m_y2; j += dy ) {
163 dc.DrawPoint( i, j );
164 }
165 }
166
167 dc.SetPen( wxNullPen );
168 }
169
170 void LookWindow::DoMask2()
171 {
172 wxClientDC dc( this );
173 wxPen pen( *wxBLUE, 10 );
174 dc.SetPen( pen );
175
176 int ss, st, es, et;
177 int ds = 3, dt = 3;
178
179 if ( m_s1 < m_s2 ) {
180 ss = m_s1; es = m_s2;
181 } else {
182 ss = m_s2; es = m_s1; // **not perform
183 }
184 if ( m_t1 < m_t2 ) {
185 st = m_t1; et = m_t2;
186 } else {
187 st = m_t2; et = m_t1;
188 }
189
190 for ( int i = m_s1; i < m_s2; i += ds ) {
191 for ( int j = m_t1; j < m_t2; j += dt ) {
192 dc.DrawPoint( i, j );
193 }
194 }
195
196 dc.SetPen( wxNullPen );
197 }
198
199
200 wxRect LookWindow::GetRealMask1Rect( void )
201 {
202 int x1 = m_x1 * m_scalex;
203 int x2 = m_x2 * m_scalex;
204 int y1 = m_y1 * m_scaley;
205 int y2 = m_y2 * m_scaley;
206 wxRect rect( wxPoint( x1, y1 ), wxPoint( x2, y2 ) );
207 return rect;
208 }
209
210 wxRect LookWindow::GetRealMask2Rect( void )
211 {
212 int x1 = m_s1 * m_scalex;
213 int x2 = m_s2 * m_scalex;
214 int y1 = m_t1 * m_scaley;
215 int y2 = m_t2 * m_scaley;
216 wxRect rect( wxPoint( x1, y1 ), wxPoint( x2, y2 ) );
217 return rect;
218 }
219
220 void LookWindow::AssignSpinControl( wxSpinCtrl* spnx, wxSpinCtrl* spny, wxSpinCtrl* spnw, wxSpinCtrl* spnh )
221 {
222 m_spnx = spnx; m_spny = spny;
223 m_spnw = spnw; m_spnh = spnh;
224 }
225