Changeset 9287
- Timestamp:
- 11/28/08 15:35:33 (5 years ago)
- Location:
- OpenSceneGraph/trunk
- Files:
-
- 35 modified
- 2 copied
-
include/osgWidget/Box (modified) (3 diffs)
-
include/osgWidget/Browser (copied) (copied from OpenSceneGraph/branches/OpenSceneGraph-osgWidget-dev/include/osgWidget/Browser)
-
include/osgWidget/Canvas (modified) (2 diffs)
-
include/osgWidget/EventInterface (modified) (8 diffs)
-
include/osgWidget/Export (modified) (2 diffs)
-
include/osgWidget/Frame (modified) (8 diffs)
-
include/osgWidget/Input (modified) (3 diffs)
-
include/osgWidget/Label (modified) (2 diffs)
-
include/osgWidget/Lua (modified) (1 diff)
-
include/osgWidget/Python (modified) (1 diff)
-
include/osgWidget/ScriptEngine (modified) (1 diff)
-
include/osgWidget/StyleInterface (modified) (1 diff)
-
include/osgWidget/StyleManager (modified) (1 diff)
-
include/osgWidget/Table (modified) (1 diff)
-
include/osgWidget/Types (modified) (2 diffs)
-
include/osgWidget/UIObjectParent (modified) (2 diffs)
-
include/osgWidget/Util (modified) (2 diffs)
-
include/osgWidget/Version (modified) (1 diff)
-
include/osgWidget/ViewerEventHandlers (modified) (8 diffs)
-
include/osgWidget/Widget (modified) (10 diffs)
-
include/osgWidget/Window (modified) (8 diffs)
-
include/osgWidget/WindowManager (modified) (6 diffs)
-
src/osgWidget/Box.cpp (modified) (2 diffs)
-
src/osgWidget/Browser.cpp (copied) (copied from OpenSceneGraph/branches/OpenSceneGraph-osgWidget-dev/src/osgWidget/Browser.cpp)
-
src/osgWidget/Canvas.cpp (modified) (2 diffs)
-
src/osgWidget/Frame.cpp (modified) (9 diffs)
-
src/osgWidget/Input.cpp (modified) (7 diffs)
-
src/osgWidget/Label.cpp (modified) (6 diffs)
-
src/osgWidget/Lua.cpp (modified) (1 diff)
-
src/osgWidget/Python.cpp (modified) (2 diffs)
-
src/osgWidget/StyleManager.cpp (modified) (1 diff)
-
src/osgWidget/Table.cpp (modified) (1 diff)
-
src/osgWidget/Util.cpp (modified) (4 diffs)
-
src/osgWidget/ViewerEventHandlers.cpp (modified) (3 diffs)
-
src/osgWidget/Widget.cpp (modified) (16 diffs)
-
src/osgWidget/Window.cpp (modified) (20 diffs)
-
src/osgWidget/WindowManager.cpp (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgWidget/Box
r8865 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: Box 46 2008-04-30 16:11:51Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_BOX … … 22 21 namespace osgWidget { 23 22 23 //! The Box object is a Window subclass that can be configured to uniformly (or 24 //! non-uniformly) position it's children either vertically or horizontally. It 25 //! is the most basic Window implementation, though there is some difficulty when 26 //! positioning children such that each child object ends up pixel-aligned. 24 27 class OSGWIDGET_EXPORT Box: public Window 25 28 { 26 29 public: 27 enum BOX_TYPE { 30 31 //! An enum corresponding to the type of Box alignment. 32 enum BoxType { 28 33 VERTICAL, 29 34 HORIZONTAL 30 35 }; 31 36 32 META_Object (osgWidget, Box); 33 34 Box (const std::string& = "", BOX_TYPE = HORIZONTAL, bool = false); 37 META_Object(osgWidget, Box); 38 39 //! The main constructor; takes the string name, the BoxType orientation, and a 40 //! boolean indicating whether or not all of the Box regions should be uniformly 41 //! sized. 42 Box (const std::string& = "", BoxType = HORIZONTAL, bool = false); 35 43 Box (const Box&, const osg::CopyOp&); 36 44 … … 44 52 private: 45 53 46 B OX_TYPE_boxType;54 BoxType _boxType; 47 55 bool _uniform; 48 56 unsigned int _lastAdd; 49 50 57 }; 51 58 -
OpenSceneGraph/trunk/include/osgWidget/Canvas
r8865 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: Canvas 66 2008-07-14 21:54:09Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_CANVAS … … 25 24 { 26 25 public: 27 META_Object (osgWidget, Canvas); 26 27 META_Object(osgWidget, Canvas); 28 28 29 29 Canvas (const std::string& = ""); 30 30 Canvas (const Canvas&, const osg::CopyOp&); 31 31 32 // This would conflict with the normal addWidget if there were default values. :(32 //! Adds a Widget at the given XY coordinate. 33 33 virtual bool addWidget(Widget*, point_type, point_type); 34 34 -
OpenSceneGraph/trunk/include/osgWidget/EventInterface
r8865 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: EventInterface 64 2008-06-30 21:32:00Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_EVENT_INTERFACE … … 68 67 69 68 Event(WindowManager* wm, EventType _type = EVENT_NONE): 70 _wm (wm),71 _window (0),72 _widget (0),73 _data (0),74 69 type (_type), 75 70 x (0.0f), 76 71 y (0.0f), 77 72 key (-1), 78 keyMask (-1) { 73 keyMask (-1), 74 _wm (wm), 75 _window (0), 76 _widget (0), 77 _data (0) { 79 78 } 80 79 … … 204 203 205 204 // The highlevel functor. 206 class OSGWIDGET_EXPORT Callback 205 class OSGWIDGET_EXPORT Callback: public osg::Referenced 207 206 { 208 207 public: 209 210 Callback():_type(EVENT_NONE),_data(0) {} 211 Callback(const Callback& rhs):_type(rhs._type),_data(rhs._data),_callback(rhs._callback) {} 212 208 Callback(): _type(EVENT_NONE), _data(0), _callback(0) {} 209 Callback(const Callback& rhs): osg::Referenced(rhs), _type(rhs._type), _data(rhs._data), _callback(rhs._callback) {} 210 211 // The more traditional style of OSG Callbacks. 212 Callback(EventType type, void* data=0): 213 _type (type), 214 _data (data), 215 _callback (0) { 216 } 217 213 218 // Creates a Callback that is bound to a member function. 214 219 template<typename T> … … 227 232 } 228 233 229 bool operator()(Event& ev) { 234 virtual ~Callback() {} 235 236 virtual bool operator()(Event& ev) { 237 if(!_callback) return false; 238 230 239 return (*_callback)(ev); 231 240 } … … 242 251 return _data; 243 252 } 253 244 254 protected: 245 255 EventType _type; 246 void* _data;256 void* _data; 247 257 248 258 // We use a ref_ptr here so that we don't have to worry about memory. … … 302 312 } 303 313 304 void addCallback( const Callback&cb) {314 void addCallback(Callback* cb) { 305 315 _callbacks.push_back(cb); 306 316 } … … 313 323 // if(i->getType() == ev.type && (*i)(ev)) return true; 314 324 315 if(i->get Type() ==ev.type) {316 ev.setData(i->get Data());317 318 if((*i )(ev)) return true;325 if(i->get()->getType() & ev.type) { 326 ev.setData(i->get()->getData()); 327 328 if((*i->get())(ev)) return true; 319 329 } 320 330 } … … 388 398 389 399 private: 390 typedef std::list< Callback> CallbackList;400 typedef std::list<osg::ref_ptr<Callback> > CallbackList; 391 401 392 402 unsigned int _eventMask; -
OpenSceneGraph/trunk/include/osgWidget/Export
r8744 r9287 11 11 * OpenSceneGraph Public License for more details. 12 12 */ 13 14 // Code by: Jeremy Moles (cubicool) 2007-2008 13 15 14 16 #ifndef OSGWIDGET_EXPORT_ … … 42 44 \namespace osgWidget 43 45 44 The osgWidget library is a NodeKit that extends the core scene graph to support 3DGUI widget set.46 The osgWidget library is a NodeKit that extends the core scene graph to support a 2D (and eventually 3D) GUI widget set. 45 47 */ 46 48 -
OpenSceneGraph/trunk/include/osgWidget/Frame
r8865 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: Frame 59 2008-05-15 20:55:31Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_FRAME … … 21 20 22 21 namespace osgWidget { 22 23 /* 24 Lets take a moment and explain how Frame texturing works. When you create a Frame, you use 25 a specially designed texture that is "chopped" up horizontally by the Frame code into 8 equal 26 regions. Each region is then textured to a corresponding portion of the Frame, in the 27 following order: 28 29 +---+---+---+---+---+---+---+---+ 30 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 31 +---+---+---+---+---+---+---+---+ 32 33 1. Upper-Left corner. 34 2. Top border (rotated 90 degrees CCW). 35 3. Upper-Right corner. 36 4. Left border. 37 5. Right border. 38 6. Bottom-Left corner. 39 7. Bottom border (rotated 90 degrees CCW). 40 8. Bottom-Right corner. 41 42 Now, these should be pretty self-explanatory if you visualize a frame as a 3x3 "table" 43 (which is exactly what it is), but note how regions 2 and 7 are rotated counter-clockwise. 44 We do this for a VERY important reason: we want to enable texture repeat on the border 45 regions, so that when the frame is resized the borders cleanly paint the texture over 46 the entire are (and don't stretch it). However, it is impossible in OpenGL to repeat a 47 sub-region of a texture without including either the vertical or horizontal bounds, so the 48 artist is required to rotate the region during their rendering so that our code can properly 49 rotate it back internally and have it repeat in the desired way. 50 51 This method of texturing a Frame object is inspired by World of Warcraft "edge files", and it 52 is both efficient and easy-to-use--once you understand the basics. If you're still confused, 53 take a look at this URL, or any of the example themes: 54 55 http://www.wowwiki.com/EdgeFiles 56 */ 23 57 24 58 class OSGWIDGET_EXPORT Frame: public Table … … 26 60 public: 27 61 28 enum C ORNER62 enum CornerType 29 63 { 30 64 CORNER_LOWER_LEFT, … … 34 68 }; 35 69 36 enum B ORDER70 enum BorderType 37 71 { 38 72 BORDER_LEFT, … … 42 76 }; 43 77 44 static std::string cornerToString (CORNER); 45 static std::string borderToString (BORDER); 78 enum FrameOptions 79 { 80 FRAME_RESIZE = 1, 81 FRAME_MOVE = 2, 82 FRAME_TEXTURE = 4, 83 FRAME_ALL = FRAME_RESIZE | FRAME_MOVE | FRAME_TEXTURE 84 }; 85 86 static std::string cornerTypeToString (CornerType); 87 static std::string borderTypeToString (BorderType); 46 88 47 89 class OSGWIDGET_EXPORT Corner: public Widget 48 90 { 49 91 public: 50 META_Object (osgWidget, Corner);51 52 Corner (C ORNER= CORNER_LOWER_LEFT, point_type = 0.0f, point_type = 0.0f);92 META_Object(osgWidget, Corner); 93 94 Corner (CornerType = CORNER_LOWER_LEFT, point_type = 0.0f, point_type = 0.0f); 53 95 Corner (const Corner&, const osg::CopyOp&); 54 96 55 bool mouseDrag(double, double, WindowManager*); 56 57 CORNER getCorner() const { 97 virtual void parented (Window*); 98 virtual bool mouseDrag (double, double, WindowManager*); 99 100 CornerType getCornerType() const 101 { 58 102 return _corner; 59 103 } 60 104 61 void setCorner(CORNER corner) { 105 void setCornerType(CornerType corner) 106 { 62 107 _corner = corner; 63 108 } 64 109 65 void setCornerAndName(CORNER corner) { 110 void setCornerTypeAndName(CornerType corner) 111 { 66 112 _corner = corner; 67 _name = cornerT oString(corner);113 _name = cornerTypeToString(corner); 68 114 } 69 115 70 116 protected: 71 CORNER _corner; 117 118 CornerType _corner; 72 119 }; 73 120 … … 75 122 { 76 123 public: 77 META_Object (osgWidget, Border);78 79 Border (B ORDER= BORDER_LEFT, point_type = 0.0f, point_type = 0.0f);124 META_Object(osgWidget, Border); 125 126 Border (BorderType = BORDER_LEFT, point_type = 0.0f, point_type = 0.0f); 80 127 Border (const Border&, const osg::CopyOp&); 81 128 82 bool mouseDrag(double, double, WindowManager*); 83 84 BORDER getBorder() const { 129 virtual void parented (Window*); 130 virtual void positioned (); 131 virtual bool mouseDrag (double, double, WindowManager*); 132 133 BorderType getBorderType() const 134 { 85 135 return _border; 86 136 } 87 137 88 void setBorder(BORDER border) { 138 void setBorderType(BorderType border) 139 { 89 140 _border = border; 90 141 } 91 142 92 void setBorderAndName(BORDER border) { 143 void setBorderTypeAndName(BorderType border) 144 { 93 145 _border = border; 94 _name = borderT oString(border);146 _name = borderTypeToString(border); 95 147 } 96 148 97 149 protected: 98 150 99 BORDER _border; 100 101 }; 102 103 META_Object (osgWidget, Frame); 104 105 Frame (const std::string& = ""); 151 BorderType _border; 152 }; 153 154 META_Object(osgWidget, Frame); 155 156 Frame (const std::string& = "", unsigned int = 0); 106 157 Frame (const Frame&, const osg::CopyOp&); 107 108 virtual void managed(WindowManager*);109 158 110 159 static Frame* createSimpleFrame( … … 114 163 point_type, 115 164 point_type, 116 Frame* = 0 165 unsigned int = 0, 166 Frame* = 0 117 167 ); 118 168 119 169 static Frame* createSimpleFrameWithSingleTexture( 120 170 const std::string&, 171 osg::Image*, 172 point_type, 173 point_type, 174 unsigned int = 0, 175 Frame* = 0 176 ); 177 178 static Frame* createSimpleFrameFromTheme( 121 179 const std::string&, 122 point_type, 123 point_type, 124 point_type, 125 point_type, 126 point_type, 127 point_type, 128 Frame* = 0 180 osg::Image*, 181 point_type, 182 point_type, 183 unsigned int = 0, 184 Frame* = 0 129 185 ); 130 186 131 187 void createSimpleFrame(point_type cw, point_type ch, point_type w, point_type h) 132 188 { 133 createSimpleFrame(_name, cw, ch, w, h, this);189 createSimpleFrame(_name, cw, ch, w, h, 0, this); 134 190 } 135 191 136 192 void createSimpleFrameWithSingleTexture( 137 const std::string& tex, 138 point_type tw, 139 point_type th, 140 point_type cw, 141 point_type ch, 142 point_type w, 143 point_type h 193 osg::Image* image, 194 point_type w, 195 point_type h 144 196 ) 145 197 { 146 createSimpleFrameWithSingleTexture(_name, tex, tw, th, cw, ch, w, h, this);198 createSimpleFrameWithSingleTexture(_name, image, w, h, 0, this); 147 199 } 148 200 … … 153 205 const EmbeddedWindow* getEmbeddedWindow() const { return dynamic_cast<const EmbeddedWindow*>(getByRowCol(1, 1)); } 154 206 155 Corner* getCorner(CORNER c) { return dynamic_cast<Corner*>(_getCorner(c)); } 156 157 const Corner* getCorner(CORNER c) const { return dynamic_cast<const Corner*>(_getCorner(c)); } 158 159 Border* getBorder(BORDER b) { return dynamic_cast<Border*>(_getBorder(b)); } 160 161 const Border* getBorder(BORDER b) const { return dynamic_cast<const Border*>(_getBorder(b)); } 207 Corner* getCorner(CornerType c) { return dynamic_cast<Corner*>(_getCorner(c)); } 208 209 const Corner* getCorner(CornerType c) const { return dynamic_cast<const Corner*>(_getCorner(c)); } 210 211 Border* getBorder(BorderType b) { return dynamic_cast<Border*>(_getBorder(b)); } 212 213 const Border* getBorder(BorderType b) const { return dynamic_cast<const Border*>(_getBorder(b)); } 214 215 // This method resizes the internal EmbeddedWindow object and then properly resizes 216 // the reset of the Frame based on the sizes of the Corners, Borders, etc. 217 bool resizeFrame(point_type, point_type); 218 219 unsigned int getFlags() const 220 { 221 return _flags; 222 } 223 224 void setFlags(unsigned int flags) 225 { 226 _flags = flags; 227 } 228 229 bool canResize() const 230 { 231 return (_flags & FRAME_RESIZE) != 0; 232 } 233 234 bool canMove() const 235 { 236 return (_flags & FRAME_MOVE) != 0; 237 } 238 239 bool canTexture() const 240 { 241 return (_flags & FRAME_TEXTURE) != 0; 242 } 162 243 163 244 protected: 164 245 165 Widget* _getCorner (CORNER) const; 166 Widget* _getBorder (BORDER) const; 167 246 Widget* _getCorner (CornerType) const; 247 Widget* _getBorder (BorderType) const; 248 249 unsigned int _flags; 168 250 }; 169 251 -
OpenSceneGraph/trunk/include/osgWidget/Input
r8691 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: Input 45 2008-04-23 16:46:11Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_INPUT … … 22 21 namespace osgWidget { 23 22 23 // This is a string of values we use to try and determine the best Y 24 // descent value (yoffset); you're welcome to use what works best for 25 // your font. 26 const std::string DESCENT_STRING("qpl"); 27 24 28 class OSGWIDGET_EXPORT Input: public Label 25 29 { 26 30 public: 31 27 32 Input(const std::string& = "", const std::string& = "", unsigned int = 20); 28 33 … … 35 40 virtual bool keyDown (int, int, WindowManager*); 36 41 37 void setCursor(Widget*); 42 void setCursor (Widget*); 43 unsigned int calculateBestYOffset (const std::string& = "qgl"); 38 44 39 45 void setXOffset(point_type xo) { -
OpenSceneGraph/trunk/include/osgWidget/Label
r8865 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: Label 59 2008-05-15 20:55:31Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_LABEL … … 35 34 virtual void parented (Window*); 36 35 virtual void unparented (Window*); 37 virtual void managed (WindowManager*);38 36 virtual void positioned (); 39 37 40 void update ();41 38 void setLabel (const std::string&); 42 39 void setFont (const std::string&); -
OpenSceneGraph/trunk/include/osgWidget/Lua
r8691 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: Lua 2 2008-01-24 16:11:26Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_LUA -
OpenSceneGraph/trunk/include/osgWidget/Python
r8691 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: Python 2 2008-01-24 16:11:26Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_PYTHON -
OpenSceneGraph/trunk/include/osgWidget/ScriptEngine
r8691 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: ScriptEngine 2 2008-01-24 16:11:26Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_SCRIPT_ENGINE -
OpenSceneGraph/trunk/include/osgWidget/StyleInterface
r8768 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: StyleInterface 63 2008-06-30 19:18:37Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_STYLE_INTERFACE -
OpenSceneGraph/trunk/include/osgWidget/StyleManager
r8770 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: StyleManager 61 2008-06-24 20:24:26Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_STYLE_MANAGER -
OpenSceneGraph/trunk/include/osgWidget/Table
r8865 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: Table 48 2008-05-05 14:13:20Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_TABLE -
OpenSceneGraph/trunk/include/osgWidget/Types
r8691 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: Types 33 2008-04-04 19:03:12Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_TYPES … … 40 39 typedef osg::Matrix::value_type matrix_type; 41 40 41 // This is multiplied by a normalized Z value [0.0f, -1.0f] to create a RenderBin number 42 // to set the state of the Window/Widget with. Perhaps at some later time this should 43 // be configurable. 44 const int OSGWIDGET_RENDERBIN_MOD = 5000; 45 42 46 } 43 47 -
OpenSceneGraph/trunk/include/osgWidget/UIObjectParent
r9036 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: UIObjectParent 55 2008-05-12 19:14:42Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_UI_OBJECT_PARENT … … 27 26 { 28 27 public: 28 29 29 typedef T object_type; 30 30 typedef osg::observer_ptr<object_type> ptr_type; -
OpenSceneGraph/trunk/include/osgWidget/Util
r9008 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: Util 59 2008-05-15 20:55:31Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_UTIL 18 17 #define OSGWIDGET_UTIL 19 18 20 #include <c type.h>19 #include <cctype> 21 20 #include <algorithm> 22 21 #include <sstream> … … 72 71 OSGWIDGET_EXPORT std::string getFilePath (const std::string&); 73 72 OSGWIDGET_EXPORT std::string generateRandomName (const std::string&); 74 75 OSGWIDGET_EXPORT osg::Matrix createInvertedYOrthoProjectionMatrix (matrix_type, matrix_type); 76 OSGWIDGET_EXPORT osg::Camera* createOrthoCamera (matrix_type, matrix_type); 77 OSGWIDGET_EXPORT osg::Camera* createInvertedYOrthoCamera (matrix_type, matrix_type); 73 OSGWIDGET_EXPORT osg::Camera* createOrthoCamera (matrix_type, matrix_type); 78 74 79 75 // This function sets up our basic example framework, and optionally sets some root 80 76 // scene data. 81 OSGWIDGET_EXPORT int createExample(osgViewer::Viewer&, WindowManager*, osg::Node* = 0); 82 83 // This function works like the above routine, except creates an additional "outside" 84 // view for looking at your 2D scene. 85 // TODO: Fix this! 86 OSGWIDGET_EXPORT int createCompositeExample( 87 osgViewer::CompositeViewer&, 88 osgViewer::View*, 89 WindowManager*, 90 osg::Node* = 0 91 ); 92 93 OSGWIDGET_EXPORT bool writeWindowManagerNode(WindowManager*); 77 OSGWIDGET_EXPORT int createExample (osgViewer::Viewer&, WindowManager*, osg::Node* = 0); 78 OSGWIDGET_EXPORT bool writeWindowManagerNode (WindowManager*); 94 79 95 80 } -
OpenSceneGraph/trunk/include/osgWidget/Version
r8593 r9287 1 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 2 // $Id: Version 64 2008-06-30 21:32:00Z cubicool $ 1 // Code by: Jeremy Moles (cubicool) 2007-2008 3 2 4 3 #ifndef OSGWIDGET_VERSION -
OpenSceneGraph/trunk/include/osgWidget/ViewerEventHandlers
r8865 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: ViewerEventHandlers 31 2008-04-01 19:36:41Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_VIEWER_EVENT_HANDLERS … … 32 31 { 33 32 public: 33 34 34 MouseHandler(WindowManager*); 35 35 … … 47 47 protected: 48 48 49 osg:: ref_ptr<WindowManager> _wm;49 osg::observer_ptr<WindowManager> _wm; 50 50 51 51 bool _handleMousePush (float, float, int); … … 58 58 MouseAction _isMouseEvent (osgGA::GUIEventAdapter::EventType) const; 59 59 bool _doMouseEvent (float, float, MouseEvent); 60 61 60 }; 62 61 … … 65 64 { 66 65 public: 66 67 67 KeyboardHandler(WindowManager*); 68 68 … … 75 75 76 76 protected: 77 osg:: ref_ptr<WindowManager> _wm;77 osg::observer_ptr<WindowManager> _wm; 78 78 79 79 }; … … 83 83 { 84 84 public: 85 ResizeHandler(WindowManager*, osg::Camera*); 85 86 ResizeHandler(WindowManager*, osg::Camera* = 0); 86 87 87 88 virtual bool handle( … … 94 95 protected: 95 96 96 osg::ref_ptr<WindowManager> _wm; 97 osg::ref_ptr<osg::Camera> _camera; 97 osg::observer_ptr<WindowManager> _wm; 98 osg::observer_ptr<osg::Camera> _camera; 99 }; 98 100 101 // This class provides a hotkey that lets you toggle back and forth between 102 // a camera and setting the CameraManipulator's home point. 103 class OSGWIDGET_EXPORT CameraSwitchHandler: public osgGA::GUIEventHandler 104 { 105 public: 106 107 CameraSwitchHandler(WindowManager*, osg::Camera*); 108 109 virtual bool handle( 110 const osgGA::GUIEventAdapter&, 111 osgGA::GUIActionAdapter&, 112 osg::Object*, 113 osg::NodeVisitor* 114 ); 115 116 protected: 117 118 osg::observer_ptr<WindowManager> _wm; 119 osg::observer_ptr<osg::Camera> _camera; 120 osg::ref_ptr<osg::Node> _oldNode; 99 121 }; 100 122 -
OpenSceneGraph/trunk/include/osgWidget/Widget
r8865 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: Widget 64 2008-06-30 21:32:00Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_WIDGET … … 45 44 UR = UPPER_RIGHT, 46 45 UL = UPPER_LEFT, 47 ALL_CORNERS = 446 ALL_CORNERS = 4 48 47 }; 49 48 50 49 enum Layer { 51 LAYER_TOP = 20,52 LAYER_HIGH = 15,53 LAYER_MIDDLE = 10,54 LAYER_LOW = 5,50 LAYER_TOP = 100, 51 LAYER_HIGH = 75, 52 LAYER_MIDDLE = 50, 53 LAYER_LOW = 25, 55 54 LAYER_BG = 0 56 55 }; … … 95 94 // TO CALL IN YOUR DERIVED METHODS!) sets the TexMat properly depending 96 95 // on what coordinate system you're using. 97 virtual void managed(WindowManager*); 96 virtual void managed(WindowManager*) { 97 } 98 98 99 99 virtual void unmanaged(WindowManager*) { … … 118 118 void addColor (color_type, color_type, color_type, color_type, Corner = ALL_CORNERS); 119 119 void setTexCoord (texcoord_type, texcoord_type, Corner = ALL_CORNERS); 120 void setLayer (Layer l, unsigned int offset = 0); 120 121 121 122 // These are additional texture coordinate setting methods. … … 128 129 void setTexCoordWrapVertical (); 129 130 130 bool setImage (osg::Image*, bool=false); 131 bool setImage (const std::string&, bool=false); 131 bool setImage (osg::Image*, bool = false, bool = false); 132 bool setImage (const std::string&, bool = false, bool = false); 133 bool setTexture (osg::Texture*, bool = false, bool = false); 132 134 133 135 void addX (point_type); … … 150 152 const TexCoord& getTexCoord (Corner = ALL_CORNERS) const; 151 153 152 Corner convertCorner (Corner) const;153 154 Color getImageColorAtXY (point_type x, point_type y) const; 154 155 XYCoord localXY (double, double) const; … … 217 218 } 218 219 220 void setTexCoordRegion(point_type x, point_type y, const XYCoord& wh) { 221 setTexCoordRegion(x, y, wh.x(), wh.y()); 222 } 223 224 void setTexCoordRegion(const XYCoord& xy, const XYCoord& wh) { 225 setTexCoordRegion(xy.x(), xy.y(), wh.x(), wh.y()); 226 } 227 219 228 void addColor(const Color& col, Corner p = ALL_CORNERS) { 220 229 addColor(col.r(), col.g(), col.b(), col.a(), p); … … 236 245 void setMinimumSize(const XYCoord& xy) { 237 246 setMinimumSize(xy.x(), xy.y()); 238 }239 240 // TODO: Refine this...241 void setLayer(Layer l, unsigned int offset = 0) {242 _layer = l + offset;243 247 } 244 248 … … 395 399 protected: 396 400 397 398 399 401 point_type _calculateZ(unsigned int) const; 400 402 … … 423 425 } 424 426 425 osg::Texture2D* _texture() { 427 osg::Texture* _texture() { 428 osg::StateSet* ss = getStateSet(); 429 430 if(!ss) return 0; 431 426 432 return dynamic_cast<osg::Texture2D*>( 427 getStateSet()->getTextureAttribute(0, osg::StateAttribute::TEXTURE)433 ss->getTextureAttribute(0, osg::StateAttribute::TEXTURE) 428 434 ); 429 435 } 430 436 431 const osg::Texture2D* _texture() const { 437 const osg::Texture* _texture() const { 438 const osg::StateSet* ss = getStateSet(); 439 440 if(!ss) return 0; 441 432 442 return dynamic_cast<const osg::Texture2D*>( 433 getStateSet()->getTextureAttribute(0, osg::StateAttribute::TEXTURE)443 ss->getTextureAttribute(0, osg::StateAttribute::TEXTURE) 434 444 ); 435 445 } -
OpenSceneGraph/trunk/include/osgWidget/Window
r8865 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: Window 66 2008-07-14 21:54:09Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_WINDOW … … 74 73 virtual void positioned (); 75 74 76 bool setWindow(Window*); 75 bool setWindow (Window*); 76 void updateSizeFromWindow (); 77 77 78 78 Window* getWindow() { … … 140 140 // This method wraps our Geode's addDrawable() method and returns the index of 141 141 // the newly-added Drawable. 142 unsigned int addDrawableAndGetIndex(osg::Drawable*); 142 unsigned int addDrawableAndGetIndex (osg::Drawable*); 143 unsigned int addChildAndGetIndex (osg::Node*); 143 144 144 145 bool isVisible () const; … … 148 149 bool setFocused (const Widget*); 149 150 bool setFocused (const std::string&); 151 bool grabFocus (); 150 152 bool setFirstFocusable (); 151 153 bool setNextFocusable (); … … 158 160 159 161 // This method wraps the current Window in a EmbeddedWindow object and returns it. 160 EmbeddedWindow* embed(); 162 EmbeddedWindow* embed( 163 const std::string& = "", 164 Widget::Layer = Widget::LAYER_MIDDLE, 165 unsigned int = 0 166 ); 161 167 162 168 Widget* getFocused() { … … 312 318 void setY(matrix_type y) { 313 319 _y = y; 320 } 321 322 void setZ(matrix_type z) { 323 _z = z; 324 } 325 326 void setZRange(matrix_type zRange) { 327 _zRange = zRange; 314 328 } 315 329 … … 329 343 } 330 344 345 void setOrigin(const XYCoord& xy) { 346 setOrigin(xy.x(), xy.y()); 347 } 348 331 349 void setRotate(matrix_type r) { 332 350 _r = r; … … 383 401 384 402 void attachMoveCallback() { 385 addCallback( Callback(&callbackWindowMove, EVENT_MOUSE_DRAG));403 addCallback(new Callback(&callbackWindowMove, EVENT_MOUSE_DRAG)); 386 404 } 387 405 388 406 void attachRotateCallback() { 389 addCallback( Callback(&callbackWindowRotate, EVENT_MOUSE_DRAG));407 addCallback(new Callback(&callbackWindowRotate, EVENT_MOUSE_DRAG)); 390 408 } 391 409 392 410 void attachScaleCallback() { 393 addCallback( Callback(&callbackWindowScale, EVENT_MOUSE_DRAG));411 addCallback(new Callback(&callbackWindowScale, EVENT_MOUSE_DRAG)); 394 412 } 395 413 396 414 void attachTabFocusCallback() { 397 addCallback( Callback(&callbackWindowTabFocus, EVENT_KEY_DOWN));415 addCallback(new Callback(&callbackWindowTabFocus, EVENT_KEY_DOWN)); 398 416 } 399 417 -
OpenSceneGraph/trunk/include/osgWidget/WindowManager
r8693 r9287 12 12 */ 13 13 14 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 15 // $Id: WindowManager 66 2008-07-14 21:54:09Z cubicool $ 14 // Code by: Jeremy Moles (cubicool) 2007-2008 16 15 17 16 #ifndef OSGWIDGET_WINDOW_MANAGER … … 41 40 public: 42 41 enum WmFlags { 43 WM_USE_LUA = 0x00000001, 44 WM_USE_PYTHON = 0x00000002, 45 WM_PICK_DEBUG = 0x00000004, 46 WM_NO_INVERT_Y = 0x00000008, 47 WM_NO_BETA_WARN = 0x00000010 42 WM_USE_LUA = 0x00000001, 43 WM_USE_PYTHON = 0x00000002, 44 WM_USE_RENDERBINS = 0x00000004, 45 WM_PICK_DEBUG = 0x00000008 48 46 }; 49 47 … … 92 90 void resizeAllWindows (bool = true); 93 91 92 XYCoord windowXY (double, double) const; 93 XYCoord localXY (double, double) const; 94 94 95 // Methods all called by the ViewerEventHandlers::MouseHandler object, or 95 96 // by some customer caller of your own. Examples of this to come... … … 120 121 } 121 122 122 bool is InvertedY() const {123 return (_flags & WM_ NO_INVERT_Y) == 0;123 bool isUsingRenderBins() const { 124 return (_flags & WM_USE_RENDERBINS) != 0; 124 125 } 125 126 … … 241 242 _width = w; 242 243 _height = h; 244 } 245 246 void setWindowSize(point_type w, point_type h) { 247 _windowWidth = w; 248 _windowHeight = h; 243 249 } 244 250 … … 283 289 }; 284 290 291 // A functor used to sort the Windows by their BinNum component in descending order. 292 struct WindowBinNumberCompare: public std::binary_function<ptr_type, ptr_type, bool> { 293 bool operator()(const ptr_type& x, const ptr_type& y) { 294 return 295 x.get()->getOrCreateStateSet()->getBinNumber() > 296 y.get()->getOrCreateStateSet()->getBinNumber() 297 ; 298 } 299 }; 300 285 301 point_type _width; 286 302 point_type _height; 287 point_type _ zNear;288 point_type _ zFar;303 point_type _windowWidth; 304 point_type _windowHeight; 289 305 matrix_type _numForeground; 290 306 matrix_type _numBackground; -
OpenSceneGraph/trunk/src/osgWidget/Box.cpp
r8769 r9287 1 1 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 2 // $Id: Box.cpp 64 2008-06-30 21:32:00Z cubicool $3 2 4 3 #include <osgWidget/Box> … … 6 5 namespace osgWidget { 7 6 8 Box::Box(const std::string& name, B OX_TYPEbt, bool uniform):7 Box::Box(const std::string& name, BoxType bt, bool uniform): 9 8 Window (name), 10 9 _boxType (bt), -
OpenSceneGraph/trunk/src/osgWidget/Canvas.cpp
r8769 r9287 1 1 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 2 // $Id: Canvas.cpp 66 2008-07-14 21:54:09Z cubicool $3 2 4 3 #include <osgWidget/Canvas> … … 21 20 22 21 bool Canvas::addWidget(Widget* widget, point_type x, point_type y) { 23 if(Window::addWidget(widget)) { 24 widget->setOrigin(x, y); 22 if(!widget) return false; 25 23 26 return true; 27 } 28 29 return false; 24 widget->setOrigin(x, y); 25 26 return Window::addWidget(widget); 30 27 } 31 28 -
OpenSceneGraph/trunk/src/osgWidget/Frame.cpp
r8769 r9287 1 1 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 2 // $Id: Frame.cpp 59 2008-05-15 20:55:31Z cubicool $ 3 2 3 #include <osg/io_utils> 4 4 #include <osgDB/ReadFile> 5 5 #include <osgWidget/WindowManager> 6 6 #include <osgWidget/Frame> 7 #include <cassert> 7 8 8 9 namespace osgWidget { 9 10 10 std::string Frame::cornerToString(CORNER c) { 11 std::string Frame::cornerTypeToString(CornerType c) 12 { 11 13 if(c == CORNER_LOWER_LEFT) return "CornerLowerLeft"; 12 14 … … 18 20 } 19 21 20 std::string Frame::borderToString(BORDER b) { 22 std::string Frame::borderTypeToString(BorderType b) 23 { 21 24 if(b == BORDER_LEFT) return "BorderLeft"; 22 25 … … 28 31 } 29 32 30 Frame::Corner::Corner(C ORNERcorner, point_type width, point_type height):31 Widget (cornerT oString(corner), width, height),32 _corner (corner) {33 setEventMask(EVENT_MASK_MOUSE_DRAG); 33 Frame::Corner::Corner(CornerType corner, point_type width, point_type height): 34 Widget (cornerTypeToString(corner), width, height), 35 _corner (corner) 36 { 34 37 } 35 38 36 39 Frame::Corner::Corner(const Corner& corner, const osg::CopyOp& co): 37 40 Widget (corner, co), 38 _corner (corner._corner) { 39 } 40 41 bool Frame::Corner::mouseDrag(double x, double y, WindowManager* wm) { 42 Window* parent = getParent(); 43 44 if(!parent) return false; 45 46 if(wm->isInvertedY()) { 47 if(_corner == CORNER_UPPER_LEFT) { 48 if(parent->resizeAdd(-x, -y)) parent->addOrigin(x, y); 49 } 50 51 else if(_corner == CORNER_UPPER_RIGHT) { 52 if(parent->resizeAdd(x, -y)) parent->addY(y); 53 } 54 55 else if(_corner == CORNER_LOWER_RIGHT) parent->resizeAdd(x, y); 56 57 else { 58 if(parent->resizeAdd(-x, y)) parent->addX(x); 59 } 60 } 61 62 // These are basically flipped-around versions of the above routines; we 63 // do it this way to avoid lots of uncessary if tests. 41 _corner (corner._corner) 42 { 43 } 44 45 void Frame::Corner::parented(Window* window) { 46 Frame* parent = dynamic_cast<Frame*>(getParent()); 47 48 if(!parent) return; 49 50 if(parent->canResize()) setEventMask(EVENT_MASK_MOUSE_DRAG); 51 } 52 53 bool Frame::Corner::mouseDrag(double x, double y, WindowManager* wm) 54 { 55 Frame* parent = dynamic_cast<Frame*>(getParent()); 56 57 if(!parent || !parent->canResize()) return false; 58 59 if(_corner == CORNER_UPPER_LEFT) { 60 if(parent->resizeAdd(-x, y)) parent->addX(x); 61 } 62 63 else if(_corner == CORNER_UPPER_RIGHT) parent->resizeAdd(x, y); 64 65 else if(_corner == CORNER_LOWER_RIGHT) { 66 if(parent->resizeAdd(x, -y)) parent->addY(y); 67 } 68 64 69 else { 65 if(_corner == CORNER_UPPER_LEFT) { 66 if(parent->resizeAdd(-x, y)) parent->addX(x); 67 } 68 69 else if(_corner == CORNER_UPPER_RIGHT) parent->resizeAdd(x, y); 70 71 else if(_corner == CORNER_LOWER_RIGHT) { 72 if(parent->resizeAdd(x, -y)) parent->addY(y); 73 } 74 75 else { 76 if(parent->resizeAdd(-x, -y)) parent->addOrigin(x, y); 77 } 70 if(parent->resizeAdd(-x, -y)) parent->addOrigin(x, y); 78 71 } 79 72 … … 83 76 } 84 77 85 Frame::Border::Border(BORDER border, point_type width, point_type height): 86 Widget (borderToString(border), width, height), 87 _border (border) { 78 Frame::Border::Border(BorderType border, point_type width, point_type height): 79 Widget (borderTypeToString(border), width, height), 80 _border (border) 81 { 88 82 setCanFill(true); 89 setEventMask(EVENT_MASK_MOUSE_DRAG);90 83 } 91 84 92 85 Frame::Border::Border(const Border& border, const osg::CopyOp& co): 93 86 Widget (border, co), 94 _border (border._border) { 95 } 96 97 bool Frame::Border::mouseDrag(double x, double y, WindowManager* wm) { 98 Window* parent = getParent(); 99 87 _border (border._border) 88 { 89 } 90 91 void Frame::Border::parented(Window* window) { 92 Frame* parent = dynamic_cast<Frame*>(getParent()); 93 94 if(!parent) return; 95 96 if(parent->canResize()) setEventMask(EVENT_MASK_MOUSE_DRAG); 97 } 98 99 void Frame::Border::positioned() 100 { 101 osg::Image* image = _image(); 102 103 if(!image) return; 104 105 Frame* parent = dynamic_cast<Frame*>(getParent()); 106 107 if(!parent || !parent->canTexture()) return; 108 109 point_type w = image->s() / 8.0f; 110 point_type h = getHeight(); 111 112 if(_border == BORDER_LEFT) setTexCoordRegion(w * 3, 0.0f, w, h); 113 114 else if(_border == BORDER_RIGHT) setTexCoordRegion(w * 4, 0.0f, w, h); 115 116 else if(_border == BORDER_TOP) { 117 // TODO: Temporary; fix this. 118 point_type tx1 = (w * 2) / image->s(); 119 point_type tx2 = w / image->s(); 120 point_type tx3 = getWidth() / w; 121 122 setTexCoord(tx1, tx3, LL); 123 setTexCoord(tx1, 0.0f, LR); 124 setTexCoord(tx2, 0.0f, UR); 125 setTexCoord(tx2, tx3, UL); 126 } 127 128 else { 129 point_type tx1 = (w * 7) / image->s(); 130 point_type tx2 = (w * 6) / image->s(); 131 point_type tx3 = getWidth() / w; 132 133 setTexCoord(tx1, tx3, LL); 134 setTexCoord(tx1, 0.0f, LR); 135 setTexCoord(tx2, 0.0f, UR); 136 setTexCoord(tx2, tx3, UL); 137 } 138 } 139 140 bool Frame::Border::mouseDrag(double x, double y, WindowManager* wm) 141 { 142 Frame* parent = dynamic_cast<Frame*>(getParent()); 143 100 144 if(!parent) return false; 101 145 102 if(_border == BORDER_LEFT) { 103 if(parent->resizeAdd(-x, 0.0f)) parent->addX(x); 104 } 105 106 else if(_border == BORDER_RIGHT) parent->resizeAdd(x, 0.0f); 107 108 else if(_border == BORDER_TOP) parent->addOrigin(x, y); 146 if(_border == BORDER_TOP && parent->canMove()) parent->addOrigin(x, y); 109 147 110 148 else { 111 // The only BORDER that inverted-Y affects is this... 112 if(wm->isInvertedY()) parent->resizeAdd(0.0f, y); 149 if(!parent->canResize()) return false; 150 151 if(_border == BORDER_LEFT) { 152 if(parent->resizeAdd(-x, 0.0f)) parent->addX(x); 153 } 154 155 else if(_border == BORDER_RIGHT) parent->resizeAdd(x, 0.0f); 113 156 114 157 else { … … 122 165 } 123 166 124 Frame::Frame(const std::string& name): 125 Table(name, 3, 3) { 167 Frame::Frame(const std::string& name, unsigned int flags): 168 Table (name, 3, 3), 169 _flags (flags) 170 { 126 171 } 127 172 128 173 Frame::Frame(const Frame& frame, const osg::CopyOp& co): 129 Table(frame, co) { 130 } 131 132 Widget* Frame::_getCorner(CORNER c) const { 133 return const_cast<Widget*>(getByName(cornerToString(c))); 134 } 135 136 Widget* Frame::_getBorder(BORDER b) const { 137 return const_cast<Widget*>(getByName(borderToString(b))); 138 } 139 140 void Frame::managed(WindowManager* wm) { 141 Window::managed(wm); 142 143 // Our Frame is created in an inverted-Y environment, so if this is the case 144 // just return here. 145 if(wm->isInvertedY()) return; 146 147 Corner* ll = getCorner(CORNER_LOWER_LEFT); 148 Corner* lr = getCorner(CORNER_LOWER_RIGHT); 149 Corner* ul = getCorner(CORNER_UPPER_LEFT); 150 Corner* ur = getCorner(CORNER_UPPER_RIGHT); 151 Border* t = getBorder(BORDER_TOP); 152 Border* b = getBorder(BORDER_BOTTOM); 153 154 if(!ll || !lr || !ul || !ur || !t || !b) { 155 warn() 156 << "One or more of your Corner/Border objects in the Frame [" 157 << _name << "] are invalid; cannot invert orientation." << std::endl 158 ; 159 160 return; 161 } 162 163 ll->setCornerAndName(CORNER_UPPER_LEFT); 164 lr->setCornerAndName(CORNER_UPPER_RIGHT); 165 ul->setCornerAndName(CORNER_LOWER_LEFT); 166 ur->setCornerAndName(CORNER_LOWER_RIGHT); 167 t->setBorderAndName(BORDER_BOTTOM); 168 b->setBorderAndName(BORDER_TOP); 169 } 170 171 bool Frame::setWindow(Window* window) { 174 Table(frame, co) 175 { 176 } 177 178 Widget* Frame::_getCorner(CornerType c) const 179 { 180 return const_cast<Widget*>(getByName(cornerTypeToString(c))); 181 } 182 183 Widget* Frame::_getBorder(BorderType b) const 184 { 185 return const_cast<Widget*>(getByName(borderTypeToString(b))); 186 } 187 188 bool Frame::setWindow(Window* window) 189 { 172 190 if(!window) return false; 173 191 … … 187 205 point_type w, 188 206 point_type h, 207 unsigned int flags, 189 208 Frame* exFrame 190 209 ) { … … 193 212 // Use an "existing frame" if we have it (for example, if you've in inherited from 194 213 // Frame and want to use this stuff. 195 if(!exFrame) frame = new Frame(name );214 if(!exFrame) frame = new Frame(name, flags); 196 215 197 216 else frame = exFrame; 198 217 199 frame->addWidget(new Corner(CORNER_ UPPER_LEFT, cw,ch), 0, 0);200 frame->addWidget(new Border(BORDER_ TOP, w,ch), 0, 1);201 frame->addWidget(new Corner(CORNER_ UPPER_RIGHT, cw, ch), 0, 2);202 frame->addWidget(new Border(BORDER_LEFT, cw, h),1, 0);203 frame->addWidget(new Border(BORDER_RIGHT, cw, h),1, 2);204 frame->addWidget(new Corner(CORNER_ LOWER_LEFT,cw, ch), 2, 0);205 frame->addWidget(new Border(BORDER_ BOTTOM, w,ch), 2, 1);206 frame->addWidget(new Corner(CORNER_ LOWER_RIGHT, cw, ch), 2, 2);218 frame->addWidget(new Corner(CORNER_LOWER_LEFT, cw, ch), 0, 0); 219 frame->addWidget(new Border(BORDER_BOTTOM, w, ch), 0, 1); 220 frame->addWidget(new Corner(CORNER_LOWER_RIGHT, cw, ch), 0, 2); 221 frame->addWidget(new Border(BORDER_LEFT, cw, h), 1, 0); 222 frame->addWidget(new Border(BORDER_RIGHT, cw, h), 1, 2); 223 frame->addWidget(new Corner(CORNER_UPPER_LEFT, cw, ch), 2, 0); 224 frame->addWidget(new Border(BORDER_TOP, w, ch), 2, 1); 225 frame->addWidget(new Corner(CORNER_UPPER_RIGHT, cw, ch), 2, 2); 207 226 208 227 EmbeddedWindow* ew = new EmbeddedWindow(name, w, h); … … 215 234 } 216 235 236 /* 217 237 Frame* Frame::createSimpleFrameWithSingleTexture( 218 238 const std::string& name, … … 248 268 return frame; 249 269 } 250 251 } 270 */ 271 272 // Inspired by: http://www.wowwiki.com/EdgeFiles 273 Frame* Frame::createSimpleFrameWithSingleTexture( 274 const std::string& name, 275 osg::Image* image, 276 point_type width, 277 point_type height, 278 unsigned int flags, 279 Frame* exFrame 280 ) { 281 Frame* frame = 0; 282 283 double w = width; 284 double h = height; 285 286 if (image) 287 { 288 w = image->s() / 8.0f; 289 h = image->t(); 290 } 291 292 // The same as above... 293 if(!exFrame) frame = createSimpleFrame(name, w, h, width, height, flags); 294 295 else frame = createSimpleFrame(name, w, h, width, height, 0, exFrame); 296 297 if (image) 298 { 299 300 for(unsigned int i = 0; i < 9; i++) frame->getObjects()[i]->setImage(image); 301 302 XYCoord twh(w, h); 303 304 frame->getCorner(CORNER_UPPER_LEFT )->setTexCoordRegion(0.0f, 0.0f, twh); 305 frame->getBorder(BORDER_TOP )->setTexCoordRegion(w, 0.0f, twh); 306 frame->getCorner(CORNER_UPPER_RIGHT)->setTexCoordRegion(w * 2, 0.0f, twh); 307 frame->getBorder(BORDER_LEFT )->setTexCoordRegion(w * 3, 0.0f, twh); 308 frame->getBorder(BORDER_RIGHT )->setTexCoordRegion(w * 4, 0.0f, twh); 309 frame->getCorner(CORNER_LOWER_LEFT )->setTexCoordRegion(w * 5, 0.0f, twh); 310 frame->getBorder(BORDER_BOTTOM )->setTexCoordRegion(w * 6, 0.0f, twh); 311 frame->getCorner(CORNER_LOWER_RIGHT)->setTexCoordRegion(w * 7, 0.0f, twh); 312 313 // We set all of these to wrap vertically, but the REAL texture coordinates will 314 // be generated properly in the positioned() method. 315 frame->getByRowCol(0, 1)->setTexCoordWrapVertical(); 316 frame->getByRowCol(1, 0)->setTexCoordWrapVertical(); 317 frame->getByRowCol(1, 2)->setTexCoordWrapVertical(); 318 frame->getByRowCol(2, 1)->setTexCoordWrapVertical(); 319 320 // frame->getEmbeddedWindow()->setTexCoordRegion(cw, ch, tw - (cw * 2.0f), th - (ch * 2.0f)); 321 } 322 else 323 { 324 osg::notify(osg::WARN) << "createSimpleFrameWithSingleTexture with a null image, the frame " << name << " will be use texture" << std::endl; 325 } 326 327 return frame; 328 } 329 330 bool Frame::resizeFrame(point_type w, point_type h) { 331 Border* left = getBorder(BORDER_LEFT); 332 Border* right = getBorder(BORDER_RIGHT); 333 Border* top = getBorder(BORDER_TOP); 334 Border* bottom = getBorder(BORDER_BOTTOM); 335 336 if(!left || !right || !top || !bottom) return false; 337 338 return resize( 339 left->getWidth() + right->getWidth() + w, 340 top->getHeight() + bottom->getHeight() + h 341 ); 342 } 343 344 345 osg::Image* createNatifEdgeImageFromTheme(osg::Image* theme); 346 347 Frame* Frame::createSimpleFrameFromTheme( 348 const std::string& name, 349 osg::Image* image, 350 point_type width, 351 point_type height, 352 unsigned int flags, 353 Frame* exFrame 354 ) { 355 356 osg::ref_ptr<osg::Image> natifImage = createNatifEdgeImageFromTheme(image); 357 Frame* frame; 358 359 frame = createSimpleFrameWithSingleTexture(name, natifImage.get(), width, height, flags, exFrame); 360 361 if (frame && image && natifImage.valid()) 362 { 363 const unsigned int bpps = image->getPixelSizeInBits() / 8; 364 const unsigned int one_third_s = image->s()/3; 365 unsigned char* srcdata = (unsigned char*)image->data(); 366 osg::Vec4 color(0,0,0,1); 367 for (unsigned int d = 0; d < bpps; d++) 368 { 369 color[d] = srcdata[one_third_s * image->s() * bpps + (one_third_s) * bpps + d] * 1.0/255.0; 370 } 371 frame->getEmbeddedWindow()->setColor(color); 372 } 373 return frame; 374 } 375 376 377 378 379 380 381 382 // (c) 2006-2008 Jean-Sébastien Guay 383 // adapted by Cedric Pinson 384 385 /** Implementation of copyImage. */ 386 template<typename T> 387 void copyDataImpl(const osg::Image* source, 388 const unsigned int x1, const unsigned int y1, 389 const unsigned int x2, const unsigned int y2, 390 osg::Image* destination, 391 const unsigned int xd = 0, const unsigned int yd = 0) 392 { 393 if ((unsigned int)destination->s() >= xd + (x2 - x1) && 394 (unsigned int)destination->t() >= yd + (y2 - y1)) 395 { 396 const unsigned int bpps = source->getPixelSizeInBits() / (8 * sizeof(T)); 397 398 T* srcdata = (T*)source->data(); 399 T* dstdata = (T*)destination->data(); 400 401 for (unsigned int y = 0; y < y2 - y1; ++y) 402 { 403 for (unsigned int x = 0; x < x2 - x1; ++x) 404 { 405 for (unsigned int d = 0; d < bpps; d++) 406 { 407 T v = srcdata[(y + y1) * source->s() * bpps + (x + x1) * bpps + d]; 408 dstdata[(yd + y) * destination->s() * bpps + (xd + x) * bpps + d] = v; 409 } 410 } 411 } 412 } 413 else 414 assert(false && "copyDataImpl: Incorrect image dimensions."); 415 } 416 417 /** Copies a rectangle of corners (x1, y1), (x2, y2) from an image into 418 another image starting at position (xd, yd). No scaling is done, the 419 pixels are just copied, so the destination image must be at least 420 (xd + (x2 - x1)) by (yd + (y2 - y1)) pixels. */ 421 void copyData(const osg::Image* source, 422 const unsigned int x1, const unsigned int y1, 423 const unsigned int x2, const unsigned int y2, 424 osg::Image* destination, 425 const unsigned int xd, const unsigned int yd) 426 { 427 if (source->getDataType() == destination->getDataType()) 428 { 429 if (source->getDataType() == GL_UNSIGNED_BYTE) 430 { 431 copyDataImpl<unsigned char>(source, x1, y1, x2, y2, 432 destination, xd, yd); 433 } 434 else 435 { 436 assert(false && "copyData not implemented for this data type"); 437 } 438 } 439 else 440 { 441 assert(false && "source and destination images must be of the same type."); 442 return; 443 } 444 } 445 446 447 /** Implementation of rotateImage. */ 448 template<typename T> 449 osg::Image* rotateImageImpl(osg::Image* image) 450 { 451 if (image->s() == image->t()) 452 { 453 const unsigned int s = image->s(); 454 const unsigned int bpp = image->getPixelSizeInBits() / (8 * sizeof(T)); 455 456 osg::ref_ptr<osg::Image> destination = new osg::Image; 457 destination->allocateImage(s, s, 1, 458 image->getPixelFormat(), image->getDataType(), 459 image->getPacking()); 460 destination->setInternalTextureFormat(image->getInternalTextureFormat()); 461 462 T* srcdata = (T*)image->data(); 463 T* dstdata = (T*)destination->data(); 464 465 for (unsigned int y = 0; y < s; ++y) 466 { 467 for (unsigned int x = 0; x < s; ++x) 468 { 469 for (unsigned int p = 0; p < bpp; p++) 470 dstdata[y * s * bpp + x * bpp + p] = srcdata[x * s * bpp + y * bpp + p]; 471 } 472 } 473 474 return destination.release(); 475 } 476 else 477 { 478 assert(false && "rotateImageImpl: Image must be square."); 479 return 0; 480 } 481 } 482 483 /** Rotates an osg::Image by 90 degrees. Returns a new osg::Image, be sure to 484 store it in a ref_ptr so it will be freed correctly. */ 485 osg::Image* rotateImage(osg::Image* image) 486 { 487 if (image->getDataType() == GL_UNSIGNED_BYTE) 488 { 489 return rotateImageImpl<unsigned char>(image); 490 } 491 else 492 { 493 assert(false && "rotateImage not implemented for this data type"); 494 return 0; 495 } 496 } 497 498 499 500 // SOURCE 501 // +---+---+---+ 502 // | 1 | 2 | 3 | 503 // +---+---+---+ 504 // | 4 | | 5 | 505 // +---+---+---+ 506 // | 6 | 7 | 8 | 507 // +---+---+---+ 508 509 510 // FINAL 511 // +---+---+---+---+---+---+---+---+ 512 // | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 513 // +---+---+---+---+---+---+---+---+ 514 515 // 1. Upper-Left corner. 516 // 2. Top border (rotated 90 degrees CCW). 517 // 3. Upper-Right corner. 518 // 4. Left border. 519 // 5. Right border. 520 // 6. Bottom-Left corner. 521 // 7. Bottom border (rotated 90 degrees CCW). 522 // 8. Bottom-Right corner. 523 524 osg::Image* createNatifEdgeImageFromTheme(osg::Image* theme) 525 { 526 if (!theme) { 527 osg::notify(osg::WARN) << "can't create a natif edge image from null image theme as argument" << std::endl; 528 return 0; 529 } 530 osg::ref_ptr<osg::Image> final = new osg::Image; 531 const int s = theme->s(); 532 const int t = theme->t(); 533 const GLenum pixelFormat = theme->getPixelFormat(); 534 const GLenum dataType = theme->getDataType(); 535 const GLint internalFormat = theme->getInternalTextureFormat(); 536 unsigned int packing = theme->getPacking(); 537 538 if (s != t) 539 { 540 osg::notify(osg::WARN) << "width and height are different, bad format theme image " << theme->getFileName() << std::endl; 541 return 0; 542 } 543 544 // check size 545 int ceilvalue = static_cast<int>(ceil(s * 1.0 / 3)); 546 int intvalue = s/3; 547 if (intvalue != ceilvalue) 548 { 549 osg::notify(osg::WARN) << "the size of theme file " << theme->getFileName() << " can not be divided by 3, check the documentation about theme format" << std::endl; 550 return 0; 551 } 552 553 const unsigned int one_third_s = s/3; 554 const unsigned int one_third_t = t/3; 555 556 final->allocateImage(8 * one_third_s , one_third_t, 1, pixelFormat, dataType, packing); 557 final->setInternalTextureFormat(internalFormat); 558 559 // copy 1 (6 in source) 560 copyData(theme, 0, 2 * one_third_s, one_third_s, 3 * one_third_s, final.get(), 0, 0); 561 562 // rotate and copy 2 563 osg::ref_ptr<osg::Image> rotateandcopy2 = new osg::Image; 564 rotateandcopy2->allocateImage(one_third_s , one_third_t, 1, pixelFormat, dataType, packing); 565 rotateandcopy2->setInternalTextureFormat(internalFormat); 566 copyData(theme, one_third_s, 0, 2 * one_third_s , one_third_s, rotateandcopy2.get(), 0, 0); 567 rotateandcopy2 = rotateImage(rotateandcopy2.get()); 568 rotateandcopy2->flipHorizontal(); 569 copyData(rotateandcopy2.get(), 0, 0, one_third_s , one_third_s, final.get(), 6*one_third_s, 0); 570 571 // copy 3 (8 in source) 572 copyData(theme, 2*one_third_s , 2 *one_third_s, 3*one_third_s , 3 * one_third_s, final.get(), 2 * one_third_s, 0); 573 574 // copy 4 575 copyData(theme, 0, one_third_s, one_third_s , 2 * one_third_s, final.get(), 3 * one_third_s, 0); 576 577 // copy 5 578 copyData(theme, 2*one_third_s , one_third_s, 3 * one_third_s , 2 * one_third_s, final.get(), 4 * one_third_s, 0); 579 580 // copy 6 (1 in source) 581 copyData(theme, 0 , 0, one_third_s, one_third_s, final.get(), 5 * one_third_s, 0); 582 583 // rotate and copy 7 584 osg::ref_ptr<osg::Image> rotateandcopy7 = new osg::Image; 585 rotateandcopy7->allocateImage(one_third_s , one_third_t, 1, pixelFormat, dataType, packing); 586 rotateandcopy7->setInternalTextureFormat(internalFormat); 587 copyData(theme, one_third_s, 2*one_third_s, 2 * one_third_s , 3 * one_third_s, rotateandcopy7.get(), 0, 0); 588 rotateandcopy7 = rotateImage(rotateandcopy7.get()); 589 rotateandcopy7->flipHorizontal(); 590 copyData(rotateandcopy7.get(), 0, 0, one_third_s , one_third_s, final.get(), one_third_s, 0); 591 592 // copy 8 (3 in source) 593 copyData(theme, 2 * one_third_s, 0, 3 * one_third_s , one_third_s , final.get(), 7 * one_third_s, 0); 594 595 return final.release(); 596 } 597 598 } -
OpenSceneGraph/trunk/src/osgWidget/Input.cpp
r9075 r9287 1 1 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 2 // $Id: Input.cpp 65 2008-07-14 16:29:28Z cubicool $3 2 4 3 #include <osg/io_utils> … … 23 22 _cursor->setCanClone(false); 24 23 _cursor->setDataVariance(osg::Object::DYNAMIC); 25 _cursor->setColor(0.0f, 0.0f, 0.0f, 0.0f);24 _cursor->setColor(0.0f, 0.0f, 0.0f, 1.0f); 26 25 27 26 setEventMask( … … 47 46 point_type height = _cursor->getHeight(); 48 47 49 if(width > getWidth()) setWidth(osg::round(width));48 // if(width > getWidth()) setWidth(osg::round(width)); 50 49 51 if(height > getHeight()) setHeight(osg::round(height));50 // if(height > getHeight()) setHeight(osg::round(height)); 52 51 } 53 52 … … 60 59 const osgText::Text::GlyphQuads& gq = tgqmi->second; 61 60 62 point_type accum = 0.0f;61 osg::Vec3 pos = _text->getPosition(); 63 62 64 std::ostream& os = warn() << "_offsets[ ";65 66 63 for(unsigned int i = 0; i < _maxSize; i++) { 67 osg::Vec 2 ul = gq.getCoords()[0 + (i * 4)];68 osg::Vec 2 ll = gq.getCoords()[1 + (i * 4)];69 osg::Vec 2 lr = gq.getCoords()[2 + (i * 4)];70 osg::Vec 2 ur = gq.getCoords()[3 + (i * 4)];64 osg::Vec3 ul = gq.getTransformedCoords(0)[0 + (i * 4)]; 65 osg::Vec3 ll = gq.getTransformedCoords(0)[1 + (i * 4)]; 66 osg::Vec3 lr = gq.getTransformedCoords(0)[2 + (i * 4)]; 67 osg::Vec3 ur = gq.getTransformedCoords(0)[3 + (i * 4)]; 71 68 72 accum += osg::round(lr.x() - ll.x()); 73 74 _offsets[i] = accum; 75 76 os << _offsets[i] << " (" << static_cast<char>(_text->getText()[i]) << ") "; 69 _offsets[i] = lr.x() - pos.x(); 70 71 // warn() << "vb: " << gq.getGlyphs()[i]->getHorizontalBearing() << std::endl; 77 72 } 78 79 os << "]" << std::endl;80 73 } 81 74 82 75 bool Input::focus(WindowManager*) { 83 _cursor->setColor( 1.0f, 1.0f, 1.0f, 0.5f);76 _cursor->setColor(0.0f, 0.0f, 0.0f, 1.0f); 84 77 85 78 return true; … … 113 106 114 107 point_type x = getX() + _xoff; 115 point_type y = getY() + th +_yoff;108 point_type y = getY() + _yoff; 116 109 117 110 // XYCoord size = getTextSize(); … … 130 123 131 124 bool Input::keyDown(int key, int mask, WindowManager*) { 132 /*133 125 osgText::String& s = _text->getText(); 134 126 … … 167 159 168 160 getParent()->resize(); 169 */170 171 warn() << "Input is disabled until someone can help me understand how to use osgText; sorry..." << std::endl;172 161 173 162 return false; 174 163 } 175 164 176 void Input::setCursor(Widget*) 177 { 178 warn() << "Input::setCursor(Widget*) not implemented yet."<<std::endl; 165 void Input::setCursor(Widget*) { 166 } 167 168 unsigned int Input::calculateBestYOffset(const std::string& s) { 169 const osgText::FontResolution fr(_text->getCharacterHeight(), _text->getCharacterHeight()); 170 171 osgText::String utf(s); 172 173 unsigned int descent = 0; 174 175 for(osgText::String::iterator i = utf.begin(); i != utf.end(); i++) { 176 osgText::Font* font = const_cast<osgText::Font*>(_text->getFont()); 177 osgText::Font::Glyph* glyph = font->getGlyph(fr, *i); 178 unsigned int d = abs(glyph->getHorizontalBearing().y()); 179 180 if(d > descent) descent = d; 181 } 182 183 return descent; 179 184 } 180 185 181 186 } 187 -
OpenSceneGraph/trunk/src/osgWidget/Label.cpp
r9075 r9287 1 1 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 2 // $Id: Label.cpp 59 2008-05-15 20:55:31Z cubicool $3 2 4 3 #include <osg/Math> … … 10 9 Label::Label(const std::string& name, const std::string& label): 11 10 Widget (name, 0, 0), 12 _textIndex (0), 13 _text (new osgText::Text()) { 14 _text->setText(label); 11 _text (new osgText::Text()), 12 _textIndex (0) { 15 13 _text->setAlignment(osgText::Text::LEFT_BOTTOM); 16 14 _text->setDataVariance(osg::Object::DYNAMIC); 15 16 if(label.size()) { 17 _text->setText(label); 18 19 _calculateSize(getTextSize()); 20 } 17 21 18 22 // TODO: Make a patch for this! … … 37 41 38 42 void Label::_calculateSize(const XYCoord& size) { 39 if(size.x() && size.y()) setMinimumSize(size.x(), size.y());43 // if(size.x() && size.y()) setMinimumSize(size.x(), size.y()); 40 44 41 45 if(getWidth() < size.x()) setWidth(size.x()); … … 46 50 // TODO: This will almost certainly get out of sync. :( 47 51 void Label::parented(Window* parent) { 48 // If we've been cloned, use the index of the old text Drawable. 49 if(_textIndex) parent->getGeode()->setDrawable(_textIndex, _text.get()); 52 osg::Geode* geode = parent->getGeode(); 53 54 // If we've been cloned, use the index of the old text Drawable if it's already there. 55 // However, we have a problem here: imagine a Label gets cloned AFTER being added to 56 // a Window; it'll have a _textIndex, but that _textIndex won't apply to the 57 // currently cloned object. In this case, we'll need to check to be SURE. 58 osgText::Text* text = dynamic_cast<osgText::Text*>(geode->getDrawable(_textIndex)); 59 60 if(text) parent->getGeode()->setDrawable(_textIndex, _text.get()); 50 61 51 62 // Otherwise, add it as new. … … 59 70 } 60 71 61 void Label::managed(WindowManager* wm) {62 if(wm->isInvertedY()) {63 // We rotate along our X axis, so we need to make sure and translate the64 // text later to preserve centering.65 _text->setAxisAlignment(osgText::Text::USER_DEFINED_ROTATION);66 _text->setRotation(osg::Quat(67 osg::DegreesToRadians(180.0f),68 osg::Vec3(1.0f, 0.0f, 0.0f)69 ));70 }71 }72 73 72 void Label::positioned() { 74 73 XYCoord size = getTextSize(); 75 74 point_type x = osg::round(((getWidth() - size.x()) / 2.0f) + getX()); 76 point_type y = 0.0f; 75 point_type y = osg::round(((getHeight() - size.y()) / 2.0f) + getY()); 76 point_type z = _calculateZ(getLayer() + 1); 77 77 78 if(getWindowManager() && getWindowManager()->isInvertedY()) y =79 osg::round(((getHeight() - size.y()) / 2.0f) + getY() + size.y())80 ;81 82 else y = osg::round(((getHeight() - size.y()) / 2.0f) + getY());83 84 78 // These values are permisable with CENTER_CENTER mode is active. 85 79 // point_type x = round(getX() + (getWidth() / 2.0f)); 86 80 // point_type y = round(getY() + (getHeight() / 2.0f)); 87 81 88 82 /* 89 83 warn() << "Label widget size : " << getWidth() << " x " << getHeight() << std::endl; … … 95 89 */ 96 90 97 _text->setPosition(osg::Vec3(x, y, _calculateZ(getLayer() + 1))); 98 } 91 const WindowManager* wm = _getWindowManager(); 99 92 100 void Label::update() 101 { 102 warn() << "Label::update() not implemented yet."<<std::endl; 93 if(wm && wm->isUsingRenderBins()) { 94 _text->getOrCreateStateSet()->setRenderBinDetails( 95 static_cast<int>(z * OSGWIDGET_RENDERBIN_MOD), 96 "RenderBin" 97 ); 98 99 z = 0.0f; 100 } 101 102 _text->setPosition(osg::Vec3(x, y, z)); 103 103 } 104 104 -
OpenSceneGraph/trunk/src/osgWidget/Lua.cpp
r8769 r9287 1 1 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 2 // $Id: Lua.cpp 2 2008-01-24 16:11:26Z cubicool $3 2 4 3 #include <osgDB/FileUtils> -
OpenSceneGraph/trunk/src/osgWidget/Python.cpp
r9124 r9287 1 1 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 2 // $Id: Python.cpp 59 2008-05-15 20:55:31Z cubicool $3 2 4 3 // Python.h needs to be included before anything else. … … 173 172 } 174 173 175 FILE* f = osgDB::fopen(filePath.c_str(), "r");174 FILE* f = fopen(filePath.c_str(), "r"); 176 175 PyObject* r = PyRun_File(f, filePath.c_str(), Py_file_input, _data->main, _data->main); 177 176 -
OpenSceneGraph/trunk/src/osgWidget/StyleManager.cpp
r8770 r9287 1 1 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 2 // $Id: StyleManager.cpp 55 2008-05-12 19:14:42Z cubicool $3 2 4 3 #include <sstream> -
OpenSceneGraph/trunk/src/osgWidget/Table.cpp
r8769 r9287 1 1 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 2 // $Id: Table.cpp 48 2008-05-05 14:13:20Z cubicool $3 2 4 3 #include <osgWidget/Table> -
OpenSceneGraph/trunk/src/osgWidget/Util.cpp
r8769 r9287 1 1 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 2 // $Id: Util.cpp 59 2008-05-15 20:55:31Z cubicool $3 2 4 3 #include <osg/io_utils> … … 37 36 } 38 37 39 osg::Matrix createInvertedYOrthoProjectionMatrix(matrix_type width, matrix_type height) {40 osg::Matrix m = osg::Matrix::ortho2D(0.0f, width, 0.0f, height);41 osg::Matrix s = osg::Matrix::scale(1.0f, -1.0f, 1.0f);42 osg::Matrix t = osg::Matrix::translate(0.0f, -height, 0.0f);43 44 return t * s * m;45 }46 47 38 osg::Camera* createOrthoCamera(matrix_type width, matrix_type height) { 48 39 osg::Camera* camera = new osg::Camera(); … … 62 53 } 63 54 64 osg::Camera* createInvertedYOrthoCamera(matrix_type width, matrix_type height) {65 osg::Camera* camera = createOrthoCamera(width, height);55 int createExample(osgViewer::Viewer& viewer, WindowManager* wm, osg::Node* node) { 56 if(!wm) return 1; 66 57 67 camera->setProjectionMatrix(createInvertedYOrthoProjectionMatrix(width, height)); 68 69 return camera; 70 } 71 72 osg::Group* _createExampleCommon(osgViewer::View* view, WindowManager* wm, osg::Node* node) { 73 if(!wm) return 0; 74 75 view->setUpViewInWindow( 76 0, 77 0, 58 viewer.setUpViewInWindow( 59 50, 60 50, 78 61 static_cast<int>(wm->getWidth()), 79 62 static_cast<int>(wm->getHeight()) … … 87 70 if(node) group->addChild(node); 88 71 89 view->addEventHandler(new osgWidget::MouseHandler(wm)); 90 view->addEventHandler(new osgWidget::KeyboardHandler(wm)); 91 view->addEventHandler(new osgWidget::ResizeHandler(wm, camera)); 92 view->addEventHandler(new osgViewer::StatsHandler()); 93 view->addEventHandler(new osgViewer::WindowSizeHandler()); 94 view->addEventHandler(new osgGA::StateSetManipulator( 95 view->getCamera()->getOrCreateStateSet() 72 viewer.addEventHandler(new osgWidget::MouseHandler(wm)); 73 viewer.addEventHandler(new osgWidget::KeyboardHandler(wm)); 74 viewer.addEventHandler(new osgWidget::ResizeHandler(wm, camera)); 75 viewer.addEventHandler(new osgWidget::CameraSwitchHandler(wm, camera)); 76 viewer.addEventHandler(new osgViewer::StatsHandler()); 77 viewer.addEventHandler(new osgViewer::WindowSizeHandler()); 78 viewer.addEventHandler(new osgGA::StateSetManipulator( 79 viewer.getCamera()->getOrCreateStateSet() 96 80 )); 97 81 98 82 wm->resizeAllWindows(); 99 100 return group;101 }102 103 int createExample(osgViewer::Viewer& viewer, WindowManager* wm, osg::Node* node) {104 osg::Group* group = _createExampleCommon(&viewer, wm, node);105 83 106 84 viewer.setSceneData(group); 107 108 return viewer.run();109 }110 111 // TODO: This function is totally broken; I don't really have any idea of how to do this.112 // Incredibly frustrating stuff.113 int createCompositeExample(114 osgViewer::CompositeViewer& viewer,115 osgViewer::View* view,116 WindowManager* wm,117 osg::Node* node118 ) {119 osg::Group* group = _createExampleCommon(view, wm, node);120 osg::MatrixTransform* watcher = new osg::MatrixTransform();121 122 watcher->addChild(wm);123 124 // Setup the main 2D view.125 viewer.addView(view);126 127 view->setSceneData(group);128 129 // The view that "watches" the main view.130 osgViewer::View* viewWatcher = new osgViewer::View();131 132 viewer.addView(viewWatcher);133 134 int w = static_cast<int>(wm->getWidth());135 int h = static_cast<int>(wm->getHeight());136 137 viewWatcher->setUpViewInWindow(0, 0, w, h);138 139 // Setup our parent MatrixTransform so things look right in perspective.140 watcher->setMatrix(141 osg::Matrix::scale(1.0f, -1.0f, 1000.0f) *142 osg::Matrix::rotate(osg::DegreesToRadians(90.0f), osg::Vec3d(1.0f, 0.0f, 0.0f))143 );144 145 watcher->getOrCreateStateSet()->setAttributeAndModes(146 new osg::Scissor(0, 0, w, h),147 osg::StateAttribute::OVERRIDE148 );149 150 osgGA::TrackballManipulator* tb = new osgGA::TrackballManipulator();151 152 warn() << watcher->getMatrix() << std::endl;153 154 /*155 const osg::BoundingSphere& bs = watcher->getBound();156 157 tb->setHomePosition(158 bs.center() + osg::Vec3(0.0f, -3.5f * bs.radius(), 0.0f),159 bs.center(),160 osg::Vec3(0.0f, 1.0f, 0.0f)161 );162 */163 164 viewWatcher->setSceneData(watcher);165 viewWatcher->setCameraManipulator(tb);166 85 167 86 return viewer.run(); -
OpenSceneGraph/trunk/src/osgWidget/ViewerEventHandlers.cpp
r8769 r9287 1 1 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 2 // $Id: ViewerEventHandlers.cpp 59 2008-05-15 20:55:31Z cubicool $3 2 4 3 #include <osgWidget/ViewerEventHandlers> … … 176 175 osg::Matrix::value_type h = gea.getWindowHeight(); 177 176 178 if(_ wm->isInvertedY()) _camera->setProjectionMatrix(179 createInvertedYOrthoProjectionMatrix(w, h)180 ); 181 182 else _camera->setProjectionMatrix(osg::Matrix::ortho2D(0.0f, w, 0.0f, h));183 184 _wm->set Size(w, h);177 if(_camera.valid()) { 178 _camera->setProjectionMatrix(osg::Matrix::ortho2D(0.0f, w, 0.0f, h)); 179 180 _wm->setSize(w, h); 181 } 182 183 _wm->setWindowSize(w, h); 185 184 _wm->resizeAllWindows(); 186 185 … … 188 187 } 189 188 190 } 189 CameraSwitchHandler::CameraSwitchHandler(WindowManager* wm, osg::Camera* camera): 190 _wm (wm), 191 _camera (camera) { 192 } 193 194 bool CameraSwitchHandler::handle( 195 const osgGA::GUIEventAdapter& gea, 196 osgGA::GUIActionAdapter& gaa, 197 osg::Object* obj, 198 osg::NodeVisitor* nv 199 ) { 200 if( 201 gea.getEventType() != osgGA::GUIEventAdapter::KEYDOWN || 202 gea.getKey() != osgGA::GUIEventAdapter::KEY_F12 203 ) return false; 204 205 osgViewer::View* view = dynamic_cast<osgViewer::View*>(&gaa); 206 207 if(!view) return false; 208 209 osg::Node* oldNode = view->getSceneData(); 210 211 osg::MatrixTransform* oldTrans = dynamic_cast<osg::MatrixTransform*>(oldNode); 212 213 if(!oldTrans) { 214 // Imagine this is the number of pixels... 215 double scale = 2000.0f; 216 double width = _wm->getWidth(); 217 double height = _wm->getHeight(); 218 219 _oldNode = oldNode; 220 221 osg::MatrixTransform* mt = new osg::MatrixTransform(); 222 223 mt->setMatrix( 224 osg::Matrix::translate(width / 2.0f, 0.0f, 0.0f) * 225 osg::Matrix::scale(1.0f, 1.0f, scale) * 226 osg::Matrix::rotate(osg::DegreesToRadians(45.0f), 0.0f, 1.0f, 0.0f) 227 ); 228 229 mt->addChild(_wm.get()); 230 mt->getOrCreateStateSet()->setMode( 231 GL_LIGHTING, 232 osg::StateAttribute::PROTECTED | osg::StateAttribute::OFF 233 ); 234 mt->getOrCreateStateSet()->setMode( 235 GL_SCISSOR_TEST, 236 osg::StateAttribute::OVERRIDE | osg::StateAttribute::OFF 237 ); 238 239 osgGA::MatrixManipulator* mm = view->getCameraManipulator(); 240 241 // mm->setDistance(3000.0f); 242 // mm->setMinimumZoomScale(10.0f); 243 mm->setHomePosition( 244 // eye 245 osg::Vec3(width / 2.0f, height, 100.0f), 246 // center 247 osg::Vec3(0.0f, 0.0f, -(scale / 2.0f)), 248 // up 249 osg::Vec3(0.0f, 1.0f, 0.0f) 250 ); 251 252 view->setSceneData(mt); 253 } 254 255 else view->setSceneData(_oldNode.get()); 256 257 return true; 258 } 259 260 } -
OpenSceneGraph/trunk/src/osgWidget/Widget.cpp
r8769 r9287 4 4 #include <osg/io_utils> 5 5 #include <osg/Math> 6 #include <osg/BlendFunc> 7 #include <osg/TexMat> 6 #include <osg/TextureRectangle> 8 7 #include <osgDB/ReadFile> 9 8 #include <osgDB/FileUtils> … … 35 34 _isManaged (false), 36 35 _isStyled (false), 37 _minWidth ( w),38 _minHeight ( h) {36 _minWidth (0.0f), 37 _minHeight (0.0f) { 39 38 _name = name.size() ? name : generateRandomName("Widget"); 40 39 … … 64 63 setDimensions(0.0f, 0.0f, w, h); 65 64 setColor(1.0f, 1.0f, 1.0f, 1.0f); 66 67 getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);68 getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);69 65 } 70 66 … … 109 105 110 106 osg::Image* Widget::_getImage() const { 111 const osg::Texture 2D* texture = _texture();107 const osg::Texture* texture = _texture(); 112 108 113 109 if(texture) return const_cast<osg::Image*>(texture->getImage(0)); 114 110 115 111 return 0; 116 }117 118 void Widget::managed(WindowManager* wm) {119 if(!wm->isInvertedY()) return;120 121 osg::Matrix s = osg::Matrix::scale(1.0f, -1.0f, 1.0f);122 osg::Matrix t = osg::Matrix::translate(0.0f, -1.0, 0.0f);123 124 getOrCreateStateSet()->setTextureAttributeAndModes(125 0,126 new osg::TexMat(t * s),127 osg::StateAttribute::ON128 );129 112 } 130 113 … … 206 189 } 207 190 191 const WindowManager* wm = _getWindowManager(); 192 193 if(wm && wm->isUsingRenderBins()) { 194 getOrCreateStateSet()->setRenderBinDetails(static_cast<int>(z), "RenderBin"); 195 196 z = 0.0f; 197 } 198 208 199 (*verts)[LL].set(x, y, z); 209 200 (*verts)[LR].set(x + w, y, z); … … 222 213 } 223 214 224 else (*cols)[ convertCorner(p)].set(r, g, b, a);215 else (*cols)[p].set(r, g, b, a); 225 216 } 226 217 … … 235 226 } 236 227 237 else (*cols)[ convertCorner(p)] += Color(r, g, b, a);228 else (*cols)[p] += Color(r, g, b, a); 238 229 } 239 230 … … 248 239 } 249 240 250 else (*texs)[convertCorner(p)].set(tx, ty); 241 else (*texs)[p].set(tx, ty); 242 } 243 244 // TODO: We chop off any offset here if you use TOP; we need to do the same 245 // for BG, etc. 246 void Widget::setLayer(Layer layer, unsigned int offset) { 247 if(layer == LAYER_TOP) offset = 0; 248 249 _layer = layer + offset; 251 250 } 252 251 … … 264 263 XYCoord t(x / tw, y / tw); 265 264 266 (*texs)[ UL] = t;265 (*texs)[LL] = t; 267 266 268 267 // Set the LOWER_RIGHT point. 269 268 t += XYCoord(w / tw, 0.0f); 270 269 271 (*texs)[ UR] = t;270 (*texs)[LR] = t; 272 271 273 272 // Set the UPPER_RIGHT point. 274 273 t += XYCoord(0.0f, h / th); 275 274 276 (*texs)[ LR] = t;275 (*texs)[UR] = t; 277 276 278 277 // Set the UPPER_LEFT point. 279 278 t += XYCoord(-(w / tw), 0.0f); 280 279 281 (*texs)[ LL] = t;280 (*texs)[UL] = t; 282 281 } 283 282 284 283 void Widget::setTexCoordWrapHorizontal() { 285 osg::Image* image = _image();286 osg::Texture 2D* texture = _texture();284 osg::Image* image = _image(); 285 osg::Texture* texture = _texture(); 287 286 288 287 if(!image || !texture || image->s() == 0.0f) return; … … 295 294 296 295 void Widget::setTexCoordWrapVertical() { 297 osg::Image* image = _image();298 osg::Texture 2D* texture = _texture();296 osg::Image* image = _image(); 297 osg::Texture* texture = _texture(); 299 298 300 299 if(!image || !texture || image->t() == 0.0f) return; … … 312 311 } 313 312 314 bool Widget::setImage(osg::Image* image, bool setTexCoords ) {313 bool Widget::setImage(osg::Image* image, bool setTexCoords, bool useTextRect) { 315 314 if(!image) { 316 315 warn() << "Widget [" << _name << "] cannot use a NULL image." << std::endl; … … 319 318 } 320 319 321 osg::Texture2D* texture = new osg::Texture2D(); 322 323 texture->setDataVariance(osg::Object::DYNAMIC); 320 osg::Texture* texture = 0; 321 322 if(useTextRect) texture = new osg::TextureRectangle(); 323 324 else texture = new osg::Texture2D(); 325 326 if(!texture) return false; 327 324 328 texture->setImage(0, image); 325 329 326 getOrCreateStateSet()->setTextureAttributeAndModes( 327 0, 328 texture, 329 osg::StateAttribute::ON 330 ); 331 332 if(setTexCoords) { 333 setTexCoord(0.0f, 0.0f, LOWER_LEFT); 334 setTexCoord(1.0f, 0.0f, LOWER_RIGHT); 335 setTexCoord(1.0f, 1.0f, UPPER_RIGHT); 336 setTexCoord(0.0f, 1.0f, UPPER_LEFT); 337 } 338 339 return true; 340 } 341 342 bool Widget::setImage(const std::string& filePath, bool setTexCoords) { 330 return setTexture(texture, setTexCoords, useTextRect); 331 } 332 333 bool Widget::setImage(const std::string& filePath, bool setTexCoords, bool useTextRect) { 343 334 if(!osgDB::findDataFile(filePath).size()) { 344 335 warn() … … 351 342 } 352 343 353 return setImage(osgDB::readImageFile(filePath), setTexCoords); 344 return setImage(osgDB::readImageFile(filePath), setTexCoords, useTextRect); 345 } 346 347 bool Widget::setTexture(osg::Texture* texture, bool setTexCoords, bool useTextRect) { 348 if(!texture) return false; 349 350 getOrCreateStateSet()->setTextureAttributeAndModes( 351 0, 352 texture, 353 osg::StateAttribute::ON 354 ); 355 356 if(setTexCoords) { 357 if(useTextRect) { 358 osg::Image* image = texture->getImage(0); 359 360 setTexCoord(0.0f, 0.0f, LOWER_LEFT); 361 setTexCoord(image->s(), 0.0f, LOWER_RIGHT); 362 setTexCoord(image->s(), image->t(), UPPER_RIGHT); 363 setTexCoord(0.0f, image->t(), UPPER_LEFT); 364 } 365 366 else { 367 setTexCoord(0.0f, 0.0f, LOWER_LEFT); 368 setTexCoord(1.0f, 0.0f, LOWER_RIGHT); 369 setTexCoord(1.0f, 1.0f, UPPER_RIGHT); 370 setTexCoord(0.0f, 1.0f, UPPER_LEFT); 371 } 372 } 373 374 return true; 354 375 } 355 376 … … 452 473 if(p == ALL_CORNERS) point = UPPER_LEFT; 453 474 454 return (*_verts())[ convertCorner(point)];475 return (*_verts())[point]; 455 476 } 456 477 … … 460 481 if(p == ALL_CORNERS) point = UPPER_LEFT; 461 482 462 return (*_cols())[ convertCorner(point)];483 return (*_cols())[point]; 463 484 } 464 485 … … 468 489 if(p == ALL_CORNERS) point = UPPER_LEFT; 469 490 470 return (*_texs())[convertCorner(point)]; 471 } 472 473 // This converts our points back and forth depding on whether or not we're in an 474 // inverted-Y WindowManager. 475 Widget::Corner Widget::convertCorner(Corner p) const { 476 const WindowManager* wm = getWindowManager(); 477 478 if(!wm || !wm->isInvertedY()) return p; 479 480 if(p == UPPER_LEFT) return LOWER_LEFT; 481 482 else if(p == UPPER_RIGHT) return LOWER_RIGHT; 483 484 else if(p == LOWER_LEFT) return UPPER_LEFT; 485 486 else if(p == LOWER_RIGHT) return UPPER_RIGHT; 487 488 else return p; 491 return (*_texs())[point]; 489 492 } 490 493 -
OpenSceneGraph/trunk/src/osgWidget/Window.cpp
r8818 r9287 71 71 72 72 void Window::EmbeddedWindow::unparented(Window*) { 73 // TODO: Figure out what's necessary here... 73 if(_window.valid()) { 74 _window->_parent = 0; 75 76 if(_parent) _parent->removeChild(_window.get()); 77 } 74 78 } 75 79 … … 96 100 // Whether or not the Window honors this reqest will be up to it. 97 101 _window->setOrigin(x, y); 102 _window->setZ(_calculateZ(getLayer() + 1)); 103 _window->setZRange(_calculateZ(LAYER_TOP - (getLayer() + 1))); 98 104 _window->setVisibleArea(0, 0, static_cast<int>(w), static_cast<int>(h)); 99 105 _window->resize(w, h); … … 110 116 } 111 117 112 // TODO: I need to handle there already being a Window here.113 118 _window = win; 114 119 … … 125 130 } 126 131 132 void Window::EmbeddedWindow::updateSizeFromWindow() { 133 setSize(_window->getSize()); 134 135 if(_parent) _parent->resize(); 136 } 137 127 138 Window::Window(const std::string& name): 128 _parent (0),129 _wm (0),130 _index (0),131 _x (0.0f),132 _y (0.0f),133 _z (0.0f),134 _zRange (0.0f),135 _strata (STRATA_NONE),136 _vis (VM_FULL),137 _r (0.0f),138 _s (1.0f),139 _scaleDenom (100.0f),140 _vAnchor (VA_NONE),141 _hAnchor (HA_NONE) {139 _parent (0), 140 _wm (0), 141 _index (0), 142 _x (0.0f), 143 _y (0.0f), 144 _z (0.0f), 145 _zRange (0.0f), 146 _strata (STRATA_NONE), 147 _vis (VM_FULL), 148 _r (0.0f), 149 _s (1.0f), 150 _scaleDenom (100.0f), 151 _vAnchor (VA_NONE), 152 _hAnchor (HA_NONE) { 142 153 _name = name.size() ? name : generateRandomName("Window"); 143 154 … … 147 158 148 159 bg->setLayer(Widget::LAYER_BG); 149 bg->setColor( 0.0f, 0.0f, 0.0f, 0.5f);160 bg->setColor(1.0f, 1.0f, 1.0f, 1.0f); 150 161 151 162 _setParented(bg); … … 202 213 Widget* widget = dynamic_cast<Widget*>(geode->getDrawable(i)); 203 214 204 if(!widget || !widget->canClone()) continue; 215 if(!widget) continue; 216 217 // TODO: Properly test this... 218 if(!widget->canClone()) { 219 // geode->removeDrawable(widget); 220 221 continue; 222 } 205 223 206 224 _setParented(widget); … … 287 305 288 306 void Window::update() { 289 // Update all embedded children; the zRange values continue to decrease in precision290 // as you add more and more embedded Windows.291 307 WindowList wl; 292 308 293 309 getEmbeddedList(wl); 294 310 295 // Each child Window gets half the zRange of it's parent Window. This means the more 296 // you embed Windows into other Windows, the less depth precision you're going to have. 297 for(WindowList::iterator w = wl.begin(); w != wl.end(); w++) { 298 Window* win = w->get(); 299 300 win->_z = _zRange / 2.0f; 301 win->_zRange = _zRange / 2.0f; 302 303 win->update(); 304 } 311 for(WindowList::iterator w = wl.begin(); w != wl.end(); w++) w->get()->update(); 305 312 306 313 matrix_type x = _x; … … 319 326 320 327 xy.set(x, y); 328 } 329 330 matrix_type z = _z; 331 332 // We can't do proper scissoring until we have access to our parent WindowManager, and 333 // we need to determine the sorting method we want to use. 334 if(_wm) { 335 if(_wm->isUsingRenderBins()) { 336 getOrCreateStateSet()->setRenderBinDetails( 337 static_cast<int>((1.0f - fabs(_z)) * OSGWIDGET_RENDERBIN_MOD), 338 "RenderBin" 339 ); 340 341 z = 0.0f; 342 } 343 344 int sx = static_cast<int>(xy.x()); 345 int sy = static_cast<int>(xy.y()); 346 int sw = static_cast<int>(_width.current); 347 int sh = static_cast<int>(_height.current); 348 349 // This sets the Scissor area to some offset defined by the user. 350 if(_vis == VM_PARTIAL) { 351 sw = static_cast<int>(_visibleArea[2]); 352 sh = static_cast<int>(_visibleArea[3]); 353 } 354 355 // Otherwise, use the size of the WindowManager itself. 356 else if(_vis == VM_ENTIRE) { 357 sx = 0; 358 sy = 0; 359 sw = static_cast<int>(_wm->getWidth()); 360 sh = static_cast<int>(_wm->getHeight()); 361 } 362 363 _scissor()->setScissor(sx, sy, sw, sh); 321 364 } 322 365 … … 327 370 osg::Vec3d(0.0f, 0.0f, 1.0f) 328 371 ); 329 372 330 373 osg::Matrix s = osg::Matrix::scale(_s, _s, 1.0f); 331 osg::Matrix t = osg::Matrix::translate(x - _visibleArea[0], y - _visibleArea[1], _z);374 osg::Matrix t = osg::Matrix::translate(x - _visibleArea[0], y - _visibleArea[1], z); 332 375 333 376 setMatrix(r * s * t); 334 335 // We can't do proper scissoring until we have access to our parent WindowManager.336 if(_wm) {337 int x = static_cast<int>(xy.x());338 int y = static_cast<int>(xy.y());339 int w = static_cast<int>(_width.current);340 int h = static_cast<int>(_height.current);341 int wmh = static_cast<int>(_wm->getHeight());342 int nx = x;343 int ny = y;344 int nw = w;345 int nh = h;346 347 // This sets the Scissor area to the full size of the Window.348 if(_vis == VM_FULL && _wm->isInvertedY()) ny = wmh - h - y;349 350 // This sets the Scissor area to some offset defined by the user.351 else if(_vis == VM_PARTIAL) {352 if(_wm->isInvertedY()) ny = wmh - y - static_cast<int>(_visibleArea[3]);353 354 // else ny = static_cast<int>(_visibleArea[3]);355 356 nw = static_cast<int>(_visibleArea[2]);357 nh = static_cast<int>(_visibleArea[3]);358 }359 360 // Otherwise, use the size of the WindowManager itself.361 else {362 nx = 0;363 ny = 0;364 nw = static_cast<int>(_wm->getWidth());365 nh = wmh;366 }367 368 _scissor()->setScissor(nx, ny, nw, nh);369 }370 377 } 371 378 … … 527 534 528 535 else { 536 widget->unparented(this); 537 529 538 widget->_parent = 0; 530 531 widget->unparented(this);532 539 } 533 540 } … … 640 647 } 641 648 649 // The topmost Window always has this method called, instead of the embedded window directly. 642 650 bool Window::setFocused(const Widget* widget) { 643 651 // TODO: I've turned on the warn() here, but perhaps I shouldn't? I need to define … … 651 659 ConstIterator i = std::find(begin(), end(), widget); 652 660 661 bool found = false; 662 653 663 if(i == end()) { 664 // We couldn't find the widget in the toplevel, so lets see if one of our 665 // EmbeddedWindow objects has it. 666 WindowList wl; 667 668 getEmbeddedList(wl); 669 670 for(WindowList::iterator w = wl.begin(); w != wl.end(); w++) { 671 ConstIterator ii = std::find(w->get()->begin(), w->get()->end(), widget); 672 673 if(ii != w->get()->end()) { 674 found = true; 675 i = ii; 676 } 677 } 678 } 679 680 else found = true; 681 682 if(!found) { 654 683 warn() 655 684 << "Window [" << _name … … 667 696 668 697 bool Window::setFocused(const std::string& name) { 669 Widget* w = getByName(name); 670 671 if(!w) { 698 Widget* w1 = getByName(name); 699 700 bool found = false; 701 702 if(!w1) { 703 // Just like above, we couldn't find the widget in the toplevel, so lets see if 704 // one of our EmbeddedWindow objects has it. The difference here is that we 705 // search by name. 706 WindowList wl; 707 708 getEmbeddedList(wl); 709 710 for(WindowList::iterator w = wl.begin(); w != wl.end(); w++) { 711 Widget* w2 = w->get()->getByName(name); 712 713 if(w2) { 714 found = true; 715 w1 = w2; 716 } 717 } 718 } 719 720 else found = true; 721 722 if(!found) { 672 723 warn() 673 724 << "Window [" << _name … … 679 730 } 680 731 681 _setFocused(w );732 _setFocused(w1); 682 733 683 734 return true; 735 } 736 737 bool Window::grabFocus() { 738 if(!_wm) return false; 739 740 return _wm->setFocused(this); 684 741 } 685 742 … … 725 782 double y = absy - xy.y(); 726 783 727 if(_wm && _wm->isInvertedY()) y = (_wm->getHeight() - absy) - xy.y();728 729 784 return XYCoord(x + _visibleArea[0], y + _visibleArea[1]); 730 785 } … … 747 802 } 748 803 749 Window::EmbeddedWindow* Window::embed() { 750 EmbeddedWindow* ew = new EmbeddedWindow(_name + "Embedded", getWidth(), getHeight()); 804 Window::EmbeddedWindow* Window::embed( 805 const std::string& newName, 806 Widget::Layer layer, 807 unsigned int layerOffset 808 ) { 809 EmbeddedWindow* ew = new EmbeddedWindow( 810 newName.size() > 0 ? newName : _name + "Embedded", 811 getWidth(), 812 getHeight() 813 ); 751 814 752 815 ew->setWindow(this); 753 816 ew->setSize(getWidth(), getHeight()); 754 ew->setMinimumSize(getMinWidth(), getMinHeight());755 817 ew->setCanFill(true); 818 ew->setLayer(layer, layerOffset); 756 819 757 820 return ew; … … 780 843 if(!ew || !ew->getWindow()) continue; 781 844 782 wl.push_back(ew->getWindow()); 845 else { 846 wl.push_back(ew->getWindow()); 847 848 ew->getWindow()->getEmbeddedList(wl); 849 } 783 850 } 784 851 … … 853 920 } 854 921 922 unsigned int Window::addChildAndGetIndex(osg::Node* node) { 923 if(addChild(node)) return getChildIndex(node); 924 925 return 0; 926 } 927 855 928 // All of the subsequent functions are very boring and uninteresting, although hopefully 856 929 // self-explanatory. They simply wrap calls to _compare<>() with the proper templates, and … … 946 1019 point_type w = osg::round(bb.xMax() - bb.xMin()); 947 1020 948 return Sizes(w, w);1021 return Sizes(w, 0.0f); 949 1022 } 950 1023 … … 954 1027 point_type h = osg::round(bb.yMax() - bb.yMin()); 955 1028 956 return Sizes(h, h);957 } 958 959 } 1029 return Sizes(h, 0.0f); 1030 } 1031 1032 } -
OpenSceneGraph/trunk/src/osgWidget/WindowManager.cpp
r8870 r9287 24 24 _width (width), 25 25 _height (height), 26 _ zNear (0.0f),27 _ zFar (-1.0f),26 _windowWidth (width), 27 _windowHeight (height), 28 28 _numForeground (0.0f), 29 29 _numBackground (0.0f), … … 57 57 } 58 58 59 if(_flags & WM_USE_RENDERBINS) getOrCreateStateSet()->setMode(GL_DEPTH_TEST, false); 60 59 61 // Setup our picking debug (is debug the right word here?) Window... 60 62 if(_flags & WM_PICK_DEBUG) { … … 80 82 } 81 83 82 if(!(_flags & WM_NO_BETA_WARN)) { 83 Box* box = new Box("BetaWarningBox", Box::VERTICAL); 84 Label* label = new Label("BetaWarning"); 85 86 label->setFontSize(15); 87 label->setFontColor(0.0f, 0.0f, 1.0f, 1.0f); 88 label->setFont("fonts/arial.ttf"); 89 label->setPadding(5.0f); 90 label->setCanFill(true); 91 label->setLabel("This is BETA software! Please see: http://osgwidget.googlecode.com"); 92 93 box->getBackground()->setColor(1.0f, 0.7f, 0.0f, 1.0f); 94 box->addWidget(label); 95 box->setNodeMask(~_nodeMask); 96 box->removeEventMask(EVENT_MASK_FOCUS); 97 box->setStrata(Window::STRATA_BACKGROUND); 98 box->setOrigin(0.0f, 0.0f); 99 100 addChild(box); 101 102 box->resizePercent(100.0f, 0.0f); 103 } 84 getOrCreateStateSet()->setMode( 85 GL_BLEND, 86 osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE 87 ); 88 getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); 104 89 } 105 90 … … 141 126 if(!_lastPush) return false; 142 127 143 bool handled = _lastPush->callMethodAndCallbacks(ev); 128 // TODO: This is the old way; it didn't allow Event handler code to call grabFocus(). 129 // bool handled = _lastPush->callMethodAndCallbacks(ev); 144 130 145 131 if(_focusMode != PFM_SLOPPY) { … … 156 142 } 157 143 158 return handled;144 return _lastPush->callMethodAndCallbacks(ev); 159 145 } 160 146 … … 182 168 void WindowManager::_getPointerXYDiff(float& x, float& y) { 183 169 x -= _lastX; 184 185 if(isInvertedY()) y = -(y - _lastY); 186 187 else y -= _lastY; 170 y -= _lastY; 188 171 } 189 172 … … 300 283 // Make sure that our window is valid, and that our pick is within the 301 284 // "visible area" of the Window. 302 if(!win || 303 (win->getVisibilityMode()==Window::VM_PARTIAL && !win->isPointerXYWithinVisible(x, y))) 304 { 285 if( 286 !win || 287 (win->getVisibilityMode() == Window::VM_PARTIAL && !win->isPointerXYWithinVisible(x, y)) 288 ) { 305 289 continue; 306 290 } … … 334 318 return false; 335 319 } 320 321 /* 322 bool WindowManager::pickAtXY(float x, float y, WidgetList& wl) { 323 Intersections intr; 324 325 if(!_view->computeIntersections(x, y, intr, _nodeMask)) return false; 326 327 typedef std::vector<osg::observer_ptr<Window> > WindowVector; 328 329 WindowVector windows; 330 331 Window* activeWin = 0; 332 333 for(Intersections::iterator i = intr.begin(); i != intr.end(); i++) { 334 Window* win = dynamic_cast<Window*>(i->nodePath.back()->getParent(0)); 335 336 if( 337 !win || 338 (win->getVisibilityMode() == Window::VM_PARTIAL && !win->isPointerXYWithinVisible(x, y)) 339 ) { 340 continue; 341 } 342 343 if(activeWin != win) { 344 activeWin = win; 345 346 windows.push_back(win); 347 } 348 } 349 350 if(!windows.size()) return false; 351 352 std::sort(windows.begin(), windows.end(), WindowBinNumberCompare()); 353 354 for(WindowVector::iterator i = windows.begin(); i != windows.end(); i++) { 355 warn() << "- " << i->get()->getName() << " " << i->get()->getOrCreateStateSet()->getBinNumber() << std::endl; 356 } 357 358 warn() << std::endl; 359 360 return false; 361 } 362 */ 336 363 337 364 bool WindowManager::setFocused(Window* window) { … … 372 399 // add 2 additional Windows here for anything that should appear in the background 373 400 // and foreground areas. 374 matrix_type zRange = (_zNear - _zFar)/ (focusable.size() + 2.0f);401 matrix_type zRange = 1.0f / (focusable.size() + 2.0f); 375 402 376 403 // Our offset for the following for() loop. … … 458 485 } 459 486 487 // Returns the application window coordinates of the WindowManager XY position. 488 XYCoord WindowManager::windowXY(double x, double y) const { 489 return XYCoord((_windowWidth / _width) * x, (_windowHeight / _height) * y); 490 } 491 492 // Returns the WindowManager coordinates of the application window XY position. 493 XYCoord WindowManager::localXY(double x, double y) const { 494 return XYCoord((_width / _windowWidth) * x, (_height / _windowHeight) * y); 495 } 496 460 497 // This is called by a ViewerEventHandler/MouseHandler (or whatever) as the pointer moves 461 498 // around and intersects with objects. It also resets our state data (_widget, _leftDown, … … 575 612 // width and height. 576 613 osg::Camera* WindowManager::createParentOrthoCamera() { 577 osg::Camera* camera = 0; 578 579 if(isInvertedY()) camera = createInvertedYOrthoCamera(_width, _height); 580 581 else camera = createOrthoCamera(_width, _height); 614 osg::Camera* camera = createOrthoCamera(_width, _height); 582 615 583 616 camera->addChild(this);
