00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00043 #include "forward.h"
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 #define UIE_GETFOCUS 1001
00059
00060
00061 #define UIE_LOSTFOCUS 1002
00062
00063
00064 #define UIE_COMMAND 1003
00065
00066
00067
00068
00069 #define UIE_MOUSEMOVE 2001
00070
00071
00072 #define UIE_MOUSEDOWN 2002
00073
00074
00075 #define UIE_MOUSEUP 2003
00076
00077
00078 #define UIE_MOUSEOVER 2004
00079
00080
00081 #define UIE_MOUSEOUT 2005
00082
00083
00084 #define UIE_MOUSEWHEEL 2006
00085
00086
00087 #define UIE_MOUSECLICK 2007
00088
00089
00090
00091
00092 #define UIE_CHAR 3001
00093
00094
00095 #define UIE_KEYDOWN 3002
00096
00097
00098 #define UIE_KEYUP 3003
00099
00100
00101 #define UIE_PARENTSIZE 4001
00102
00103
00104
00105
00106 #define UI_KEYFLAG_CTRL (1<<0)
00107
00108
00109 #define UI_KEYFLAG_SHIFT (1<<1)
00110
00111
00112 #define UI_KEYFLAG_ALT (1<<2)
00113
00114
00115 #define UI_KEYFLAG_ALTGR (1<<3)
00116
00117
00118
00119
00120 #define UI_KEY_BACKSPACE 0x0008
00121
00122
00123 #define UI_KEY_TAB 0x0009
00124
00125
00126 #define UI_KEY_DELETE 0x007F
00127
00128
00129 #define UI_KEY_LEFT 0x0101
00130
00131
00132 #define UI_KEY_RIGHT 0x0102
00133
00134
00135 #define UI_KEY_UP 0x0103
00136
00137
00138 #define UI_KEY_DOWN 0x0104
00139
00140
00141 #define UI_KEY_HOME 0x0105
00142
00143
00144 #define UI_KEY_END 0x0106
00145
00146
00147
00148
00149 #define UIC_FACE 1
00150
00151
00152 #define UIC_LIGHT 2
00153
00154
00155 #define UIC_SHADOW 3
00156
00157
00158 #define UIC_HIGHLIGHT 4
00159
00160
00161 #define UIC_SELECTION 5
00162
00163
00164 #define UIC_FOCUS 6
00165
00166
00167 #define UIC_BORDER 7
00168
00169
00170 #define UIC_EDIT 8
00171
00172
00173 #define UIC_TEXT 9
00174
00175
00176 #define UIC_DISABLED 10
00177
00178
00179 #define UIC_WINDOW 11
00180
00181
00182 #define UIC_BLACK 12
00183
00184 #define UIC_COUNT 13
00185
00186
00187
00188
00189 #define UI_BORDER_OUTERRAISED (1<<0)
00190
00191
00192 #define UI_BORDER_OUTERSUNKEN (1<<1)
00193
00194
00195 #define UI_BORDER_INNERRAISED (1<<2)
00196
00197
00198 #define UI_BORDER_INNERSUNKEN (1<<3)
00199
00200
00201 #define UI_BORDER_RAISED 5
00202
00203
00204 #define UI_BORDER_SUNKEN 10
00205
00206
00207 #define UI_BORDER_FLAT (1<<4)
00208
00209
00210 #define UI_TRANSPARENT (1<<5)
00211
00212
00213 #define UI_CHECK_BUTTON (1<<6)
00214
00215
00216
00217
00218 #define UII_WINDOW 0
00219
00220
00221 #define UII_CHECKBOX 1
00222
00223
00224 #define UII_SLIDER 2
00225
00226
00227 #define UII_CURSOR 3
00228
00229
00230 #define UII_COUNT 4
00231
00232
00233
00234
00235 #define UIP_POINTER 0
00236
00237
00238 #define UIP_WAIT 1
00239
00240
00241 #define UIP_TEXT 2
00242
00243
00244 #define UIP_RESIZEH 3
00245
00246
00247 #define UIP_RESIZEV 4
00248
00249
00250 #define UIP_RESIZEDIAG1 5
00251
00252
00253 #define UIP_RESIZEDIAG2 6
00254
00255
00256 #define UIP_POINTER2 7
00257
00258
00259 #define UIP_COUNT 8
00260
00261
00262
00263
00264 #define UIF_FONT8 0
00265
00266
00267 #define UIF_FONT16 1
00268
00269
00270 #define UIF_FONT8_FIXED 2
00271
00272
00273 #define UIF_FONT16_FIXED 3
00274
00275
00276 #define UIF_COUNT 4
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00291 struct uievent_s
00292 {
00293 ulong event;
00294 slong x,y;
00295 ushort key;
00296 ushort mod;
00297 class uiobject_c * obj;
00298 };
00299
00300
00301
00302
00303
00304
00305
00306
00307
00312 class uiobject_c
00313 {
00314 protected:
00315
00316 friend class gui_c;
00317
00318 struct font_s *fnt;
00319
00320 char *classname;
00321 ulong id;
00322
00323 sshort posx, posy;
00324 ushort width, height;
00325
00326 image_c *img;
00327
00328 list_c<uiobject_c> *children;
00329 uiobject_c *parent;
00330
00331 bool needsrefresh;
00332 bool visible;
00333 bool disabled;
00334
00335 ulong styleflags;
00336
00337 char *text;
00338
00339 sshort growth[4];
00340
00341 color_t bgcolor;
00342
00343 bool movable;
00344 bool mousedrag;
00345 slong dragdownx,
00346 dragdowny;
00347
00348 ushort cursor;
00349
00350 public:
00351
00353
00354 uiobject_c();
00355 virtual ~uiobject_c();
00356
00358
00359
00360 virtual void
00361 add_child(uiobject_c *obj);
00362
00363 virtual void
00364 remove_child(uiobject_c *obj);
00365
00366 virtual void
00367 bring_child_to_front(uiobject_c *obj);
00368
00369 virtual inline list_c<uiobject_c> *
00370 get_children();
00371
00372 uiobject_c
00373 *get_object(ulong id);
00374
00375 uiobject_c
00376 *find_mouse_object(ushort mx, ushort my);
00377
00379
00380 void
00381 draw(image_c *dst);
00382
00383 void
00384 refresh();
00385
00386 virtual void
00387 paint();
00388
00390
00391 virtual void
00392 move(sshort x, sshort y);
00393
00394 virtual void
00395 resize(ushort w, ushort h);
00396
00398
00399 inline sshort
00400 get_posx();
00401
00402 inline sshort
00403 get_posy();
00404
00405 inline ushort
00406 get_width();
00407
00408 inline ushort
00409 get_height();
00410
00411 inline void
00412 set_id(ulong i);
00413
00414 inline ulong
00415 get_id();
00416
00417 inline void
00418 set_visible(bool v);
00419
00420 inline bool
00421 is_visible();
00422
00423 inline void
00424 set_enabled(bool e);
00425
00426 inline bool
00427 is_enabled();
00428
00429 void
00430 set_growth(sshort x, sshort y, sshort w, sshort h);
00431
00432 inline void
00433 set_bgcolor(color_t color);
00434
00435 inline color_t
00436 get_bgcolor();
00437
00438 inline void
00439 set_style(ulong style);
00440
00441 inline ulong
00442 get_style();
00443
00444 virtual inline ushort
00445 get_cursor();
00446
00447 virtual void
00448 set_text(const char *txt);
00449
00450 inline void
00451 set_font(struct font_s *f);
00452
00453 sshort
00454 get_screenposx();
00455
00456 sshort
00457 get_screenposy();
00458
00460
00461 virtual void
00462 event(uievent_s *eve);
00463
00464 virtual inline const char *
00465 get_classname();
00466
00467 inline void
00468 set_needs_refresh();
00469 };
00470
00472
00473
00474 inline const char *uiobject_c::get_classname()
00475 {
00476 AssertThisValue("generic");
00477 return classname;
00478 }
00479
00480 inline list_c<uiobject_c> *uiobject_c::get_children()
00481 {
00482 AssertThisV; return children;
00483 }
00484
00485 inline void uiobject_c::set_needs_refresh()
00486 {
00487 AssertThis;
00488
00489 needsrefresh = true;
00490 if (parent && parent!=this)
00491 parent->set_needs_refresh();
00492 }
00493
00494 inline sshort uiobject_c::get_posx()
00495 {
00496 AssertThisV; return posx;
00497 }
00498
00499 inline sshort uiobject_c::get_posy()
00500 {
00501 AssertThisV; return posy;
00502 }
00503
00504 inline ushort uiobject_c::get_width()
00505 {
00506 AssertThisV; return width;
00507 }
00508
00509 inline ushort uiobject_c::get_height()
00510 {
00511 AssertThisV; return height;
00512 }
00513
00514 inline void uiobject_c::set_id(ulong i)
00515 {
00516 AssertThis; id = i;
00517 }
00518
00519 inline ulong uiobject_c::get_id()
00520 {
00521 AssertThisV; return id;
00522 }
00523
00524 inline void uiobject_c::set_visible(bool v)
00525 {
00526 AssertThis; visible = v;
00527 }
00528
00529 inline bool uiobject_c::is_visible()
00530 {
00531 AssertThisV; return visible;
00532 }
00533
00534 inline void uiobject_c::set_enabled(bool e)
00535 {
00536 AssertThis; disabled = !e;
00537 }
00538
00539 inline bool uiobject_c::is_enabled()
00540 {
00541 AssertThisV; return !disabled;
00542 }
00543
00544 inline void uiobject_c::set_bgcolor(color_t color)
00545 {
00546 AssertThis; bgcolor = color;
00547 }
00548
00549 inline color_t uiobject_c::get_bgcolor()
00550 {
00551 AssertThisV; return bgcolor;
00552 }
00553
00554 inline void uiobject_c::set_style(ulong style)
00555 {
00556 AssertThis; styleflags = style;
00557 }
00558
00559 inline ulong uiobject_c::get_style()
00560 {
00561 AssertThisV; return styleflags;
00562 }
00563
00564 inline ushort uiobject_c::get_cursor()
00565 {
00566 AssertThisV; return cursor;
00567 }
00568
00569 inline void uiobject_c::set_font(struct font_s *f)
00570 {
00571 AssertThis; fnt = f; set_needs_refresh();
00572 }
00573
00575
00576
00577
00578
00579
00580
00581
00586 class uibutton_c:public uiobject_c
00587 {
00588 protected:
00589
00590 bool hilite;
00591 bool pressed;
00592
00593 public:
00594
00596
00597 uibutton_c();
00598 virtual ~uibutton_c();
00599
00601
00602 virtual void event(uievent_s *eve);
00603 virtual void paint();
00604 };
00605
00606
00607
00612 class uilabel_c:public uiobject_c
00613 {
00614 protected:
00615
00616 bool wordwrap;
00617
00618
00619 public:
00620
00622
00623 uilabel_c();
00624 virtual ~uilabel_c();
00625
00627
00628 virtual void paint();
00629 inline void set_wordwrap(bool ww);
00630 };
00631
00633
00634
00635 inline void uilabel_c::set_wordwrap(bool ww)
00636 {
00637 AssertThis; wordwrap = ww;
00638 }
00639
00641
00642
00643
00644
00645
00646
00647
00648
00653 class uiedit_c:public uiobject_c
00654 {
00655 protected:
00656
00657 sshort selstart;
00658 sshort selend;
00659 sshort cursorpos;
00660
00661 bool hilite;
00662 bool mousedown;
00663
00664 sshort left;
00665
00666 ushort
00667 find_pos_for_point(ushort x);
00668
00669 public:
00670
00672
00673 uiedit_c();
00674 virtual ~uiedit_c();
00675
00677
00678 virtual void
00679 paint();
00680
00681 virtual void
00682 event(uievent_s *eve);
00683
00684 void
00685 replace_selection(char *txt);
00686
00687 inline ushort
00688 get_cursor();
00689 };
00690
00691 inline ushort uiedit_c::get_cursor()
00692 {
00693 AssertThisV; return UIP_TEXT;
00694 }
00695
00696
00697
00698
00699
00700
00701
00702
00707 class uiwindow_c:public uiobject_c
00708 {
00709 protected:
00710
00711 uiobject_c *clientarea;
00712 uilabel_c *statuswindow;
00713 bool showstatus;
00714
00715 public:
00716
00718
00719 uiwindow_c();
00720 virtual ~uiwindow_c();
00721
00723
00724 inline void
00725 add_child(uiobject_c *obj);
00726
00727 inline void
00728 remove_child(uiobject_c *obj);
00729
00730 inline void
00731 bring_child_to_front(uiobject_c *obj);
00732
00733 inline list_c<uiobject_c> *
00734 get_children();
00735
00736 virtual void
00737 event(uievent_s *eve);
00738
00739 virtual void
00740 paint();
00741
00742 virtual void
00743 resize(ushort w, ushort h);
00744
00745 inline uiobject_c *
00746 get_client_area();
00747
00748 inline uilabel_c *
00749 get_status_window();
00750
00751 inline void
00752 show_status(bool s);
00753 };
00754
00755
00756 inline void uiwindow_c::add_child(uiobject_c *obj)
00757 {
00758 AssertThis; if (clientarea) clientarea->add_child(obj);
00759 }
00760
00761 inline void uiwindow_c::remove_child(uiobject_c *obj)
00762 {
00763 AssertThis; if (clientarea) clientarea->remove_child(obj);
00764 }
00765
00766 inline void uiwindow_c::bring_child_to_front(uiobject_c *obj)
00767 {
00768 AssertThis; if (clientarea) clientarea->bring_child_to_front(obj);
00769 }
00770
00771 inline list_c<uiobject_c> *uiwindow_c::get_children()
00772 {
00773 AssertThisV; if (clientarea) return clientarea->get_children();
00774 return NULL;
00775 }
00776
00777 inline uiobject_c *uiwindow_c::get_client_area()
00778 {
00779 AssertThisV; return clientarea;
00780 }
00781
00782 inline uilabel_c *uiwindow_c::get_status_window()
00783 {
00784 AssertThisV; return statuswindow;
00785 }
00786
00787 inline void uiwindow_c::show_status(bool s)
00788 {
00789 AssertThis;
00790
00791 showstatus = s;
00792 set_needs_refresh();
00793 statuswindow->set_visible(s);
00794 };
00795
00796
00797
00798
00799
00800
00801
00806 class uicheckbutton_c:public uibutton_c
00807 {
00808 protected:
00809
00810 bool radio;
00811 bool checked;
00812
00813 public:
00814
00816
00817 uicheckbutton_c();
00818 ~uicheckbutton_c();
00819
00821
00822 virtual void
00823 event(uievent_s *eve);
00824
00825 virtual void
00826 paint();
00827
00828 inline void
00829 set_checked(bool c);
00830
00831 inline bool
00832 is_checked();
00833
00834 inline void
00835 set_radio(bool r);
00836 };
00837
00838 inline void uicheckbutton_c::set_checked(bool c)
00839 {
00840 AssertThis;
00841 checked = c;
00842 set_needs_refresh();
00843 }
00844
00845 inline bool uicheckbutton_c::is_checked()
00846 {
00847 AssertThisV;
00848 return checked;
00849 }
00850
00851 inline void uicheckbutton_c::set_radio(bool r)
00852 {
00853 AssertThis;
00854 radio = r;
00855 set_needs_refresh();
00856 }
00857
00858
00859
00860
00861
00862
00863
00868 class uislider_c:public uiobject_c
00869 {
00870 protected:
00871
00872 float min,
00873 max,
00874 pos;
00875
00876 public:
00877
00878 uislider_c();
00879 virtual ~uislider_c();
00880
00881 virtual void
00882 paint();
00883
00884 virtual void
00885 event(uievent_s *eve);
00886
00887 inline void
00888 set_min(float m);
00889
00890 inline void
00891 set_max(float m);
00892
00893 inline void
00894 set_pos(float p);
00895
00896 inline float
00897 get_min();
00898
00899 inline float
00900 get_max();
00901
00902 inline float
00903 get_pos();
00904
00905 void
00906 set_text(const char *txt);
00907
00908 inline ushort
00909 get_cursor();
00910 };
00911
00912 inline void uislider_c::set_min(float m)
00913 {
00914 AssertThis;
00915 min = m;
00916 set_needs_refresh();
00917 }
00918
00919 inline void uislider_c::set_max(float m)
00920 {
00921 AssertThis;
00922 max = m;
00923 set_needs_refresh();
00924 }
00925
00926 inline void uislider_c::set_pos(float p)
00927 {
00928 AssertThis;
00929 pos = p;
00930 set_needs_refresh();
00931 }
00932
00933 inline float uislider_c::get_min()
00934 {
00935 AssertThisV;
00936 return min;
00937 }
00938
00939 inline float uislider_c::get_max()
00940 {
00941 AssertThisV;
00942 return max;
00943 }
00944
00945 inline float uislider_c::get_pos()
00946 {
00947 AssertThisV;
00948 return pos;
00949 }
00950
00951 inline ushort uislider_c::get_cursor()
00952 {
00953 AssertThisV;
00954 if (width>height)
00955 return UIP_RESIZEH;
00956 return UIP_RESIZEV;
00957 }
00958
00959
00960
00966 class gui_c
00967 {
00968 protected:
00969
00970 uiobject_c *desktop;
00971 uiobject_c *focus,
00972 *mouseobj,
00973 *lmouseobj;
00974
00975 ushort cursor;
00976
00977 sshort cursorx,
00978 cursory;
00979
00980 sshort cursorlx,
00981 cursorly;
00982
00983 sshort cursordx,
00984 cursordy;
00985
00986 struct font_s *font[UIF_COUNT];
00987
00988 color_t colors[UIC_COUNT];
00989
00990 class animation_c *images;
00991
00992 ushort lastkeydown;
00993 ulong keydownstarttime;
00994 ulong keylastrepeattime;
00995
00996 ushort currentkeymod;
00997
00998 public:
00999
01000 gui_c();
01001 ~gui_c();
01002
01003 inline uiobject_c *
01004 get_focus();
01005
01006 inline void
01007 set_focus(uiobject_c *f);
01008
01009 inline uiobject_c *
01010 get_desktop();
01011
01012 void
01013 draw();
01014
01015 void
01016 update();
01017
01018 color_t
01019 get_color(ulong nr);
01020
01021 class animation_c *
01022 get_image(ulong nr);
01023
01024 inline struct font_s *
01025 get_font(ulong font);
01026
01027 void
01028 send_generic_event(uiobject_c *obj, ushort event);
01029
01030 void
01031 send_mouse_event(uiobject_c *obj, ushort event);
01032
01033 void
01034 send_keyboard_event(uiobject_c *obj, ushort event, ushort key);
01035
01036 ushort
01037 get_key_ascii(uchar key);
01038
01039 inline sshort
01040 get_cursor_x();
01041
01042 inline sshort
01043 get_cursor_y();
01044
01045 inline sshort
01046 get_cursor_dx();
01047
01048 inline sshort
01049 get_cursor_dy();
01050
01051 void
01052 load(const char *fname);
01053 };
01054
01055
01056
01057 inline uiobject_c *gui_c::get_focus()
01058 {
01059 AssertThisV; return focus;
01060 }
01061
01062 inline void gui_c::set_focus(uiobject_c *obj)
01063 {
01064 AssertThis; focus = obj;
01065 }
01066
01067 inline color_t gui_c::get_color(ulong nr)
01068 {
01069 AssertThisV;
01070 AssertReturnValue2(nr>=0, nr<UIC_COUNT, 0);
01071 return colors[nr];
01072 }
01073
01074 inline struct font_s *gui_c::get_font(ulong nr)
01075 {
01076 AssertThisV; return font[nr];
01077 }
01078
01079 inline uiobject_c *gui_c::get_desktop()
01080 {
01081 AssertThisV; return desktop;
01082 }
01083
01084 inline sshort gui_c::get_cursor_x()
01085 {
01086 AssertThisV; return cursorx;
01087 }
01088
01089 inline sshort gui_c::get_cursor_y()
01090 {
01091 AssertThisV; return cursory;
01092 }
01093
01094 inline sshort gui_c::get_cursor_dx()
01095 {
01096 AssertThisV; return cursordx;
01097 }
01098
01099 inline sshort gui_c::get_cursor_dy()
01100 {
01101 AssertThisV; return cursordy;
01102 }