Mercurial > mercurial > hgweb_kaigo.hg.cgi
comparison horori/merger/src/lookwin.cpp @ 0:aaaa401818a1 draft
first commit.
| author | pyon <pyon@macmini> |
|---|---|
| date | Mon, 24 May 2021 21:32:58 +0900 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:aaaa401818a1 |
|---|---|
| 1 // Filename : lookwin.cpp | |
| 2 // Last Change: 2020-03-23 月 08:34:17. | |
| 3 // | |
| 4 #include "utils.h" | |
| 5 #include "lookwin.h" | |
| 6 | |
| 7 LookWindow::LookWindow(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) | |
| 8 : wxWindow(parent, id, pos, size, style) | |
| 9 { | |
| 10 m_dcw = size.GetWidth(); | |
| 11 m_dch = size.GetHeight(); | |
| 12 } | |
| 13 | |
| 14 LookWindow::~LookWindow() | |
| 15 { | |
| 16 } | |
| 17 | |
| 18 // Event Table | |
| 19 BEGIN_EVENT_TABLE(LookWindow, wxWindow) | |
| 20 EVT_PAINT(LookWindow::OnPaint) | |
| 21 EVT_LEFT_DOWN(LookWindow::OnLeftDown) | |
| 22 EVT_RIGHT_DOWN(LookWindow::OnRightDown) | |
| 23 EVT_LEFT_UP(LookWindow::OnLeftUp) | |
| 24 EVT_RIGHT_UP(LookWindow::OnRightUp) | |
| 25 EVT_MOTION(LookWindow::OnMotion) | |
| 26 END_EVENT_TABLE() | |
| 27 | |
| 28 /* Event Handlers */ | |
| 29 void LookWindow::OnPaint(wxPaintEvent &WXUNUSED(event)) | |
| 30 { | |
| 31 if (!wxFileExists(m_file)) return; | |
| 32 wxImage image(m_file, wxBITMAP_TYPE_TIFF); | |
| 33 | |
| 34 wxRect rect(0, 0, m_w, m_h); | |
| 35 | |
| 36 image = image.GetSubImage(rect); | |
| 37 m_bitmap = wxBitmap(image.Scale(m_dcw, m_dch, wxIMAGE_QUALITY_HIGH)); | |
| 38 | |
| 39 wxPaintDC dc(this); | |
| 40 dc.DrawBitmap(m_bitmap, 0, 0); | |
| 41 } | |
| 42 | |
| 43 void LookWindow::OnMotion(wxMouseEvent &event) | |
| 44 { | |
| 45 if (event.Dragging() && event.LeftIsDown()) { | |
| 46 event.GetPosition(&m_s1, &m_t1); | |
| 47 DoMask1(); | |
| 48 } else if (event.Dragging() && event.RightIsDown() && m_masknum == 2) { | |
| 49 event.GetPosition(&m_s2, &m_t2); | |
| 50 DoMask2(); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 void LookWindow::OnLeftDown(wxMouseEvent &event) | |
| 55 { | |
| 56 event.GetPosition(&m_x1, &m_y1); | |
| 57 ReloadImage(); | |
| 58 if (m_masknum == 2) DoMask2(); | |
| 59 } | |
| 60 | |
| 61 void LookWindow::OnLeftUp(wxMouseEvent &event) | |
| 62 { | |
| 63 event.GetPosition(&m_s1, &m_t1); | |
| 64 ReloadImage(); | |
| 65 DoMask1(); | |
| 66 if (m_masknum ==2) DoMask2(); | |
| 67 } | |
| 68 | |
| 69 void LookWindow::OnRightDown(wxMouseEvent &event) | |
| 70 { | |
| 71 if (m_masknum == 1) return; | |
| 72 event.GetPosition(&m_x2, &m_y2); | |
| 73 ReloadImage(); | |
| 74 DoMask1(); | |
| 75 } | |
| 76 | |
| 77 void LookWindow::OnRightUp(wxMouseEvent &event) | |
| 78 { | |
| 79 if (m_masknum ==1) return; | |
| 80 event.GetPosition(&m_s2, &m_t2); | |
| 81 ReloadImage(); | |
| 82 DoMask2(); | |
| 83 DoMask1(); | |
| 84 } | |
| 85 | |
| 86 /* Functions */ | |
| 87 void LookWindow::SetDefaultParams(wxRect r, int n) | |
| 88 { | |
| 89 m_masknum = n; | |
| 90 | |
| 91 m_w = r.GetWidth(); | |
| 92 m_h = r.GetHeight(); | |
| 93 | |
| 94 m_scalex = (float)m_w / m_dcw; | |
| 95 m_scaley = (float)m_h / m_dch; | |
| 96 } | |
| 97 | |
| 98 void LookWindow::LoadImage(wxString file) | |
| 99 { | |
| 100 m_file = file; | |
| 101 | |
| 102 if (!wxFileExists(m_file)) return; | |
| 103 wxImage image(m_file, wxBITMAP_TYPE_TIFF); | |
| 104 | |
| 105 wxRect rect(0, 0, m_w, m_h); | |
| 106 | |
| 107 image = image.GetSubImage(rect); | |
| 108 m_bitmap = wxBitmap(image.Scale(m_dcw, m_dch, wxIMAGE_QUALITY_HIGH)); | |
| 109 | |
| 110 wxClientDC dc(this); | |
| 111 dc.DrawBitmap(m_bitmap, 0, 0); | |
| 112 } | |
| 113 | |
| 114 void LookWindow::ReloadImage() | |
| 115 { | |
| 116 wxClientDC dc(this); | |
| 117 dc.DrawBitmap(m_bitmap, 0, 0); | |
| 118 } | |
| 119 | |
| 120 void LookWindow::SetMaskLoc(wxRect loc1, wxRect loc2) | |
| 121 { | |
| 122 m_x1 = (int)((float)loc1.x / m_scalex); | |
| 123 m_y1 = (int)((float)loc1.y / m_scaley); | |
| 124 m_s1 = (int)((float)(loc1.x + loc1.GetWidth()) / m_scalex); | |
| 125 m_t1 = (int)((float)(loc1.y + loc1.GetHeight()) / m_scaley); | |
| 126 m_x2 = (int)((float)loc2.x / m_scalex); | |
| 127 m_y2 = (int)((float)loc2.y / m_scaley); | |
| 128 m_s2 = (int)((float)(loc2.x + loc2.GetWidth()) / m_scalex); | |
| 129 m_t2 = (int)((float)(loc2.y + loc2.GetHeight()) / m_scaley); | |
| 130 } | |
| 131 | |
| 132 void LookWindow::GetMaskLoc(int n, wxString* xs, wxString* ys, wxString* ws, wxString* hs) | |
| 133 { | |
| 134 int x = m_x1; | |
| 135 int y = m_y1; | |
| 136 int w = m_s1 - m_x1; | |
| 137 int h = m_t1 - m_y1; | |
| 138 if (n == 2) { | |
| 139 x = m_x2; | |
| 140 y = m_y2; | |
| 141 w = m_s2 - m_x2; | |
| 142 h = m_t2 - m_y2; | |
| 143 } | |
| 144 *xs = wxString::Format(wxT("%d"), (int)(x * m_scalex)); | |
| 145 *ys = wxString::Format(wxT("%d"), (int)(y * m_scaley)); | |
| 146 *ws = wxString::Format(wxT("%d"), (int)(w * m_scalex)); | |
| 147 *hs = wxString::Format(wxT("%d"), (int)(h * m_scaley)); | |
| 148 } | |
| 149 | |
| 150 void LookWindow::DoMask1() | |
| 151 { | |
| 152 if (m_x1 > m_s1 || m_y1 > m_t1) | |
| 153 return; | |
| 154 | |
| 155 wxClientDC dc(this); | |
| 156 wxPen pen(*wxRED, 10); | |
| 157 dc.SetPen(pen); | |
| 158 | |
| 159 int dx = 3, dy = 3; | |
| 160 for (int x = m_x1; x < m_s1; x += dx) | |
| 161 for (int y = m_y1; y < m_t1; y += dy) | |
| 162 dc.DrawPoint(x, y); | |
| 163 | |
| 164 dc.SetPen(wxNullPen); | |
| 165 } | |
| 166 | |
| 167 void LookWindow::DoMask2() | |
| 168 { | |
| 169 if (m_x2 > m_s2 || m_y2 > m_t2) | |
| 170 return; | |
| 171 | |
| 172 wxClientDC dc(this); | |
| 173 wxPen pen(*wxBLUE, 10); | |
| 174 dc.SetPen(pen); | |
| 175 | |
| 176 int dx = 3, dy = 3; | |
| 177 for (int x = m_x2; x < m_s2; x += dx) | |
| 178 for (int y = m_y2; y < m_t2; y += dy) | |
| 179 dc.DrawPoint(x, y); | |
| 180 | |
| 181 dc.SetPen(wxNullPen); | |
| 182 } | |
| 183 |
