dsrc isn't necessary for this repo
[client-tools.git] / src / external / 3rd / application / UiBuilder / SelectRegion.cpp
blob2d6d5ed5290b18989fb3aed13b206eac1a310778
1 #include "FirstUiBuilder.h"
2 #include "SelectRegion.h"
4 #include "resource.h"
5 #include "UIDirect3DPrimaryCanvas.h"
6 #include "UIImage.h"
7 #include "UIImageFrame.h"
8 #include "UIImageStyle.h"
9 #include "UIUtils.h"
10 #include "UnicodeUtils.h"
12 #include <cstdio>
14 SelectRegionDialogBox *SelectRegionDialogBox::sThis = 0;
16 extern UIColor gHighlightOutlineColor;
17 extern UIColor gHighlightFillColor;
19 extern HWND gTooltip;
20 extern void AddTooltipFromControlID( HWND TooltipWindow, HWND ParentWindow, UINT ControlID, char *Tooltip );
21 extern void ClearDefPushButtonLook( HWND hwndDlg, UINT nControlID );
22 extern void MoveSizeDlgControl( HWND hwnd, UINT itemID, UIPoint Move, UIPoint Size );
24 static const float cMaxZoomLevel = 8.0f;
26 //-----------------------------------------------------------------
28 SelectRegionDialogBox::SelectRegionDialogBox( void ) :
29 mHwnd(0),
30 mStyle(0),
31 mImage(0),
32 mDisplay(0),
33 mZoomLevel(1.0f),
34 mImageSize(0,0),
35 mScrollOffset(0,0),
36 mOldSize(0,0),
37 mDrawHighlight(true)
39 mSelectionRect.SetUseBounds (true);
42 //-----------------------------------------------------------------
44 bool SelectRegionDialogBox::EditProperty( HWND hwndParent, UIImageStyle *theStyle, UIString &Value )
46 bool rv = false;
48 mImage = new UIImage;
50 mStyle = UI_ASOBJECT(UIImageStyle, theStyle->DuplicateObject());
51 const UICanvas * const theCanvas = theStyle->GetSourceCanvas();
53 if (!theCanvas)
54 return false;
56 theCanvas->GetSize (mImageSize);
58 const UIRect bounds (mImageSize);
59 mSelectionRect.SetBounds (bounds);
61 mImage->SetCanvas (const_cast<UICanvas *>(theCanvas));
62 mImage->SetSourceRect (&bounds);
64 mImage->SetSize( mImageSize );
65 UIUtils::ParseRect( Value, mRegion );
66 mSelectionRect.SetRect( mRegion );
68 sThis = this;
70 if( DialogBox( GetModuleHandle(0), MAKEINTRESOURCE(IDD_SELECTREGION), hwndParent, StaticDialogProc ) )
72 UIUtils::FormatRect( Value, mRegion );
73 rv = true;
76 mImage = 0;
77 mStyle = 0;
79 return rv;
82 //-----------------------------------------------------------------
84 bool SelectRegionDialogBox::EditProperty( HWND hwndParent, UIImage *theImage, UIString &Value )
86 bool rv = false;
88 mImage = UI_ASOBJECT(UIImage, theImage->DuplicateObject());
90 const UICanvas *theCanvas = mImage->GetCanvas();
92 if( !theCanvas )
93 return false;
95 const UIRect src( 0, 0, theCanvas->GetWidth(), theCanvas->GetHeight() );
96 mImage->SetSourceRect( &src );
97 mImageSize = UISize( theCanvas->GetWidth(), theCanvas->GetHeight() );
98 mImage->SetColor(UIColor::white);
99 mImage->SetBackgroundOpacity(0.0f);
100 mImage->SetMaximumSize( mImageSize );
101 mImage->SetSize( mImageSize );
102 mSelectionRect.SetBounds ( UIRect ( 0, 0, mImageSize.x, mImageSize.y ) );
103 UIUtils::ParseRect( Value, mRegion );
104 mSelectionRect.SetRect( mRegion );
106 sThis = this;
108 if( DialogBox( GetModuleHandle(0), MAKEINTRESOURCE(IDD_SELECTREGION), hwndParent, StaticDialogProc ) )
110 UIUtils::FormatRect( Value, mRegion );
111 rv = true;
114 mImage = 0;
115 mStyle = 0;
117 return rv;
120 //-----------------------------------------------------------------
122 void SelectRegionDialogBox::UpdateTextbox( void )
124 UIString RectString;
125 UIUtils::FormatRect( RectString, mRegion );
126 SetDlgItemText( mHwnd, IDC_VALUE, Unicode::wideToNarrow (RectString).c_str() );
129 //-----------------------------------------------------------------
131 void SelectRegionDialogBox::UpdateSelectionRect( void )
133 mSelectionRect.SetRect( mRegion );
136 //-----------------------------------------------------------------
138 void SelectRegionDialogBox::ReadRectFromTextbox( void )
140 HWND hControl = GetDlgItem( mHwnd, IDC_VALUE );
141 long TextLength = SendMessage( hControl, WM_GETTEXTLENGTH, 0, 0 ) + 1;
142 char *Buffer = new char[ TextLength ];
144 SendMessage( hControl, WM_GETTEXT, TextLength, (LPARAM)Buffer );
146 UIUtils::ParseRect( Buffer, mRegion );
149 //-----------------------------------------------------------------
151 void SelectRegionDialogBox::EnableControls( void )
153 if( mZoomLevel <= 1.0f )
155 EnableWindow( GetDlgItem( mHwnd, IDC_ZOOMIN ), TRUE );
156 EnableWindow( GetDlgItem( mHwnd, IDC_ZOOMOUT ), FALSE );
158 else if( mZoomLevel >= cMaxZoomLevel )
160 EnableWindow( GetDlgItem( mHwnd, IDC_ZOOMIN ), FALSE );
161 EnableWindow( GetDlgItem( mHwnd, IDC_ZOOMOUT ), TRUE );
163 else
165 EnableWindow( GetDlgItem( mHwnd, IDC_ZOOMIN ), TRUE );
166 EnableWindow( GetDlgItem( mHwnd, IDC_ZOOMOUT ), TRUE );
170 //-----------------------------------------------------------------
172 void SelectRegionDialogBox::UpdateScrollbars( HWND hwnd, const UIPoint * center)
174 UISize ZoomedImageSize( UIScalar( float(mImageSize.x) * mZoomLevel ), UIScalar( float(mImageSize.y) * mZoomLevel ) );
175 RECT rc;
177 GetWindowRect( hwnd, &rc );
179 rc.right -= rc.left;
180 rc.left = 0;
182 rc.bottom -= rc.top;
183 rc.top = 0;
185 if( rc.right < ZoomedImageSize.x || rc.bottom < ZoomedImageSize.y )
186 GetClientRect( hwnd, &rc );
188 UISize NewSize( rc.right, rc.bottom );
190 //-----------------------------------------------------------------
191 //-- center on the specified pixel
193 if (center)
195 mScrollOffset.x = static_cast<long>(static_cast<float>(center->x) * mZoomLevel) - rc.right / 2;
196 mScrollOffset.y = static_cast<long>(static_cast<float>(center->y) * mZoomLevel) - rc.bottom / 2;
199 // Validate scroll positions
200 if( mScrollOffset.x + NewSize.x > ZoomedImageSize.x )
201 mScrollOffset.x = ZoomedImageSize.x - NewSize.x;
203 if( mScrollOffset.x < 0 )
204 mScrollOffset.x = 0;
206 if( mScrollOffset.y + NewSize.y > ZoomedImageSize.y )
207 mScrollOffset.y = ZoomedImageSize.y - NewSize.y;
209 if( mScrollOffset.y < 0 )
210 mScrollOffset.y = 0;
212 SCROLLINFO si;
213 si.cbSize = sizeof( si );
214 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
215 si.nPage = NewSize.x;
216 si.nMin = 0;
217 si.nMax = ZoomedImageSize.x;
218 si.nPos = mScrollOffset.x;
220 SetScrollInfo( hwnd, SB_HORZ, &si, TRUE );
222 si.cbSize = sizeof( si );
223 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
224 si.nPage = NewSize.y;
225 si.nMin = 0;
226 si.nMax = ZoomedImageSize.y;
227 si.nPos = mScrollOffset.y;
229 SetScrollInfo( hwnd, SB_VERT, &si, TRUE );
232 //-----------------------------------------------------------------
234 void SelectRegionDialogBox::UpdateCanvasScrollPosition( HWND hwnd, UINT uMsg, WPARAM wParam )
236 UISize ZoomedImageSize( UIScalar( float(mImageSize.x) * mZoomLevel ), UIScalar( float(mImageSize.y) * mZoomLevel ) );
237 RECT rc;
239 GetWindowRect( hwnd, &rc );
241 rc.right -= rc.left;
242 rc.left = 0;
244 rc.bottom -= rc.top;
245 rc.top = 0;
247 if( rc.right < ZoomedImageSize.x || rc.bottom < ZoomedImageSize.y )
248 GetClientRect( hwnd, &rc );
250 UISize NewSize( rc.right, rc.bottom );
252 if( uMsg == WM_HSCROLL )
254 switch( LOWORD( wParam ) )
256 case SB_LEFT:
257 mScrollOffset.x = 0;
258 break;
260 case SB_RIGHT:
261 mScrollOffset.x = ZoomedImageSize.x - NewSize.x;
262 break;
264 case SB_LINELEFT:
265 mScrollOffset.x -= int( mZoomLevel );
267 if( mScrollOffset.x < 0 )
268 mScrollOffset.x = 0;
269 break;
271 case SB_LINERIGHT:
272 mScrollOffset.x += int( mZoomLevel );
274 if( mScrollOffset.x > ZoomedImageSize.x - NewSize.x )
275 mScrollOffset.x = ZoomedImageSize.x - NewSize.x;
277 break;
279 case SB_PAGELEFT:
280 mScrollOffset.x -= int( 10.0f * mZoomLevel );
282 if( mScrollOffset.x < 0 )
283 mScrollOffset.x = 0;
285 break;
287 case SB_PAGERIGHT:
288 mScrollOffset.x += int( 10.0f * mZoomLevel );
290 if( mScrollOffset.x > ZoomedImageSize.x - NewSize.x )
291 mScrollOffset.x = ZoomedImageSize.x - NewSize.x;
293 break;
295 case SB_THUMBTRACK:
296 SCROLLINFO si;
297 si.cbSize = sizeof( si );
298 si.fMask = SIF_TRACKPOS;
300 GetScrollInfo( hwnd, SB_HORZ, &si );
301 mScrollOffset.x = si.nTrackPos;
302 break;
305 else
307 switch( LOWORD( wParam ) )
309 case SB_LEFT:
310 mScrollOffset.y = 0;
311 break;
313 case SB_RIGHT:
314 mScrollOffset.y = ZoomedImageSize.y - NewSize.y;
315 break;
317 case SB_LINELEFT:
318 mScrollOffset.y -= int( mZoomLevel );
320 if( mScrollOffset.y < 0 )
321 mScrollOffset.y = 0;
322 break;
324 case SB_LINERIGHT:
325 mScrollOffset.y += int( mZoomLevel );
327 if( mScrollOffset.y > ZoomedImageSize.y - NewSize.y )
328 mScrollOffset.y = ZoomedImageSize.y - NewSize.y;
330 break;
332 case SB_PAGELEFT:
333 mScrollOffset.y -= int( 10.0f * mZoomLevel );
335 if( mScrollOffset.y < 0 )
336 mScrollOffset.y = 0;
338 break;
340 case SB_PAGERIGHT:
341 mScrollOffset.y += int( 10.0f * mZoomLevel );
343 if( mScrollOffset.y > ZoomedImageSize.y - NewSize.y )
344 mScrollOffset.y = ZoomedImageSize.y - NewSize.y;
346 break;
348 case SB_THUMBTRACK:
349 SCROLLINFO si;
350 si.cbSize = sizeof( si );
351 si.fMask = SIF_TRACKPOS;
353 GetScrollInfo( hwnd, SB_VERT, &si );
354 mScrollOffset.y = si.nTrackPos;
355 break;
360 //-----------------------------------------------------------------
362 void SelectRegionDialogBox::SizeToContent( void )
364 RECT rcDialog;
365 RECT rcImage;
366 RECT rcDesktop;
368 GetWindowRect( mHwnd, &rcDialog );
369 GetWindowRect( GetDlgItem( mHwnd, IDC_CANVAS ), &rcImage );
371 // Note, I'm not using this rect as a rect, the right and bottom elements
372 // are actually the width and height.
373 rcDialog.right -= rcDialog.left; rcDialog.left = 0;
374 rcDialog.bottom -= rcDialog.top; rcDialog.top = 0;
376 rcImage.right -= rcImage.left; rcImage.left = 0;
377 rcImage.bottom -= rcImage.top; rcImage.top = 0;
379 UISize ZoomedImageSize( UIScalar( float(mImageSize.x) * mZoomLevel ), UIScalar( float(mImageSize.y) * mZoomLevel ) );
381 while( (ZoomedImageSize.x < rcImage.right) && (ZoomedImageSize.y < rcImage.bottom ) )
383 mZoomLevel *= 2.0f;
385 ZoomedImageSize.x = UIScalar( float(mImageSize.x) * mZoomLevel );
386 ZoomedImageSize.y = UIScalar( float(mImageSize.y) * mZoomLevel );
388 if( mZoomLevel >= cMaxZoomLevel )
390 mZoomLevel = cMaxZoomLevel;
391 break;
395 rcDialog.right = rcDialog.right - rcImage.right + ZoomedImageSize.x + 1;
396 rcDialog.bottom = rcDialog.bottom - rcImage.bottom + ZoomedImageSize.y + 1;
398 SystemParametersInfo( SPI_GETWORKAREA, 0, &rcDesktop, 0 );
400 // Center on desktop
401 rcDialog.left = (rcDesktop.right - rcDesktop.left) / 2 + rcDesktop.left - rcDialog.right / 2;
402 rcDialog.top = (rcDesktop.bottom - rcDesktop.top) / 2 + rcDesktop.top - rcDialog.bottom / 2;
404 MoveWindow( mHwnd, rcDialog.left, rcDialog.top, rcDialog.right, rcDialog.bottom, TRUE );
407 //-----------------------------------------------------------------
409 void SelectRegionDialogBox::ShowZoomLevel( void )
411 char Buffer[256];
413 if( mZoomLevel != 1.0f )
414 sprintf( Buffer, "(%d%% Zoom)", int(mZoomLevel * 100.0f) );
415 else
416 sprintf( Buffer, "(Actual Pixels)" );
418 SetDlgItemText( mHwnd, IDC_ZOOMLEVEL, Buffer );
421 //-----------------------------------------------------------------
423 LPARAM SelectRegionDialogBox::InverseTranslateLParam( LPARAM lParam )
425 long x = LOWORD( lParam );
426 long y = HIWORD( lParam );
428 x += mScrollOffset.x;
429 y += mScrollOffset.y;
431 x = static_cast<long>( static_cast<float>(x) / mZoomLevel );
432 y = static_cast<long>( static_cast<float>(y) / mZoomLevel );
434 return MAKELPARAM( x, y );
437 //-----------------------------------------------------------------
439 BOOL CALLBACK SelectRegionDialogBox::DialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
441 switch( uMsg )
443 case WM_INITDIALOG:
445 mHwnd = hwndDlg;
446 UpdateTextbox();
447 UpdateSelectionRect();
449 HWND theCanvasWindow = GetDlgItem( hwndDlg, IDC_CANVAS );
451 if( theCanvasWindow )
453 sThis = this;
454 SetWindowLong( theCanvasWindow, GWL_WNDPROC, (LONG)StaticCanvasProc );
455 SendMessage( theCanvasWindow, WM_APP, 0, 0 );
458 AddTooltipFromControlID( gTooltip, hwndDlg, IDC_ZOOMIN, "Zoom In" );
459 AddTooltipFromControlID( gTooltip, hwndDlg, IDC_ZOOMOUT, "Zoom Out" );
461 SendDlgItemMessage( hwndDlg, IDC_ZOOMIN, BM_SETIMAGE, IMAGE_ICON,
462 (LPARAM)LoadImage( GetModuleHandle(0), MAKEINTRESOURCE(IDI_ZOOMIN), IMAGE_ICON, 16, 16, 0 ) );
463 SendDlgItemMessage( hwndDlg, IDC_ZOOMOUT, BM_SETIMAGE, IMAGE_ICON,
464 (LPARAM)LoadImage( GetModuleHandle(0), MAKEINTRESOURCE(IDI_ZOOMOUT), IMAGE_ICON, 16, 16, 0 ) );
466 SendDlgItemMessage( hwndDlg, IDC_DRAWHIGHLIGHT, BM_SETIMAGE, IMAGE_ICON,
467 (LPARAM)LoadImage( GetModuleHandle(0), MAKEINTRESOURCE(IDI_DRAWHIGHLIGHT), IMAGE_ICON, 16, 16, 0 ) );
468 CheckDlgButton( hwndDlg, IDC_DRAWHIGHLIGHT, BST_CHECKED );
470 mZoomLevel = 1.0f;
472 RECT rcClient;
473 GetClientRect( hwndDlg, &rcClient );
474 SendMessage( hwndDlg, WM_SIZE, 0, MAKELPARAM( rcClient.right, rcClient.bottom ) );
476 SizeToContent();
477 EnableControls();
478 ShowZoomLevel();
479 return TRUE;
482 case WM_CLOSE:
483 // Equivalent to pressing cancel
484 EndDialog( hwndDlg, 0 );
485 return 0;
487 case WM_GETMINMAXINFO:
489 LPMINMAXINFO pmmi = (LPMINMAXINFO)lParam;
490 RECT rc;
492 rc.left = 0;
493 rc.top = 0;
494 rc.right = mInitialSize.x;
495 rc.bottom = mInitialSize.y;
497 AdjustWindowRectEx( &rc, GetWindowLong( hwndDlg, GWL_STYLE ), TRUE, GetWindowLong( hwndDlg, GWL_EXSTYLE ) );
498 pmmi->ptMinTrackSize.x = rc.right - rc.left;
499 pmmi->ptMinTrackSize.y = rc.bottom - rc.top;
501 return 0;
504 case WM_SIZE:
506 UISize NewSize;
508 NewSize.x = LOWORD(lParam);
509 NewSize.y = HIWORD(lParam);
511 if( (NewSize.x == 0) || (NewSize.y == 0) )
512 return 0;
514 if( mOldSize.x != 0 )
516 UISize DeltaSize = NewSize - mOldSize;
518 MoveSizeDlgControl( hwndDlg, IDC_CANVAS, UIPoint(0,0), UIPoint( DeltaSize.x, DeltaSize.y ) );
519 MoveSizeDlgControl( hwndDlg, IDOK, UIPoint(DeltaSize.x,0), UIPoint( 0, 0 ) );
520 MoveSizeDlgControl( hwndDlg, IDCANCEL, UIPoint(DeltaSize.x,0), UIPoint( 0, 0 ) );
521 MoveSizeDlgControl( hwndDlg, IDC_DRAWHIGHLIGHT, UIPoint(DeltaSize.x,DeltaSize.y), UIPoint( 0, 0 ) );
522 MoveSizeDlgControl( hwndDlg, IDC_ZOOMIN, UIPoint(DeltaSize.x,DeltaSize.y), UIPoint( 0, 0 ) );
523 MoveSizeDlgControl( hwndDlg, IDC_ZOOMOUT, UIPoint(DeltaSize.x,DeltaSize.y), UIPoint( 0, 0 ) );
524 MoveSizeDlgControl( hwndDlg, IDC_ZOOMLEVEL, UIPoint(DeltaSize.x,DeltaSize.y), UIPoint( 0, 0 ) );
525 MoveSizeDlgControl( hwndDlg, IDC_VALUELABEL, UIPoint(0,DeltaSize.y), UIPoint( 0, 0 ) );
526 MoveSizeDlgControl( hwndDlg, IDC_VALUE, UIPoint(0,DeltaSize.y), UIPoint( DeltaSize.x, 0 ) );
528 else
529 mInitialSize = NewSize;
531 mOldSize = NewSize;
533 return 0;
536 case WM_COMMAND:
537 if( LOWORD( wParam ) == IDOK )
539 ReadRectFromTextbox();
540 EndDialog( hwndDlg, 1 );
542 else if( LOWORD( wParam ) == IDCANCEL )
543 EndDialog( hwndDlg, 0 );
544 else if( LOWORD( wParam ) == IDC_DRAWHIGHLIGHT )
546 mDrawHighlight = IsDlgButtonChecked( hwndDlg, IDC_DRAWHIGHLIGHT ) != 0;
547 SetFocus( GetDlgItem( hwndDlg, IDC_VALUE ) );
548 InvalidateRect( GetDlgItem( hwndDlg, IDC_CANVAS ), 0, FALSE );
550 else if( LOWORD( wParam ) == IDC_ZOOMIN )
552 if( HIWORD(wParam) == BN_CLICKED )
554 SetFocus( GetDlgItem( hwndDlg, IDC_VALUE ) );
555 ClearDefPushButtonLook( hwndDlg, IDC_ZOOMIN );
557 mZoomLevel *= 2.0f;
558 if( mZoomLevel > cMaxZoomLevel )
559 mZoomLevel = cMaxZoomLevel;
560 EnableControls();
561 ShowZoomLevel();
563 const UIRect & rect = mSelectionRect.GetRect ();
564 const UIPoint center ((rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2);
566 UpdateScrollbars( GetDlgItem( hwndDlg, IDC_CANVAS ), &center );
567 InvalidateRect( GetDlgItem( hwndDlg, IDC_CANVAS ), 0, FALSE );
570 else if( LOWORD( wParam ) == IDC_ZOOMOUT )
572 if( HIWORD(wParam) == BN_CLICKED )
574 SetFocus( GetDlgItem( hwndDlg, IDC_VALUE ) );
575 ClearDefPushButtonLook( hwndDlg, IDC_ZOOMOUT );
577 mZoomLevel /= 2.0f;
578 if( mZoomLevel < 1.0f )
579 mZoomLevel = 1.0f;
580 EnableControls();
581 ShowZoomLevel();
583 const UIRect & rect = mSelectionRect.GetRect ();
584 const UIPoint center ((rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2);
586 UpdateScrollbars( GetDlgItem( hwndDlg, IDC_CANVAS ), &center );
587 InvalidateRect( GetDlgItem( hwndDlg, IDC_CANVAS ), 0, FALSE );
590 else if( LOWORD( wParam ) == IDC_VALUE )
592 if( HIWORD( wParam ) == EN_CHANGE )
594 ReadRectFromTextbox();
595 UpdateSelectionRect();
596 InvalidateRect( GetDlgItem( hwndDlg, IDC_CANVAS ), 0, FALSE );
600 return 0;
602 default:
603 return 0;
607 //-----------------------------------------------------------------
609 BOOL CALLBACK SelectRegionDialogBox::CanvasProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
611 switch( uMsg )
613 case WM_GETDLGCODE:
614 return DLGC_WANTARROWS;
616 case WM_NCHITTEST:
618 BOOL rc = DefWindowProc( hwnd, uMsg, wParam, lParam );
620 if( rc == HTNOWHERE )
621 rc = HTCLIENT;
623 return rc;
626 case WM_MOUSEACTIVATE:
627 return MA_ACTIVATE;
629 case WM_APP:
631 RECT rc;
632 GetClientRect( hwnd, &rc );
633 mDisplay = new UIDirect3DPrimaryCanvas( UISize( rc.right, rc.bottom ), hwnd, false );
634 mDisplay->Attach( 0 );
636 DWORD dwStyle = GetWindowLong( hwnd, GWL_STYLE );
638 dwStyle |= WS_HSCROLL;
639 dwStyle |= WS_VSCROLL;
641 SetWindowLong( hwnd, GWL_STYLE, dwStyle );
642 SendMessage( hwnd, WM_SIZE, 0, MAKELPARAM( rc.right, rc.bottom ) );
643 return 0;
646 case WM_SIZE:
648 UISize NewSize( LOWORD(lParam), HIWORD(lParam) );
649 UISize ZoomedImageSize( UIScalar( float(mImageSize.x) * mZoomLevel ), UIScalar( float(mImageSize.y) * mZoomLevel ) );
650 mDisplay->SetSize( NewSize );
652 UpdateScrollbars( hwnd );
653 return 0;
656 case WM_HSCROLL:
657 case WM_VSCROLL:
659 UpdateCanvasScrollPosition( hwnd, uMsg, wParam );
660 UpdateScrollbars( hwnd );
661 InvalidateRect( hwnd, 0, FALSE );
662 return 0;
665 case WM_PAINT:
667 PAINTSTRUCT ps;
669 BeginPaint( hwnd, &ps );
670 EndPaint( hwnd, &ps );
672 if( mDisplay->BeginRendering() )
674 UIColor FillColor;
675 DWORD dwFillColor = GetSysColor( COLOR_3DFACE );
676 dwFillColor = 0xff666666;
678 mDisplay->PushState();
680 FillColor.r = GetRValue( dwFillColor );
681 FillColor.g = GetGValue( dwFillColor );
682 FillColor.b = GetBValue( dwFillColor );
683 FillColor.a = 255;
685 mDisplay->SetOpacity( 1.0f );
686 mDisplay->ClearTo( FillColor, UIRect (0, 0, mDisplay->GetWidth (), mDisplay->GetHeight () ));
687 mDisplay->Translate( -mScrollOffset );
689 mDisplay->Scale( mZoomLevel, mZoomLevel );
690 mImage->Render( *mDisplay );
692 mDisplay->Flush();
694 if( mDrawHighlight )
696 mSelectionRect.SetFillColor( gHighlightFillColor );
697 mSelectionRect.SetOutlineColor( gHighlightOutlineColor );
698 mSelectionRect.SetCanDrawHandles( true );
699 mSelectionRect.Render( mDisplay );
702 mDisplay->EndRendering();
703 mDisplay->Flip();
705 mDisplay->PopState();
707 return 0;
710 case WM_LBUTTONDOWN:
711 case WM_MBUTTONDOWN:
712 case WM_RBUTTONDOWN:
713 SetCapture( hwnd );
714 mSelectionRect.ProcessMessage( hwnd, uMsg, wParam, InverseTranslateLParam( lParam ) );
715 InvalidateRect( hwnd, 0, FALSE );
716 mRegion = mSelectionRect.GetRect();
717 UpdateTextbox();
718 return 0;
720 case WM_LBUTTONUP:
721 case WM_MBUTTONUP:
722 case WM_RBUTTONUP:
723 ReleaseCapture();
724 mSelectionRect.ProcessMessage( hwnd, uMsg, wParam, InverseTranslateLParam( lParam ) );
725 InvalidateRect( hwnd, 0, FALSE );
726 mRegion = mSelectionRect.GetRect();
727 UpdateTextbox();
728 return 0;
730 case WM_MOUSEMOVE:
731 case WM_KEYDOWN:
732 mSelectionRect.ProcessMessage( hwnd, uMsg, wParam, InverseTranslateLParam( lParam ) );
733 InvalidateRect( hwnd, 0, FALSE );
734 mRegion = mSelectionRect.GetRect();
735 UpdateTextbox();
736 return 0;
738 case WM_ERASEBKGND:
739 return 1;
741 case WM_DESTROY:
742 mDisplay->Detach();
743 mDisplay = 0;
744 return DefWindowProc( hwnd, uMsg, wParam, lParam );
746 default:
747 return DefWindowProc( hwnd, uMsg, wParam, lParam );
751 //-----------------------------------------------------------------
753 BOOL CALLBACK SelectRegionDialogBox::StaticCanvasProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
755 SelectRegionDialogBox *thisCache = static_cast<SelectRegionDialogBox *>( GetProp( hwnd, "this" ) );
757 if( !thisCache )
759 thisCache = sThis;
760 SetProp( hwnd, "this", sThis );
763 return thisCache->CanvasProc( hwnd, uMsg, wParam, lParam );
766 //-----------------------------------------------------------------
768 BOOL CALLBACK SelectRegionDialogBox::StaticDialogProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
770 SelectRegionDialogBox *thisCache = static_cast<SelectRegionDialogBox *>( GetProp( hwnd, "this" ) );
772 if( !thisCache )
774 thisCache = sThis;
775 SetProp( hwnd, "this", sThis );
778 return thisCache->DialogProc( hwnd, uMsg, wParam, lParam );