00001 //--- < CAMERA.H > --------------| ViewGraph - A Flexible Graph view Framework | 00002 // 00003 // This class implements a camera overlooking 00004 // a portion of the scene. 00005 // 00006 // 00007 // $Author: botik32 $ 00008 // $Revision: 1.6 $ 00009 // $Date: 2004/06/02 08:36:01 $ 00010 //-----------------------------------------------------------------------------/ 00011 00012 #ifndef CAMERA_H 00013 #define CAMERA_H 00014 00015 #include <list> 00016 #include <map> 00017 #include <cZUI/zoomableview.h> 00018 #include <cZUI/cameraevent.h> 00019 #include <cZUI/message.h> 00020 #include <cZUI/scene.h> 00021 #include <cZUI/context.h> 00022 #include <cZUI/eventhub.h> 00023 #include <cZUI/eventlistener.h> 00024 00025 class LayerNode; 00026 class SelectionGroupNode; 00027 class BaseGraphWindow; 00028 00029 class Camera : public Context, public EventHub, public EventListener 00030 { 00031 protected: 00032 char *name; 00033 bool need_repaint; 00034 BaseGraphWindow *parent; 00035 Scene *scene; 00036 ZoomableView *view; 00037 ZoomableView *hudview; 00038 bool HUDmode_on; 00039 std::list<LayerNode*> layers; 00040 SelectionGroupNode *selection_handler; 00041 CameraEvent *status; 00042 BaseSceneNode *mouse_owner; 00043 // area taken by visible nodes 00044 double rx1, ry1, rx2, ry2; 00045 // initially false, true after first recount 00046 bool valid_bounds; 00047 void recompute_visible_area( void ); 00048 public: 00049 Camera( const char *, ZoomableView *, ZoomableView* ); 00050 void assign_parent( BaseGraphWindow * ); 00051 BaseGraphWindow* get_parent( void ); 00052 00053 const char* get_name( void ); 00054 virtual ZoomableView* get_view( void ); 00055 00056 void add_selection_handler( SelectionGroupNode * ); 00057 SelectionGroupNode* remove_selection_handler( void ); 00058 00059 // the functions below can be overriden if special 00060 // behaviour is needed 00061 00062 /// Adds new layer to the front 00063 virtual void add_layer( LayerNode * ); 00064 virtual void add_layer_first( LayerNode * ); 00065 virtual void add_layer_last( LayerNode * ); 00066 virtual void insert_layer( LayerNode *, LayerNode * ); 00067 00068 // disable/enable layer automatically sends a redraw event 00069 // to itself 00070 virtual void disable_layer( LayerNode * ); 00071 virtual void enable_layer( LayerNode * ); 00072 00073 virtual bool handle_event( Event * ); 00074 // A camera redraws its contents on focus/blur events 00075 virtual bool handle_event( CameraFocusEvent * ); 00076 virtual bool handle_event( CameraBlurEvent * ); 00077 virtual bool handle_message( Message * ); 00078 virtual void listen_event( Event * ); 00079 00080 virtual bool accepts_mouse_events( void ); 00081 00082 // dumb scroll 00083 void scroll_camera( int xmov, int ymov ); 00084 00085 // handle invalidate rect notification from scene nodes 00086 void invalidate_rect( double, double, double, double ); 00087 00088 // handle repaint rect notification from scene nodes 00089 void repaint_rect( double, double, double, double ); 00090 void repaint_screenrect( double, double, double, double ); 00091 00092 // mouse_in and mouse_out support 00093 void register_mouse_owner( BaseSceneNode * ); 00094 00095 bool mousefits( int, int ); 00096 00097 void get_screenrect( double&, double&, 00098 double&, double& ); 00099 void screen2scenerect( double&, double&, 00100 double&, double& ); 00101 void screen2scenepos( double&, double& ); 00102 00103 // Context retrieval functions 00104 Context* get_window_context( void ); 00105 Context* get_scene_context( void ); 00106 00107 // hud switch function: 00108 void switch_to_HUD( void ); 00109 void switch_to_view( void ); 00110 bool HUD_status( void ){ return HUDmode_on; }; 00111 void HUD2scenepos( double&, double& ); 00112 void screen2HUDpos( double&, double& ); 00113 00114 // This function is used to specify scroll/zoom 00115 // borders and supply external scrollers with 00116 // the size 00117 void get_visible_area( double& x1, double& y1, 00118 double& x2, double& y2 ); 00119 00120 bool needs_repaint( void ) 00121 { 00122 bool ret = need_repaint; 00123 return ret; 00124 }; 00125 00126 ~Camera(); 00127 }; 00128 #endif 00129 00130 ///$Log: camera.h,v $ 00131 ///Revision 1.6 2004/06/02 08:36:01 botik32 00132 ///Fixed a bug in Camera in get_visible_area() 00133 ///Added recompute_scenerect() to all node adds/removes 00134 ///of GroupNode 00135 /// 00136 ///Revision 1.5 2004/05/14 18:35:08 botik32 00137 ///Fixed a bug related to HUDGroups and a few that I do not 00138 ///remember now. 00139 /// 00140 ///Revision 1.4 2004/05/03 21:02:01 botik32 00141 ///Significant changes and many bugfixes. 00142 ///ScrollableView now has a background color used to 00143 ///tell SurfaceDriver to clear with. 00144 ///SurfaceDriver's clear() requires a color now 00145 ///Added SceneEvents for all node additions/removals 00146 ///in GroupNode and Camera. 00147 ///Added paint_selected and paint_selected_invalid 00148 ///to ActiveLeaf 00149 ///Modified ActiveLeaf's mouse_down and mouse_up 00150 ///handler signatures to accept an Event* instead of 00151 ///Camera* 00152 ///- Many more bugfixes 00153 /// 00154 ///Revision 1.3 2004/04/30 12:39:21 botik32 00155 ///Numerous changes related to making the SceneChangedEvents 00156 ///to work. 00157 ///- Moved listen_event() from BaseSceneNode to EventListener class 00158 ///- Made GroupNode listen to the added children's SceneChangedEvents 00159 ///- Changed Camera to listen to layers' SceneChangedEvents 00160 ///- Moved eventlistener list cleanup from Camera to EventHub class 00161 /// where it belonged in the first place 00162 /// 00163 ///Revision 1.2 2004/04/20 08:55:51 botik32 00164 ///Major interface change. 00165 ///Added HUDView in Camera; switch_to_HUDmode for Camera 00166 ///BaseSceneNode: internal implementation changes; 00167 ///Major changes in HUDGroup behaviour 00168 /// 00169 ///Revision 1.1.1.1 2004/03/26 10:50:21 botik32 00170 ///Initial release 00171 /// 00172 ///Revision 1.1.1.1 2004/03/26 08:53:33 botik 00173 ///initial import 00174 /// 00175 /// 00176 ///Revision 1.21 2003/12/03 18:48:51 botik 00177 ///Split event listener functionality off camera into 00178 ///eventhub. 00179 /// 00180 ///Revision 1.20 2003/12/02 20:09:22 botik 00181 ///Changed repaint policy to repaint only when Camera and 00182 ///CameraMovement events happened. 00183 ///Added CameraUpdatedEvent specifically for this purpose 00184 ///so scene nodes can trigger a repaint. 00185 /// 00186 ///Revision 1.19 2003/12/02 14:39:37 botik 00187 ///Changed the repaint strategy to always repaint the scene 00188 ///Added Context class to handle context-related data for 00189 ///scene nodes 00190 ///Added get_surfacerect() to ScrollableView 00191 ///Camera, Scene and GraphWindow now inherit from Context 00192 ///Changed activeleaf to use Scene context to store hover 00193 ///status 00194 /// 00195 ///Revision 1.18 2003/11/29 16:11:23 botik 00196 ///Added event listener support to basescenenode and camera 00197 ///classes 00198 /// 00199 ///Revision 1.17 2003/11/24 20:45:29 botik 00200 ///Merged four features from surfacecamera into camera. 00201 ///Modified ScrollableView to hold a width/height of 00202 ///the viewport and to report it to whoever asks. 00203 ///Added scenex, sceney fields to Event. 00204 ///Added coordinate transform for all messages, done 00205 ///at camera level. This should speed up drawability 00206 ///and mouseover checks. 00207 /// 00208 ///Repaint and mouse detection work now over arbitrary 00209 ///magnification. 00210 ///Borderlayer is broken and scrolling segfaults in 00211 ///a weird way. 00212 /// 00213 ///Revision 1.16 2003/11/24 16:12:10 botik 00214 ///Halfway through major redesign of a view's geometric 00215 ///parameters. This will influence zooming and repainting. 00216 /// 00217 ///Revision 1.15 2003/11/20 00:32:41 botik 00218 ///Changed the way repaint works by using a screen 00219 ///rectangle as intermediate event. 00220 ///Added get_screenrect to Camera 00221 ///Added screen2scenerect to Camera 00222 /// 00223 ///Revision 1.14 2003/11/18 13:54:06 botik 00224 ///Got the borderlayer to scroll well. 00225 /// 00226 ///Revision 1.13 2003/11/17 23:38:45 botik 00227 ///Fixed the framework to work with multiple cameras on 00228 ///one window. There is a clear bug that does not clear 00229 ///the upper camera. 00230 ///Changed scrolling to remove flicker when multiple 00231 ///cameras are present on a window. 00232 ///Scrolling is still slow. 00233 /// 00234 ///Revision 1.12 2003/11/14 16:00:42 botik 00235 ///Got camerafocus to ignore cameras in 'Off' state 00236 ///Fixed camera to keep latest camera status change 00237 ///event as status. 00238 /// 00239 ///Revision 1.11 2003/11/14 12:09:32 botik 00240 ///Added camera->repaint_rect routine. 00241 /// 00242 ///Revision 1.10 2003/11/13 18:50:18 botik 00243 ///Fixed (almost) clear and update rect behaviour. 00244 ///Added update_rect to framework and sdl wrapper. 00245 ///Added mouse_in/mouse_out handling 00246 ///Fixed message handling 00247 ///Many small bugfixes 00248 /// 00249 ///Revision 1.9 2003/11/12 00:47:31 botik 00250 ///Further work on getting repaints to work, tested with 00251 ///scrolling 00252 /// 00253 ///Revision 1.8 2003/11/11 23:18:31 botik 00254 ///Got sdlxp driver to work, fixed a few architecture 00255 ///errors and some bugs 00256 /// 00257 ///Revision 1.7 2003/11/09 18:05:37 botik 00258 ///Contrib/borderlayer works! Fixed a lot of small bugs. 00259 /// 00260 ///Revision 1.6 2003/11/08 18:54:59 botik 00261 ///Changed handle_event to return bool 00262 /// 00263 ///Revision 1.5 2003/10/30 19:42:18 botik 00264 ///Filled code for camera member functions 00265 /// 00266 ///Revision 1.4 2003/10/30 13:47:31 botik 00267 ///Broke up event files into 3 categories 00268 /// 00269 ///Revision 1.3 2003/10/29 10:47:39 botik 00270 ///Moved the x,y event position into the base class 00271 ///Added has_focus() method and blur/focus event 00272 ///handlers to Camera class. 00273 ///Added Makefile 00274 /// 00275 ///Revision 1.2 2003/10/28 15:43:55 botik 00276 ///More work on event framework and camera composition and 00277 ///z-ordering 00278 /// 00279 ///Revision 1.1 2003/10/24 16:29:10 botik 00280 ///Added more scene support: special scene nodes as well as a 00281 ///camera class that acts as glue between the graph master and the 00282 ///surface. 00283 ///