Advertisement
Guest User

Untitled

a guest
May 5th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 94.96 KB | None | 0 0
  1. /****************************************************************************
  2.  
  3. GLUI User Interface Toolkit
  4. ---------------------------
  5.  
  6. glui.h - Main (and only) external header for
  7. GLUI User Interface Toolkit
  8.  
  9. --------------------------------------------------
  10.  
  11. Copyright (c) 1998 Paul Rademacher
  12.  
  13. WWW: http://sourceforge.net/projects/glui/
  14. Forums: http://sourceforge.net/forum/?group_id=92496
  15.  
  16. This software is provided 'as-is', without any express or implied
  17. warranty. In no event will the authors be held liable for any damages
  18. arising from the use of this software.
  19.  
  20. Permission is granted to anyone to use this software for any purpose,
  21. including commercial applications, and to alter it and redistribute it
  22. freely, subject to the following restrictions:
  23.  
  24. 1. The origin of this software must not be misrepresented; you must not
  25. claim that you wrote the original software. If you use this software
  26. in a product, an acknowledgment in the product documentation would be
  27. appreciated but is not required.
  28. 2. Altered source versions must be plainly marked as such, and must not be
  29. misrepresented as being the original software.
  30. 3. This notice may not be removed or altered from any source distribution.
  31.  
  32. *****************************************************************************/
  33.  
  34. #ifndef GLUI_GLUI_H
  35. #define GLUI_GLUI_H
  36.  
  37. // Having stdlib here first fixes some 'exit() redefined' errors on MSVC.NET
  38. // that come from old GLUT headers.
  39. #include <cstdlib>
  40.  
  41. #if defined(GLUI_FREEGLUT)
  42.  
  43. // FreeGLUT does not yet work perfectly with GLUI
  44. // - use at your own risk.
  45.  
  46. #include <GL/freeglut.h>
  47.  
  48. #elif defined(GLUI_OPENGLUT)
  49.  
  50. // OpenGLUT does not yet work properly with GLUI
  51. // - use at your own risk.
  52.  
  53. #include <GL/openglut.h>
  54.  
  55. #else
  56.  
  57. #ifdef __APPLE__
  58. #include <GLUT/glut.h>
  59. #else
  60. #include <GL/glut.h>
  61. #endif
  62.  
  63. #endif
  64.  
  65. #include <cstdio>
  66. #include <cstring>
  67. #include <string>
  68. #include <vector>
  69.  
  70. /* GLUI API shared library export/import declarations. */
  71. #if defined(_WIN32)
  72. # ifdef GLUI_BUILDING_LIB
  73. # ifdef GLUIDLL
  74. # define GLUIAPI __declspec(dllexport)
  75. # else
  76. # define GLUIAPI
  77. # endif
  78. # else
  79. # ifdef GLUIDLL
  80. # define GLUIAPI __declspec(dllimport)
  81. # else
  82. # define GLUIAPI
  83. # endif
  84. # endif
  85. #else
  86. #define GLUIAPI
  87. #endif
  88.  
  89.  
  90. #define GLUI_VERSION 2.36f /********** Current version **********/
  91.  
  92. #if defined(_WIN32)
  93. # if !defined(GLUI_NO_LIB_PRAGMA) && !defined(GLUI_BUILDING_LIB)
  94. // Link automatically with GLUI library
  95. # if defined GLUIDLL // define this when using glui dynamic library
  96. # pragma comment(lib, "glui32dll.lib")
  97. # else
  98. # pragma comment(lib, "glui32.lib")
  99. # endif
  100. # endif
  101. #endif
  102.  
  103.  
  104. /********** List of GLUT callbacks ********/
  105.  
  106. enum GLUI_Glut_CB_Types
  107. {
  108. GLUI_GLUT_RESHAPE,
  109. GLUI_GLUT_KEYBOARD,
  110. GLUI_GLUT_DISPLAY,
  111. GLUI_GLUT_MOUSE,
  112. GLUI_GLUT_MOTION,
  113. GLUI_GLUT_SPECIAL,
  114. GLUI_GLUT_PASSIVE_MOTION,
  115. GLUI_GLUT_ENTRY,
  116. GLUI_GLUT_VISIBILITY
  117. };
  118.  
  119. /********* Constants for window placement **********/
  120.  
  121. #define GLUI_XOFF 6
  122. #define GLUI_YOFF 6
  123. #define GLUI_ITEMSPACING 3
  124. #define GLUI_CHECKBOX_SIZE 13
  125. #define GLUI_RADIOBUTTON_SIZE 13
  126. #define GLUI_BUTTON_SIZE 20
  127. #define GLUI_STATICTEXT_SIZE 13
  128. #define GLUI_SEPARATOR_HEIGHT 8
  129. #define GLUI_DEFAULT_CONTROL_WIDTH 100
  130. #define GLUI_DEFAULT_CONTROL_HEIGHT 13
  131. #define GLUI_EDITTEXT_BOXINNERMARGINX 3
  132. #define GLUI_EDITTEXT_HEIGHT 20
  133. #define GLUI_EDITTEXT_WIDTH 130
  134. #define GLUI_EDITTEXT_MIN_INT_WIDTH 35
  135. #define GLUI_EDITTEXT_MIN_TEXT_WIDTH 50
  136. #define GLUI_PANEL_NAME_DROP 8
  137. #define GLUI_PANEL_EMBOSS_TOP 4
  138. /* #define GLUI_ROTATION_WIDTH 60 */
  139. /* #define GLUI_ROTATION_HEIGHT 78 */
  140. #define GLUI_ROTATION_WIDTH 50
  141. #define GLUI_ROTATION_HEIGHT (GLUI_ROTATION_WIDTH+18)
  142. #define GLUI_MOUSE_INTERACTION_WIDTH 50
  143. #define GLUI_MOUSE_INTERACTION_HEIGHT (GLUI_MOUSE_INTERACTION_WIDTH)+18
  144.  
  145. /** Different panel control types **/
  146. #define GLUI_PANEL_NONE 0
  147. #define GLUI_PANEL_EMBOSSED 1
  148. #define GLUI_PANEL_RAISED 2
  149.  
  150. /** Max # of els in control's float_array **/
  151. #define GLUI_DEF_MAX_ARRAY 30
  152.  
  153. /********* The control's 'active' behavior *********/
  154. #define GLUI_CONTROL_ACTIVE_MOUSEDOWN 1
  155. #define GLUI_CONTROL_ACTIVE_PERMANENT 2
  156.  
  157. /********* Control alignment types **********/
  158. #define GLUI_ALIGN_CENTER 1
  159. #define GLUI_ALIGN_RIGHT 2
  160. #define GLUI_ALIGN_LEFT 3
  161.  
  162. /********** Limit types - how to limit spinner values *********/
  163. #define GLUI_LIMIT_NONE 0
  164. #define GLUI_LIMIT_CLAMP 1
  165. #define GLUI_LIMIT_WRAP 2
  166.  
  167. /********** Translation control types ********************/
  168. #define GLUI_TRANSLATION_XY 0
  169. #define GLUI_TRANSLATION_Z 1
  170. #define GLUI_TRANSLATION_X 2
  171. #define GLUI_TRANSLATION_Y 3
  172.  
  173. #define GLUI_TRANSLATION_LOCK_NONE 0
  174. #define GLUI_TRANSLATION_LOCK_X 1
  175. #define GLUI_TRANSLATION_LOCK_Y 2
  176.  
  177. /********** How was a control activated? *****************/
  178. #define GLUI_ACTIVATE_MOUSE 1
  179. #define GLUI_ACTIVATE_TAB 2
  180.  
  181. /********** What type of live variable does a control have? **********/
  182. #define GLUI_LIVE_NONE 0
  183. #define GLUI_LIVE_INT 1
  184. #define GLUI_LIVE_FLOAT 2
  185. #define GLUI_LIVE_TEXT 3
  186. #define GLUI_LIVE_STRING 6
  187. #define GLUI_LIVE_DOUBLE 4
  188. #define GLUI_LIVE_FLOAT_ARRAY 5
  189.  
  190. /************* Textbox and List Defaults - JVK ******************/
  191. #define GLUI_TEXTBOX_HEIGHT 130
  192. #define GLUI_TEXTBOX_WIDTH 130
  193. #define GLUI_LIST_HEIGHT 130
  194. #define GLUI_LIST_WIDTH 130
  195. #define GLUI_DOUBLE_CLICK 1
  196. #define GLUI_SINGLE_CLICK 0
  197. #define GLUI_TAB_WIDTH 50 /* In pixels */
  198. #define GLUI_TEXTBOX_BOXINNERMARGINX 3
  199. #define GLUI_TEXTBOX_MIN_TEXT_WIDTH 50
  200. #define GLUI_LIST_BOXINNERMARGINX 3
  201. #define GLUI_LIST_MIN_TEXT_WIDTH 50
  202.  
  203. /*********************** TreePanel Defaults - JVK *****************************/
  204. #define GLUI_TREEPANEL_DEFAULTS 0 // bar, standard bar color
  205. #define GLUI_TREEPANEL_ALTERNATE_COLOR 1 // Alternate between 8 different bar colors
  206. #define GLUI_TREEPANEL_ENABLE_BAR 2 // enable the bar
  207. #define GLUI_TREEPANEL_DISABLE_BAR 4 // disable the bar
  208. #define GLUI_TREEPANEL_DISABLE_DEEPEST_BAR 8 // disable only the deepest bar
  209. #define GLUI_TREEPANEL_CONNECT_CHILDREN_ONLY 16 // disable only the bar of the last child of each root
  210. #define GLUI_TREEPANEL_DISPLAY_HIERARCHY 32 // display some sort of hierachy in the tree node title
  211. #define GLUI_TREEPANEL_HIERARCHY_NUMERICDOT 64 // display hierarchy in 1.3.2 (etc... ) format
  212. #define GLUI_TREEPANEL_HIERARCHY_LEVEL_ONLY 128 // display hierarchy as only the level depth
  213.  
  214. /******************* GLUI Scrollbar Defaults - JVK ***************************/
  215. #define GLUI_SCROLL_ARROW_WIDTH 16
  216. #define GLUI_SCROLL_ARROW_HEIGHT 16
  217. #define GLUI_SCROLL_BOX_MIN_HEIGHT 5
  218. #define GLUI_SCROLL_BOX_STD_HEIGHT 16
  219. #define GLUI_SCROLL_STATE_NONE 0
  220. #define GLUI_SCROLL_STATE_UP 1
  221. #define GLUI_SCROLL_STATE_DOWN 2
  222. #define GLUI_SCROLL_STATE_BOTH 3
  223. #define GLUI_SCROLL_STATE_SCROLL 4
  224. #define GLUI_SCROLL_DEFAULT_GROWTH_EXP 1.05f
  225. #define GLUI_SCROLL_VERTICAL 0
  226. #define GLUI_SCROLL_HORIZONTAL 1
  227.  
  228.  
  229. /** Size of the character width hash table for faster lookups.
  230. Make sure to keep this a power of two to avoid the slow divide.
  231. This is also a speed/memory tradeoff; 128 is enough for low ASCII.
  232. */
  233. #define CHAR_WIDTH_HASH_SIZE 128
  234.  
  235. /********** Translation codes **********/
  236.  
  237. enum TranslationCodes
  238. {
  239. GLUI_TRANSLATION_MOUSE_NONE = 0,
  240. GLUI_TRANSLATION_MOUSE_UP,
  241. GLUI_TRANSLATION_MOUSE_DOWN,
  242. GLUI_TRANSLATION_MOUSE_LEFT,
  243. GLUI_TRANSLATION_MOUSE_RIGHT,
  244. GLUI_TRANSLATION_MOUSE_UP_LEFT,
  245. GLUI_TRANSLATION_MOUSE_UP_RIGHT,
  246. GLUI_TRANSLATION_MOUSE_DOWN_LEFT,
  247. GLUI_TRANSLATION_MOUSE_DOWN_RIGHT
  248. };
  249.  
  250. /************ A string type for us to use **********/
  251.  
  252. typedef std::string GLUI_String;
  253. GLUIAPI GLUI_String& glui_format_str(GLUI_String &str, const char* fmt, ...);
  254.  
  255. /********* Pre-declare classes as needed *********/
  256.  
  257. class GLUI;
  258. class GLUI_Control;
  259. class GLUI_Listbox;
  260. class GLUI_StaticText;
  261. class GLUI_EditText;
  262. class GLUI_Panel;
  263. class GLUI_Spinner;
  264. class GLUI_RadioButton;
  265. class GLUI_RadioGroup;
  266. class GLUI_Glut_Window;
  267. class GLUI_TreePanel;
  268. class GLUI_Scrollbar;
  269. class GLUI_List;
  270.  
  271. class Arcball;
  272.  
  273. /*** Flags for GLUI class constructor ***/
  274. #define GLUI_SUBWINDOW ((long)(1<<1))
  275. #define GLUI_SUBWINDOW_TOP ((long)(1<<2))
  276. #define GLUI_SUBWINDOW_BOTTOM ((long)(1<<3))
  277. #define GLUI_SUBWINDOW_LEFT ((long)(1<<4))
  278. #define GLUI_SUBWINDOW_RIGHT ((long)(1<<5))
  279.  
  280. /*** Codes for different type of edittext boxes and spinners ***/
  281. #define GLUI_EDITTEXT_TEXT 1
  282. #define GLUI_EDITTEXT_INT 2
  283. #define GLUI_EDITTEXT_FLOAT 3
  284. #define GLUI_SPINNER_INT GLUI_EDITTEXT_INT
  285. #define GLUI_SPINNER_FLOAT GLUI_EDITTEXT_FLOAT
  286. #define GLUI_SCROLL_INT GLUI_EDITTEXT_INT
  287. #define GLUI_SCROLL_FLOAT GLUI_EDITTEXT_FLOAT
  288. // This is only for deprecated interface
  289. #define GLUI_EDITTEXT_STRING 4
  290.  
  291. /*** Definition of callbacks ***/
  292. typedef void (*GLUI_Update_CB) (int id);
  293. typedef void (*GLUI_Control_CB)(GLUI_Control *);
  294. typedef void (*Int1_CB) (int);
  295. typedef void (*Int2_CB) (int, int);
  296. typedef void (*Int3_CB) (int, int, int);
  297. typedef void (*Int4_CB) (int, int, int, int);
  298.  
  299. /************************************************************/
  300. /**
  301. Callback Adapter Class
  302. Allows us to support different types of callbacks;
  303. like a GLUI_Update_CB function pointer--which takes an int;
  304. and a GLUI_Control_CB function pointer--which takes a GUI_Control object.
  305. */
  306. class GLUIAPI GLUI_CB
  307. {
  308. public:
  309. GLUI_CB() : idCB(0),objCB(0) {}
  310. GLUI_CB(GLUI_Update_CB cb) : idCB(cb),objCB(0) {}
  311. GLUI_CB(GLUI_Control_CB cb) : idCB(0),objCB(cb) {}
  312. // (Compiler generated copy constructor)
  313.  
  314. /** This control just activated. Fire our callback.*/
  315. void operator()(GLUI_Control *ctrl) const;
  316. bool operator!() const { return !idCB && !objCB; }
  317. operator bool() const { return !(!(*this)); }
  318. private:
  319. GLUI_Update_CB idCB;
  320. GLUI_Control_CB objCB;
  321. };
  322.  
  323. /************************************************************/
  324. /* */
  325. /* Base class, for hierarchical relationships */
  326. /* */
  327. /************************************************************/
  328.  
  329. class GLUI_Control;
  330.  
  331. /**
  332. GLUI_Node is a node in a sort of tree of GLUI controls.
  333. Each GLUI_Node has a list of siblings (in a circular list)
  334. and a linked list of children.
  335.  
  336. Everything onscreen is a GLUI_Node--windows, buttons, etc.
  337. The nodes are traversed for event processing, sizing, redraws, etc.
  338. */
  339. class GLUIAPI GLUI_Node
  340. {
  341. friend class GLUI_Tree; /* JVK */
  342. friend class GLUI_Rollout;
  343. friend class GLUI_Main;
  344.  
  345. public:
  346. GLUI_Node();
  347. virtual ~GLUI_Node() {}
  348.  
  349. GLUI_Node *first_sibling();
  350. GLUI_Node *last_sibling();
  351. GLUI_Node *prev();
  352. GLUI_Node *next();
  353.  
  354. GLUI_Node *first_child() { return child_head; }
  355. GLUI_Node *last_child() { return child_tail; }
  356. GLUI_Node *parent() { return parent_node; }
  357.  
  358. /** Link in a new child control */
  359. virtual int add_control( GLUI_Control *control );
  360.  
  361. void link_this_to_parent_last (GLUI_Node *parent );
  362. void link_this_to_parent_first(GLUI_Node *parent );
  363. void link_this_to_sibling_next(GLUI_Node *sibling );
  364. void link_this_to_sibling_prev(GLUI_Node *sibling );
  365. void unlink();
  366.  
  367. void dump( FILE *out, const char *name );
  368.  
  369. protected:
  370. static void add_child_to_control(GLUI_Node *parent,GLUI_Control *child);
  371. GLUI_Node *parent_node;
  372. GLUI_Node *child_head;
  373. GLUI_Node *child_tail;
  374. GLUI_Node *next_sibling;
  375. GLUI_Node *prev_sibling;
  376. };
  377.  
  378.  
  379. /************************************************************/
  380. /* */
  381. /* Standard Bitmap stuff */
  382. /* */
  383. /************************************************************/
  384.  
  385. enum GLUI_StdBitmaps_Codes
  386. {
  387. GLUI_STDBITMAP_CHECKBOX_OFF = 0,
  388. GLUI_STDBITMAP_CHECKBOX_ON,
  389. GLUI_STDBITMAP_RADIOBUTTON_OFF,
  390. GLUI_STDBITMAP_RADIOBUTTON_ON,
  391. GLUI_STDBITMAP_UP_ARROW,
  392. GLUI_STDBITMAP_DOWN_ARROW,
  393. GLUI_STDBITMAP_LEFT_ARROW,
  394. GLUI_STDBITMAP_RIGHT_ARROW,
  395. GLUI_STDBITMAP_SPINNER_UP_OFF,
  396. GLUI_STDBITMAP_SPINNER_UP_ON,
  397. GLUI_STDBITMAP_SPINNER_DOWN_OFF,
  398. GLUI_STDBITMAP_SPINNER_DOWN_ON,
  399. GLUI_STDBITMAP_CHECKBOX_OFF_DIS, /*** Disactivated control bitmaps ***/
  400. GLUI_STDBITMAP_CHECKBOX_ON_DIS,
  401. GLUI_STDBITMAP_RADIOBUTTON_OFF_DIS,
  402. GLUI_STDBITMAP_RADIOBUTTON_ON_DIS,
  403. GLUI_STDBITMAP_SPINNER_UP_DIS,
  404. GLUI_STDBITMAP_SPINNER_DOWN_DIS,
  405. GLUI_STDBITMAP_LISTBOX_UP,
  406. GLUI_STDBITMAP_LISTBOX_DOWN,
  407. GLUI_STDBITMAP_LISTBOX_UP_DIS,
  408. GLUI_STDBITMAP_NUM_ITEMS
  409. };
  410.  
  411. /************************************************************/
  412. /* */
  413. /* Class GLUI_Bitmap */
  414. /* */
  415. /************************************************************/
  416.  
  417. /**
  418. GLUI_Bitmap is a simple 2D texture map. It's used
  419. to represent small textures like checkboxes, arrows, etc.
  420. via the GLUI_StdBitmaps class.
  421. */
  422. class GLUIAPI GLUI_Bitmap
  423. {
  424. friend class GLUI_StdBitmaps;
  425.  
  426. public:
  427. GLUI_Bitmap();
  428. ~GLUI_Bitmap();
  429.  
  430. /** Create bitmap from greyscale byte image */
  431. void init_grey(unsigned char *array);
  432.  
  433. /** Create bitmap from color int image */
  434. void init(int *array);
  435.  
  436. private:
  437. /** RGB pixel data */
  438. unsigned char *pixels;
  439. int w, h;
  440. };
  441.  
  442.  
  443. /************************************************************/
  444. /* */
  445. /* Class GLUI_StdBitmap */
  446. /* */
  447. /************************************************************/
  448.  
  449. /**
  450. Keeps an array of GLUI_Bitmap objects to represent all the
  451. images used in the UI: checkboxes, arrows, etc.
  452. */
  453. class GLUIAPI GLUI_StdBitmaps
  454. {
  455. public:
  456. GLUI_StdBitmaps();
  457. ~GLUI_StdBitmaps();
  458.  
  459. /** Return the width (in pixels) of the n'th standard bitmap. */
  460. int width (int n) const;
  461. /** Return the height (in pixels) of the n'th standard bitmap. */
  462. int height(int n) const;
  463.  
  464. /** Draw the n'th standard bitmap (one of the enums
  465. listed in GLUI_StdBitmaps_Codes) at pixel corner (x,y).
  466. */
  467. void draw(int n, int x, int y) const;
  468.  
  469. private:
  470. GLUI_Bitmap bitmaps[GLUI_STDBITMAP_NUM_ITEMS];
  471. };
  472.  
  473. /************************************************************/
  474. /* */
  475. /* Master GLUI Class */
  476. /* */
  477. /************************************************************/
  478.  
  479. /**
  480. The master manages our interaction with GLUT.
  481. There's only one GLUI_Master_Object.
  482. */
  483. class GLUIAPI GLUI_Master_Object
  484. {
  485.  
  486. friend void glui_idle_func();
  487.  
  488. public:
  489.  
  490. GLUI_Master_Object();
  491. ~GLUI_Master_Object();
  492.  
  493. GLUI_Node gluis;
  494. GLUI_Control *active_control, *curr_left_button_glut_menu;
  495. GLUI *active_control_glui;
  496. int glui_id_counter;
  497.  
  498. GLUI_Glut_Window *find_glut_window( int window_id );
  499.  
  500. void set_glutIdleFunc(void (*f)(void));
  501.  
  502. /**************
  503. void (*glut_keyboard_CB)(unsigned char, int, int);
  504. void (*glut_reshape_CB)(int, int);
  505. void (*glut_special_CB)(int, int, int);
  506. void (*glut_mouse_CB)(int,int,int,int);
  507.  
  508. void (*glut_passive_motion_CB)(int,int);
  509. void (*glut_visibility_CB)(int);
  510. void (*glut_motion_CB)(int,int);
  511. void (*glut_display_CB)(void);
  512. void (*glut_entry_CB)(int);
  513. **********/
  514.  
  515. void set_left_button_glut_menu_control( GLUI_Control *control );
  516.  
  517. /********** GLUT callthroughs **********/
  518. /* These are the glut callbacks that we do not handle */
  519.  
  520. void set_glutReshapeFunc (void (*f)(int width, int height));
  521. void set_glutKeyboardFunc(void (*f)(unsigned char key, int x, int y));
  522. void set_glutSpecialFunc (void (*f)(int key, int x, int y));
  523. void set_glutMouseFunc (void (*f)(int, int, int, int ));
  524.  
  525. void set_glutDisplayFunc(void (*f)(void)) {glutDisplayFunc(f);}
  526. void set_glutTimerFunc(unsigned int millis, void (*f)(int value), int value)
  527. { ::glutTimerFunc(millis,f,value);}
  528. void set_glutOverlayDisplayFunc(void(*f)(void)){glutOverlayDisplayFunc(f);}
  529. void set_glutSpaceballMotionFunc(Int3_CB f) {glutSpaceballMotionFunc(f);}
  530. void set_glutSpaceballRotateFunc(Int3_CB f) {glutSpaceballRotateFunc(f);}
  531. void set_glutSpaceballButtonFunc(Int2_CB f) {glutSpaceballButtonFunc(f);}
  532. void set_glutTabletMotionFunc(Int2_CB f) {glutTabletMotionFunc(f);}
  533. void set_glutTabletButtonFunc(Int4_CB f) {glutTabletButtonFunc(f);}
  534. /* void set_glutWindowStatusFunc(Int1_CB f) {glutWindowStatusFunc(f);} */
  535. void set_glutMenuStatusFunc(Int3_CB f) {glutMenuStatusFunc(f);}
  536. void set_glutMenuStateFunc(Int1_CB f) {glutMenuStateFunc(f);}
  537. void set_glutButtonBoxFunc(Int2_CB f) {glutButtonBoxFunc(f);}
  538. void set_glutDialsFunc(Int2_CB f) {glutDialsFunc(f);}
  539.  
  540.  
  541. GLUI *create_glui( const char *name, long flags=0, int x=-1, int y=-1 );
  542. GLUI *create_glui_subwindow( int parent_window, long flags=0 );
  543. GLUI *find_glui_by_window_id( int window_id );
  544. void get_viewport_area( int *x, int *y, int *w, int *h );
  545. void auto_set_viewport();
  546. void close_all();
  547. void sync_live_all();
  548.  
  549. void reshape();
  550.  
  551. float get_version() { return GLUI_VERSION; }
  552.  
  553. void glui_setIdleFuncIfNecessary(void);
  554.  
  555. private:
  556. GLUI_Node glut_windows;
  557. void (*glut_idle_CB)(void);
  558.  
  559. void add_cb_to_glut_window(int window,int cb_type,void *cb);
  560. };
  561.  
  562. /**
  563. This is the only GLUI_Master_Object in existence.
  564. */
  565. extern GLUIAPI GLUI_Master_Object GLUI_Master;
  566.  
  567. /************************************************************/
  568. /* */
  569. /* Class for managing a GLUT window */
  570. /* */
  571. /************************************************************/
  572.  
  573. /**
  574. A top-level window. The GLUI_Master GLUT callback can route events
  575. to the callbacks in this class, for arbitrary use by external users.
  576. (see GLUI_Master_Object::set_glutKeyboardFunc).
  577.  
  578. This entire approach seems to be superceded by the "subwindow" flavor
  579. of GLUI.
  580. */
  581. class GLUIAPI GLUI_Glut_Window : public GLUI_Node
  582. {
  583. public:
  584. GLUI_Glut_Window();
  585.  
  586. int glut_window_id;
  587.  
  588. /*********** Pointers to GLUT callthrough functions *****/
  589. void (*glut_keyboard_CB)(unsigned char, int, int);
  590. void (*glut_special_CB)(int, int, int);
  591. void (*glut_reshape_CB)(int, int);
  592. void (*glut_passive_motion_CB)(int,int);
  593. void (*glut_mouse_CB)(int,int,int,int);
  594. void (*glut_visibility_CB)(int);
  595. void (*glut_motion_CB)(int,int);
  596. void (*glut_display_CB)(void);
  597. void (*glut_entry_CB)(int);
  598. };
  599.  
  600. /************************************************************/
  601. /* */
  602. /* Main Window GLUI class (not user-level) */
  603. /* */
  604. /************************************************************/
  605.  
  606. /**
  607. A GLUI_Main handles GLUT events for one window, routing them to the
  608. appropriate controls. The central user-visible "GLUI" class
  609. inherits from this class; users should not allocate GLUT_Main objects.
  610.  
  611. There's a separate GLUI_Main object for:
  612. - Each top-level window with GUI stuff in it.
  613. - Each "subwindow" of another top-level window.
  614.  
  615. All the GLUI_Main objects are listed in GLUI_Master.gluis.
  616. A better name for this class might be "GLUI_Environment";
  617. this class provides the window-level context for every control.
  618. */
  619. class GLUIAPI GLUI_Main : public GLUI_Node
  620. {
  621. /********** Friend classes *************/
  622.  
  623. friend class GLUI_Control;
  624. friend class GLUI_Rotation;
  625. friend class GLUI_Translation;
  626. friend class GLUI;
  627. friend class GLUI_Master_Object;
  628.  
  629. /*********** Friend functions **********/
  630.  
  631. friend void glui_mouse_func(int button, int state, int x, int y);
  632. friend void glui_keyboard_func(unsigned char key, int x, int y);
  633. friend void glui_special_func(int key, int x, int y);
  634. friend void glui_passive_motion_func(int x, int y);
  635. friend void glui_reshape_func( int w, int h );
  636. friend void glui_visibility_func(int state);
  637. friend void glui_motion_func(int x, int y);
  638. friend void glui_entry_func(int state);
  639. friend void glui_display_func( void );
  640. friend void glui_idle_func(void);
  641.  
  642. friend void glui_parent_window_reshape_func( int w, int h );
  643. friend void glui_parent_window_keyboard_func( unsigned char, int, int );
  644. friend void glui_parent_window_special_func( int, int, int );
  645. friend void glui_parent_window_mouse_func( int, int, int, int );
  646.  
  647. protected:
  648. /*** Variables ***/
  649. int main_gfx_window_id;
  650. int mouse_button_down;
  651. int glut_window_id;
  652. int top_level_glut_window_id;
  653. GLUI_Control *active_control;
  654. GLUI_Control *mouse_over_control;
  655. GLUI_Panel *main_panel;
  656. enum buffer_mode_t {
  657. buffer_front=1, ///< Draw updated controls directly to screen.
  658. buffer_back=2 ///< Double buffering: postpone updates until next redraw.
  659. };
  660. buffer_mode_t buffer_mode; ///< Current drawing mode
  661. int curr_cursor;
  662. int w, h;
  663. long flags;
  664. bool closing;
  665. int parent_window;
  666. int glui_id;
  667.  
  668. /********** Misc functions *************/
  669.  
  670. GLUI_Control *find_control( int x, int y );
  671. GLUI_Control *find_next_control( GLUI_Control *control );
  672. GLUI_Control *find_next_control_rec( GLUI_Control *control );
  673. GLUI_Control *find_next_control_( GLUI_Control *control );
  674. GLUI_Control *find_prev_control( GLUI_Control *control );
  675. void create_standalone_window( const char *name, int x=-1, int y=-1 );
  676. void create_subwindow( int parent,int window_alignment );
  677. void setup_default_glut_callbacks( void );
  678.  
  679. void mouse(int button, int state, int x, int y);
  680. void keyboard(unsigned char key, int x, int y);
  681. void special(int key, int x, int y);
  682. void passive_motion(int x, int y);
  683. void reshape( int w, int h );
  684. void visibility(int state);
  685. void motion(int x, int y);
  686. void entry(int state);
  687. void display( void );
  688. void idle(void);
  689. int needs_idle(void);
  690.  
  691. void (*glut_mouse_CB)(int, int, int, int);
  692. void (*glut_keyboard_CB)(unsigned char, int, int);
  693. void (*glut_special_CB)(int, int, int);
  694. void (*glut_reshape_CB)(int, int);
  695.  
  696.  
  697. /*********** Controls ************/
  698.  
  699. virtual int add_control( GLUI_Node *parent, GLUI_Control *control );
  700.  
  701.  
  702. /********** Constructors and Destructors ***********/
  703.  
  704. GLUI_Main( void );
  705.  
  706. public:
  707. GLUI_StdBitmaps std_bitmaps;
  708. GLUI_String window_name;
  709. unsigned char bkgd_color[3];
  710. float bkgd_color_f[3];
  711.  
  712. void *font;
  713. int curr_modifiers;
  714.  
  715. void adjust_glut_xy( int &x, int &y ) { y = h-y; }
  716. void activate_control( GLUI_Control *control, int how );
  717. void align_controls( GLUI_Control *control );
  718. void deactivate_current_control( void );
  719.  
  720. /** Draw a 3D-look pushed-out box around this rectangle */
  721. void draw_raised_box( int x, int y, int w, int h );
  722. /** Draw a 3D-look pushed-in box around this rectangle */
  723. void draw_lowered_box( int x, int y, int w, int h );
  724.  
  725. /** Return true if this control should redraw itself immediately (front buffer);
  726. Or queue up a redraw and return false if it shouldn't (back buffer).
  727. */
  728. bool should_redraw_now(GLUI_Control *ctl);
  729.  
  730. /** Switch to the appropriate draw buffer now. Returns the old draw buffer.
  731. This routine should probably only be called from inside the GLUI_DrawingSentinal,
  732. in glui_internal_control.h
  733. */
  734. int set_current_draw_buffer();
  735. /** Go back to using this draw buffer. Undoes set_current_draw_buffer. */
  736. void restore_draw_buffer( int buffer_state );
  737.  
  738. /** Pack, resize the window, and redraw all the controls. */
  739. void refresh();
  740.  
  741. /** Redraw the main graphics window */
  742. void post_update_main_gfx();
  743.  
  744. /** Recompute the sizes and positions of all controls */
  745. void pack_controls();
  746.  
  747. void close_internal();
  748. void check_subwindow_position();
  749. void set_ortho_projection();
  750. void set_viewport();
  751. int get_glut_window_id( void ) { return glut_window_id; } /* JVK */
  752. };
  753.  
  754. /************************************************************/
  755. /* */
  756. /* GLUI_Control: base class for all controls */
  757. /* */
  758. /************************************************************/
  759.  
  760. /**
  761. All the GUI objects inherit from GLUI_Control: buttons,
  762. checkboxes, labels, edit boxes, scrollbars, etc.
  763. Most of the work of this class is in routing events,
  764. like keystrokes, mouseclicks, redraws, and sizing events.
  765.  
  766. Yes, this is a huge and hideous class. It needs to be
  767. split up into simpler subobjects. None of the data members
  768. should be directly accessed by users (they should be protected,
  769. not public); only subclasses.
  770. */
  771. class GLUIAPI GLUI_Control : public GLUI_Node
  772. {
  773. public:
  774.  
  775. /** Onscreen coordinates */
  776. int w, h; /* dimensions of control */
  777. int x_abs, y_abs;
  778. int x_off, y_off_top, y_off_bot; /* INNER margins, by which child
  779. controls are indented */
  780. int contain_x, contain_y;
  781. int contain_w, contain_h;
  782. /* if this is a container control (e.g.,
  783. radiogroup or panel) this indicated dimensions
  784. of inner area in which controls reside */
  785.  
  786. /** "activation" for tabbing between controls. */
  787. int active_type; ///< "GLUI_CONTROL_ACTIVE_..."
  788. bool active; ///< If true, we've got the focus
  789. bool can_activate; ///< If false, remove from tab order.
  790. bool spacebar_mouse_click; ///< Spacebar simulates click.
  791.  
  792. /** Callbacks */
  793. long user_id; ///< Integer to pass to callback function.
  794. GLUI_CB callback; ///< User callback function, or NULL.
  795.  
  796. /** Variable value storage */
  797. float float_val; /**< Our float value */
  798. int int_val; /**< Our integer value */
  799. float float_array_val[GLUI_DEF_MAX_ARRAY];
  800. int float_array_size;
  801. GLUI_String text; /**< The text inside this control */
  802.  
  803. /** "Live variable" updating */
  804. void *ptr_val; /**< A pointer to the user's live variable value */
  805. int live_type;
  806. bool live_inited;
  807. /* These variables store the last value that live variable was known to have. */
  808. int last_live_int;
  809. float last_live_float;
  810. GLUI_String last_live_text;
  811. float last_live_float_array[GLUI_DEF_MAX_ARRAY];
  812.  
  813. /** Properties of our control */
  814. GLUI *glui; /**< Our containing event handler (NEVER NULL during event processing!) */
  815. bool is_container; /**< Is this a container class (e.g., panel) */
  816. int alignment;
  817. bool enabled; /**< Is this control grayed out? */
  818. GLUI_String name; /**< The name of this control */
  819. void *font; /**< Our glutbitmap font */
  820. bool collapsible, is_open;
  821. GLUI_Node collapsed_node;
  822. bool hidden; /* Collapsed controls (and children) are hidden */
  823. int char_widths[CHAR_WIDTH_HASH_SIZE][2]; /* Character width hash table */
  824.  
  825. public:
  826. /*** Get/Set values ***/
  827. virtual void set_name( const char *string );
  828. virtual void set_int_val( int new_int ) { int_val = new_int; output_live(true); }
  829. virtual void set_float_val( float new_float ) { float_val = new_float; output_live(true); }
  830. virtual void set_ptr_val( void *new_ptr ) { ptr_val = new_ptr; output_live(true); }
  831. virtual void set_float_array_val( float *array_ptr );
  832.  
  833. virtual float get_float_val( void ) { return float_val; }
  834. virtual int get_int_val( void ) { return int_val; }
  835. virtual void get_float_array_val( float *array_ptr );
  836. virtual int get_id( void ) const { return user_id; }
  837. virtual void set_id( int id ) { user_id=id; }
  838.  
  839. virtual int mouse_down_handler( int local_x, int local_y ) { return false; }
  840. virtual int mouse_up_handler( int local_x, int local_y, bool inside ) { return false; }
  841. virtual int mouse_held_down_handler( int local_x, int local_y, bool inside) { return false; }
  842. virtual int key_handler( unsigned char key, int modifiers ) { return false; }
  843. virtual int special_handler( int key,int modifiers ) { return false; }
  844.  
  845. virtual void update_size( void ) { }
  846. virtual void idle( void ) { }
  847. virtual int mouse_over( int state, int x, int y ) { return false; }
  848.  
  849. virtual void enable( void );
  850. virtual void disable( void );
  851. virtual void activate( int how ) { active = true; }
  852. virtual void deactivate( void ) { active = false; }
  853.  
  854. /** Hide (shrink into a rollout) and unhide (expose from a rollout) */
  855. void hide_internal( int recurse );
  856. void unhide_internal( int recurse );
  857.  
  858. /** Return true if it currently makes sense to draw this class. */
  859. int can_draw( void ) { return (glui != NULL && hidden == false); }
  860.  
  861. /** Redraw this control.
  862. In single-buffering mode (drawing to GL_FRONT), this is just
  863. a call to translate_and_draw_front (after a can_draw() check).
  864. In double-buffering mode (drawing to GL_BACK), this queues up
  865. a redraw and returns false, since you shouldn't draw yet.
  866. */
  867. void redraw(void);
  868.  
  869. /** Redraw everybody in our window. */
  870. void redraw_window(void);
  871.  
  872. virtual void align( void );
  873. void pack( int x, int y ); /* Recalculate positions and offsets */
  874. void pack_old( int x, int y );
  875. void draw_recursive( int x, int y );
  876. int set_to_glut_window( void );
  877. void restore_window( int orig );
  878. void translate_and_draw_front( void );
  879. void translate_to_origin( void )
  880. {glTranslatef((float)x_abs+.5,(float)y_abs+.5,0.0);}
  881. virtual void draw( int x, int y )=0;
  882. void set_font( void *new_font );
  883. void *get_font( void );
  884. int string_width( const char *text );
  885. int string_width( const GLUI_String &str )
  886. { return string_width(str.c_str()); }
  887. int char_width( char c );
  888.  
  889. void draw_name( int x, int y );
  890. void draw_box_inwards_outline( int x_min, int x_max,
  891. int y_min, int y_max );
  892. void draw_box( int x_min, int x_max, int y_min, int y_max,
  893. float r, float g, float b );
  894. void draw_bkgd_box( int x_min, int x_max, int y_min, int y_max );
  895. void draw_emboss_box( int x_min, int x_max,int y_min,int y_max);
  896. void draw_string( const char *text );
  897. void draw_string( const GLUI_String &s )
  898. { draw_string(s.c_str()); }
  899. void draw_char( char c );
  900. void draw_active_box( int x_min, int x_max, int y_min, int y_max );
  901. void set_to_bkgd_color( void );
  902.  
  903. void set_w( int new_w );
  904. void set_h( int new_w );
  905. void set_alignment( int new_align );
  906. void sync_live( int recurse, int draw ); /* Reads live variable */
  907. void init_live( void );
  908. void output_live( int update_main_gfx ); /** Writes live variable **/
  909. virtual void set_text( const char *t ) {}
  910. void execute_callback( void );
  911. void get_this_column_dims( int *col_x, int *col_y,
  912. int *col_w, int *col_h,
  913. int *col_x_off, int *col_y_off );
  914. virtual bool needs_idle( void ) const;
  915. virtual bool wants_tabs() const { return false; }
  916.  
  917. GLUI_Control(void)
  918. {
  919. x_off = GLUI_XOFF;
  920. y_off_top = GLUI_YOFF;
  921. y_off_bot = GLUI_YOFF;
  922. x_abs = GLUI_XOFF;
  923. y_abs = GLUI_YOFF;
  924. active = false;
  925. enabled = true;
  926. int_val = 0;
  927. last_live_int = 0;
  928. float_array_size = 0;
  929. glui_format_str(name, "Control: %p", this);
  930. float_val = 0.0;
  931. last_live_float = 0.0;
  932. ptr_val = NULL;
  933. glui = NULL;
  934. w = GLUI_DEFAULT_CONTROL_WIDTH;
  935. h = GLUI_DEFAULT_CONTROL_HEIGHT;
  936. font = NULL;
  937. active_type = GLUI_CONTROL_ACTIVE_MOUSEDOWN;
  938. alignment = GLUI_ALIGN_LEFT;
  939. is_container = false;
  940. can_activate = true; /* By default, you can activate a control */
  941. spacebar_mouse_click = true; /* Does spacebar simulate a mouse click? */
  942. live_type = GLUI_LIVE_NONE;
  943. text = "";
  944. last_live_text == "";
  945. live_inited = false;
  946. collapsible = false;
  947. is_open = true;
  948. hidden = false;
  949. memset(char_widths, -1, sizeof(char_widths)); /* JVK */
  950. int i;
  951. for( i=0; i<GLUI_DEF_MAX_ARRAY; i++ )
  952. float_array_val[i] = last_live_float_array[i] = 0.0;
  953. }
  954.  
  955. virtual ~GLUI_Control();
  956. };
  957.  
  958. /************************************************************/
  959. /* */
  960. /* Button class (container) */
  961. /* */
  962. /************************************************************/
  963. /**
  964. An onscreen, clickable button--an outlined label that
  965. can be clicked. When clicked, a button
  966. calls its GLUI_CB callback with its ID.
  967. */
  968. class GLUIAPI GLUI_Button : public GLUI_Control
  969. {
  970. public:
  971. bool currently_inside;
  972.  
  973. int mouse_down_handler( int local_x, int local_y );
  974. int mouse_up_handler( int local_x, int local_y, bool inside );
  975. int mouse_held_down_handler( int local_x, int local_y, bool inside );
  976. int key_handler( unsigned char key,int modifiers );
  977.  
  978. void draw( int x, int y );
  979. void draw_pressed( void );
  980. void draw_text( int sunken );
  981.  
  982. void update_size( void );
  983.  
  984. /**
  985. Create a new button.
  986.  
  987. @param parent The panel our object is inside; or the main GLUI object.
  988. @param name The text inside the button.
  989. @param id Optional ID number, to pass to the optional callback function.
  990. @param callback Optional callback function, taking either the int ID or control.
  991. */
  992. GLUI_Button( GLUI_Node *parent, const char *name,
  993. int id=-1, GLUI_CB cb=GLUI_CB() );
  994. GLUI_Button( void ) { common_init(); };
  995.  
  996. protected:
  997. void common_init(void) {
  998. glui_format_str(name, "Button: %p", this );
  999. h = GLUI_BUTTON_SIZE;
  1000. w = 100;
  1001. alignment = GLUI_ALIGN_CENTER;
  1002. can_activate = true;
  1003. }
  1004. };
  1005.  
  1006.  
  1007. /************************************************************/
  1008. /* */
  1009. /* Checkbox class (container) */
  1010. /* */
  1011. /************************************************************/
  1012.  
  1013. /**
  1014. A checkbox, which can be checked on or off. Can be linked
  1015. to an int value, which gets 1 for on and 0 for off.
  1016. */
  1017. class GLUIAPI GLUI_Checkbox : public GLUI_Control
  1018. {
  1019. public:
  1020. int orig_value;
  1021. bool currently_inside;
  1022. int text_x_offset;
  1023.  
  1024. int mouse_down_handler( int local_x, int local_y );
  1025. int mouse_up_handler( int local_x, int local_y, bool inside );
  1026. int mouse_held_down_handler( int local_x, int local_y, bool inside );
  1027. int key_handler( unsigned char key,int modifiers );
  1028.  
  1029. void update_size( void );
  1030.  
  1031. void draw( int x, int y );
  1032.  
  1033. void draw_active_area( void );
  1034. void draw_empty_box( void );
  1035. void set_int_val( int new_val );
  1036.  
  1037. /**
  1038. Create a new checkbox object.
  1039.  
  1040. @param parent The panel our object is inside; or the main GLUI object.
  1041. @param name Label next to our checkbox.
  1042. @param value_ptr Optional integer value to attach to this checkbox. When the
  1043. checkbox is checked or unchecked, *value_ptr will also be changed. ("Live Vars").
  1044. @param id Optional ID number, to pass to the optional callback function.
  1045. @param callback Optional callback function, taking either the int ID or control.
  1046. */
  1047. GLUI_Checkbox(GLUI_Node *parent, const char *name, int *value_ptr=NULL,
  1048. int id=-1, GLUI_CB callback=GLUI_CB());
  1049. GLUI_Checkbox( void ) { common_init(); }
  1050.  
  1051. protected:
  1052. void common_init(void) {
  1053. glui_format_str( name, "Checkbox: %p", this );
  1054. w = 100;
  1055. h = GLUI_CHECKBOX_SIZE;
  1056. orig_value = -1;
  1057. text_x_offset = 18;
  1058. can_activate = true;
  1059. live_type = GLUI_LIVE_INT; /* This control has an 'int' live var */
  1060. }
  1061. };
  1062.  
  1063. /************************************************************/
  1064. /* */
  1065. /* Column class */
  1066. /* */
  1067. /************************************************************/
  1068.  
  1069. /**
  1070. A GLUI_Column object separates all previous controls
  1071. from subsequent controls with a vertical bar.
  1072. */
  1073. class GLUIAPI GLUI_Column : public GLUI_Control
  1074. {
  1075. public:
  1076. void draw( int x, int y );
  1077.  
  1078. /**
  1079. Create a new column, which separates the previous controls
  1080. from subsequent controls.
  1081.  
  1082. @param parent The panel our object is inside; or the main GLUI object.
  1083. @param draw_bar If true, draw a visible bar between new and old controls.
  1084. */
  1085. GLUI_Column( GLUI_Node *parent, int draw_bar = true );
  1086. GLUI_Column( void ) { common_init(); }
  1087.  
  1088. protected:
  1089. void common_init() {
  1090. w = 0;
  1091. h = 0;
  1092. int_val = 0;
  1093. can_activate = false;
  1094. }
  1095. };
  1096.  
  1097.  
  1098. /************************************************************/
  1099. /* */
  1100. /* Panel class (container) */
  1101. /* */
  1102. /************************************************************/
  1103.  
  1104. /**
  1105. A GLUI_Panel contains a group of related controls.
  1106. */
  1107. class GLUIAPI GLUI_Panel : public GLUI_Control
  1108. {
  1109. public:
  1110.  
  1111. /**
  1112. Create a new panel. A panel groups together a set of related controls.
  1113.  
  1114. @param parent The outer panel our panel is inside; or the main GLUI object.
  1115. @param name The string name at the top of our panel.
  1116. @param type Optional style to display the panel with--GLUI_PANEL_EMBOSSED by default.
  1117. GLUI_PANEL_RAISED causes the panel to appear higher than the surroundings.
  1118. GLUI_PANEL_NONE causes the panel's outline to be invisible.
  1119. */
  1120. GLUI_Panel( GLUI_Node *parent, const char *name,
  1121. int type=GLUI_PANEL_EMBOSSED );
  1122. GLUI_Panel() { common_init(); }
  1123.  
  1124. void draw( int x, int y );
  1125. void set_name( const char *text );
  1126. void set_type( int new_type );
  1127.  
  1128. void update_size( void );
  1129.  
  1130. protected:
  1131. void common_init( void ) {
  1132. w = 300;
  1133. h = GLUI_DEFAULT_CONTROL_HEIGHT + 7;
  1134. int_val = GLUI_PANEL_EMBOSSED;
  1135. alignment = GLUI_ALIGN_CENTER;
  1136. is_container = true;
  1137. can_activate = false;
  1138. name="";
  1139. };
  1140. };
  1141.  
  1142. /************************************************************/
  1143. /* */
  1144. /* File Browser class (container) */
  1145. /* JVK */
  1146. /************************************************************/
  1147.  
  1148. /**
  1149. A list of files the user can select from.
  1150. */
  1151. class GLUIAPI GLUI_FileBrowser : public GLUI_Panel
  1152. {
  1153. public:
  1154. /**
  1155. Create a new list of files the user can select from.
  1156.  
  1157. @param parent The panel our object is inside; or the main GLUI object.
  1158. @param name Prompt to give to the user at the top of the file browser.
  1159. @param frame_type Optional style to display the panel with--GLUI_PANEL_EMBOSSED by default.
  1160. GLUI_PANEL_RAISED causes the panel to appear higher than the surroundings.
  1161. GLUI_PANEL_NONE causes the panel's outline to be invisible.
  1162. @param id Optional ID number, to pass to the optional callback function.
  1163. @param callback Optional callback function, taking either the int ID or control.
  1164. */
  1165. GLUI_FileBrowser( GLUI_Node *parent,
  1166. const char *name,
  1167. int frame_type = GLUI_PANEL_EMBOSSED,
  1168. int user_id = -1,
  1169. GLUI_CB callback = GLUI_CB());
  1170.  
  1171. GLUI_List *list;
  1172. GLUI_String current_dir;
  1173.  
  1174. void fbreaddir(const char *);
  1175. static void dir_list_callback(GLUI_Control*);
  1176.  
  1177. void set_w(int w);
  1178. void set_h(int h);
  1179. const char* get_file() { return file.c_str(); }
  1180. void set_allow_change_dir(int c) { allow_change_dir = c; }
  1181.  
  1182. protected:
  1183. void common_init()
  1184. {
  1185. w = GLUI_DEFAULT_CONTROL_WIDTH;
  1186. h = GLUI_DEFAULT_CONTROL_HEIGHT;
  1187. int_val = GLUI_PANEL_EMBOSSED;
  1188. alignment = GLUI_ALIGN_CENTER;
  1189. is_container = true;
  1190. can_activate = false;
  1191. allow_change_dir = true;
  1192. last_item = -1;
  1193. user_id = -1;
  1194. name = "";
  1195. current_dir = ".";
  1196. file = "";
  1197. };
  1198.  
  1199. private:
  1200. int last_item;
  1201. GLUI_String file;
  1202. int allow_change_dir;
  1203.  
  1204. };
  1205.  
  1206. /************************************************************/
  1207. /* */
  1208. /* Rollout class (container) */
  1209. /* */
  1210. /************************************************************/
  1211. /**
  1212. A rollout contains a set of controls,
  1213. like a panel, but can be collapsed to just the name.
  1214. */
  1215. class GLUIAPI GLUI_Rollout : public GLUI_Panel
  1216. {
  1217. public:
  1218.  
  1219. /**
  1220. Create a new rollout. A rollout contains a set of controls,
  1221. like a panel, but can be collapsed to just the name.
  1222.  
  1223. @param parent The panel our object is inside; or the main GLUI object.
  1224. @param name String to show at the top of the rollout.
  1225. @param open Optional boolean. If true (the default), the rollout's controls are displayed.
  1226. If false, the rollout is closed to display only the name.
  1227. @param type Optional style to display the panel with--GLUI_PANEL_EMBOSSED by default.
  1228. GLUI_PANEL_RAISED causes the panel to appear higher than the surroundings.
  1229. GLUI_PANEL_NONE causes the panel's outline to be invisible.
  1230. */
  1231. GLUI_Rollout( GLUI_Node *parent, const char *name, int open=true,
  1232. int type=GLUI_PANEL_EMBOSSED );
  1233. GLUI_Rollout( void ) { common_init(); }
  1234.  
  1235.  
  1236. bool currently_inside, initially_inside;
  1237. GLUI_Button button;
  1238.  
  1239. void draw( int x, int y );
  1240. void draw_pressed( void );
  1241. int mouse_down_handler( int local_x, int local_y );
  1242. int mouse_up_handler( int local_x, int local_y, bool inside );
  1243. int mouse_held_down_handler( int local_x, int local_y, bool inside );
  1244.  
  1245. void open( void );
  1246. void close( void );
  1247.  
  1248. void update_size( void );
  1249.  
  1250. protected:
  1251. void common_init() {
  1252. currently_inside = false;
  1253. initially_inside = false;
  1254. can_activate = true;
  1255. is_container = true;
  1256. h = GLUI_DEFAULT_CONTROL_HEIGHT + 7;
  1257. w = GLUI_DEFAULT_CONTROL_WIDTH;
  1258. y_off_top = 21;
  1259. collapsible = true;
  1260. name = "";
  1261. }
  1262. };
  1263.  
  1264. /************************************************************/
  1265. /* */
  1266. /* Tree Panel class (container) */
  1267. /* JVK */
  1268. /************************************************************/
  1269.  
  1270. /**
  1271. One collapsible entry in a GLUI_TreePanel.
  1272. */
  1273. class GLUIAPI GLUI_Tree : public GLUI_Panel
  1274. {
  1275. public:
  1276. GLUI_Tree(GLUI_Node *parent, const char *name,
  1277. int open=false, int inset=0);
  1278.  
  1279. private:
  1280. int level; // how deep is this node
  1281. float red; //Color coding of column line
  1282. float green;
  1283. float blue;
  1284. float lred; //Color coding of level name
  1285. float lgreen;
  1286. float lblue;
  1287. int id;
  1288. GLUI_Column *column;
  1289. int is_current; // Whether this tree is the
  1290. // current root in a treePanel
  1291. int child_number;
  1292. int format;
  1293.  
  1294. public:
  1295. bool currently_inside, initially_inside;
  1296. GLUI_Button button;
  1297. GLUI_String level_name; // level name, eg: 1.1.2, III, or 3
  1298. GLUI_TreePanel *panel;
  1299.  
  1300. void draw( int x, int y );
  1301. void draw_pressed( void );
  1302. int mouse_down_handler( int local_x, int local_y );
  1303. int mouse_up_handler( int local_x, int local_y, bool inside );
  1304. int mouse_held_down_handler( int local_x, int local_y, bool inside );
  1305. void set_column(GLUI_Column *c) { column = c; }
  1306. void open( void );
  1307. void close( void );
  1308.  
  1309. /* void set_name( const char *text ) { panel.set_name( text ); }; */
  1310. void update_size( void );
  1311. void set_id(int i) { id = i; }
  1312. void set_level(int l) { level = l; }
  1313. void set_format(int f) { format = f; }
  1314. void set_current(int c) { is_current = c; }
  1315. int get_id() { return id; }
  1316. int get_level() { return level; }
  1317. int get_child_number() { return child_number; }
  1318. void enable_bar() { if (column) { column->int_val = 1; set_color(red, green, blue); } }
  1319. void disable_bar() { if (column) { column->int_val = 0; } }
  1320. void set_child_number(int c) { child_number = c; }
  1321. void set_level_color(float r, float g, float b) {
  1322. lred = r;
  1323. lgreen = g;
  1324. lblue = b;
  1325. }
  1326. void set_color(float r, float g, float b) {
  1327. red = r;
  1328. green = g;
  1329. blue = b;
  1330. }
  1331. protected:
  1332. void common_init()
  1333. {
  1334. currently_inside = false;
  1335. initially_inside = false;
  1336. can_activate = true;
  1337. is_container = true;
  1338. h = GLUI_DEFAULT_CONTROL_HEIGHT + 7;
  1339. w = GLUI_DEFAULT_CONTROL_WIDTH;
  1340. y_off_top = 21;
  1341. collapsible = true;
  1342. red = .5;
  1343. green = .5;
  1344. blue = .5;
  1345. lred = 0;
  1346. lgreen = 0;
  1347. lblue = 0;
  1348. column = NULL;
  1349. is_current = 0;
  1350. child_number = 0;
  1351. format = 0;
  1352. panel = NULL;
  1353. name = "";
  1354. level_name = "";
  1355. level = 0;
  1356.  
  1357. };
  1358. };
  1359.  
  1360.  
  1361. /************************************************************/
  1362. /* */
  1363. /* TreePanel class (container) JVK */
  1364. /* */
  1365. /************************************************************/
  1366.  
  1367. /**
  1368. Manages, maintains, and formats a tree of GLUI_Tree objects.
  1369. These are shown in a heirarchical, collapsible display.
  1370.  
  1371. FIXME: There's an infinite loop in the traversal code (OSL 2006/06)
  1372. */
  1373. class GLUIAPI GLUI_TreePanel : public GLUI_Panel
  1374. {
  1375. public:
  1376. GLUI_TreePanel(GLUI_Node *parent, const char *name,
  1377. bool open=false, int inset=0);
  1378.  
  1379. int max_levels;
  1380. int next_id;
  1381. int format;
  1382. float red;
  1383. float green;
  1384. float blue;
  1385. float lred;
  1386. float lgreen;
  1387. float lblue;
  1388. int root_children;
  1389. /* These variables allow the tree panel to traverse the tree
  1390. using only two function calls. (Well, four, if you count
  1391. going in reverse */
  1392.  
  1393. GLUI_Tree *curr_branch; /* Current Branch */
  1394. GLUI_Panel *curr_root; /* Current Root */
  1395.  
  1396. public:
  1397. void set_color(float r, float g, float b);
  1398. void set_level_color(float r, float g, float b);
  1399. void set_format(int f) { format = f; }
  1400.  
  1401. /* Adds branch to curr_root */
  1402. GLUI_Tree * ab(const char *name, GLUI_Tree *root = NULL);
  1403. /* Goes up one level, resets curr_root and curr_branch to parents*/
  1404. void fb(GLUI_Tree *branch= NULL);
  1405. /* Deletes the curr_branch, goes up one level using fb */
  1406. void db(GLUI_Tree *branch = NULL);
  1407. /* Finds the very last branch of curr_root, resets vars */
  1408. void descendBranch(GLUI_Panel *root = NULL);
  1409. /* Resets curr_root and curr branch to TreePanel and lastChild */
  1410. void resetToRoot(GLUI_Panel *new_root = NULL);
  1411. void next( void );
  1412. void refresh( void );
  1413. void expand_all( void );
  1414. void collapse_all( void );
  1415. void update_all( void );
  1416. void initNode(GLUI_Tree *temp);
  1417. void formatNode(GLUI_Tree *temp);
  1418.  
  1419. protected:
  1420. int uniqueID( void ) { next_id++; return next_id - 1; }
  1421. void common_init()
  1422. {
  1423. GLUI_Panel();
  1424. next_id = 0;
  1425. curr_root = this;
  1426. curr_branch = NULL;
  1427. red = .5;
  1428. green = .5;
  1429. blue = .5;
  1430. root_children = 0;
  1431. }
  1432. };
  1433.  
  1434. /************************************************************/
  1435. /* */
  1436. /* User-Level GLUI class */
  1437. /* */
  1438. /************************************************************/
  1439.  
  1440. class GLUI_Rotation;
  1441. class GLUI_Translation;
  1442.  
  1443. /**
  1444. The main user-visible interface object to GLUI.
  1445.  
  1446. */
  1447. class GLUIAPI GLUI : public GLUI_Main
  1448. {
  1449. public:
  1450. /** DEPRECATED interface for creating new GLUI objects */
  1451. int add_control( GLUI_Control *control ) { return main_panel->add_control(control); }
  1452.  
  1453. void add_column( int draw_bar = true );
  1454. void add_column_to_panel( GLUI_Panel *panel, int draw_bar = true );
  1455.  
  1456. void add_separator( void );
  1457. void add_separator_to_panel( GLUI_Panel *panel );
  1458.  
  1459. GLUI_RadioGroup
  1460. *add_radiogroup( int *live_var=NULL,
  1461. int user_id=-1,GLUI_CB callback=GLUI_CB());
  1462.  
  1463. GLUI_RadioGroup
  1464. *add_radiogroup_to_panel( GLUI_Panel *panel,
  1465. int *live_var=NULL,
  1466. int user_id=-1, GLUI_CB callback=GLUI_CB() );
  1467. GLUI_RadioButton
  1468. *add_radiobutton_to_group( GLUI_RadioGroup *group,
  1469. const char *name );
  1470.  
  1471. GLUI_Listbox *add_listbox( const char *name, int *live_var=NULL,
  1472. int id=-1, GLUI_CB callback=GLUI_CB() );
  1473. GLUI_Listbox *add_listbox_to_panel( GLUI_Panel *panel,
  1474. const char *name, int *live_var=NULL,
  1475. int id=-1, GLUI_CB callback=GLUI_CB());
  1476.  
  1477. GLUI_Rotation *add_rotation( const char *name, float *live_var=NULL,
  1478. int id=-1, GLUI_CB callback=GLUI_CB() );
  1479. GLUI_Rotation *add_rotation_to_panel( GLUI_Panel *panel,
  1480. const char *name, float *live_var=NULL,
  1481. int id=-1, GLUI_CB callback=GLUI_CB());
  1482.  
  1483. GLUI_Translation *add_translation( const char *name,
  1484. int trans_type, float *live_var=NULL,
  1485. int id=-1, GLUI_CB callback=GLUI_CB() );
  1486. GLUI_Translation *add_translation_to_panel(
  1487. GLUI_Panel *panel, const char *name,
  1488. int trans_type, float *live_var=NULL,
  1489. int id=-1, GLUI_CB callback=GLUI_CB());
  1490.  
  1491. GLUI_Checkbox *add_checkbox( const char *name,
  1492. int *live_var=NULL,
  1493. int id=-1, GLUI_CB callback=GLUI_CB());
  1494. GLUI_Checkbox *add_checkbox_to_panel( GLUI_Panel *panel, const char *name,
  1495. int *live_var=NULL, int id=-1,
  1496. GLUI_CB callback=GLUI_CB());
  1497.  
  1498. GLUI_Button *add_button( const char *name, int id=-1,
  1499. GLUI_CB callback=GLUI_CB());
  1500. GLUI_Button *add_button_to_panel( GLUI_Panel *panel, const char *name,
  1501. int id=-1, GLUI_CB callback=GLUI_CB() );
  1502.  
  1503. GLUI_StaticText *add_statictext( const char *name );
  1504. GLUI_StaticText *add_statictext_to_panel( GLUI_Panel *panel, const char *name );
  1505.  
  1506. GLUI_EditText *add_edittext( const char *name,
  1507. int data_type=GLUI_EDITTEXT_TEXT,
  1508. void*live_var=NULL,
  1509. int id=-1, GLUI_CB callback=GLUI_CB() );
  1510. GLUI_EditText *add_edittext_to_panel( GLUI_Panel *panel,
  1511. const char *name,
  1512. int data_type=GLUI_EDITTEXT_TEXT,
  1513. void *live_var=NULL, int id=-1,
  1514. GLUI_CB callback=GLUI_CB() );
  1515. GLUI_EditText *add_edittext( const char *name, GLUI_String& live_var,
  1516. int id=-1, GLUI_CB callback=GLUI_CB() );
  1517. GLUI_EditText *add_edittext_to_panel( GLUI_Panel *panel, const char *name,
  1518. GLUI_String& live_var, int id=-1,
  1519. GLUI_CB callback=GLUI_CB() );
  1520.  
  1521. GLUI_Spinner *add_spinner( const char *name,
  1522. int data_type=GLUI_SPINNER_INT,
  1523. void *live_var=NULL,
  1524. int id=-1, GLUI_CB callback=GLUI_CB() );
  1525. GLUI_Spinner *add_spinner_to_panel( GLUI_Panel *panel,
  1526. const char *name,
  1527. int data_type=GLUI_SPINNER_INT,
  1528. void *live_var=NULL,
  1529. int id=-1,
  1530. GLUI_CB callback=GLUI_CB() );
  1531.  
  1532. GLUI_Panel *add_panel( const char *name, int type=GLUI_PANEL_EMBOSSED );
  1533. GLUI_Panel *add_panel_to_panel( GLUI_Panel *panel, const char *name,
  1534. int type=GLUI_PANEL_EMBOSSED );
  1535.  
  1536.  
  1537. GLUI_Rollout *add_rollout( const char *name, int open=true,
  1538. int type=GLUI_PANEL_EMBOSSED);
  1539. GLUI_Rollout *add_rollout_to_panel( GLUI_Panel *panel, const char *name,
  1540. int open=true,
  1541. int type=GLUI_PANEL_EMBOSSED);
  1542.  
  1543.  
  1544. /** Set the window where our widgets should be displayed. */
  1545. void set_main_gfx_window( int window_id );
  1546. int get_glut_window_id( void ) { return glut_window_id; }
  1547.  
  1548. void enable( void ) { main_panel->enable(); }
  1549. void disable( void );
  1550.  
  1551. void sync_live( void );
  1552.  
  1553. void close( void );
  1554.  
  1555. void show( void );
  1556. void hide( void );
  1557.  
  1558. /***** GLUT callback setup functions *****/
  1559. /*
  1560. void set_glutDisplayFunc(void (*f)(void));
  1561. void set_glutReshapeFunc(void (*f)(int width, int height));
  1562. void set_glutKeyboardFunc(void (*f)(unsigned char key, int x, int y));
  1563. void set_glutSpecialFunc(void (*f)(int key, int x, int y));
  1564. void set_glutMouseFunc(void (*f)(int button, int state, int x, int y));
  1565. void set_glutMotionFunc(void (*f)(int x, int y));
  1566. void set_glutPassiveMotionFunc(void (*f)(int x, int y));
  1567. void set_glutEntryFunc(void (*f)(int state));
  1568. void set_glutVisibilityFunc(void (*f)(int state));
  1569. void set_glutInit( int *argcp, const char **argv );
  1570. void set_glutInitWindowSize(int width, int height);
  1571. void set_glutInitWindowPosition(int x, int y);
  1572. void set_glutInitDisplayMode(unsigned int mode);
  1573. int set_glutCreateWindow(const char *name);
  1574. */
  1575.  
  1576. /***** Constructors and desctructors *****/
  1577.  
  1578. int init( const char *name, long flags, int x, int y, int parent_window );
  1579. protected:
  1580. virtual int add_control( GLUI_Node *parent, GLUI_Control *control ) {
  1581. return GLUI_Main::add_control( parent, control );
  1582. }
  1583. };
  1584.  
  1585. /************************************************************/
  1586. /* */
  1587. /* EditText class */
  1588. /* */
  1589. /************************************************************/
  1590.  
  1591. class GLUIAPI GLUI_EditText : public GLUI_Control
  1592. {
  1593. public:
  1594. int has_limits;
  1595. int data_type;
  1596. GLUI_String orig_text;
  1597. int insertion_pt;
  1598. int title_x_offset;
  1599. int text_x_offset;
  1600. int substring_start; /*substring that gets displayed in box*/
  1601. int substring_end;
  1602. int sel_start, sel_end; /* current selection */
  1603. int num_periods;
  1604. int last_insertion_pt;
  1605. float float_low, float_high;
  1606. int int_low, int_high;
  1607. GLUI_Spinner *spinner;
  1608. int debug;
  1609. int draw_text_only;
  1610.  
  1611.  
  1612. int mouse_down_handler( int local_x, int local_y );
  1613. int mouse_up_handler( int local_x, int local_y, bool inside );
  1614. int mouse_held_down_handler( int local_x, int local_y, bool inside );
  1615. int key_handler( unsigned char key,int modifiers );
  1616. int special_handler( int key, int modifiers );
  1617.  
  1618. void activate( int how );
  1619. void deactivate( void );
  1620.  
  1621. void draw( int x, int y );
  1622.  
  1623. int mouse_over( int state, int x, int y );
  1624.  
  1625. int find_word_break( int start, int direction );
  1626. int substring_width( int start, int end );
  1627. void clear_substring( int start, int end );
  1628. int find_insertion_pt( int x, int y );
  1629. int update_substring_bounds( void );
  1630. void update_and_draw_text( void );
  1631. void draw_text( int x, int y );
  1632. void draw_insertion_pt( void );
  1633. void set_numeric_text( void );
  1634. void update_x_offsets( void );
  1635. void update_size( void );
  1636.  
  1637. void set_float_limits( float low,float high,int limit_type=GLUI_LIMIT_CLAMP);
  1638. void set_int_limits( int low, int high, int limit_type=GLUI_LIMIT_CLAMP );
  1639. void set_float_val( float new_val );
  1640. void set_int_val( int new_val );
  1641. void set_text( const char *text );
  1642. void set_text( const GLUI_String &s) { set_text(s.c_str()); }
  1643. const char *get_text() { return text.c_str(); }
  1644.  
  1645. void dump( FILE *out, const char *text );
  1646.  
  1647. // Constructor, no live variable
  1648. GLUI_EditText( GLUI_Node *parent, const char *name,
  1649. int text_type=GLUI_EDITTEXT_TEXT,
  1650. int id=-1, GLUI_CB callback=GLUI_CB() );
  1651. // Constructor, int live variable
  1652. GLUI_EditText( GLUI_Node *parent, const char *name,
  1653. int *live_var,
  1654. int id=-1, GLUI_CB callback=GLUI_CB() );
  1655. // Constructor, float live variable
  1656. GLUI_EditText( GLUI_Node *parent, const char *name,
  1657. float *live_var,
  1658. int id=-1, GLUI_CB callback=GLUI_CB() );
  1659. // Constructor, char* live variable
  1660. GLUI_EditText( GLUI_Node *parent, const char *name,
  1661. char *live_var,
  1662. int id=-1, GLUI_CB callback=GLUI_CB() );
  1663. // Constructor, std::string live variable
  1664. GLUI_EditText( GLUI_Node *parent, const char *name,
  1665. std::string &live_var,
  1666. int id=-1, GLUI_CB callback=GLUI_CB() );
  1667.  
  1668. // Deprecated constructor, only called internally
  1669. GLUI_EditText( GLUI_Node *parent, const char *name,
  1670. int text_type, void *live_var,
  1671. int id, GLUI_CB callback );
  1672. // Deprecated constructor, only called internally
  1673. GLUI_EditText( void ) { common_init(); }
  1674.  
  1675. protected:
  1676. void common_init( void ) {
  1677. h = GLUI_EDITTEXT_HEIGHT;
  1678. w = GLUI_EDITTEXT_WIDTH;
  1679. title_x_offset = 0;
  1680. text_x_offset = 55;
  1681. insertion_pt = -1;
  1682. last_insertion_pt = -1;
  1683. name = "";
  1684. substring_start = 0;
  1685. data_type = GLUI_EDITTEXT_TEXT;
  1686. substring_end = 2;
  1687. num_periods = 0;
  1688. has_limits = GLUI_LIMIT_NONE;
  1689. sel_start = 0;
  1690. sel_end = 0;
  1691. active_type = GLUI_CONTROL_ACTIVE_PERMANENT;
  1692. can_activate = true;
  1693. spacebar_mouse_click = false;
  1694. spinner = NULL;
  1695. debug = false;
  1696. draw_text_only = false;
  1697. }
  1698. void common_construct( GLUI_Node *parent, const char *name,
  1699. int data_type, int live_type, void *live_var,
  1700. int id, GLUI_CB callback );
  1701. };
  1702.  
  1703. /************************************************************/
  1704. /* */
  1705. /* CommandLine class */
  1706. /* */
  1707. /************************************************************/
  1708.  
  1709. class GLUIAPI GLUI_CommandLine : public GLUI_EditText
  1710. {
  1711. public:
  1712. typedef GLUI_EditText Super;
  1713.  
  1714. enum { HIST_SIZE = 100 };
  1715.  
  1716. #ifdef _MSC_VER
  1717. // Explicit template instantiation needed for dll
  1718. template class GLUIAPI std::allocator<GLUI_String>;
  1719. template class GLUIAPI std::vector<GLUI_String, std::allocator<GLUI_String> >;
  1720. #endif
  1721.  
  1722. std::vector<GLUI_String> hist_list;
  1723. int curr_hist;
  1724. int oldest_hist;
  1725. int newest_hist;
  1726. bool commit_flag;
  1727.  
  1728. public:
  1729. int key_handler( unsigned char key,int modifiers );
  1730. int special_handler( int key,int modifiers );
  1731. void deactivate( void );
  1732.  
  1733. virtual const char *get_history( int command_number ) const
  1734. { return hist_list[command_number - oldest_hist].c_str(); }
  1735. virtual GLUI_String& get_history_str( int command_number )
  1736. { return hist_list[command_number - oldest_hist]; }
  1737. virtual const GLUI_String& get_history_str( int command_number ) const
  1738. { return hist_list[command_number - oldest_hist]; }
  1739. virtual void recall_history( int history_number );
  1740. virtual void scroll_history( int direction );
  1741. virtual void add_to_history( const char *text );
  1742. virtual void reset_history( void );
  1743.  
  1744. void dump( FILE *out, const char *text );
  1745.  
  1746.  
  1747. GLUI_CommandLine( GLUI_Node *parent, const char *name, void *live_var=NULL,
  1748. int id=-1, GLUI_CB callback=GLUI_CB() );
  1749. GLUI_CommandLine( void ) { common_init(); }
  1750. protected:
  1751. void common_init() {
  1752. hist_list.resize(HIST_SIZE);
  1753. curr_hist = 0;
  1754. oldest_hist = 0;
  1755. newest_hist = 0;
  1756. commit_flag = false;
  1757. }
  1758.  
  1759. };
  1760.  
  1761. /************************************************************/
  1762. /* */
  1763. /* RadioGroup class (container) */
  1764. /* */
  1765. /************************************************************/
  1766.  
  1767. class GLUIAPI GLUI_RadioGroup : public GLUI_Control
  1768. {
  1769. public:
  1770. int num_buttons;
  1771.  
  1772. void draw( int x, int y );
  1773. void set_name( const char *text );
  1774. void set_int_val( int int_val );
  1775. void set_selected( int int_val );
  1776.  
  1777. void draw_group( int translate );
  1778.  
  1779. GLUI_RadioGroup( GLUI_Node *parent, int *live_var=NULL,
  1780. int user_id=-1,GLUI_CB callback=GLUI_CB() );
  1781. GLUI_RadioGroup( void ) { common_init(); }
  1782.  
  1783. protected:
  1784. void common_init( void ) {
  1785. x_off = 0;
  1786. y_off_top = 0;
  1787. y_off_bot = 0;
  1788. is_container = true;
  1789. w = 300;
  1790. h = 300;
  1791. num_buttons = 0;
  1792. name = "";
  1793. can_activate = false;
  1794. live_type = GLUI_LIVE_INT;
  1795. }
  1796. };
  1797.  
  1798. /************************************************************/
  1799. /* */
  1800. /* RadioButton class (container) */
  1801. /* */
  1802. /************************************************************/
  1803.  
  1804. class GLUIAPI GLUI_RadioButton : public GLUI_Control
  1805. {
  1806. public:
  1807. int orig_value;
  1808. bool currently_inside;
  1809. int text_x_offset;
  1810.  
  1811. int mouse_down_handler( int local_x, int local_y );
  1812. int mouse_up_handler( int local_x, int local_y, bool inside );
  1813. int mouse_held_down_handler( int local_x, int local_y, bool inside );
  1814.  
  1815. void draw( int x, int y );
  1816. void update_size( void );
  1817.  
  1818. void draw_active_area( void );
  1819. void draw_checked( void );
  1820. void draw_unchecked( void );
  1821. void draw_O( void );
  1822.  
  1823. GLUI_RadioButton( GLUI_RadioGroup *group, const char *name );
  1824. GLUI_RadioGroup *group;
  1825.  
  1826. protected:
  1827. void common_init()
  1828. {
  1829. glui_format_str( name, "RadioButton: %p", (void *) this );
  1830. h = GLUI_RADIOBUTTON_SIZE;
  1831. group = NULL;
  1832. orig_value = -1;
  1833. text_x_offset = 18;
  1834. can_activate = true;
  1835. }
  1836. };
  1837.  
  1838.  
  1839. /************************************************************/
  1840. /* */
  1841. /* Separator class (container) */
  1842. /* */
  1843. /************************************************************/
  1844.  
  1845. class GLUIAPI GLUI_Separator : public GLUI_Control
  1846. {
  1847. public:
  1848. void draw( int x, int y );
  1849.  
  1850. GLUI_Separator( GLUI_Node *parent );
  1851. GLUI_Separator( void ) { common_init(); }
  1852.  
  1853. protected:
  1854. void common_init() {
  1855. w = 100;
  1856. h = GLUI_SEPARATOR_HEIGHT;
  1857. can_activate = false;
  1858. }
  1859. };
  1860.  
  1861. #define GLUI_SPINNER_ARROW_WIDTH 12
  1862. #define GLUI_SPINNER_ARROW_HEIGHT 8
  1863. #define GLUI_SPINNER_ARROW_Y 2
  1864.  
  1865. #define GLUI_SPINNER_STATE_NONE 0
  1866. #define GLUI_SPINNER_STATE_UP 1
  1867. #define GLUI_SPINNER_STATE_DOWN 2
  1868. #define GLUI_SPINNER_STATE_BOTH 3
  1869.  
  1870. #define GLUI_SPINNER_DEFAULT_GROWTH_EXP 1.05f
  1871.  
  1872. /************************************************************/
  1873. /* */
  1874. /* Spinner class (container) */
  1875. /* */
  1876. /************************************************************/
  1877.  
  1878. class GLUIAPI GLUI_Spinner : public GLUI_Control
  1879. {
  1880. public:
  1881. // Constructor, no live var
  1882. GLUI_Spinner( GLUI_Node* parent, const char *name,
  1883. int data_type=GLUI_SPINNER_INT, int id=-1, GLUI_CB callback=GLUI_CB() );
  1884. // Constructor, int live var
  1885. GLUI_Spinner( GLUI_Node* parent, const char *name,
  1886. int *live_var, int id=-1, GLUI_CB callback=GLUI_CB() );
  1887. // Constructor, float live var
  1888. GLUI_Spinner( GLUI_Node* parent, const char *name,
  1889. float *live_var, int id=-1, GLUI_CB callback=GLUI_CB() );
  1890. // Deprecated constructor
  1891. GLUI_Spinner( GLUI_Node* parent, const char *name,
  1892. int data_type,
  1893. void *live_var,
  1894. int id=-1, GLUI_CB callback=GLUI_CB() );
  1895. // Deprecated constructor
  1896. GLUI_Spinner( void ) { common_init(); }
  1897.  
  1898. bool currently_inside;
  1899. int state;
  1900. float growth, growth_exp;
  1901. int last_x, last_y;
  1902. int data_type;
  1903. int callback_count;
  1904. int last_int_val;
  1905. float last_float_val;
  1906. int first_callback;
  1907. float user_speed;
  1908.  
  1909. GLUI_EditText *edittext;
  1910.  
  1911. int mouse_down_handler( int local_x, int local_y );
  1912. int mouse_up_handler( int local_x, int local_y, bool inside );
  1913. int mouse_held_down_handler( int local_x, int local_y, bool inside );
  1914. int key_handler( unsigned char key,int modifiers );
  1915. int special_handler( int key,int modifiers );
  1916.  
  1917. void draw( int x, int y );
  1918. void draw_pressed( void );
  1919. void draw_unpressed( void );
  1920. void draw_text( int sunken );
  1921.  
  1922. void update_size( void );
  1923.  
  1924. void set_float_limits( float low,float high,int limit_type=GLUI_LIMIT_CLAMP);
  1925. void set_int_limits( int low, int high,int limit_type=GLUI_LIMIT_CLAMP);
  1926. int find_arrow( int local_x, int local_y );
  1927. void do_drag( int x, int y );
  1928. void do_callbacks( void );
  1929. void do_click( void );
  1930. void idle( void );
  1931. bool needs_idle( void ) const;
  1932.  
  1933. const char *get_text( void );
  1934.  
  1935. void set_float_val( float new_val );
  1936. void set_int_val( int new_val );
  1937. float get_float_val( void );
  1938. int get_int_val( void );
  1939. void increase_growth( void );
  1940. void reset_growth( void );
  1941.  
  1942. void set_speed( float speed ) { user_speed = speed; }
  1943.  
  1944. protected:
  1945. void common_init() {
  1946. glui_format_str( name, "Spinner: %p", this );
  1947. h = GLUI_EDITTEXT_HEIGHT;
  1948. w = GLUI_EDITTEXT_WIDTH;
  1949. x_off = 0;
  1950. y_off_top = 0;
  1951. y_off_bot = 0;
  1952. can_activate = true;
  1953. state = GLUI_SPINNER_STATE_NONE;
  1954. edittext = NULL;
  1955. growth_exp = GLUI_SPINNER_DEFAULT_GROWTH_EXP;
  1956. callback_count = 0;
  1957. first_callback = true;
  1958. user_speed = 1.0;
  1959. }
  1960. void common_construct( GLUI_Node* parent, const char *name,
  1961. int data_type, void *live_var,
  1962. int id, GLUI_CB callback );
  1963. };
  1964.  
  1965. /************************************************************/
  1966. /* */
  1967. /* StaticText class */
  1968. /* */
  1969. /************************************************************/
  1970.  
  1971. class GLUIAPI GLUI_StaticText : public GLUI_Control
  1972. {
  1973. public:
  1974. void set_text( const char *text );
  1975. void draw( int x, int y );
  1976. void draw_text( void );
  1977. void update_size( void );
  1978. void erase_text( void );
  1979.  
  1980. GLUI_StaticText(GLUI_Node *parent, const char *name);
  1981. GLUI_StaticText( void ) { common_init(); }
  1982.  
  1983. protected:
  1984. void common_init() {
  1985. h = GLUI_STATICTEXT_SIZE;
  1986. name = "";
  1987. can_activate = false;
  1988. }
  1989. };
  1990.  
  1991. /************************************************************/
  1992. /* */
  1993. /* TextBox class - JVK */
  1994. /* */
  1995. /************************************************************/
  1996.  
  1997. class GLUIAPI GLUI_TextBox : public GLUI_Control
  1998. {
  1999. public:
  2000. /* GLUI Textbox - JVK */
  2001. GLUI_TextBox(GLUI_Node *parent, GLUI_String &live_var,
  2002. bool scroll = false, int id=-1, GLUI_CB callback=GLUI_CB() );
  2003. GLUI_TextBox( GLUI_Node *parent,
  2004. bool scroll = false, int id=-1,
  2005. GLUI_CB callback=GLUI_CB() );
  2006.  
  2007. GLUI_String orig_text;
  2008. int insertion_pt;
  2009. int substring_start; /*substring that gets displayed in box*/
  2010. int substring_end;
  2011. int sel_start, sel_end; /* current selection */
  2012. int last_insertion_pt;
  2013. int debug;
  2014. int draw_text_only;
  2015. int tab_width;
  2016. int start_line;
  2017. int num_lines;
  2018. int curr_line;
  2019. int visible_lines;
  2020. int insert_x; /* Similar to "insertion_pt", these variables keep */
  2021. int insert_y; /* track of where the ptr is, but in pixels */
  2022. int keygoal_x; /* where up down keys would like to put insertion pt*/
  2023. GLUI_Scrollbar *scrollbar;
  2024.  
  2025. int mouse_down_handler( int local_x, int local_y );
  2026. int mouse_up_handler( int local_x, int local_y, bool inside );
  2027. int mouse_held_down_handler( int local_x, int local_y, bool inside );
  2028. int key_handler( unsigned char key,int modifiers );
  2029. int special_handler( int key,int modifiers );
  2030.  
  2031. void activate( int how );
  2032. void deactivate( void );
  2033.  
  2034. void enable( void );
  2035. void disable( void );
  2036.  
  2037. void draw( int x, int y );
  2038.  
  2039. int mouse_over( int state, int x, int y );
  2040.  
  2041. int get_box_width();
  2042. int find_word_break( int start, int direction );
  2043. int substring_width( int start, int end, int initial_width=0 );
  2044. void clear_substring( int start, int end );
  2045. int find_insertion_pt( int x, int y );
  2046. int update_substring_bounds( void );
  2047. void update_and_draw_text( void );
  2048. void draw_text( int x, int y );
  2049. void draw_insertion_pt( void );
  2050. void update_x_offsets( void );
  2051. void update_size( void );
  2052.  
  2053. void set_text( const char *text );
  2054. const char *get_text( void ) { return text.c_str(); }
  2055.  
  2056. void dump( FILE *out, char *text );
  2057. void set_tab_w(int w) { tab_width = w; }
  2058. void set_start_line(int l) { start_line = l; }
  2059. static void scrollbar_callback(GLUI_Control*);
  2060.  
  2061. bool wants_tabs( void ) const { return true; }
  2062.  
  2063. protected:
  2064. void common_init()
  2065. {
  2066. h = GLUI_TEXTBOX_HEIGHT;
  2067. w = GLUI_TEXTBOX_WIDTH;
  2068. tab_width = GLUI_TAB_WIDTH;
  2069. num_lines = 0;
  2070. visible_lines = 0;
  2071. start_line = 0;
  2072. curr_line = 0;
  2073. insert_y = -1;
  2074. insert_x = -1;
  2075. insertion_pt = -1;
  2076. last_insertion_pt = -1;
  2077. name[0] = '\0';
  2078. substring_start = 0;
  2079. substring_end = 2;
  2080. sel_start = 0;
  2081. sel_end = 0;
  2082. active_type = GLUI_CONTROL_ACTIVE_PERMANENT;
  2083. can_activate = true;
  2084. spacebar_mouse_click = false;
  2085. scrollbar = NULL;
  2086. debug = false;
  2087. draw_text_only = false;
  2088. }
  2089. void common_construct(
  2090. GLUI_Node *parent, GLUI_String *live_var,
  2091. bool scroll, int id, GLUI_CB callback);
  2092. };
  2093.  
  2094. /************************************************************/
  2095. /* */
  2096. /* List class - JVK */
  2097. /* */
  2098. /************************************************************/
  2099.  
  2100. class GLUIAPI GLUI_List_Item : public GLUI_Node
  2101. {
  2102. public:
  2103. GLUI_String text;
  2104. int id;
  2105. };
  2106.  
  2107. /************************************************************/
  2108. /* */
  2109. /* List class - JVK */
  2110. /* */
  2111. /************************************************************/
  2112.  
  2113. class GLUIAPI GLUI_List : public GLUI_Control
  2114. {
  2115. public:
  2116. /* GLUI List - JVK */
  2117. GLUI_List( GLUI_Node *parent, bool scroll = false,
  2118. int id=-1, GLUI_CB callback=GLUI_CB() );
  2119. /*, GLUI_Control *object = NULL
  2120. ,GLUI_InterObject_CB obj_cb = NULL);*/
  2121.  
  2122. GLUI_List( GLUI_Node *parent,
  2123. GLUI_String& live_var, bool scroll = false,
  2124. int id=-1,
  2125. GLUI_CB callback=GLUI_CB()
  2126. /*,GLUI_Control *object = NULL */
  2127. /*,GLUI_InterObject_CB obj_cb = NULL*/);
  2128.  
  2129.  
  2130. GLUI_String orig_text;
  2131. int debug;
  2132. int draw_text_only;
  2133. int start_line;
  2134. int num_lines;
  2135. int curr_line;
  2136. int visible_lines;
  2137. GLUI_Scrollbar *scrollbar;
  2138. GLUI_List_Item items_list;
  2139. GLUI_Control *associated_object;
  2140. GLUI_CB obj_cb;
  2141. int cb_click_type;
  2142. int last_line;
  2143. int last_click_time;
  2144.  
  2145. int mouse_down_handler( int local_x, int local_y );
  2146. int mouse_up_handler( int local_x, int local_y, bool inside );
  2147. int mouse_held_down_handler( int local_x, int local_y, bool inside );
  2148. int key_handler( unsigned char key,int modifiers );
  2149. int special_handler( int key,int modifiers );
  2150.  
  2151. void activate( int how );
  2152. void deactivate( void );
  2153.  
  2154. void draw( int x, int y );
  2155.  
  2156. int mouse_over( int state, int x, int y );
  2157.  
  2158. int get_box_width();
  2159. int find_word_break( int start, int direction );
  2160. int substring_width( const char *t, int start, int end );
  2161. int find_line( int x, int y );
  2162. void update_and_draw_text( void );
  2163. void draw_text( const char *t, int selected, int x, int y );
  2164. void update_size( void );
  2165.  
  2166.  
  2167. int add_item( int id, const char *text );
  2168. int delete_item( const char *text );
  2169. int delete_item( int id );
  2170. int delete_all();
  2171.  
  2172. GLUI_List_Item *get_item_ptr( const char *text );
  2173. GLUI_List_Item *get_item_ptr( int id );
  2174.  
  2175. void dump( FILE *out, const char *text );
  2176. void set_start_line(int l) { start_line = l; }
  2177. static void scrollbar_callback(GLUI_Control*);
  2178. int get_current_item() { return curr_line; }
  2179. void set_click_type(int d) {
  2180. cb_click_type = d; }
  2181. void set_object_callback(GLUI_CB cb=GLUI_CB(), GLUI_Control*obj=NULL)
  2182. { obj_cb=cb; associated_object=obj; }
  2183.  
  2184. protected:
  2185. void common_init()
  2186. {
  2187. h = GLUI_LIST_HEIGHT;
  2188. w = GLUI_LIST_WIDTH;
  2189. num_lines = 0;
  2190. visible_lines = 0;
  2191. start_line = 0;
  2192. curr_line = 0;
  2193. name[0] = '\0';
  2194. active_type = GLUI_CONTROL_ACTIVE_PERMANENT;
  2195. can_activate = true;
  2196. spacebar_mouse_click = false;
  2197. scrollbar = NULL;
  2198. debug = false;
  2199. draw_text_only = false;
  2200. cb_click_type = GLUI_SINGLE_CLICK;
  2201. last_line = -1;
  2202. last_click_time = 0;
  2203. associated_object = NULL;
  2204. };
  2205. void common_construct(
  2206. GLUI_Node *parent,
  2207. GLUI_String* live_var, bool scroll,
  2208. int id,
  2209. GLUI_CB callback
  2210. /*,GLUI_Control *object*/
  2211. /*,GLUI_InterObject_CB obj_cb*/);
  2212. };
  2213.  
  2214. /************************************************************/
  2215. /* */
  2216. /* Scrollbar class - JVK */
  2217. /* */
  2218. /************************************************************/
  2219.  
  2220. class GLUIAPI GLUI_Scrollbar : public GLUI_Control
  2221. {
  2222. public:
  2223. // Constructor, no live var
  2224. GLUI_Scrollbar( GLUI_Node *parent,
  2225. const char *name,
  2226. int horz_vert=GLUI_SCROLL_HORIZONTAL,
  2227. int data_type=GLUI_SCROLL_INT,
  2228. int id=-1, GLUI_CB callback=GLUI_CB()
  2229. /*,GLUI_Control *object = NULL*/
  2230. /*,GLUI_InterObject_CB obj_cb = NULL*/
  2231. );
  2232.  
  2233. // Constructor, int live var
  2234. GLUI_Scrollbar( GLUI_Node *parent, const char *name, int horz_vert,
  2235. int *live_var,
  2236. int id=-1, GLUI_CB callback=GLUI_CB()
  2237. /*,GLUI_Control *object = NULL*/
  2238. /*,GLUI_InterObject_CB obj_cb = NULL*/
  2239. );
  2240.  
  2241. // Constructor, float live var
  2242. GLUI_Scrollbar( GLUI_Node *parent, const char *name, int horz_vert,
  2243. float *live_var,
  2244. int id=-1, GLUI_CB callback=GLUI_CB()
  2245. /*,GLUI_Control *object = NULL*/
  2246. /*,GLUI_InterObject_CB obj_cb = NULL*/
  2247. );
  2248.  
  2249. bool currently_inside;
  2250. int state;
  2251. float growth, growth_exp;
  2252. int last_x, last_y;
  2253. int data_type;
  2254. int callback_count;
  2255. int last_int_val; ///< Used to prevent repeated callbacks.
  2256. float last_float_val;
  2257. int first_callback;
  2258. float user_speed;
  2259. float float_min, float_max;
  2260. int int_min, int_max;
  2261. int horizontal;
  2262. double last_update_time; ///< GLUI_Time() we last advanced scrollbar.
  2263. double velocity_limit; ///< Maximum distance to advance per second.
  2264. int box_length;
  2265. int box_start_position;
  2266. int box_end_position;
  2267. int track_length;
  2268.  
  2269.  
  2270. /* Rather than directly access an Editbox or Textbox for
  2271. changing variables, a pointer to some object is defined
  2272. along with a static callback in the form func(void *, int) -
  2273. the int is the new value, the void * must be cast to that
  2274. particular object type before use.
  2275. */
  2276. void * associated_object; /* Lets the Spinner manage it's own callbacks */
  2277. GLUI_CB object_cb; /* function pointer to object call_back */
  2278.  
  2279. int mouse_down_handler( int local_x, int local_y );
  2280. int mouse_up_handler( int local_x, int local_y, bool inside );
  2281. int mouse_held_down_handler( int local_x, int local_y, bool inside );
  2282. int key_handler( unsigned char key,int modifiers );
  2283. int special_handler( int key,int modifiers );
  2284.  
  2285. void draw( int x, int y );
  2286. void draw_pressed( void );
  2287. void draw_unpressed( void );
  2288. void draw_text( int sunken );
  2289.  
  2290. void update_size( void );
  2291.  
  2292. void set_int_limits( int low, int high,int limit_type=GLUI_LIMIT_CLAMP);
  2293. void set_float_limits( float low,float high,int limit_type=GLUI_LIMIT_CLAMP);
  2294. int find_arrow( int local_x, int local_y );
  2295. void do_drag( int x, int y );
  2296. void do_callbacks( void );
  2297. void draw_scroll( void );
  2298. void do_click( void );
  2299. void idle( void );
  2300. bool needs_idle( void ) const;
  2301. void set_int_val( int new_val );
  2302. void set_float_val( float new_val );
  2303. void increase_growth( void );
  2304. void reset_growth( void );
  2305.  
  2306. void set_speed( float speed ) { user_speed = speed; };
  2307. void update_scroll_parameters();
  2308. void set_object_callback(GLUI_CB cb=GLUI_CB(), GLUI_Control*obj=NULL)
  2309. { object_cb=cb; associated_object=obj; }
  2310.  
  2311. protected:
  2312. void common_init ( void );
  2313. void common_construct(
  2314. GLUI_Node *parent,
  2315. const char *name,
  2316. int horz_vert,
  2317. int data_type, void* live_var,
  2318. int id, GLUI_CB callback
  2319. /*,GLUI_Control *object
  2320. ,GLUI_InterObject_CB obj_cb*/
  2321. );
  2322.  
  2323. virtual void draw_scroll_arrow(int arrowtype, int x, int y);
  2324. virtual void draw_scroll_box(int x, int y, int w, int h);
  2325. };
  2326.  
  2327. /************************************************************/
  2328. /* */
  2329. /* Listbox class */
  2330. /* */
  2331. /************************************************************/
  2332.  
  2333. class GLUIAPI GLUI_Listbox_Item : public GLUI_Node
  2334. {
  2335. public:
  2336. GLUI_String text;
  2337. int id;
  2338. };
  2339.  
  2340. class GLUIAPI GLUI_Listbox : public GLUI_Control
  2341. {
  2342. public:
  2343. GLUI_String curr_text;
  2344. GLUI_Listbox_Item items_list;
  2345. int depressed;
  2346.  
  2347. int orig_value;
  2348. bool currently_inside;
  2349. int text_x_offset, title_x_offset;
  2350. int glut_menu_id;
  2351.  
  2352. int mouse_down_handler( int local_x, int local_y );
  2353. int mouse_up_handler( int local_x, int local_y, bool inside );
  2354. int mouse_held_down_handler( int local_x, int local_y, bool inside );
  2355. int key_handler( unsigned char key,int modifiers );
  2356. int special_handler( int key,int modifiers );
  2357.  
  2358. void update_size( void );
  2359. void draw( int x, int y );
  2360. int mouse_over( int state, int x, int y );
  2361.  
  2362. void set_int_val( int new_val );
  2363. void dump( FILE *output );
  2364.  
  2365. int add_item( int id, const char *text );
  2366. int delete_item( const char *text );
  2367. int delete_item( int id );
  2368. int sort_items( void );
  2369.  
  2370. int do_selection( int item );
  2371.  
  2372. GLUI_Listbox_Item *get_item_ptr( const char *text );
  2373. GLUI_Listbox_Item *get_item_ptr( int id );
  2374.  
  2375.  
  2376. GLUI_Listbox( GLUI_Node *parent,
  2377. const char *name, int *live_var=NULL,
  2378. int id=-1, GLUI_CB callback=GLUI_CB() );
  2379. GLUI_Listbox( void ) { common_init(); }
  2380.  
  2381. protected:
  2382. /** Change w and return true if we need to be widened to fit the current item. */
  2383. bool recalculate_item_width( void );
  2384. void common_init() {
  2385. glui_format_str( name, "Listbox: %p", this );
  2386. w = GLUI_EDITTEXT_WIDTH;
  2387. h = GLUI_EDITTEXT_HEIGHT;
  2388. orig_value = -1;
  2389. title_x_offset = 0;
  2390. text_x_offset = 55;
  2391. can_activate = true;
  2392. curr_text = "";
  2393. live_type = GLUI_LIVE_INT; /* This has an integer live var */
  2394. depressed = false;
  2395. glut_menu_id = -1;
  2396. }
  2397.  
  2398. ~GLUI_Listbox();
  2399. };
  2400.  
  2401. /************************************************************/
  2402. /* */
  2403. /* Mouse_Interaction class */
  2404. /* */
  2405. /************************************************************/
  2406.  
  2407. /**
  2408. This is the superclass of translation and rotation widgets.
  2409. */
  2410. class GLUIAPI GLUI_Mouse_Interaction : public GLUI_Control
  2411. {
  2412. public:
  2413. /*int get_main_area_size( void ) { return MIN( h-18, */
  2414. int draw_active_area_only;
  2415.  
  2416. int mouse_down_handler( int local_x, int local_y );
  2417. int mouse_up_handler( int local_x, int local_y, bool inside );
  2418. int mouse_held_down_handler( int local_x, int local_y, bool inside );
  2419. int special_handler( int key, int modifiers );
  2420. void update_size( void );
  2421. void draw( int x, int y );
  2422. void draw_active_area( void );
  2423.  
  2424. /*** The following methods (starting with "iaction_") need to
  2425. be overloaded ***/
  2426. virtual int iaction_mouse_down_handler( int local_x, int local_y ) = 0;
  2427. virtual int iaction_mouse_up_handler( int local_x, int local_y, bool inside )=0;
  2428. virtual int iaction_mouse_held_down_handler( int local_x, int local_y, bool inside )=0;
  2429. virtual int iaction_special_handler( int key, int modifiers )=0;
  2430. virtual void iaction_draw_active_area_persp( void )=0;
  2431. virtual void iaction_draw_active_area_ortho( void )=0;
  2432. virtual void iaction_dump( FILE *output )=0;
  2433. virtual void iaction_init( void ) = 0;
  2434.  
  2435. GLUI_Mouse_Interaction( void ) {
  2436. glui_format_str( name, "Mouse_Interaction: %p", this );
  2437. w = GLUI_MOUSE_INTERACTION_WIDTH;
  2438. h = GLUI_MOUSE_INTERACTION_HEIGHT;
  2439. can_activate = true;
  2440. live_type = GLUI_LIVE_NONE;
  2441. alignment = GLUI_ALIGN_CENTER;
  2442. draw_active_area_only = false;
  2443. }
  2444. };
  2445.  
  2446. /************************************************************/
  2447. /* */
  2448. /* Rotation class */
  2449. /* */
  2450. /************************************************************/
  2451.  
  2452. /**
  2453. An onscreen rotation controller--allows the user to interact with
  2454. a 3D rotation via a spaceball-like interface.
  2455. */
  2456. class GLUIAPI GLUI_Rotation : public GLUI_Mouse_Interaction
  2457. {
  2458. public:
  2459. Arcball *ball;
  2460. GLUquadricObj *quadObj;
  2461. bool can_spin, spinning;
  2462. float damping;
  2463.  
  2464. int iaction_mouse_down_handler( int local_x, int local_y );
  2465. int iaction_mouse_up_handler( int local_x, int local_y, bool inside );
  2466. int iaction_mouse_held_down_handler( int local_x, int local_y, bool inside );
  2467. int iaction_special_handler( int key, int modifiers );
  2468. void iaction_init( void ) { init_ball(); }
  2469. void iaction_draw_active_area_persp( void );
  2470. void iaction_draw_active_area_ortho( void );
  2471. void iaction_dump( FILE *output );
  2472.  
  2473. /* void update_size( void ); */
  2474. /* void draw( int x, int y ); */
  2475. /* int mouse_over( int state, int x, int y ); */
  2476.  
  2477. void setup_texture( void );
  2478. void setup_lights( void );
  2479. void draw_ball( float radius );
  2480.  
  2481. void init_ball( void );
  2482.  
  2483. void reset( void );
  2484.  
  2485. bool needs_idle( void ) const;
  2486. void idle( void );
  2487.  
  2488. void copy_float_array_to_ball( void );
  2489. void copy_ball_to_float_array( void );
  2490.  
  2491. void set_spin( float damp_factor );
  2492.  
  2493. GLUI_Rotation( GLUI_Node *parent, const char *name, float *live_var=NULL,
  2494. int id=-1, GLUI_CB callback=GLUI_CB() );
  2495. GLUI_Rotation(void) { common_init(); }
  2496.  
  2497. protected:
  2498. void common_init();
  2499. };
  2500.  
  2501. /************************************************************/
  2502. /* */
  2503. /* Translation class */
  2504. /* */
  2505. /************************************************************/
  2506.  
  2507. /**
  2508. An onscreen translation controller--allows the user to interact with
  2509. a 3D translation.
  2510. */
  2511. class GLUIAPI GLUI_Translation : public GLUI_Mouse_Interaction
  2512. {
  2513. public:
  2514. int trans_type; /* Is this an XY or a Z controller? */
  2515. int down_x, down_y;
  2516. float scale_factor;
  2517. GLUquadricObj *quadObj;
  2518. int trans_mouse_code;
  2519. float orig_x, orig_y, orig_z;
  2520. int locked;
  2521.  
  2522. int iaction_mouse_down_handler( int local_x, int local_y );
  2523. int iaction_mouse_up_handler( int local_x, int local_y, bool inside );
  2524. int iaction_mouse_held_down_handler( int local_x, int local_y, bool inside );
  2525. int iaction_special_handler( int key, int modifiers );
  2526. void iaction_init( void ) { }
  2527. void iaction_draw_active_area_persp( void );
  2528. void iaction_draw_active_area_ortho( void );
  2529. void iaction_dump( FILE *output );
  2530.  
  2531. void set_speed( float s ) { scale_factor = s; }
  2532.  
  2533. void setup_texture( void );
  2534. void setup_lights( void );
  2535. void draw_2d_arrow( int radius, int filled, int orientation );
  2536. void draw_2d_x_arrows( int radius );
  2537. void draw_2d_y_arrows( int radius );
  2538. void draw_2d_z_arrows( int radius );
  2539. void draw_2d_xy_arrows( int radius );
  2540.  
  2541. int get_mouse_code( int x, int y );
  2542.  
  2543. /* Float array is either a single float (for single-axis controls),
  2544. or two floats for X and Y (if an XY controller) */
  2545.  
  2546. float get_z( void ) { return float_array_val[0]; }
  2547. float get_x( void ) { return float_array_val[0]; }
  2548. float get_y( void ) {
  2549. if ( trans_type == GLUI_TRANSLATION_XY ) return float_array_val[1];
  2550. else return float_array_val[0];
  2551. }
  2552.  
  2553. void set_z( float val );
  2554. void set_x( float val );
  2555. void set_y( float val );
  2556. void set_one_val( float val, int index );
  2557.  
  2558. GLUI_Translation( GLUI_Node *parent, const char *name,
  2559. int trans_type, float *live_var=NULL,
  2560. int id=-1, GLUI_CB callback=GLUI_CB() );
  2561. GLUI_Translation( void ) { common_init(); }
  2562.  
  2563. protected:
  2564. void common_init() {
  2565. locked = GLUI_TRANSLATION_LOCK_NONE;
  2566. glui_format_str( name, "Translation: %p", this );
  2567. w = GLUI_MOUSE_INTERACTION_WIDTH;
  2568. h = GLUI_MOUSE_INTERACTION_HEIGHT;
  2569. can_activate = true;
  2570. live_type = GLUI_LIVE_FLOAT_ARRAY;
  2571. float_array_size = 0;
  2572. alignment = GLUI_ALIGN_CENTER;
  2573. trans_type = GLUI_TRANSLATION_XY;
  2574. scale_factor = 1.0;
  2575. quadObj = NULL;
  2576. trans_mouse_code = GLUI_TRANSLATION_MOUSE_NONE;
  2577. }
  2578. };
  2579.  
  2580. /********** Misc functions *********************/
  2581. int _glutBitmapWidthString( void *font, const char *s );
  2582. void _glutBitmapString( void *font, const char *s );
  2583.  
  2584. /********** Our own callbacks for glut *********/
  2585. /* These are the callbacks that we pass to glut. They take
  2586. some action if necessary, then (possibly) call the user-level
  2587. glut callbacks.
  2588. */
  2589.  
  2590. void glui_display_func( void );
  2591. void glui_reshape_func( int w, int h );
  2592. void glui_keyboard_func(unsigned char key, int x, int y);
  2593. void glui_special_func(int key, int x, int y);
  2594. void glui_mouse_func(int button, int state, int x, int y);
  2595. void glui_motion_func(int x, int y);
  2596. void glui_passive_motion_func(int x, int y);
  2597. void glui_entry_func(int state);
  2598. void glui_visibility_func(int state);
  2599. void glui_idle_func(void);
  2600.  
  2601. void glui_parent_window_reshape_func( int w, int h );
  2602. void glui_parent_window_keyboard_func(unsigned char key, int x, int y);
  2603. void glui_parent_window_mouse_func(int, int, int, int );
  2604. void glui_parent_window_special_func(int key, int x, int y);
  2605.  
  2606. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement