hipp  1.0
hipp/nodes/PaintableTexture.h
Go to the documentation of this file.
00001 /*
00002         Copyright 2011 Certec, Lund University, Sweden
00003 
00004     This file is part of HIPP.
00005 
00006     HIPP is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 
00011     HIPP is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with HIPP.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019  */
00020  
00021 #ifndef __PAINTABLETEXTURE_H__
00022 #define __PAINTABLETEXTURE_H__
00023 
00024 #include "global.h"
00025 
00026 #include <H3D/X3DTexture2DNode.h>
00027 #include <H3D/SFVec3f.h>
00028 #include <H3D/MFVec2d.h>
00029 #include <H3D/SFColorRGBA.h>
00030 #include <H3D/MFNode.h>
00031 #include <H3DUtil/Console.h>
00032 #include <H3DUtil/AutoRef.h>
00033 #include <H3DUtil/FreeImageImage.h>
00034 #include "freeimage\dist\freeimage.h"
00035 
00036 #include <cairomm/cairommconfig.h>
00037 #include <cairomm/context.h>
00038 #include <cairomm/surface.h>
00039 
00040 #include <wx/wx.h>
00041 
00042 namespace H3D {
00052 class HIPP_API PaintableTexture: public X3DTexture2DNode {
00053 public:
00054 
00058         class HIPP_API PainterField: public OnNewValueSField<AutoUpdate<SFVec3f> > {
00059         protected:
00076                 virtual void onNewValue(const Vec3f &v);
00077 
00078                 void loadPenOptions(PaintableTexture *pt);
00079         };
00080 
00083         class HIPP_API DrawingModeField: public OnValueChangeSField<AutoUpdate<
00084                         SFBool> > {
00085         protected:
00086                 virtual void onValueChange(const bool &drawingMode);
00087         };
00088 
00090         PaintableTexture(Inst<DisplayList> _displayList = 0,
00091                         Inst<SFNode> _metadata = 0, Inst<SFBool> _repeatS = 0,
00092                         Inst<SFBool> _repeatT = 0, Inst<SFBool> _scaleToP2 = 0, Inst<
00093                                         SFImage> _image = 0,
00094                         Inst<SFTextureProperties> _textureProperties = 0,
00095                         Inst<SFInt32> _width = 0, Inst<SFInt32> _height = 0,
00096                         Inst<PainterField> _paintAtTexCoord = 0,
00097                         Inst<SFBool> _isHaptic = 0,
00098                         Inst<SFBool> _isInContact = 0,
00099                         Inst<DrawingModeField> _isInDrawingMode = 0,
00100                         Inst<SFBool> _mouseButtonIsPressed = 0,
00101                         Inst<SFBool> _mainButtonIsPressed = 0);
00102 
00104     ~PaintableTexture(void);
00105 
00108         virtual void initialize();
00109 
00110         void flushHapticPoints();
00111 
00112         void drawHapticPoints(wxPoint pos);
00113 
00114         Cairo::RefPtr<Cairo::Context> beginDraw();
00115         void endDraw();
00116 
00117         void setDefaultBackground();
00118         void setDefaultForeground();
00119         void setEvtHandler(wxEvtHandler* evtHandler);
00120 
00121         virtual Field *getField(const string &name);
00122 
00123         void savePenOptions(bool* white, int* width);
00124         void loadPenOptions();
00125 
00126         Cairo::RefPtr<Cairo::Context> context;
00127         Cairo::RefPtr<Cairo::ImageSurface> surface;
00128         static const Cairo::Format visual_format = Cairo::FORMAT_ARGB32;
00129         static const Cairo::Format haptic_format = Cairo::FORMAT_A8;
00130 
00131         FIBITMAP *png;
00132         FreeImageImage * fii;
00133         std::deque<wxPoint> bufPoints;
00134 
00138         auto_ptr<SFInt32> width;
00139 
00143         auto_ptr<SFInt32> height;
00144 
00149         auto_ptr<PainterField> paintAtTexCoord;
00150 
00154         auto_ptr<SFBool> isHaptic;
00155 
00159         auto_ptr<SFBool> isInContact;
00160 
00164         auto_ptr<DrawingModeField> isInDrawingMode;
00165 
00169         auto_ptr<SFBool> mainButtonIsPressed;
00170 
00174         auto_ptr<SFBool> mouseButtonIsPressed;
00175 
00177         static H3DNodeDatabase database;
00178 
00179     wxSize windowSize;
00180 
00181 protected:
00182         wxEvtHandler* evtHandler;
00183         vector<wxPoint*> points;
00184         bool* penWhitePtr;
00185         int* penWidthPtr;
00186 };
00187 }
00188 
00189 // define a new event class
00190 class PolylineEvent: public wxCommandEvent {
00191 public:
00192         PolylineEvent(wxEventType eventType, int id, const vector<wxPoint*> points) :
00193                 wxCommandEvent(eventType, id), m_points(points)
00194     {
00195                 wxLogDebug (_("PolylineEvent: Created a new event (%d)"), id);
00196         }
00197 
00198         PolylineEvent(const PolylineEvent& event):wxCommandEvent(event) {}
00199 
00200         // accessors
00201         const vector<wxPoint*> GetPoints() {return m_points;}
00202 
00203         // implement the base class pure virtual
00204         virtual wxEvent *Clone() const {return new PolylineEvent(*this);}
00205         //DECLARE_DYNAMIC_CLASS(PolylineEvent);
00206 private:
00207         const vector<wxPoint*> m_points;
00208 };
00209 
00210 wxDECLARE_EVENT(POLYLINE_CREATED, PolylineEvent);
00211 
00212 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines