Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

glui_dialogs.H

Go to the documentation of this file.
00001 #ifndef GLUI_DIALOGS_H_INCLUDED
00002 #define GLUI_DIALOGS_H_INCLUDED
00003 
00004 #include "widgets/file_select.H"
00005 #include "widgets/alert_box.H" 
00006 
00007 
00008 class GLUI;
00009 class GLUI_Panel;
00010 class GLUI_Slider;
00011 class GLUI_Button;
00012 class GLUI_Rollout;
00013 class GLUI_Listbox;
00014 class GLUI_EditText;
00015 class GLUI_Checkbox;
00016 class GLUI_BitmapBox;
00017 class GLUI_StaticText;
00018 class GLUI_ActiveText;
00019 class GLUI_RadioGroup;
00020 class GLUI_RadioButton;
00021 class GLUT_WINSYS;
00022 
00023 /*****************************************************************
00024  * GLUIPopUp
00025  *****************************************************************/
00026 
00027 #define ID_SHIFT                 10
00028 #define ID_MASK                  ((1<<ID_SHIFT)-1)
00029 
00030 class GLUIPopUp {
00031  protected:
00032    /******** MEMBER CLASSES ********/
00033    class IconBitmap {
00034       public:
00035          int      _width, _height;
00036          uchar*   _data;
00037 
00038          IconBitmap(int w, int h) : _width(0), _height(0), _data(NULL) { set_size(w,h); }
00039          IconBitmap() : _width(0), _height(0), _data(NULL) {}
00040          ~IconBitmap() { if (_data) delete[] _data; }
00041 
00042          void set(int *icon) 
00043          { 
00044             set_size(icon[0],icon[1]);
00045             // Input icon arrays have origin in upper left,
00046             // we prefer lower left...
00047             for (int y=0; y<_height; y++)
00048             {
00049                for (int x=0; x<_width*3; x++)
00050                {
00051                   _data[3*_width*(_height-1-y)+x] = icon[3*_width*y+x + 2];
00052                }
00053             }
00054          }
00055          void set_size(int w, int h)
00056          {
00057             if (_data) delete[] _data; _width = w; _height = h;
00058             _data = new uchar[_width * _height * 3]; assert(_data);  
00059          }
00060          void copy( int sx, int sy, IconBitmap *src, 
00061                     int dx, int dy, int w, int h)
00062          {
00063             IconBitmap *dst = this;
00064 
00065             assert(src); 
00066             //if ((w==-1) || (h==-1)) { w = src->_width; h = src->_height; }
00067             assert((sx >= 0) && ( sx    <  src->_width));
00068             assert((sy >= 0) && ( sy    <  src->_height));
00069             assert(( w >  0) && ((sx+w) <= src->_width));
00070             assert(( h >  0) && ((sy+h) <= src->_height));
00071             assert(dst);
00072             assert((dx >= 0) && ( dx    <  dst->_width));
00073             assert((dy >= 0) && ( dy    <  dst->_height));
00074             assert(             ((dx+w) <= dst->_width));
00075             assert(             ((dy+h) <= dst->_height));
00076 
00077             for (int x=0; x<w; x++)
00078             {
00079                for (int y=0; y<h; y++)
00080                {
00081                   dst->_data[3*((dy+y)*dst->_width + (dx+x)) + 0] = src->_data[3*((sy+y)*src->_width + (sx+x)) + 0];
00082                   dst->_data[3*((dy+y)*dst->_width + (dx+x)) + 1] = src->_data[3*((sy+y)*src->_width + (sx+x)) + 1];
00083                   dst->_data[3*((dy+y)*dst->_width + (dx+x)) + 2] = src->_data[3*((sy+y)*src->_width + (sx+x)) + 2];
00084                }
00085             }
00086          }
00087    };
00088 
00089  protected:
00090    /******** STATIC MEMBER VARIABLES ********/
00091    static ARRAY<GLUIPopUp*>      _ui;
00092 
00093  public :    
00094    /******** STATIC MEMBER METHODS ********/
00095    static void                   slider_cbs(int id);
00096    static void                   button_cbs(int id);
00097    static void                   listbox_cbs(int id);
00098    static void                   edittext_cbs(int id);
00099    static void                   checkbox_cbs(int id);
00100    static void                   bitmapbox_cbs(int id);
00101    static void                   activetext_cbs(int id);
00102    static void                   radiogroup_cbs(int id);
00103 
00104  protected:
00105    /******** MEMBER VARIABLES ********/
00106    
00107    GLUT_WINSYS*                  _glut_winsys;
00108    GLUI*                         _glui;
00109 
00110    bool                          _blocking;
00111 
00112    int                           _id;
00113 
00114    ARRAY<GLUI_Panel*>            _panel;
00115    ARRAY<GLUI_Button*>           _button;
00116    ARRAY<GLUI_Slider*>           _slider;
00117    ARRAY<GLUI_Rollout*>          _rollout;
00118    ARRAY<GLUI_Listbox*>          _listbox;
00119    ARRAY<GLUI_EditText*>         _edittext;
00120    ARRAY<GLUI_Checkbox*>         _checkbox;
00121    ARRAY<GLUI_BitmapBox*>        _bitmapbox;
00122    ARRAY<GLUI_StaticText*>       _statictext;
00123    ARRAY<GLUI_ActiveText*>       _activetext;
00124    ARRAY<GLUI_RadioGroup*>       _radiogroup;
00125    ARRAY<GLUI_RadioButton*>      _radiobutton;
00126 
00127    /******** CONSTRUCTOR/DECONSTRUCTOR *******/
00128  public  :
00129    GLUIPopUp(GLUT_WINSYS *w);
00130    virtual ~GLUIPopUp();
00131 
00132  protected:
00133    /******** MEMBER METHODS ********/
00134    virtual bool      is_showing() { return _glui != NULL; }
00135 
00136    virtual bool      show_glui(bool blocking);
00137    virtual bool      hide_glui();
00138    virtual void      build_glui();
00139    virtual void      unbuild_glui();
00140 
00141    virtual void      slider_cb(int id) {}
00142    virtual void      button_cb(int id) {}
00143    virtual void      listbox_cb(int id) {}
00144    virtual void      edittext_cb(int id) {}
00145    virtual void      checkbox_cb(int id) {}
00146    virtual void      bitmapbox_cb(int id) {}
00147    virtual void      activetext_cb(int id) {}
00148    virtual void      radiogroup_cb(int id) {}
00149 
00150 };
00151 
00152 
00153 /*****************************************************************
00154  * GLUIAlertBox
00155  *****************************************************************/
00156 
00157 class GLUIAlertBox : public AlertBox, public GLUIPopUp  {
00158  protected:
00159    /******** WIDGET IDs ********/
00160    enum bitmapbox_id_t {
00161       BITMAPBOX_ICON = 0,
00162       BITMAPBOX_NUM
00163    };
00164 
00165    enum panel_id_t {
00166       PANEL_TEXT=0,
00167       PANEL_BUTTONS,
00168       PANEL_NUM
00169    };
00170 
00171  protected:
00172    /******** STATIC MEMBER VARIABLES ********/
00173    static bool       _icon_init;
00174    static IconBitmap _icons[ICON_NUM];
00175 
00176  public :    
00177    /******** STATIC MEMBER METHODS ********/
00178 
00179  protected:
00180    /******** MEMBER VARIABLES ********/
00181    alert_cb_t        _cb;
00182    void*             _vp;
00183    void*             _vpd;
00184    int               _idx;
00185 
00186    /******** CONSTRUCTOR/DECONSTRUCTOR *******/
00187  public  :
00188    GLUIAlertBox(GLUT_WINSYS *w);
00189    virtual ~GLUIAlertBox();
00190 
00191    /******** AlertBox METHODS ********/
00192  protected:   
00193    virtual bool      undisplay(int button);
00194 
00195  public:
00196    virtual bool      display(bool blocking, alert_cb_t cb, void *vp, void *vpd, int idx);
00197 
00198    virtual bool      is_displaying();
00199 
00200    /******** PopUp METHODS ********/
00201  protected:      
00202    virtual void      build_glui();
00203    virtual void      unbuild_glui();
00204 
00205    virtual void      button_cb(int id);
00206    virtual void      bitmapbox_cb(int id) {}
00207 
00208 };
00209 
00210 /*****************************************************************
00211  * GLUIFileSelect
00212  *****************************************************************/
00213 
00214 MAKE_PTR_BASEC(DIR_ENTRY);
00215 
00216 #define CDIR_ENTRYlist const DIR_ENTRYlist
00217 
00218 class DIR_ENTRYlist : public LIST<DIR_ENTRYptr> 
00219 { 
00220  public :
00221    DIR_ENTRYlist(int num=8) : LIST<DIR_ENTRYptr>(num)  { }
00222 };
00223 
00224 #define CDIR_ENTRYptr const DIR_ENTRYptr
00225 
00226 class DIR_ENTRY : public REFcounter {
00227  public:
00228    enum dir_entry_t {
00229       DIR_ENTRY_ROOT,
00230       DIR_ENTRY_DRIVE,
00231       DIR_ENTRY_DIRECTORY,
00232       DIR_ENTRY_FILE,
00233       DIR_ENTRY_UNKNOWN
00234    };
00235 
00236  public:
00237 
00238    DIR_ENTRYptr      _parent;
00239    DIR_ENTRYlist     _contents;
00240 
00241    str_ptr           _name;
00242    str_ptr           _full_path;
00243 
00244    double            _size;  
00245    time_t            _date;
00246 
00247    dir_entry_t       _type;
00248    
00249  public:
00250 
00251    DIR_ENTRY()       { clear(); }
00252    ~DIR_ENTRY()      { clear(); }
00253 
00254    void              clear()
00255    {
00256       _parent = NULL;
00257       _contents.clear();
00258       _name = NULL_STR;
00259       _full_path = NULL_STR;
00260       _size = -1.0;
00261       _date = 0;
00262       _type = DIR_ENTRY_UNKNOWN;
00263 
00264    }
00265 
00266 };
00267 
00268 
00269 class GLUIFileSelect : public FileSelect, public GLUIPopUp {
00270  protected:
00271    /******** ENUMS ********/
00272    enum bitmapbox_id_t {
00273       BITMAPBOX_ICON = 0,
00274       BITMAPBOX_R,
00275       BITMAPBOX_UP,
00276       BITMAPBOX_DOT,
00277       BITMAPBOX_PLUS,
00278       BITMAPBOX_X,
00279       BITMAPBOX_UP_FILE,
00280       BITMAPBOX_SCROLL_FILE,
00281       BITMAPBOX_DOWN_FILE,
00282       BITMAPBOX_NUM
00283    };
00284 
00285    enum statictext_id_t {
00286       STATICTEXT_SPACER_PATH=0,
00287       STATICTEXT_SPACER_R,
00288       STATICTEXT_SPACER_UP,
00289       STATICTEXT_SPACER_DOT,
00290       STATICTEXT_SPACER_X,
00291       STATICTEXT_SPACER_PLUS,
00292       //STATICTEXT_SPACER_PATH_MARGIN1,
00293       STATICTEXT_SPACER_PATH_MARGIN2,
00294       STATICTEXT_SPACER_FILES_TYPE,
00295       STATICTEXT_SPACER_FILES_NAME,
00296       STATICTEXT_SPACER_FILES_SIZE,
00297       STATICTEXT_SPACER_FILES_DATE,
00298       STATICTEXT_SPACER_FILES_SCROLL,
00299       //STATICTEXT_SPACER_ACTION_MARGIN1,
00300       //STATICTEXT_SPACER_ACTION_MARGIN2,
00301       STATICTEXT_LABEL_DOT,
00302       STATICTEXT_NUM
00303    };
00304 
00305    enum activetext_id_t {
00306       ACTIVETEXT_NUM=0
00307    };
00308 
00309    enum edittext_id_t {
00310       EDITTEXT_FILE = 0,
00311       EDITTEXT_NUM
00312    };
00313 
00314    enum checkbox_id_t {
00315       CHECKBOX_DOT = 0,
00316       CHECKBOX_NUM
00317    };
00318 
00319    enum listbox_id_t {
00320       LIST_PATH=0,
00321       LIST_FILTER,
00322       LIST_NUM
00323    };
00324 
00325    enum panel_id_t {
00326       PANEL_PATH=0,
00327       PANEL_FILES,
00328       PANEL_ACTION,
00329       PANEL_NUM
00330    };
00331 
00332    enum button_id_t {
00333       BUT_ACTION=0,
00334       BUT_CANCEL,
00335       BUT_HEADING_TYPE, 
00336       BUT_HEADING_NAME,
00337       BUT_HEADING_SIZE,
00338       BUT_HEADING_DATE,
00339       BUT_HEADING_SCROLL,
00340       BUT_NUM
00341    };
00342 
00343    enum bitmap_t {
00344       BITMAP_R = 0,
00345       BITMAP_UP,
00346       BITMAP_DOT,
00347       BITMAP_X,
00348       BITMAP_PLUS,
00349       BITMAP_UPARROW,
00350       BITMAP_DOWNARROW,
00351       BITMAP_SCROLL,
00352       BITMAP_FOLDER,
00353       BITMAP_DOC,
00354       BITMAP_DRIVE,
00355       BITMAP_BLANK,
00356       BITMAP_NUM
00357    };
00358 
00359    enum sort_t {
00360       SORT_NAME_UP = 0,
00361       SORT_NAME_DOWN,
00362       SORT_DATE_UP,
00363       SORT_DATE_DOWN,
00364       SORT_SIZE_UP,
00365       SORT_SIZE_DOWN
00366    };
00367 
00368    enum scrollbar_state_t {
00369       BAR_STATE_NONE = 0,
00370       BAR_STATE_UPPER_DOWN,
00371       BAR_STATE_LOWER_DOWN,
00372       BAR_STATE_SCROLL_DOWN
00373    };
00374 
00375    enum mode_t {
00376       MODE_NORMAL = 0,
00377       MODE_ADD,
00378       MODE_RENAME,
00379       MODE_DELETE
00380    };
00381 
00382  protected:
00383    /******** STATIC MEMBER VARIABLES ********/
00384    static bool       _icon_init;
00385    static IconBitmap _icons[ICON_NUM];
00386    static bool       _bitmap_init;
00387    static IconBitmap _bitmaps[BITMAP_NUM];
00388 
00389  public :    
00390    /******** STATIC MEMBER METHODS ********/
00391 
00392  protected:
00393    /******** MEMBER VARIABLES ********/
00394    file_cb_t         _cb;
00395    void*             _vp;
00396    int               _idx;
00397 
00398    DIR_ENTRYptr      _current_path;
00399    mode_t            _current_mode;
00400    str_ptr           _current_mode_saved_file;
00401    str_list          _current_recent_paths;
00402    sort_t            _current_sort;
00403    int               _current_selection;
00404    double            _current_selection_time;
00405    int               _current_scroll;
00406    bool              _current_scrollbar_wheel;
00407    int               _current_scrollbar_wheel_position;
00408    int               _current_scrollbar_wheel_index;
00409    int               _current_scrollbar_state;
00410    bool              _current_scrollbar_state_inside;
00411    int               _current_scrollbar_state_pixel_position;
00412    int               _current_scrollbar_state_index_position;
00413    double            _current_scrollbar_state_above_ratio;
00414    double            _current_scrollbar_state_below_ratio;
00415 
00416 
00417    
00418    /******** CONSTRUCTOR/DECONSTRUCTOR *******/
00419  public:
00420    GLUIFileSelect(GLUT_WINSYS *w);
00421    virtual ~GLUIFileSelect();
00422 
00423    /******** MEMBER METHODS ********/
00424  protected:
00425    void              init();
00426 
00427    void              update();
00428 
00429    void              update_paths();
00430    void              update_files();
00431    void              update_actions();
00432 
00433    void              update_icons();
00434    void              update_pathlist();
00435 
00436    void              update_headings();
00437    void              update_listing();
00438    void              update_scroll();
00439 
00440    str_ptr           shorten_string(int, Cstr_ptr &);
00441 
00442    DIR_ENTRYptr      generate_dir_tree(Cstr_ptr &);
00443    DIR_ENTRYptr      generate_dir_entry(Cstr_ptr &full_path,Cstr_ptr &name);
00444    bool              generate_dir_contents(DIR_ENTRYptr &);
00445 
00446    void              sort_dir_contents(DIR_ENTRYptr &, sort_t);
00447 
00448    DIR_ENTRYptr      get_selected_entry();
00449    void              set_selected_entry(DIR_ENTRYptr);
00450 
00451    bool              do_directory_change(Cstr_ptr &);
00452    void              do_entry_select(int);
00453    void              do_sort_toggle(int);
00454    void              do_scrollbar(int,int,int,int,int,int);
00455    void              do_path_listbox();
00456    void              do_edittext_event();
00457    void              do_scroll_delta(int);
00458    void              do_scroll_set(int);
00459    void              do_up_directory();
00460    void              do_refresh();
00461    void              do_add_mode();
00462    void              do_rename_mode();
00463    void              do_delete_mode();
00464    void              do_add_action();
00465    void              do_rename_action();
00466    void              do_delete_action();
00467    void              do_cancel_action();
00468 
00469    void              compute_scroll_geometry(int, int &, int &, int &, int &, int &, int &);
00470 /*
00471    str_ptr           getcwd_();
00472    bool              chdir_(Cstr_ptr &);
00473    bool              mkdir_(Cstr_ptr &);
00474    bool              rmdir_(Cstr_ptr &);
00475    bool              remove_(Cstr_ptr &);
00476    bool              rename_(Cstr_ptr &, Cstr_ptr &);
00477 */
00478    str_list          readdir_(Cstr_ptr &, Cstr_ptr &);
00479    bool              stat_(Cstr_ptr &, DIR_ENTRYptr &);
00480 
00481 
00482    /******** FileSelect METHODS ********/
00483  public:
00484    virtual bool      is_displaying();
00485    virtual bool      display(bool blocking, file_cb_t cb, void *vp, int idx);
00486 
00487  protected:   
00488    virtual bool      undisplay(int button, str_ptr path, str_ptr file);
00489 
00490    /******** PopUp METHODS ********/
00491  protected:      
00492    virtual void      build_glui();
00493    virtual void      unbuild_glui();
00494 
00495    virtual void      button_cb(int id);
00496    virtual void      checkbox_cb(int id);
00497    virtual void      bitmapbox_cb(int id);
00498    virtual void      listbox_cb(int id);
00499    virtual void      edittext_cb(int id);
00500    virtual void      activetext_cb(int id);
00501 
00502 };
00503 
00504 
00505 #endif
00506 
00507 /* end of file glui_dialogs.H */

Generated on Mon Sep 18 11:39:31 2006 for jot by  doxygen 1.4.4