-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathComparerView.cpp
More file actions
719 lines (568 loc) · 17.5 KB
/
Copy pathComparerView.cpp
File metadata and controls
719 lines (568 loc) · 17.5 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
// ComparerViewC.cpp : implementation file
//
#include "stdafx.h"
#include "Comparer.h"
#include "ComparerDoc.h"
#include "ComparerView.h"
#include "ComparerViews.h"
#include "MainFrm.h"
#include "PosInfoView.h"
#include "QCommon.h"
#include "QDebug.h"
#include "QMath.h"
#include <QViewerCmn.h>
#include <QImageStr.h>
// CComparerView
CComparerView::CComparerView()
: mXDst(0)
, mYDst(0)
, mWClient(0)
, mHClient(0)
, mWCanvas(0)
, mHCanvas(0)
, mIsClicked(false)
, mProcessing(false)
, mRgbBufSize(0)
, mRgbBuf(NULL)
{
LOGFONT lf;
::ZeroMemory(&lf, sizeof(lf));
lf.lfWeight = FW_NORMAL;
::lstrcpy(lf.lfFaceName, Q1UI_FONT_MONO);
mDefPixelTextFont.CreateFontIndirect(&lf);
mCsMenu.CreatePopupMenu();
CString str;
for (int i = 0; i < ARRAY_SIZE(qcsc_info_table); i++) {
str = qcsc_info_table[i].name;
str.MakeUpper();
mCsMenu.AppendMenu(MF_STRING, ID_CS_START + i, str);
}
CheckCsRadio(qcsc_info_table[QIMG_DEF_CS_IDX].cs);
mRcControls.SetRectEmpty();
mRcCsQMenu.SetRectEmpty();
mRcNameQMenu.SetRectEmpty();
}
CComparerView::~CComparerView()
{
mCsMenu.DestroyMenu();
if (mRgbBuf)
_mm_free(mRgbBuf);
}
BEGIN_MESSAGE_MAP(CComparerView, CScrollView)
ON_COMMAND_RANGE(ID_CS_START, ID_CS_END, CComparerView::OnCsChange)
ON_WM_CREATE()
ON_WM_DROPFILES()
ON_WM_ERASEBKGND()
ON_WM_MOUSEWHEEL()
ON_WM_SIZE()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_SETCURSOR()
ON_WM_KEYDOWN()
ON_WM_RBUTTONDOWN()
END_MESSAGE_MAP()
enum {
STATIC_CS_EVENT_ID = 0x1000,
STATIC_BLANK_EVENT_ID,
};
void CComparerView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
sizeTotal.cx = sizeTotal.cy = MIN_SIDE;
SetScrollSizes(MM_TEXT, sizeTotal);
}
void CComparerView::ScaleNearestNeighbor(CComparerDoc *pDoc, BYTE *src, BYTE *dst, int sDst,
q1::GridInfo &gi)
{
long gap, yStart, yEnd, xStart, xEnd;
if (mYDst > 0 || mXDst > 0) // The image is smaller than the canvas.
memset(dst, 0xf7, sDst * mHClient * QIMG_DST_RGB_BYTES);
// Visible range of the scaled image on the canvas.
if (mYDst > 0) {
dst += sDst * mYDst * QIMG_DST_RGB_BYTES;
yStart = 0;
yEnd = pDoc->mHDst;
} else {
yStart = -mYDst;
yEnd = mHClient - mYDst - mRcControls.bottom;
}
if (mXDst > 0) {
gap = (sDst - pDoc->mWDst) * QIMG_DST_RGB_BYTES;
dst += mXDst * QIMG_DST_RGB_BYTES;
xStart = 0;
xEnd = pDoc->mWDst;
} else {
gap = (sDst - mWClient) * QIMG_DST_RGB_BYTES;
xStart = -mXDst;
xEnd = mWClient - mXDst;
}
if (pDoc->mInterpol) {
q1::Interpolate(src, pDoc->mH, pDoc->mW, mWCanvas, xStart, xEnd, yStart, yEnd, pDoc->mNnOffsetBuf, dst);
} else {
q1::NearestNeighbor(src, pDoc->mH, pDoc->mW, pDoc->mHDst, pDoc->mWDst, mXDst, mYDst, pDoc->mN,
xStart, xEnd, yStart, yEnd, gap, gi,
pDoc->mNnOffsetBuf, pDoc->mNnOffsetYBorderFlag, pDoc->mNnOffsetXBorderFlag, dst);
}
}
void CComparerView::ScaleRgbBuf(CComparerDoc *pDoc, BYTE *rgbBuffer, q1::GridInfo &gi)
{
int sDst = ROUNDUP_DWORD(mWClient);
int rgbBufSize = sDst * mHClient * QIMG_DST_RGB_BYTES;
if (mRgbBufSize < rgbBufSize) {
if (mRgbBuf)
_mm_free(mRgbBuf);
mRgbBufSize = rgbBufSize;
mRgbBuf = static_cast<BYTE *>(_mm_malloc(mRgbBufSize, 16));
}
int maxL = QMAX(pDoc->mWDst, pDoc->mHDst);
if (pDoc->mPreN != pDoc->mN || pDoc->mPreMaxL < maxL) {
if (pDoc->mNnOffsetBufSize < maxL) {
if (pDoc->mNnOffsetBuf)
_mm_free(pDoc->mNnOffsetBuf);
if (pDoc->mNnOffsetYBorderFlag)
_mm_free(pDoc->mNnOffsetYBorderFlag);
if (pDoc->mNnOffsetXBorderFlag)
_mm_free(pDoc->mNnOffsetXBorderFlag);
pDoc->mNnOffsetBufSize = maxL;
pDoc->mNnOffsetBuf =
static_cast<qu16 *>(_mm_malloc(pDoc->mNnOffsetBufSize * sizeof(qu16), 16));
pDoc->mNnOffsetYBorderFlag =
static_cast<qu8 *>(_mm_malloc(pDoc->mNnOffsetBufSize * sizeof(qu8), 16));
pDoc->mNnOffsetXBorderFlag =
static_cast<qu8 *>(_mm_malloc(pDoc->mNnOffsetBufSize * sizeof(qu8), 16));
}
float ratio = 1 / pDoc->mN;
for (int i = 0; i < maxL; i++)
pDoc->mNnOffsetBuf[i] = int(i * ratio) * QIMG_DST_RGB_BYTES;
pDoc->mPreN = pDoc->mN;
pDoc->mPreMaxL = maxL;
}
ScaleNearestNeighbor(pDoc, rgbBuffer, mRgbBuf, sDst, gi);
BITMAPINFOHEADER &bmiHeader = pDoc->mBmi.bmiHeader;
bmiHeader.biWidth = sDst;
bmiHeader.biHeight = -mHClient;
}
void CComparerView::OnDraw(CDC *pDC)
{
CComparerDoc *pDoc = GetDocument();
ComparerPane *pane = GetPane(pDoc);
if (!pane->isAvail()) {
DrawEmptyPane(pDC, pDoc);
return;
}
CDC memDC;
memDC.CreateCompatibleDC(pDC);
CBitmap bitmap;
bitmap.CreateCompatibleBitmap(pDC, mWCanvas, mHCanvas);
memDC.SelectObject(bitmap);
memDC.SetStretchBltMode(COLORONCOLOR);
if (pDoc->mWDst < mWCanvas || pDoc->mHDst < mHCanvas)
memDC.FillSolidRect(CRect(0, 0, mWCanvas, mHCanvas), Q1UI_COLOR_CANVAS_BG);
q1::GridInfo gi;
ScaleRgbBuf(pDoc, pane->rgbBuf, gi);
#ifdef USE_STRETCH_DIB
StretchDIBits(memDC.m_hDC,
mXDst, mYDst, pDoc->mWDst, pDoc->mHDst,
0, 0, pDoc->mW, pDoc->mH,
pane->rgbBuf, &pDoc->mBmi, DIB_RGB_COLORS, SRCCOPY); // main image
#else
SetDIBitsToDevice(memDC.m_hDC,
0, 0, mWClient, mHClient,
0, 0, 0, mHClient,
mRgbBuf, &pDoc->mBmi, DIB_RGB_COLORS);
#endif
if (pDoc->mN > ZOOM_TEXT_START) {
CString label;
CRect rect;
LOGFONT lf;
CFont pixelTextFont;
mDefPixelTextFont.GetLogFont(&lf);
lf.lfHeight = LONG(pDoc->mN * 4 / 15);
pixelTextFont.CreateFontIndirect(&lf);
memDC.SelectObject(&pixelTextFont);
memDC.SetTextColor(COLOR_PIXEL_TEXT);
memDC.DrawText(_T("000\n000\n000"), -1, rect, DT_CENTER | DT_CALCRECT);
int y = gi.y;
for (int i = 0; i < (int)gi.Hs.size(); i++) {
int x = gi.x;
for (int j = 0; j < (int)gi.Ws.size(); j++) {
cv::Vec3b px = gi.pixelMap.at<cv::Vec3b>(i, j);
label.Format(pDoc->mRgbFormat, px[2], px[1], px[0]);
CRect rect(x, y + (gi.Hs[i] - rect.Height()) / 2,
x + gi.Ws[j] - 1, y + gi.Hs[i] - 1);
memDC.SetBkColor(RGB((0x80+px[2])/2, (0x80+px[1])/2, (0x80+px[0])/2));
memDC.DrawText(label, &rect, DT_CENTER | DT_VCENTER);
x += gi.Ws[j];
}
y += gi.Hs[i];
}
}
pDC->BitBlt(0, mRcControls.bottom, mWCanvas, mHCanvas, &memDC, 0, 0, SRCCOPY);
mProcessing = false;
}
void CComparerView::DrawEmptyPane(CDC *pDC, CComparerDoc *pDoc)
{
CRect canvas(0, mRcControls.bottom, mWClient, mHClient);
pDC->FillSolidRect(canvas, Q1UI_COLOR_CANVAS_BG);
LOGFONT lf;
mDefPixelTextFont.GetLogFont(&lf);
::lstrcpy(lf.lfFaceName, Q1UI_FONT_TEXT);
CFont titleFont;
lf.lfHeight = 18;
lf.lfWeight = FW_SEMIBOLD;
titleFont.CreateFontIndirect(&lf);
CFont bodyFont;
lf.lfHeight = 13;
lf.lfWeight = FW_NORMAL;
bodyFont.CreateFontIndirect(&lf);
CString title(_T("Drop a frame source"));
CString body(_T("Use 2-4 panes to compare images, raw dumps, or video frames"));
CRect textRect = canvas;
textRect.DeflateRect(12, 12);
CRect titleRect = textRect;
titleRect.bottom = canvas.CenterPoint().y - 3;
CRect bodyRect = textRect;
bodyRect.top = canvas.CenterPoint().y + 6;
pDC->SetBkMode(TRANSPARENT);
CFont *prevFont = pDC->SelectObject(&titleFont);
pDC->SetTextColor(Q1UI_COLOR_TEXT);
pDC->DrawText(title, &titleRect, DT_SINGLELINE | DT_CENTER | DT_BOTTOM | DT_END_ELLIPSIS);
pDC->SelectObject(&bodyFont);
pDC->SetTextColor(Q1UI_COLOR_TEXT_MUTED);
pDC->DrawText(body, &bodyRect, DT_SINGLELINE | DT_CENTER | DT_TOP | DT_END_ELLIPSIS);
pDC->SelectObject(prevFont);
}
#ifdef _DEBUG
void CComparerView::AssertValid() const
{
CScrollView::AssertValid();
}
#ifndef _WIN32_WCE
void CComparerView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
#endif
CComparerDoc* CComparerView::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CComparerDoc)));
return (CComparerDoc*)m_pDocument;
}
#endif //_DEBUG
int CComparerView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CScrollView::OnCreate(lpCreateStruct) == -1)
return -1;
DragAcceptFiles(TRUE);
CString str = CA2W(qcsc_info_table[QIMG_DEF_CS_IDX].name);
str.MakeUpper();
mCsQMenu.Create(str, mRcCsQMenu, this, &mCsMenu);
mCsQMenu.CalcRect(&mRcCsQMenu);
mRcCsQMenu.InflateRect(0, 0, 0, QMENUITEM_IN_MARGIN_H);
mCsQMenu.MoveWindow(&mRcCsQMenu);
mRcControls.bottom = mRcCsQMenu.bottom;
mRcNameQMenu.left = mRcCsQMenu.right;
mNameQMenu.Create(CString(""), mRcNameQMenu, this, NULL, DT_RIGHT);
mNameQMenu.CalcRect(&mRcNameQMenu);
mRcNameQMenu.InflateRect(0, 0, 0, QMENUITEM_IN_MARGIN_H);
mNameQMenu.MoveWindow(&mRcNameQMenu);
return 0;
}
void CComparerView::OnDropFiles(HDROP hDropInfo)
{
UINT uDragCount = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0);
if (uDragCount <= 0) {
CScrollView::OnDropFiles(hDropInfo);
return;
}
std::vector<CString> filenames(uDragCount);
for (UINT i = 0; i < uDragCount; i++) {
TCHAR szPathName[MAX_PATH];
DragQueryFile(hDropInfo, i, szPathName, MAX_PATH);
filenames[i] = szPathName;
}
CComparerDoc *pDoc = GetDocument();
if (uDragCount == 1) {
ComparerPane* pane = GetPane(pDoc);
const int previousW = pDoc->mW;
const int previousH = pDoc->mH;
pane->pathName = filenames[0];
pDoc->ProcessDocument(mPane);
CPosInfoView* posInfoView = pDoc->mPosInfoView;
posInfoView->ConfigureScrollSizes(pDoc);
CMainFrame* pMainFrm = static_cast<CMainFrame*>(AfxGetMainWnd());
pMainFrm->UpdateResolutionLabel(pDoc->mW, pDoc->mH);
pMainFrm->CheckResolutionRadio(pDoc->mW, pDoc->mH);
AdjustWindowSize(pMainFrm->mNumOfViews);
if (previousW != pDoc->mW || previousH != pDoc->mH)
pDoc->ResetViewToFit();
pDoc->UpdateAllViews(NULL);
} else {
pDoc->OpenMultiFiles(filenames);
}
CScrollView::OnDropFiles(hDropInfo);
}
BOOL CComparerView::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
void CComparerView::AdjustWindowSize(int numPrevViews, int splitBarChange) const
{
CComparerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CSize fullScnSz;
fullScnSz.cx = (LONG)::GetSystemMetrics(SM_CXFULLSCREEN);
fullScnSz.cy = (LONG)::GetSystemMetrics(SM_CYFULLSCREEN);
CMainFrame *pMainFrm = static_cast<CMainFrame *>(AfxGetMainWnd());
DWORD dsStyle = pMainFrm->GetStyle();
DWORD dsStyleEx = pMainFrm->GetExStyle();
CRect mainRcClient, viewRcClient;
pMainFrm->GetClientRect(&mainRcClient);
GetClientRect(&viewRcClient);
// Preserve the current frame overhead while resizing for the active panes.
int wGap = mainRcClient.Width() - viewRcClient.Width() * numPrevViews;
int hGap = mainRcClient.Height() - viewRcClient.Height();
int wViewClient = MAX(CANVAS_DEF_W, pDoc->mW);
int hViewClient = MAX(CANVAS_DEF_H, pDoc->mH) + mRcControls.bottom;
int wMainWindow = wViewClient * pMainFrm->mNumOfViews + wGap + splitBarChange;
int hMainWindow = hViewClient + hGap;
if (wMainWindow >= fullScnSz.cx || hMainWindow >= fullScnSz.cy) {
if (!pMainFrm->IsZoomed()) {
pMainFrm->SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE,
(LPARAM)pMainFrm->GetSafeHwnd());
}
return;
} else if (pMainFrm->IsZoomed()) {
// Restore first so resizing is based on normal frame geometry.
pMainFrm->SendMessage(WM_SYSCOMMAND, SC_RESTORE,
(LPARAM)pMainFrm->GetSafeHwnd());
}
CRect rcWin(0, 0, wMainWindow, hMainWindow);
::AdjustWindowRectEx(&rcWin, dsStyle, TRUE, dsStyleEx);
pMainFrm->SetWindowPos(NULL, 0, 0,
rcWin.Width(), rcWin.Height(), SWP_NOMOVE | SWP_FRAMECHANGED);
}
void CComparerView::DeterminDestOriginCoord(CComparerDoc *pDoc)
{
mXDst = q1::DeterminDestPos(mWCanvas, pDoc->mWDst, pDoc->mXOff, pDoc->mN);
mYDst = q1::DeterminDestPos(mHCanvas, pDoc->mHDst, pDoc->mYOff, pDoc->mN);
}
void CComparerView::Initialize(CComparerDoc *pDoc)
{
// OnSize has already updated the client and canvas dimensions.
DeterminDestOriginCoord(pDoc);
}
BOOL CComparerView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
CPoint clientPoint;
CComparerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
goto OnMouseWheelDefault;
clientPoint.x = pt.x;
clientPoint.y = pt.y - mRcCsQMenu.bottom;
ScreenToClient(&clientPoint);
float xShift = clientPoint.x - (float)mWCanvas / 2 + 0.5f;
float yShift = clientPoint.y - (float)mHCanvas / 2 + 0.5f;
pDoc->mXOff -= xShift / pDoc->mN;
pDoc->mYOff -= yShift / pDoc->mN;
pDoc->ViewOnMouseWheel(zDelta, mWCanvas, mHCanvas);
pDoc->mXOff += xShift / pDoc->mN;
pDoc->mYOff += yShift / pDoc->mN;
DeterminDestOriginCoord(pDoc);
for (auto view : GetOhterViews(pDoc))
view->DeterminDestOriginCoord(pDoc);
pDoc->UpdateAllViews(NULL);
OnMouseWheelDefault:
return CScrollView::OnMouseWheel(nFlags, zDelta, pt);
}
void CComparerView::OnSize(UINT nType, int cx, int cy)
{
CScrollView::OnSize(nType, cx, cy);
CComparerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
mRcControls.right = cx;
mWClient = cx;
mHClient = cy;
mWCanvas = mWClient;
mHCanvas = mHClient - mRcControls.bottom;
mRcNameQMenu.right = mWClient;
if (mNameQMenu.GetSafeHwnd())
mNameQMenu.MoveWindow(mRcNameQMenu);
DeterminDestOriginCoord(pDoc);
}
void CComparerView::OnMouseMove(UINT nFlags, CPoint point)
{
CComparerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
goto OnMouseMoveDefault;
if (mIsClicked) {
pDoc->mXOff = pDoc->mXInitOff + (point.x - mPointS.x) / pDoc->mN;
pDoc->mYOff = pDoc->mYInitOff + (point.y - mPointS.y) / pDoc->mN;
DeterminDestOriginCoord(pDoc);
for (auto view : GetOhterViews(pDoc))
view->DeterminDestOriginCoord(pDoc);
Invalidate(FALSE);
for (auto view : GetOhterViews(pDoc))
view->Invalidate(FALSE);
}
OnMouseMoveDefault:
CScrollView::OnMouseMove(nFlags, point);
}
void CComparerView::OnLButtonDown(UINT nFlags, CPoint point)
{
SetCapture();
CComparerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc || mRcControls.PtInRect(point)) {
CScrollView::OnLButtonDown(nFlags, point);
return;
}
mIsClicked = true;
mPointS = point;
pDoc->mXInitOff = pDoc->mXOff;
pDoc->mYInitOff = pDoc->mYOff;
::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_HAND));
CScrollView::OnLButtonDown(nFlags, point);
}
void CComparerView::OnLButtonUp(UINT nFlags, CPoint point)
{
mIsClicked = false;
::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
CScrollView::OnLButtonUp(nFlags, point);
::ReleaseCapture();
}
BOOL CComparerView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (mIsClicked) {
::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_HAND));
return TRUE;
}
return CScrollView::OnSetCursor(pWnd, nHitTest, message);
}
void CComparerView::CheckCsRadio(int cs)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(qcsc_info_table); i++) {
if (qcsc_info_table[i].cs == cs)
break;
}
ASSERT(i < ARRAY_SIZE(qcsc_info_table));
UINT id = ID_CS_START + i;
mCsMenu.CheckMenuRadioItem(ID_CS_START, ID_CS_END,
id, MF_CHECKED | MF_BYCOMMAND);
}
void CComparerView::UpdateCsLabel(const TCHAR *csLabel)
{
mCsQMenu.SetWindowText(csLabel);
mCsQMenu.CalcRect(&mRcCsQMenu);
mRcCsQMenu.InflateRect(0, 0, 0, QMENUITEM_IN_MARGIN_H);
mCsQMenu.MoveWindow(&mRcCsQMenu);
mRcNameQMenu.left = mRcCsQMenu.right;
mNameQMenu.MoveWindow(mRcNameQMenu);
}
void CComparerView::UpdateFileName(const TCHAR* filename)
{
mNameQMenu.SetWindowText(filename);
mCsQMenu.CalcRect(&mRcCsQMenu);
mRcNameQMenu.left = mRcCsQMenu.right;
mNameQMenu.MoveWindow(mRcNameQMenu);
}
void CComparerView::OnCsChange(UINT nID)
{
CComparerDoc* pDoc = GetDocument();
CString str;
mCsMenu.GetMenuString(nID, str, MF_BYCOMMAND);
str.MakeLower();
const struct qcsc_info * const ci =
q1::image_find_cs(pDoc->mSortedCscInfo, CT2A(str));
if (ci == NULL) {
LOGERR("couldn't get the right index of color space");
return;
}
ComparerPane *pane = GetPane(pDoc);
if (ci->cs == pane->colorSpace)
return;
UpdateCsLabel(str.MakeUpper());
CheckCsRadio(ci->cs);
pane->SetColorInfo(ci);
if (pane->isAvail()) {
pDoc->RefleshPaneImages(pane, true);
// Recompute timeline geometry after frame counts are refreshed.
CPosInfoView* posInfoView = pDoc->mPosInfoView;
posInfoView->ConfigureScrollSizes(pDoc);
pDoc->UpdateAllViews(NULL);
}
}
void CComparerView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CComparerDoc* pDoc = GetDocument();
bool isProcessing = pDoc->CheckImgViewProcessing();
if (nChar != VK_SPACE && isProcessing)
return;
CMainFrame *pMainFrm = static_cast<CMainFrame *>(AfxGetMainWnd());
switch (nChar) {
case VK_RIGHT:
pDoc->OffsetScenes(1);
break;
case VK_LEFT:
pDoc->OffsetScenes(-1);
break;
case VK_SPACE:
if (!pDoc->mIsPlaying) {
pDoc->mIsPlaying = true;
pMainFrm->SetTimer(CTI_ID_PLAY, ROUND2I((1000 / pDoc->mFps) - FPS_ADJUSTMENT), NULL);
bool changed = pDoc->NextScenes();
if (!changed)
pDoc->SetScenes(0);
} else {
pDoc->KillPlayTimer();
}
break;
case 'H': // Toggle hexadecimal pixel values.
pDoc->mHexMode = !pDoc->mHexMode;
pDoc->mRgbFormat = pDoc->mHexMode ? pDoc->mRgbHex : pDoc->mRgbDec;
Invalidate(FALSE);
break;
case 'I':
pDoc->mInterpol = !pDoc->mInterpol;
Invalidate(FALSE);
break;
}
// Most shortcuts affect shared document/view state, so refresh once at the end.
pDoc->MarkImgViewProcessing();
pDoc->UpdateAllViews(NULL);
CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
}
std::vector<CComparerView *> CComparerView::GetOhterViews(CComparerDoc* pDoc)
{
CMainFrame* pMainFrm = static_cast<CMainFrame*>(AfxGetMainWnd());
std::vector<CComparerView *> otherViews;
for (int i = 0; i < pMainFrm->mNumOfViews; i++) {
CComparerView* pView = pDoc->mPane[i].pView;
if (pView == this)
continue;
otherViews.push_back(pView);
}
return otherViews;
}
ComparerPane* CComparerView::GetPane(CComparerDoc* pDoc) const
{
for (int i = 0; i < CComparerDoc::IMG_VIEW_MAX; i++) {
CComparerView* pView = pDoc->mPane[i].pView;
if (pView == this)
return &pDoc->mPane[i];
}
return nullptr;
}
void CComparerView::OnRButtonDown(UINT nFlags, CPoint point)
{
CScrollView::OnRButtonDown(nFlags, point);
}