wxArt2D
sttoolext.cpp
1 /*! \file editor/src/sttoolext.cpp
2  \author Klaas Holwerda
3 
4  Copyright: 2001-2004 (c) Klaas Holwerda
5 
6  Licence: wxWidgets Licence
7 
8  RCS-ID: $Id: sttoolext.cpp,v 1.28 2008/08/19 23:17:13 titato Exp $
9 */
10 
11 #include "a2dprec.h"
12 
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16 
17 #ifndef WX_PRECOMP
18 #include "wx/wx.h"
19 #endif
20 
21 #include "a2dprivate.h"
22 
23 #if wxART2D_USE_CANEXTOBJ
24 
25 #include "wx/canvas/canmod.h"
26 #include "wx/filename.h"
27 
28 #include "wx/canvas/sttool.h"
29 #include "wx/canextobj/sttoolext.h"
30 
31 IMPLEMENT_CLASS( a2dRenderImageZoomTool, a2dStTool )
32 
33 const a2dCommandId a2dRenderImageZoomTool::COMID_PushTool_RenderImageZoom( wxT( "PushTool_RenderImageZoom" ) );
34 
35 BEGIN_EVENT_TABLE( a2dRenderImageZoomTool, a2dStTool )
36  EVT_CHAR( a2dRenderImageZoomTool::OnChar )
37  EVT_MOUSE_EVENTS( a2dRenderImageZoomTool::OnMouseEvent )
38 END_EVENT_TABLE()
39 
40 a2dRenderImageZoomTool::a2dRenderImageZoomTool( a2dStToolContr* controller ): a2dStTool( controller )
41 {
42  GetDrawingPart()->SetMouseEvents( false );
43  m_stcontroller = controller;
44  m_toolcursor = a2dCanvasGlobals->GetCursor( a2dCURSOR_MAGNIFIER );
45  m_stroke = a2dStroke( *wxBLACK, 0 , a2dSTROKE_LONG_DASH );
46 }
47 
48 a2dRenderImageZoomTool::~a2dRenderImageZoomTool()
49 {
50 }
51 
52 void a2dRenderImageZoomTool::OnChar( wxKeyEvent& event )
53 {
54  if ( GetBusy() )
55  {
56  switch( event.GetKeyCode() )
57  {
58  case WXK_SPACE:
59  {
61  //to be save
62  m_canvasobject = 0;
63  }
64  break;
65  default:
66  event.Skip();
67  }
68  }
69  else
70  event.Skip();
71 
72 }
73 
74 void a2dRenderImageZoomTool::OnMouseEvent( wxMouseEvent& event )
75 {
76  if ( !m_active )
77  {
78  event.Skip();
79  return;
80  }
81 
82  if ( GetBusy() )
83  GetDrawingPart()->SetCursor( a2dCanvasGlobals->GetCursor( a2dCURSOR_CROSS ) );
84  else
85  GetDrawingPart()->SetCursor( m_toolcursor );
86 
87  int x = event.GetX();
88  int y = event.GetY();
89 
90  //to world coordinates to do hit test in world coordinates
91  double xw = GetDrawer2D()->DeviceToWorldX( x );
92  double yw = GetDrawer2D()->DeviceToWorldY( y );
93 
94  wxPoint pos = event.GetPosition();
95 
96  if ( event.LeftDClick() && !GetBusy() )
97  {
98  a2dCanvasObject* object;
99  object = GetDrawingPart()->IsHitWorld( xw, yw );
100 
101  if ( !object )
102  return;
103  if ( 0 == wxDynamicCast( object , a2dRenderImage ) )
104  {
105  m_renderimage = 0;
106  return;
107  }
108  m_renderimage = ( a2dRenderImage* )object;
109 
110  m_renderimage->SetMappingWidthHeight( m_renderimage->GetShowObject()->GetBboxMinX(),
111  m_renderimage->GetShowObject()->GetBboxMinY(),
112  m_renderimage->GetShowObject()->GetBboxWidth(),
113  m_renderimage->GetShowObject()->GetBboxHeight()
114  );
115  }
116  else if ( event.LeftDown() )
117  {
118  a2dCanvasObject* object;
119  object = GetDrawingPart()->IsHitWorld( xw, yw );
120 
121  if ( !object )
122  return;
123  if ( 0 == wxDynamicCast( object , a2dRenderImage ) )
124  {
125  m_renderimage = 0;
126  return;
127  }
128 
129  m_renderimage = ( a2dRenderImage* )object;
130 
131  m_zoom_x1 = m_zoom_x2 = x;
132  m_zoom_y1 = m_zoom_y2 = y;
133  EnterBusyMode();
134  event.Skip();
135  }
136  else if ( event.RightDown() )
137  {
138  event.Skip();
139  }
140  else if ( event.LeftUp() && GetBusy() )
141  {
142  //to be able to intercept doubleclick
143  //ignore the LeftDown and LeftUp if mouse position is the same
144  if ( abs( m_zoom_x1 - m_zoom_x2 ) < 3 && abs( m_zoom_y1 - m_zoom_y2 ) < 3 )
145  {
146  FinishBusyMode();
147  GetDisplayWindow()->Refresh();
148  if ( m_oneshot )
149  StopTool();
150  event.Skip();
151  }
152  else
153  {
154  m_zoom_x2 = pos.x;
155  m_zoom_y2 = pos.y;
156  //wich way the zoom rectangle is drawn must be irrelevant
157  //first determine lefttop and bottomright in device coordinates
158  int topx = wxMin( m_zoom_x1, m_zoom_x2 );
159  int topy = wxMin( m_zoom_y1, m_zoom_y2 );
160  int botx = wxMax( m_zoom_x1, m_zoom_x2 );
161  int boty = wxMax( m_zoom_y1, m_zoom_y2 );
162 
163  double x1 = GetDrawer2D()->DeviceToWorldX( topx );
164  double y1 = GetDrawer2D()->DeviceToWorldY( topy );
165  double x2 = GetDrawer2D()->DeviceToWorldX( botx );
166  double y2 = GetDrawer2D()->DeviceToWorldY( boty );
167 
168  a2dIterC ic( GetDrawingPart() );
169  if ( m_renderimage->GetYaxis() )
170  m_renderimage->SetMappingAbs( ic, x1, y2, fabs( x1 - x2 ), fabs( y1 - y2 ) );
171  else
172  m_renderimage->SetMappingAbs( ic, x1, y1, fabs( x1 - x2 ), fabs( y1 - y2 ) );
173 
174  FinishBusyMode();
175  event.Skip();
176  }
177  }
178  else if ( event.Dragging() && event.m_leftDown && GetBusy() )
179  {
180  wxClientDC dc( GetDisplayWindow() );
181  GetDisplayWindow()->PrepareDC( dc );
182  wxPen pen( m_stroke.GetColour(), 0, wxSOLID );
183  dc.SetPen( pen );
184  dc.SetBrush( wxNullBrush );
185  dc.SetLogicalFunction( wxINVERT );
186  dc.DrawRectangle( m_zoom_x1, m_zoom_y1, m_zoom_x2 - m_zoom_x1, m_zoom_y2 - m_zoom_y1 );
187  m_zoom_x2 = pos.x;
188  m_zoom_y2 = pos.y;
189  dc.DrawRectangle( m_zoom_x1, m_zoom_y1, m_zoom_x2 - m_zoom_x1, m_zoom_y2 - m_zoom_y1 );
190  dc.SetBrush( wxNullBrush );
191  dc.SetPen( wxNullPen );
192  }
193  else
194  event.Skip();
195 }
196 
197 #endif // wxART2D_USE_CANEXTOBJ
a2dCanvasObjectPtr m_canvasobject
This is the object currently edited.
Definition: sttool.h:381
#define wxDynamicCast(obj, className)
Define wxDynamicCast so that it will give a compiler error for unrelated types.
Definition: gen.h:75
Base class for all types of strokes, understood by a2dDrawer2D classes.
Definition: stylebase.h:378
Interactive Zooming into a a2dRenderImage canvasobject.
Definition: sttoolext.h:36
wxCursor m_toolcursor
cursor to use
Definition: tools.h:768
a2dRenderImage is an a2dCanvasObject that is able to display a complete a2dCanvasDocument as a a2dCan...
Definition: rendimg.h:42
The a2dStTool is used to derive tools from.
Definition: sttool.h:115
double GetBboxMinY()
get minimum Y of the boundingbox in world coordinates relative to its parents
Definition: canobj.h:682
a2dDrawingPart * GetDrawingPart()
Access to the tool controllers drawer.
Definition: tools.h:632
void SetMappingWidthHeight(double vx1, double vy1, double width, double height)
Definition: rendimg.cpp:155
bool m_active
tool is operational
Definition: tools.h:777
bool GetYaxis() const
get y axis orientation
Definition: rendimg.h:55
virtual void FinishBusyMode(bool closeCommandGroup=true)
Called when the user finishes editing a distinct object */.
Definition: sttool.cpp:1161
double GetBboxMinX()
get minimum X of the boundingbox in world coordinates relative to its parents
Definition: canobj.h:676
int m_zoom_y2
mouse position used for zooming
Definition: sttoolext.h:62
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
wxColour GetColour() const
return colour 1
Definition: stylebase.cpp:6131
a2dStroke m_stroke
stroke for new object
Definition: tools.h:826
double GetBboxWidth()
get width of the boundingbox in world coordinates relative to its parents
Definition: canobj.h:700
a2dDrawer2D * GetDrawer2D()
Access to the tool controllers drawers drawer2d.
Definition: tools.cpp:959
double DeviceToWorldY(double y) const
convert y from device to world coordinates
Definition: drawer2d.h:439
a2dCanvasObject * GetShowObject() const
return pointer of then currently shown object on the canvas.
Definition: rendimg.cpp:97
The a2dStToolContr is a Tool Controller specialized for working with a2dCanvasView.
Definition: sttool.h:485
wxWindow * GetDisplayWindow()
Access to the tool controllers drawers canvas.
Definition: tools.cpp:964
bool m_oneshot
do it only once
Definition: tools.h:817
int m_zoom_x1
mouse position used for zooming
Definition: sttoolext.h:56
int m_zoom_x2
mouse position used for zooming
Definition: sttoolext.h:60
Each a2dCommand is given a command id at construction.
Definition: comevt.h:99
void SetMappingAbs(a2dIterC &ic, double vx1, double vy1, double width, double height)
set mapping using absolute world coordinates of parent
Definition: rendimg.cpp:170
while iterating a a2dCanvasDocument, this holds the context.
Definition: canobj.h:3212
double DeviceToWorldX(double x) const
convert x from device to world coordinates
Definition: drawer2d.h:437
a2dCanvasObject * IsHitWorld(double x, double y, int layer=wxLAYER_ALL, a2dHitOption option=a2dCANOBJHITOPTION_NONE, bool filterSelectableLayers=false)
do a hittest on the view at coordinates x,y
Definition: drawer.cpp:1565
double GetBboxHeight()
get height of the boundingbox in world coordinates relative to its parents
Definition: canobj.h:706
virtual bool EnterBusyMode()
starts a new action (e.g drawing something ) in a tool that is already pushed.
Definition: sttool.cpp:1147
a2dCanvasGlobal * a2dCanvasGlobals
global a2dCanvasGlobal to have easy access to global settings
Definition: canglob.cpp:1234
all headers of the canvas module
int m_zoom_y1
mouse position used for zooming
Definition: sttoolext.h:58
bool GetBusy()
Check if the tool is busy editing a distinct object */.
Definition: tools.h:513
stack based tools controller and tools for drawing and editing.
void StopTool(bool abort=false)
call to stop a tool, internal and external.
Definition: tools.cpp:785
sttoolext.cpp Source File -- Sun Oct 12 2014 17:04:25 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation