diff src/custom.cpp @ 0:2f5584f0d127

first commit.
author pyon@macmini
date Sat, 08 Jun 2019 16:21:40 +0900
parents
children f40a65687079
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/custom.cpp	Sat Jun 08 16:21:40 2019 +0900
@@ -0,0 +1,225 @@
+// Filename   : custom.cpp
+// Last Change: 2019-06-07 金 17:36:31.
+//
+
+#include "id.h"
+#include "appconf.h"
+#include "custom.h"
+
+/*** LookWindow Class ***/
+LookWindow::LookWindow( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
+	: wxWindow( parent, id, pos, size, style )
+{
+}
+
+LookWindow::~LookWindow()
+{
+}
+
+// Event Table
+BEGIN_EVENT_TABLE( LookWindow, wxWindow )
+	EVT_PAINT( LookWindow::OnPaint )
+	EVT_LEFT_DOWN( LookWindow::OnLeftDown )
+	EVT_RIGHT_DOWN( LookWindow::OnRightDown )
+	EVT_MOTION( LookWindow::OnMotion )
+END_EVENT_TABLE()
+
+/* Event Handlers & Functions */
+// Event Handlers
+void LookWindow::OnPaint( wxPaintEvent &event )
+{
+	LoadImage();
+}
+
+void LookWindow::OnMotion( wxMouseEvent &event )
+{
+	if ( event.Dragging() && event.LeftIsDown() ) {
+		event.GetPosition( &m_x2, &m_y2 );
+		//m_spnx->SetValue( m_x1 ); // **seg fault
+		DoMask1();
+	} else if ( event.Dragging() && event.RightIsDown() && m_masknum == 2 ) {
+		event.GetPosition( &m_s2, &m_t2 );
+		DoMask2();
+	}
+}
+
+void LookWindow::OnLeftDown( wxMouseEvent &event )
+{
+	event.GetPosition( &m_x1, &m_y1 );
+	ReloadImage();
+	if ( m_masknum == 2 ) DoMask2();
+}
+
+void LookWindow::OnLeftUp( wxMouseEvent &event )
+{
+	event.GetPosition( &m_x2, &m_y2 );
+}
+
+void LookWindow::OnRightDown( wxMouseEvent &event )
+{
+	if ( m_masknum == 1 ) return;
+
+	event.GetPosition( &m_s1, &m_t1 );
+	ReloadImage();
+	DoMask1();
+}
+
+void LookWindow::OnRightUp( wxMouseEvent &event )
+{
+	event.GetPosition( &m_s2, &m_t2 );
+}
+
+// Functions
+void LookWindow::SetDefaultParams( int i, int w, int h, int dcw, int dch )
+{
+	AppConf appconf;
+	wxRect r = appconf.LoadMask( i );
+
+	m_w   = w;   m_h   = h;
+	m_dcw = dcw; m_dch = dch;
+
+	m_scalex = m_w / m_dcw;
+	m_scaley = m_h / m_dch;
+
+	m_x0 = r.x / m_scalex;
+	m_y0 = r.y / m_scaley;
+	m_w0 = r.width  / m_scalex;
+	m_h0 = r.height / m_scaley;
+}
+
+void LookWindow::AddMask( void )
+{
+	AppConf appconf;
+	wxRect r = appconf.LoadMask( 4 );
+
+	m_s0 = r.x / m_scalex;
+	m_t0 = r.y / m_scaley;
+	m_u0 = r.width  / m_scalex;
+	m_v0 = r.height / m_scaley;
+
+	m_masknum = 2;
+}
+
+void LookWindow::ResetMask1( void )
+{
+	m_x1 = m_x0;
+	m_y1 = m_y0;
+	m_x2 = m_x0 + m_w0;
+	m_y2 = m_y0 + m_h0;
+	DoMask1();
+	if ( m_masknum == 2 ) DoMask2();
+}
+
+void LookWindow::ResetMask2( void )
+{
+	m_s1 = m_s0;
+	m_t1 = m_t0;
+	m_s2 = m_s0 + m_u0;
+	m_t2 = m_t0 + m_v0;
+	DoMask2();
+	DoMask1();
+}
+
+void LookWindow::LoadImage( void )
+{
+    wxImage image( m_file, wxBITMAP_TYPE_JPEG );
+	wxRect rect( 0, 0, m_w, m_h );
+
+    image = image.GetSubImage( rect );
+    m_bitmap = wxBitmap( image.Scale( m_dcw, m_dch, wxIMAGE_QUALITY_HIGH ) );
+
+	wxPaintDC dc( this );
+	dc.DrawBitmap( m_bitmap, 0, 0 );
+}
+
+void LookWindow::ReloadImage( void )
+{
+	wxClientDC dc( this );
+	dc.DrawBitmap( m_bitmap, 0, 0 );
+}
+
+void LookWindow::DoMask1()
+{
+	wxClientDC dc( this );
+	wxPen pen( *wxRED, 10 );
+	dc.SetPen( pen );
+
+	int sx, sy, ex, ey;
+	int dx = 3, dy = 3;
+
+	if ( m_x1 < m_x2 ) {
+		sx = m_x1; ex = m_x2;
+	} else {
+		sx = m_x2; ex = m_x1;	// **not perform
+	}
+	if ( m_y1 < m_y2 ) {
+		sy = m_y1; ey = m_y2;
+	} else {
+		sy = m_y2; ey = m_y1;
+	}
+
+	for ( int i = m_x1; i < m_x2; i += dx ) {
+		for ( int j = m_y1; j < m_y2; j += dy ) {
+			dc.DrawPoint( i, j );
+		}
+	}
+
+	dc.SetPen( wxNullPen );
+}
+
+void LookWindow::DoMask2()
+{
+	wxClientDC dc( this );
+	wxPen pen( *wxBLUE, 10 );
+	dc.SetPen( pen );
+
+	int ss, st, es, et;
+	int ds = 3, dt = 3;
+
+	if ( m_s1 < m_s2 ) {
+		ss = m_s1; es = m_s2;
+	} else {
+		ss = m_s2; es = m_s1;	// **not perform
+	}
+	if ( m_t1 < m_t2 ) {
+		st = m_t1; et = m_t2;
+	} else {
+		st = m_t2; et = m_t1;
+	}
+
+	for ( int i = m_s1; i < m_s2; i += ds ) {
+		for ( int j = m_t1; j < m_t2; j += dt ) {
+			dc.DrawPoint( i, j );
+		}
+	}
+
+	dc.SetPen( wxNullPen );
+}
+
+
+wxRect LookWindow::GetRealMask1Rect( void )
+{
+	int x1 = m_x1 * m_scalex;
+	int x2 = m_x2 * m_scalex;
+	int y1 = m_y1 * m_scaley;
+	int y2 = m_y2 * m_scaley;
+	wxRect rect( wxPoint( x1, y1 ), wxPoint( x2, y2 ) );
+	return rect;
+}
+
+wxRect LookWindow::GetRealMask2Rect( void )
+{
+	int x1 = m_s1 * m_scalex;
+	int x2 = m_s2 * m_scalex;
+	int y1 = m_t1 * m_scaley;
+	int y2 = m_t2 * m_scaley;
+	wxRect rect( wxPoint( x1, y1 ), wxPoint( x2, y2 ) );
+	return rect;
+}
+
+void LookWindow::AssignSpinControl( wxSpinCtrl* spnx, wxSpinCtrl* spny, wxSpinCtrl* spnw, wxSpinCtrl* spnh )
+{
+	m_spnx = spnx; m_spny = spny;
+	m_spnw = spnw; m_spnh = spnh;
+}
+