Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00045
00047 #ifndef __PAINTABLETEXTURE_H__
00048 #define __PAINTABLETEXTURE_H__
00049
00050 #include "global.h"
00051
00052 #include <H3D/X3DTexture2DNode.h>
00053 #include <H3D/SFVec3f.h>
00054 #include <H3D/MFVec2d.h>
00055 #include <H3D/SFColorRGBA.h>
00056 #include <H3D/MFNode.h>
00057 #include <H3DUtil/Console.h>
00058 #include <H3DUtil/AutoRef.h>
00059 #include <H3DUtil/FreeImageImage.h>
00060 #include "freeimage\dist\freeimage.h"
00061
00062 #include <cairomm/cairommconfig.h>
00063 #include <cairomm/context.h>
00064 #include <cairomm/surface.h>
00065
00066 #include <wx/wx.h>
00067
00068 namespace H3D {
00078 class HIPP_API PaintableTexture: public X3DTexture2DNode {
00079 public:
00080
00084 class HIPP_API PainterField: public OnNewValueSField<AutoUpdate<SFVec3f> > {
00085 protected:
00102 virtual void onNewValue(const Vec3f &v);
00103
00104 void loadPenOptions(PaintableTexture *pt);
00105 };
00106
00109 class HIPP_API DrawingModeField: public OnValueChangeSField<AutoUpdate<
00110 SFBool> > {
00111 protected:
00112 virtual void onValueChange(const bool &drawingMode);
00113 };
00114
00116 PaintableTexture(Inst<DisplayList> _displayList = 0,
00117 Inst<SFNode> _metadata = 0, Inst<SFBool> _repeatS = 0,
00118 Inst<SFBool> _repeatT = 0, Inst<SFBool> _scaleToP2 = 0, Inst<
00119 SFImage> _image = 0,
00120 Inst<SFTextureProperties> _textureProperties = 0,
00121 Inst<SFInt32> _width = 0, Inst<SFInt32> _height = 0,
00122 Inst<PainterField> _paintAtTexCoord = 0,
00123 Inst<SFBool> _isHaptic = 0,
00124 Inst<SFBool> _isInContact = 0,
00125 Inst<DrawingModeField> _isInDrawingMode = 0,
00126 Inst<SFBool> _mouseButtonIsPressed = 0,
00127 Inst<SFBool> _mainButtonIsPressed = 0);
00128
00130 ~PaintableTexture(void);
00131
00134 virtual void initialize();
00135
00136 void flushHapticPoints();
00137
00138 void drawHapticPoints(wxPoint pos);
00139
00140 Cairo::RefPtr<Cairo::Context> beginDraw();
00141 void endDraw();
00142
00143 void setDefaultBackground();
00144 void setDefaultForeground();
00145 void setEvtHandler(wxEvtHandler* evtHandler);
00146
00147 virtual Field *getField(const string &name);
00148
00149 void savePenOptions(bool* white, int* width);
00150 void loadPenOptions();
00151
00152 Cairo::RefPtr<Cairo::Context> context;
00153 Cairo::RefPtr<Cairo::ImageSurface> surface;
00154 static const Cairo::Format visual_format = Cairo::FORMAT_ARGB32;
00155 static const Cairo::Format haptic_format = Cairo::FORMAT_A8;
00156
00157 FIBITMAP *png;
00158 FreeImageImage * fii;
00159 std::deque<wxPoint> bufPoints;
00160
00164 auto_ptr<SFInt32> width;
00165
00169 auto_ptr<SFInt32> height;
00170
00175 auto_ptr<PainterField> paintAtTexCoord;
00176
00180 auto_ptr<SFBool> isHaptic;
00181
00185 auto_ptr<SFBool> isInContact;
00186
00190 auto_ptr<DrawingModeField> isInDrawingMode;
00191
00195 auto_ptr<SFBool> mainButtonIsPressed;
00196
00200 auto_ptr<SFBool> mouseButtonIsPressed;
00201
00203 static H3DNodeDatabase database;
00204
00205 wxSize windowSize;
00206
00207 protected:
00208 wxEvtHandler* evtHandler;
00209 vector<wxPoint*> points;
00210 bool* penWhitePtr;
00211 int* penWidthPtr;
00212 };
00213 }
00214
00215
00216 class PolylineEvent: public wxCommandEvent {
00217 public:
00218 PolylineEvent(wxEventType eventType, int id, const vector<wxPoint*> points) :
00219 wxCommandEvent(eventType, id), m_points(points)
00220 {
00221 wxLogDebug (_("PolylineEvent: Created a new event (%d)"), id);
00222 }
00223
00224 PolylineEvent(const PolylineEvent& event):wxCommandEvent(event) {}
00225
00226
00227 const vector<wxPoint*> GetPoints() {return m_points;}
00228
00229
00230 virtual wxEvent *Clone() const {return new PolylineEvent(*this);}
00231
00232 private:
00233 const vector<wxPoint*> m_points;
00234 };
00235
00236 wxDECLARE_EVENT(POLYLINE_CREATED, PolylineEvent);
00237
00238 #endif