Mercurial > mercurial > hgweb_kaigo.hg.cgi
view horori/merger/src/lookwin.cpp @ 7:3b16a1b57e00 draft default tip
add qtuti/95y.
author | pyon |
---|---|
date | Sat, 27 Nov 2021 14:50:30 +0900 |
parents | aaaa401818a1 |
children |
line wrap: on
line source
// Filename : lookwin.cpp // Last Change: 2020-03-23 月 08:34:17. // #include "utils.h" #include "lookwin.h" LookWindow::LookWindow(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) : wxWindow(parent, id, pos, size, style) { m_dcw = size.GetWidth(); m_dch = size.GetHeight(); } LookWindow::~LookWindow() { } // Event Table BEGIN_EVENT_TABLE(LookWindow, wxWindow) EVT_PAINT(LookWindow::OnPaint) EVT_LEFT_DOWN(LookWindow::OnLeftDown) EVT_RIGHT_DOWN(LookWindow::OnRightDown) EVT_LEFT_UP(LookWindow::OnLeftUp) EVT_RIGHT_UP(LookWindow::OnRightUp) EVT_MOTION(LookWindow::OnMotion) END_EVENT_TABLE() /* Event Handlers */ void LookWindow::OnPaint(wxPaintEvent &WXUNUSED(event)) { if (!wxFileExists(m_file)) return; wxImage image(m_file, wxBITMAP_TYPE_TIFF); 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::OnMotion(wxMouseEvent &event) { if (event.Dragging() && event.LeftIsDown()) { event.GetPosition(&m_s1, &m_t1); 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_s1, &m_t1); ReloadImage(); DoMask1(); if (m_masknum ==2) DoMask2(); } void LookWindow::OnRightDown(wxMouseEvent &event) { if (m_masknum == 1) return; event.GetPosition(&m_x2, &m_y2); ReloadImage(); DoMask1(); } void LookWindow::OnRightUp(wxMouseEvent &event) { if (m_masknum ==1) return; event.GetPosition(&m_s2, &m_t2); ReloadImage(); DoMask2(); DoMask1(); } /* Functions */ void LookWindow::SetDefaultParams(wxRect r, int n) { m_masknum = n; m_w = r.GetWidth(); m_h = r.GetHeight(); m_scalex = (float)m_w / m_dcw; m_scaley = (float)m_h / m_dch; } void LookWindow::LoadImage(wxString file) { m_file = file; if (!wxFileExists(m_file)) return; wxImage image(m_file, wxBITMAP_TYPE_TIFF); wxRect rect(0, 0, m_w, m_h); image = image.GetSubImage(rect); m_bitmap = wxBitmap(image.Scale(m_dcw, m_dch, wxIMAGE_QUALITY_HIGH)); wxClientDC dc(this); dc.DrawBitmap(m_bitmap, 0, 0); } void LookWindow::ReloadImage() { wxClientDC dc(this); dc.DrawBitmap(m_bitmap, 0, 0); } void LookWindow::SetMaskLoc(wxRect loc1, wxRect loc2) { m_x1 = (int)((float)loc1.x / m_scalex); m_y1 = (int)((float)loc1.y / m_scaley); m_s1 = (int)((float)(loc1.x + loc1.GetWidth()) / m_scalex); m_t1 = (int)((float)(loc1.y + loc1.GetHeight()) / m_scaley); m_x2 = (int)((float)loc2.x / m_scalex); m_y2 = (int)((float)loc2.y / m_scaley); m_s2 = (int)((float)(loc2.x + loc2.GetWidth()) / m_scalex); m_t2 = (int)((float)(loc2.y + loc2.GetHeight()) / m_scaley); } void LookWindow::GetMaskLoc(int n, wxString* xs, wxString* ys, wxString* ws, wxString* hs) { int x = m_x1; int y = m_y1; int w = m_s1 - m_x1; int h = m_t1 - m_y1; if (n == 2) { x = m_x2; y = m_y2; w = m_s2 - m_x2; h = m_t2 - m_y2; } *xs = wxString::Format(wxT("%d"), (int)(x * m_scalex)); *ys = wxString::Format(wxT("%d"), (int)(y * m_scaley)); *ws = wxString::Format(wxT("%d"), (int)(w * m_scalex)); *hs = wxString::Format(wxT("%d"), (int)(h * m_scaley)); } void LookWindow::DoMask1() { if (m_x1 > m_s1 || m_y1 > m_t1) return; wxClientDC dc(this); wxPen pen(*wxRED, 10); dc.SetPen(pen); int dx = 3, dy = 3; for (int x = m_x1; x < m_s1; x += dx) for (int y = m_y1; y < m_t1; y += dy) dc.DrawPoint(x, y); dc.SetPen(wxNullPen); } void LookWindow::DoMask2() { if (m_x2 > m_s2 || m_y2 > m_t2) return; wxClientDC dc(this); wxPen pen(*wxBLUE, 10); dc.SetPen(pen); int dx = 3, dy = 3; for (int x = m_x2; x < m_s2; x += dx) for (int y = m_y2; y < m_t2; y += dy) dc.DrawPoint(x, y); dc.SetPen(wxNullPen); }