[an error occurred while processing this directive]
Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

hugin1/hugin/PreviewToolHelper.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00023 /* A preview tool helper manages information that any tool may want to use,
00024  * and guides the interaction between tools. These features are available:
00025  * - Notification of user events:
00026  *      - When the mouse moves
00027  *      - When the set of images under the mouse pointer changes
00028  *      - When the mouse button is pressed / released.
00029  *      - When a key is pressed / released
00030  * - Notifications when drawing things on the preview, allowing:
00031  *      - Drawing under / above the set of images.
00032  *      - Drawing under / above each individual image.
00033  *      - Replacing or stopping the drawing of each individual image.
00034  * - Notification of when:
00035  *      - The tool is activated.
00036  * - The tool can request the mouse position.
00037  * - The tool can request a list of images under the mouse.
00038  * - The tool can access the panorama, and make changes to it.
00039  * - The tool can access the ViewState. This allows it to respond to, and cause,
00040  *     interactive changes.
00041  * - The tool can deactivate itself, for example, when asked to give up events.
00042  * - Possible extensions:
00043  *      - What images have been selected
00044  *      - Provide a menu over the preview
00045  */
00046 
00047 #ifndef _PREVIEWTOOLHELPER_H
00048 #define _PREVIEWTOOLHELPER_H
00049 
00050 #include "hugin_utils/utils.h"
00051 #include "base_wx/platform.h"
00052 #include <wx/defs.h>
00053 #include <wx/event.h>
00054 #include <wx/string.h>
00055 
00056 #include <set>
00057 #include <vector>
00058 
00059 #include <hugin_math/hugin_math.h>
00060 #include "ViewState.h"
00061 #include "PT/Panorama.h"
00062 
00063 class PreviewTool;
00064 class GLPreviewFrame;
00065 
00066 class PreviewToolHelper
00067 {
00068 public:
00069     enum Event
00070     {
00071         MOUSE_MOVE, MOUSE_PRESS, KEY_PRESS,
00072         DRAW_UNDER_IMAGES, DRAW_OVER_IMAGES,
00073         IMAGES_UNDER_MOUSE_CHANGE, REALLY_DRAW_OVER_IMAGES
00074     };
00075     PreviewToolHelper(PT::Panorama *pano,
00076                       ViewState *view_state,
00077                       GLPreviewFrame * frame);
00078     ~PreviewToolHelper();
00079     // working with tools
00080     // Activate a tool, the tool will then request notifications it needs.
00081     // Then return a list of tools that had to be dactivated to comply.
00082     std::set<PreviewTool*> ActivateTool(PreviewTool *tool);
00083     // deactivate a tool: remove all it's notifications.
00084     void DeactivateTool(PreviewTool *tool);
00085     
00086     // Events
00087     // the x and y coordinates are in pixels from the top left of the panorama.
00088     void MouseMoved(int x, int y, wxMouseEvent & e);
00089     // pressed is true if the button is pushed down, false if let go
00090     void MouseButtonEvent(wxMouseEvent &e);
00091     // keycode is the wxWidgets keycode.
00092     void KeypressEvent(int keycode, int modifiers, bool pressed);
00093     void BeforeDrawImages();
00094     void AfterDrawImages();
00095     // Return true if we want it drawn, return false and draw the image as the
00096     // tools specify otherwise.
00097     bool BeforeDrawImageNumber(unsigned int image);
00098     void AfterDrawImageNumber(unsigned int image);
00099     void MouseLeave();
00100     
00101     // Get information
00102     std::set<unsigned int> GetImageNumbersUnderMouse();
00103     hugin_utils::FDiff2D GetMousePosition();
00104     ViewState *GetViewStatePtr();
00105     PT::Panorama *GetPanoramaPtr();
00106     
00107     // Setting up notifications
00108     void NotifyMe(Event event, PreviewTool *tool);
00109     void NotifyMeBeforeDrawing(unsigned int image_nr, PreviewTool *tool);
00110     void NotifyMeAfterDrawing(unsigned int image_nr, PreviewTool *tool);
00111     void DoNotNotifyMe(Event event, PreviewTool *tool);
00112     void DoNotNotifyMeBeforeDrawing(unsigned int image_nr, PreviewTool *tool);
00113     void DoNotNotifyMeAfterDrawing(unsigned int image_nr, PreviewTool *tool);
00114     
00115     // status message to be something relevant for a tool.
00116     void SetStatusMessage(wxString message);
00117 private:
00118     std::set<PreviewTool *> tools_deactivated;
00119     PT::Panorama *pano;
00120     ViewState *view_state;
00121     GLPreviewFrame *frame;
00122     
00123     double mouse_x, mouse_y;
00124     
00125     // What tools are notified of what events.
00126     std::set<PreviewTool *> mouse_move_notified_tools;
00127     PreviewTool * mouse_button_notified_tool;
00128     PreviewTool * keypress_notified_tool;
00129     std::set<PreviewTool *> draw_under_notified_tools;
00130     std::set<PreviewTool *> draw_over_notified_tools;
00131     std::set<PreviewTool *> really_draw_over_notified_tools;
00132     std::set<PreviewTool *> images_under_mouse_notified_tools;
00133     // these are vectors: the index is the image that a single tool uses.
00134     std::vector<PreviewTool *> image_draw_begin_tools;
00135     std::vector<PreviewTool *> image_draw_end_tools;
00136     // stop notifying the given tool of an event.
00137     void RemoveTool(PreviewTool *tool, PreviewTool **single);
00138     void RemoveTool(PreviewTool *tool, std::set<PreviewTool *> *set);
00139     void RemoveTool(PreviewTool *tool, std::vector<PreviewTool *> *vector);
00140     void RemoveTool(PreviewTool *tool, std::vector<PreviewTool *> *vector,
00141                     unsigned int index);
00142     // set the tool up for notification, deactivating any tools in the way.
00143     void AddTool(PreviewTool *tool, PreviewTool **single);
00144     void AddTool(PreviewTool *tool, std::set<PreviewTool *> *set);
00145     void AddTool(PreviewTool *tool, std::vector<PreviewTool *> *vector,
00146                  unsigned int index);
00147                  
00148     // is the set of images under the mouse up to date?
00149     bool images_under_mouse_current, mouse_over_pano;
00150     // which images are under the mouse?
00151     std::set<unsigned int> images_under_mouse;
00152     void UpdateImagesUnderMouse();
00153     void InvalidateImagesUnderMouse();
00154 };
00155 
00156 #endif

Generated on Mon Sep 20 01:01:26 2010 for Hugintrunk by doxygen 1.3.9.1