Canvas.h

Go to the documentation of this file.
00001 
00011 #ifndef __CANVAS_H__
00012 #define __CANVAS_H__
00013 
00014 #include <wx/wx.h>
00015 
00016 #include "../Matrix.h"
00017 #include "../configs/ConfigCanvas.h"
00018 
00019 // A part of the GUI
00020 namespace GUI {
00021 
00029 class Canvas : public wxWindow {
00030 public:
00032         enum MouseStatus {
00033                 MOUSE_NOACTION,
00034                 MOUSE_INSERTING,
00035                 MOUSE_ERASING
00036         };
00037 
00047         Canvas(wxWindow * parent, Matrix * m, const ConfigCanvas & config,
00048                 const wxSize & winSize = wxDefaultSize, bool interact = true,
00049                 bool isSimulationSaved = false);
00050 
00054         ~Canvas();
00055 
00059         void Redraw();
00060 
00064         int GetCellSize() const {
00065                 return cellsize;
00066         }
00067 
00072         void SetCellSize(int cs);
00073 
00079         void Recenter(wxInt32 i, wxInt32 j);
00080 
00085         void SetCurrentObjectConfig(Object::Config * coc) {
00086                 CurrentObjectConfig = coc;
00087         }
00088 
00093         void SetMouseStatus(MouseStatus ms);
00094 
00101         ConfigCanvas * GetConfigCanvas() const;
00102 
00111         void LoadFromConfig(const ConfigCanvas & config, bool fullLoad = true);
00112 
00116         long GetInterval() const {
00117                 return interval;
00118         }
00119 
00124         void SetInterval(long newInterval) {
00125                 interval = newInterval;
00126         }
00127 
00131         bool IsSimulationSaved() const {
00132                 return simulationWasSaved;
00133         }
00134 
00139         void SetSimulationSavedStatus(bool newStatus) {
00140                 simulationWasSaved = newStatus;
00141         }
00142 
00146         string GetSimulationName() const {
00147                 return simulationName;
00148         }
00149 
00154         void SetSavedSimulationFileName(string newSimulationSavedFileName) {
00155                 savedSimulationFileName = newSimulationSavedFileName;
00156         }
00157 
00163         string GetSavedSimulationFileName() const {
00164                 return savedSimulationFileName;
00165         }
00166 
00171         void SetInteractive(bool si) {
00172                 interactive = si;
00173         }
00174 
00181         void SetNotHoldingObject() {
00182                 HoldingObject::SetNotHoldingObject();
00183         }
00184 
00193         virtual bool ProcessEvent(wxEvent & event);
00194 
00195 private:
00196         // Any class wishing to process wxWidgets events must use this macro
00197         DECLARE_EVENT_TABLE()
00198 
00199         // Event handlers
00200         void OnPaint(wxPaintEvent & event);
00201         void OnMouseMotion(wxMouseEvent& event);
00202         void OnMouseLeftDown(wxMouseEvent & event);
00203         void OnMouseRightDown(wxMouseEvent& event);
00204         void OnMouseMiddleDown(wxMouseEvent& event);
00205         void OnSize(wxSizeEvent & event);
00206         void OnScroll(wxScrollWinEvent & event);
00207 
00209         wxInt32 XToCell(wxCoord x) const { return (x / cellsize) + viewportX; }
00211         wxInt32 YToCell(wxCoord y) const { return (y / cellsize) + viewportY; }
00213         wxCoord CellToX(wxInt32 i) const { return (i - viewportX) * cellsize; }
00215         wxCoord CellToY(wxInt32 j) const { return (j - viewportY) * cellsize; }
00216 
00217 private:
00224         class HoldingObject {
00225         public:
00231                 static void SetHoldingObject(Matrix::SizeType xIndex, Matrix::SizeType yIndex) {
00232                         x = xIndex;
00233                         y = yIndex;
00234                         isHolding = true;
00235                 }
00236 
00238                 static bool IsHoldingSomething() { return isHolding; }
00239 
00241                 static void SetNotHoldingObject() {     isHolding = false; }
00242 
00244                 static Matrix::SizeType GetX() { return x; }
00245 
00247                 static Matrix::SizeType GetY() { return y; }
00248 
00249         private:
00251                 static bool isHolding;
00253                 static Matrix::SizeType x;
00255                 static Matrix::SizeType y;
00256 
00257         private:
00258                 // Protections - not implemented
00259                 HoldingObject();
00260                 ~HoldingObject();
00261                 HoldingObject(const HoldingObject &);
00262                 HoldingObject & operator=(const HoldingObject &);
00263         };
00264 
00265 private:
00267         Matrix * matrix;
00269         int cellsize;
00271         bool interactive;
00273         long interval;
00275         MouseStatus status;
00277         wxInt32 viewportX;
00279         wxInt32 viewportY;
00281         wxInt32 viewportW;
00283         wxInt32 viewportH;
00285         int thumbX;
00287         int thumbY;
00289         wxInt32 mi, mj;
00291         Object::Config * CurrentObjectConfig;
00293         MouseStatus mouseStatus;
00295         bool simulationWasSaved;
00297         string simulationName;
00299         string savedSimulationFileName;
00300 };
00301 
00302 } /* namespace GUI */
00303 
00304 #endif /* #ifndef __CANVAS__H__ */
00305 
00306 /* End of file Canvas.h */

Generated on Sun Apr 29 11:46:10 2007 for IPP/ICP2007 by  doxygen 1.4.7