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 #ifndef __WINDOW_H
00028 #define __WINDOW_H
00029
00030 #include "fgcolor.h"
00031 #include "base.h"
00032 #include <tinycfg.h>
00033
00034 #include <list>
00035
00036 #ifdef FG_NAMESPACE
00037 namespace fgl {
00038 #endif
00039
00040
00041
00042 #ifdef __BORLANDC__
00043 #pragma option push -b
00044 #pragma option push -a4
00045 #endif
00046
00047 enum
00048 {
00049 BNORMAL = 7,
00050 BMASK = BNORMAL,
00051 BPUSHED = 3,
00052 BDISABLED = 5
00053 };
00054
00055 #define FGFONT_TITLE FONTSYS
00056 #define FGFONT_MENU FONTSYSLIGHT
00057 #define FGFONT_BUTTON FONTSYSLIGHT
00058
00063
00064 #define IM CScheme->window_fore // CBLACK standard menu fore & background colors
00065
00066 #define PM CScheme->window_back
00067
00069 const unsigned WFRAMED = 0x0001;
00071 const unsigned WTITLED = 0x0002;
00073 const unsigned WMODAL = 0x0004;
00075 const unsigned WNOTIFY = 0x0008;
00077 const unsigned WHIDEN = 0x0010;
00079 const unsigned WUNMOVED = 0x0020;
00081 const unsigned WMENU = 0x0040;
00083 const unsigned WNOPICTO = 0x0080;
00085 const unsigned WBITMAP = 0x0100;
00087 const unsigned WCLICKABLE = 0x0200;
00089 const unsigned WDIRTY = 0x0400;
00091 const unsigned WUSESELECTEDCONTROL = 0x0800;
00093 const unsigned WLOCKED = 0x1000;
00095 const unsigned WTRIGGER = 0x2000;
00097 const unsigned WLASTFOCUS = 0x4000;
00099 const unsigned WSIZEABLE = 0x8000;
00101 const unsigned WUSELAST = 0x00010000;
00103 const unsigned WMINIMIZE = 0x00020000;
00105 const unsigned WSTATUSBAR = 0x00040000;
00107
00109 const unsigned WGLCONTEXT = 0x00100000;
00117 const unsigned WNOTEBOOK = 0x00200000;
00119 const unsigned WBACK = 0x00400000;
00121 const unsigned WCENTRED = 0x00800000;
00123 const unsigned WESCAPE = 0x01000000;
00125 const unsigned WALIGNED = 0x02000000;
00127 const unsigned WFASTMOVE = 0x04000000;
00129 const unsigned WTOP = 0x08000000;
00131 const unsigned WNOICON = 0x10000000;
00133 const unsigned WNODRAWFROMCONSTRUCTOR = 0x20000000;
00135 const unsigned WICONWINDOWTYPE = 0x40000000;
00137 const unsigned WMENUWINDOWTYPE = 0x80000000;
00139 const unsigned WSTANDARD = (WTITLED|WFRAMED);
00140
00142 const unsigned APP_WINDOWDATABASE = 1;
00144 const unsigned APP_CFG = 2;
00146 const unsigned APP_ENABLEALTX = 4;
00148 const unsigned APP_MAGNIFIER = 8;
00150 const unsigned APP_ROOTWINDOW = 16;
00152 const unsigned APP_ENABLEEFECTS = 0x20;
00154 const unsigned APP_ALL = 0x1F;
00156 const unsigned APP_LOCALDIR = 0x80000000;
00157
00164 enum ENUM_OS { OSTYPE_LINUX=1, OSTYPE_MSDOS, OSTYPE_WIN32, OSTYPE_QNX };
00165
00170 enum MODAL_RETURN
00171 { mrNone = -1,
00172 mrOk = -2,
00173 mrCancel = -3,
00174 mrYes = -2,
00175 mrNo = -3,
00176 mrAll = -4,
00177 mrIgnore = -5,
00178 mrClose = -6,
00179 mrQuit = -7,
00180 mrRetry = -8,
00181 mrUnknown= -9
00182 };
00183
00184 class FGBaseGui;
00185 class FGFileDialog;
00186 class FGColorDialog;
00187 class FGControl;
00188 class FGWindow;
00189 class FGMenuWindow;
00190 class FGBitmap;
00191 class FGEditBox;
00192 class FGButtonGroup;
00193 class FGListBox;
00194 class FGPushButton ;
00195 class FGRadioButton;
00196 class FGCheckBox;
00197 class FGBaseMenuItem;
00198 class FGPushButton;
00199 class FGSlider;
00200
00201 #define FGCheckButton FGCheckBox
00202 #define FGPointButton FGRadioButton
00203 #define AddPointButton AddRadioButton
00204 #define AddCheckButton AddCheckBox
00205
00212 extern "C" void IError(char *s, int flag);
00213
00219 struct FGColorScheme
00220 {
00222 int window_back;
00224 int window_fore;
00226 int active_title;
00228 int inactive_title;
00230 int wnd_bord1;
00232 int wnd_bord2;
00234 int wnd_bord3;
00236 int statusbar;
00238 int menu_back;
00240 int menu_fore;
00242 int menu_back_active;
00244 int menu_fore_active;
00246 int button_fore;
00248 int button_back;
00250 int button_fore_pushed;
00252 int button_back_pushed;
00254 int button_bord1;
00256 int button_bord2;
00258 int button_bord3;
00260 int edit_background_active;
00262 int edit_foreground;
00264 int edit_border;
00266 int edit_background;
00268 int slider;
00270 int menuwindow_back;
00272 int menuwindow_fore;
00274 int menuwindow_frame;
00276 int pdmenu_back_active;
00278 int pdmenu_fore_active;
00280 int pdmenu_gray;
00282 int pdmenu_color_of_frame;
00284 int edit_fore_disable;
00286 int notebook_active;
00288 int slider_disable;
00289 public:
00290 FGColorScheme();
00291 };
00292
00293
00294
00295 extern FGColorScheme * CScheme;
00296
00301 typedef unsigned int (*TimerCall)(unsigned int);
00302
00303 #define TIMER_RESOLUTION 10
00304
00308 class FGTimer : public FGConnector
00309 {
00310 protected:
00311 friend void HandleAlarm(int sig);
00312 int state;
00313 static void StartTicks(void);
00314 public:
00315 FGTimer(unsigned int val, TimerCall cb)
00316 {
00317 state = SetTimer(val, cb);
00318 }
00319 FGTimer(TimerCall cb)
00320 {
00321 state = SetTimer(0, cb);
00322 }
00323 virtual ~FGTimer()
00324 {
00325 TimerQuit();
00326 }
00327 static int SetTimer(unsigned int val, TimerCall cb);
00328 static unsigned int GetTicks(void);
00329 static void Delay(unsigned int);
00330 static int TimerInit(void);
00331 static void TimerQuit(void);
00332 };
00333
00338 class FGEvent
00339 {
00340 friend class FGBaseGui;
00341 friend class FGApp;
00342 int type;
00343 int key;
00344 int buttons, x, y, w, h;
00350 int guiType;
00351
00352 static const char *eventName[];
00353 protected:
00354 public:
00361 FGWindow *wnd;
00367 int GetObjectType(void) const { return guiType; }
00373 FGControl *accel;
00381 FGEvent(int T=NOEVENT, int K=0, int X=0, int Y=0, int W=0, int H=0)
00382 : type(T), key(K), x(X), y(Y), w(W), h(H), guiType(0), wnd(0), accel(0)
00383 {
00384 }
00386 int GetKey(void) const { return key; }
00388 const char *GetName(void) const { if (type<0 || type>=LASTEVENT) return eventName[LASTEVENT]; return eventName[type]; }
00390 int GetType(void) const { return type; }
00392 static const char* GetKeySymbolName(unsigned int code);
00400 int GetButtons(void) const { return buttons; }
00402 int GetX(void) const { return x; }
00404 int GetY(void) const { return y; }
00406 int GetW(void) const { return w; }
00408 int GetH(void) const { return h; }
00409 };
00410
00418 typedef void (*TimerProc)(int);
00422 typedef void (*GuiHwnd)(FGEvent *);
00426 typedef int (*MainHwnd)(FGEvent *);
00430 typedef FGControl * CallBack;
00434 typedef void (*FGListBoxCallBack)(int flag, FGWindow *wnd, int x, int y, void *data, int index);
00438 typedef void (*FileDialogCallBack)(char * filename, FGFileDialog *);
00442 typedef void (*ColorDialogCallBack)(FGPixel color);
00446 typedef void (*FontDialogCallBack)(int f);
00447
00453 typedef void (*ControlCall)(FGControl *);
00454
00456
00463 class FGBaseGui : public FGDrawBuffer
00464 {
00465 protected:
00466 enum bs { EBOX_LOW=1, EBOX_UPR, BDOWN, BUP, WHIDE, WVISIBLE, WDEACTIVE, WACTIVE };
00467
00468 int x;
00469 int y;
00470 void* tab_page_controls;
00471 void* private_data;
00472 void* user_data;
00473 unsigned ink;
00474 unsigned paper;
00475 bool temporary_hidden;
00476
00477 void FGAPI Resize(int dx, int dy);
00478 void frame(void);
00479 virtual void DrawAsSelected(void) {}
00480
00481 virtual ~FGBaseGui();
00482
00483 public:
00484 FGBaseGui(int xs, int ys, int ws, int hs, const char *nm, ObjectType typ, FGPixel i, FGPixel p, long flag);
00485
00487 unsigned FGAPI GetInk(void) const { return ink; }
00489 unsigned FGAPI GetPaper(void) const { return paper; }
00490
00494 bool IsVisible(void) const { return ! ( (status&WHIDEN) || temporary_hidden ); }
00498 void SetColors(void)
00499 {
00500 set_colors(ink, paper);
00501 }
00505 int GetX(void) const { return x; }
00509 int GetY(void) const { return y; }
00513 virtual void OnFocus(void) { }
00517 virtual void OnLostFocus(void) { }
00519 void* GetPrivateData(void) const { return private_data; }
00521 void SetPrivateData(void* val) { private_data = val; }
00523 void* GetUserData(void) const { return user_data; }
00525 void SetUserData(void* val) { user_data = val; }
00526 };
00527
00528 #ifndef __GNUC__
00529 #pragma pack(1)
00530 #endif
00531
00533 class FGBitmap : public FGDrawBuffer
00534 {
00535 public:
00537 enum ReturnValues { IMAGE_OK, IMAGE_FILE_NOT_FOUND, IMAGE_UNKNOWN_FORMAT,
00538 IMAGE_UNSUPPORTED_FORMAT, IMAGE_FILE_WRITE_ERROR };
00539 private:
00540 struct RGB3
00541 {
00542 char bBlue;
00543 char bGreen;
00544 char bRed;
00545 };
00546 struct RGB4
00547 {
00548 char bBlue;
00549 char bGreen;
00550 char bRed;
00551 char fcOptions;
00552 };
00553 struct bitmap_file_header
00554 {
00555 unsigned short usType;
00556 unsigned short cbSizeLow, cbSizeHigh;
00557 short reserve1, reserve2;
00558 };
00559 struct bitmap_info
00560 {
00561 unsigned short imageOffset;
00562 short reserve;
00563 };
00564 struct bitmap_info_header1
00565 {
00566 unsigned long size;
00567 unsigned short cx;
00568 unsigned short cy;
00569 unsigned short cPlanes;
00570 unsigned short cBitCount;
00571 unsigned long ulCompression;
00572 unsigned long cbImage;
00573 unsigned long cxResolution;
00574 unsigned long cyResolution;
00575 unsigned long cclrUsed;
00576 unsigned long cclrImportant;
00577 };
00578 struct bitmap_info_header2
00579 {
00580 unsigned long size;
00581 unsigned long cx;
00582 unsigned long cy;
00583 unsigned short cPlanes;
00584 unsigned short cBitCount;
00585 unsigned long ulCompression;
00586 unsigned long cbImage;
00587 unsigned long cxResolution;
00588 unsigned long cyResolution;
00589 unsigned long cclrUsed;
00590 unsigned long cclrImportant;
00591 };
00592
00593 void init(void);
00594 bitmap_file_header bmfh;
00595 bitmap_info bmi;
00596 union {
00597 bitmap_info_header1 bmih1;
00598 bitmap_info_header2 bmih2;
00599 } bmih;
00600 union {
00601 RGB3 rgb3[256];
00602 RGB4 rgb4[256];
00603 } rgb;
00604
00605 int* cUsedTable;
00606 int format;
00607 char szLastError[256];
00608
00609 void DoPalette(int);
00610 void RGBtoBGR(unsigned char *buffer, unsigned char *input, int length);
00611
00612 ReturnValues pcx(char *n, int& one, unsigned int& bits, unsigned int& c);
00613 ReturnValues bmp(char *n, int& one, unsigned int& bits, unsigned int& c);
00614 ReturnValues gif(char *n, int& one, unsigned int& bits, unsigned int& c);
00615 ReturnValues jpg(char *n, int& one, unsigned int& bits, unsigned int& c);
00616 ReturnValues png(char *n, int& one, unsigned int& bits, unsigned int& c);
00617 ReturnValues tga(char *n, int& one, unsigned int& bits, unsigned int& c);
00618 ReturnValues tiff(char *n, int& one, unsigned int& bits, unsigned int& c);
00619
00620 int detect(const char *);
00621
00622 public:
00623 enum ImageFormats { IMAGE_AUTO, IMAGE_BMP, IMAGE_GIF, IMAGE_TGA,
00624 IMAGE_PNG, IMAGE_JPG, IMAGE_TIF, IMAGE_PCX, IMAGE_UNKNOWN,
00625 IMAGE_LAST };
00631 FGBitmap();
00639 FGBitmap(const char *name);
00640 FGBitmap(FGDrawBuffer *);
00641 FGBitmap(int,int,FGPixel=CBLACK);
00642 FGBitmap(FGBitmap& old) : FGDrawBuffer(old)
00643 {
00644 bmfh = old.bmfh;
00645 bmi = old.bmi;
00646 bmih = old.bmih;
00647 rgb = old.rgb;
00648 cUsedTable = 0;
00649 #ifdef INDEX_COLORS
00650 if (old.cUsedTable)
00651 {
00652 cUsedTable = new int[256];
00653 memcpy(cUsedTable, old.cUsedTable, sizeof(long)*256);
00654 }
00655 #endif
00656 }
00657 virtual ~FGBitmap();
00659 ReturnValues BitmapSave(const char *, bool convert=false);
00660 ReturnValues JpegSave(const char *name);
00661 ReturnValues PngSave(const char *name);
00662
00663 ReturnValues LoadImage(const char* name, int imagefmt = IMAGE_AUTO);
00664 ReturnValues SaveImage(const char* name, int imagefmt);
00665
00666 };
00667 #ifndef __GNUC__
00668 #pragma pack()
00669 #endif
00670
00680 class FGButtonGroup
00681 {
00682 friend class FGControl;
00683 FGControl* curr;
00684 FGControl** array;
00685 int count;
00686 int size;
00687 int type;
00688
00689 public:
00693 FGButtonGroup(int maximum=32)
00694 {
00695 size = maximum;
00696 count = type = 0;
00697 curr = 0;
00698 array = new FGControl *[size];
00699 }
00700 FGButtonGroup(const FGButtonGroup& old)
00701 {
00702 size = old.size;
00703 count = old.count;
00704 type = old.type;
00705 curr = old.curr;
00706 array = new FGControl *[size];
00707 for(int i=0; i<count; i++)
00708 {
00709 array[i] = old.array[i];
00710 }
00711 }
00712 ~FGButtonGroup() { delete [] array; }
00720 void FGAPI AddToGroup(FGControl *p, int activ = 0);
00724 void FGAPI Clear(void) { type = count = 0; curr = 0; }
00726 void FGAPI RefreshGroup(FGControl *c);
00728 void FGAPI DisableGroup(void);
00730 void FGAPI EnableGroup(void);
00731 };
00732
00734
00748 class FGControl : public FGBaseGui
00749 {
00750 friend class FGWindow;
00751 friend class FGMenuWindow;
00752 friend class FGButtonGroup;
00753 friend class FGApp;
00754 friend class FGControlContainer;
00755
00756 ControlCall GetHandler(void) const { return fnc; }
00757
00758 void RegisterToGroup(FGButtonGroup *g) { grp = g;}
00759 void RefreshGroup(void);
00760 void RemoveFromGroup(void) { grp = 0; }
00761 static FGControl * ButtonFind(FGEvent *e,int n);
00762
00763 protected:
00764 int local_id;
00765 int key;
00766 ControlCall fnc;
00767 FGWindow* owner;
00768 FGButtonGroup *grp;
00769 char* closure_name;
00770
00771 FGControl(int xs, int ys, int ws, int hs, const char *nm, ObjectType typ, int key, FGWindow *, ControlCall f, FGPixel p, FGPixel i, void* user_data);
00772 virtual ~FGControl();
00773
00774 int GetXr(void);
00775 int GetYr(void);
00776 void Underscore(int xo, int yo, int c);
00777 void update_owner(void);
00778 virtual void ClickDown(void) {}
00779 virtual void WheelSpin(int) {}
00780 virtual void GetHints(int& xx, int& yy, int& ww, int& hh) { xx = x; yy = y; ww = w; hh = h; }
00781 virtual void DrawAsSelected(void);
00782 bool IsYourTabPage(void);
00783 bool IsSelected(void);
00784 virtual FGPixel GetColorOfFrame(void) const { return CYELLOW; }
00785 public:
00789 virtual void draw(void) {}
00793 virtual void SetName(const char *s) { FGDrawBuffer::SetName(s); draw(); }
00798 virtual void OnActivate(void) { RunSignal(); }
00802 void SetKey(int k) { if (k>='a' && k<='z') k = toupper(k); key=k; draw(); }
00806 int GetKey(void) const { return key; }
00810 void Enable(void);
00814 void Disable(void);
00820 virtual void ClickUp(int a);
00824 void SetTrigger(int a) { if (a) status |= WTRIGGER; else status &= (~WTRIGGER); draw();}
00828 int GetTrigger(void) const { return status&WTRIGGER?1:0; }
00832 FGWindow *GetOwner(void) const { return owner; }
00841 int GetLocalId() const { return local_id; }
00845 void SetInk(FGPixel i) { state._ink = ink = i; draw(); }
00849 void SetPaper(FGPixel p) { state._paper = paper = p; draw(); }
00853 void SetFont(unsigned f) { set_font(f); draw(); }
00857 void SetHandler(ControlCall w) { fnc=w; }
00859 void AttachSignalName(const char* val);
00861 const char* GetSignalName() { return closure_name; }
00869 static void Close(CallBack cb);
00877 static void Quit(CallBack cb);
00878
00880 virtual const double ToDouble() const { assert(!"Not implemented!!!"); return 0; }
00882 virtual const int ToInteger() const { assert(!"Not implemented!!!"); return 0; }
00884 virtual const char* ToString() const { assert(!"Not implemented!!!"); return 0; }
00885 };
00886
00903 class FGLabel : public FGControl
00904 {
00905 protected:
00906 void ClickUp(int a);
00907 unsigned int is_transparent:1;
00908 virtual ~FGLabel() { }
00909 public:
00910
00911 virtual void draw(void);
00912 FGLabel(int xs, int ys, const char *nm, int key, FGWindow *w, ControlCall f, unsigned i, unsigned p, void* user_data);
00913 void SetTransparent(void) { is_transparent = 1; draw(); }
00914 };
00915
00923 class FGPanel : public FGControl
00924 {
00925 protected:
00926 FGPixel ink1, ink2;
00927 virtual ~FGPanel() { }
00928 public:
00929
00930 virtual void draw(void);
00931 FGPanel(int xs, int ys, int ws, int hs, const char *nm, FGWindow *w, int i1, int i2, int p);
00932 };
00933
00940 class FGImage : public FGControl
00941 {
00942 protected:
00943 FGDrawBuffer* bitmap;
00944 virtual ~FGImage() { }
00945 public:
00947 virtual void draw(void);
00949 FGImage(int xs, int ys, FGDrawBuffer* img, FGWindow *w);
00950 };
00951
00958 class FGText : public FGControl
00959 {
00960 protected:
00961 virtual ~FGText() { }
00962 public:
00963 FGText(int xs, int ys, const char *nm, FGWindow *w, int i, int p);
00964
00965 virtual void draw(void);
00966 };
00967
00986 class FGPushButton : public FGControl {
00987 FGDrawBuffer* icon;
00988 FGDrawBuffer* pushed;
00989 FGDrawBuffer* disabled;
00990 FGPixel back_pushed;
00991 FGPixel fore_pushed;
00992 protected:
00993 virtual ~FGPushButton() { }
00994 public:
00995 FGPushButton(int xs, int ys, int ws, int hs, const char *nm, int key, FGWindow *w, ControlCall f, void* user_data)
00996 : FGControl(xs, ys, ws, hs, nm, PUSHBUTTON, key, w, f, CWHITE, CBLACK, user_data)
00997 {
00998 set_font(FGFONT_BUTTON);
00999 icon = 0;
01000 pushed = disabled = 0;
01001 ink = CScheme->button_fore;
01002 paper = CScheme->button_back;
01003 back_pushed = CScheme->button_back_pushed;
01004 fore_pushed = CScheme->button_fore_pushed;
01005 draw();
01006 }
01007 FGPushButton(int xs, int ys, int key, FGWindow *w, FGDrawBuffer *bm, ControlCall f, void* user_data)
01008 : FGControl(xs, ys, bm->GetW() + 4, bm->GetH() + 4, "", PUSHBUTTON_IMAGE, key, w, f, CWHITE, CBLACK, user_data)
01009 {
01010 set_font(FONTSYS);
01011 icon = bm;
01012 pushed = disabled = 0;
01013 draw();
01014 }
01015 FGPushButton(int xs, int ys, int ws, int hs, const char* nm, int key, FGWindow *w, FGDrawBuffer *bm, ControlCall f, void* user_data)
01016 : FGControl(xs, ys, ws, hs, nm, PUSHBUTTON_IMAGE, key, w, f, CWHITE, CBLACK, user_data)
01017 {
01018 set_font(FONTSYS);
01019 icon = bm;
01020 pushed = disabled = 0;
01021 draw();
01022 }
01023 void ClickDown(void);
01024 void ClickUp(int);
01025 void Push(void);
01026 void Release(void);
01027
01028 virtual void draw(void);
01029 void AddBitmaps(FGDrawBuffer* push=0, FGDrawBuffer* disable=0)
01030 {
01031 pushed = push;
01032 disabled = disable;
01033 draw();
01034 }
01035 };
01036
01054 class FGCheckBox : public FGControl {
01055 protected:
01056 int mask;
01057 int * variable;
01058 virtual ~FGCheckBox() { }
01059 public:
01060 FGCheckBox(int m, int xs, int ys, const char *nm, int key, FGWindow *w, int fg, int bg, ControlCall f, int *var, void* user_data)
01061 : FGControl(xs, ys, strlen(nm)?strlen(nm)*8+20:16, 16, nm, CHECKBUTTON, key, w, f, bg, fg, user_data)
01062 {
01063 set_font(FGFONT_BUTTON);
01064 variable = var;
01065 mask = m;
01066 if (variable) SetTrigger(*variable&mask); else draw();
01067 }
01068 FGCheckBox(int xs, int ys, const char *nm, int key, FGWindow *w, int fg, int bg, ControlCall f, bool *var, void* user_data)
01069 : FGControl(xs, ys, strlen(nm)?strlen(nm)*8+20:16, 16, nm, CHECKBUTTON, key, w, f,bg,fg, user_data)
01070 {
01071 set_font(FGFONT_BUTTON);
01072 variable = (int *)var;
01073 mask = 1;
01074 if (variable) SetTrigger(*variable&mask); else draw();
01075 }
01076 void ChangeItem(int *v) { variable = v; SetTrigger(*variable&mask); draw(); }
01077 void ChangeItem(bool *v) { variable = (int *)v; SetTrigger(*variable&mask); draw(); }
01078
01079 virtual void draw(void);
01080 virtual const int ToInteger() const { return *variable; }
01081 };
01082
01100 class FGRadioButton : public FGControl {
01101 protected:
01102 int mask;
01103 int * variable;
01104 virtual ~FGRadioButton() { }
01105 public:
01106 FGRadioButton(int m, int xs, int ys, const char *nm, int key, FGWindow *w, int fg, int bg, ControlCall f, int *var, void* user_data)
01107 : FGControl(xs, ys, strlen(nm)?strlen(nm)*8+20:16, 16, nm, POINTBUTTON, key, w, f,bg,fg,user_data)
01108 {
01109 set_font(FGFONT_BUTTON);
01110 variable = var;
01111 mask = m;
01112 if (variable) SetTrigger(*variable&mask); else draw();
01113 }
01114 FGRadioButton(int m, int xs, int ys, const char *nm, int key, FGWindow *w, int fg, int bg, ControlCall f, bool *var, void* user_data)
01115 : FGControl(xs, ys, strlen(nm)?strlen(nm)*8+20:16, 16, nm, POINTBUTTON, key, w, f,bg,fg,user_data)
01116 {
01117 set_font(FGFONT_BUTTON);
01118 variable = (int *)var;
01119 mask = m;
01120 if (variable) SetTrigger(*variable&mask); else draw();
01121 }
01122 void ChangeItem(int *v) { variable = v; SetTrigger(*v&mask); draw(); }
01123 void ChangeItem(bool *v) { variable = (int *)v; SetTrigger(*variable&mask); draw(); }
01124
01125 virtual void draw(void);
01126 virtual const int ToInteger() const { return *variable; }
01127 };
01128
01132 class FGTwoStateButton : public FGRadioButton
01133 {
01134 protected:
01135 virtual ~FGTwoStateButton() { }
01136 public:
01137 FGTwoStateButton(int xs, int ys, int ws, int hs, const char *nm, int key, FGWindow *wnd, int *var, ControlCall f, void* user_data) :
01138 FGRadioButton(1, xs,ys,"", key, wnd, 0, 15, f, var, user_data)
01139 {
01140 Resize(ws-w, hs-h);
01141 SetName(nm);
01142 }
01143
01144 virtual void draw(void);
01145 };
01146
01159 class FGEditBox : public FGControl
01160 {
01161 public:
01163 static const int bufsize = 252;
01164 private:
01165 friend class FGUpDown;
01166 friend class FGWindow;
01167
01168 enum dtype { EDIT_INT, EDIT_STRING, EDIT_DOUBLE};
01169
01170 void init(void);
01171 void UpDown(double step)
01172 {
01173 if (data_type==EDIT_INT)
01174 {
01175 *(int *)ptr += int(step);
01176 }
01177 else if (data_type==EDIT_DOUBLE)
01178 {
01179 *(double *)ptr += step;
01180 }
01181 TestRange();
01182 }
01183 void TestRange(void)
01184 {
01185 if (check_range==0) return;
01186 if (data_type==EDIT_INT)
01187 {
01188 int dato = *(int *)ptr;
01189 if (dato<min) *(int *)ptr = min;
01190 else if (dato>max) *(int *)ptr = max;
01191 }
01192 else if (data_type==EDIT_DOUBLE)
01193 {
01194 double dato = *(double *)ptr;
01195 if (dato<mind) *(double *)ptr = mind;
01196 else if (dato>maxd) *(double *)ptr = maxd;
01197 }
01198 }
01199 int inputproc(unsigned);
01200 void input(void);
01201 void FlushInput(bool reset=false)
01202 {
01203 if (isinput)
01204 {
01205 inputproc(reset ? ESC : CR);
01206 }
01207 }
01208 virtual void WheelSpin(int direction)
01209 {
01210 if (direction<0) UpDown(-1);
01211 else UpDown(1);
01212 draw();
01213 if (fnc)
01214 fnc(this);
01215 }
01216
01217 protected:
01218 int w1,w2,min,max;
01219 dtype data_type;
01220 unsigned first:1,passwd:1,check_range:1,hex:1,caps:2,isinput:1;
01221 double mind,maxd;
01222 void * ptr;
01223 char buf[bufsize];
01224 static char clip[bufsize];
01225 static int is_clip;
01226 int pos, maxpos, iline, icol, offset, size;
01227
01229 virtual void draw(bool cursor, bool first_time=false);
01230 virtual ~FGEditBox();
01231
01232 public:
01233
01234 virtual void draw(void);
01236 const double ToDouble() const { if (data_type!=EDIT_DOUBLE) assert(!"Not a double type!!!"); return *(double*)ptr; }
01238 const int ToInteger() const { if (data_type!=EDIT_INT) assert(!"Not an integer type!!!"); return *(int*)ptr; }
01240 const char* ToString() const { if (data_type!=EDIT_STRING) assert(!"Not a string type!!!"); return (const char*)ptr; }
01244 void ClickUp(int state=1);
01248 void PasswdMode(int m) { passwd = m; draw(); }
01252 void HexMode(int m) { hex = m; draw(); }
01256 void CapsMode(int m);
01261 void ChangeItem(int *p)
01262 {
01263 assert(data_type==EDIT_INT);
01264 ptr = p;
01265 draw();
01266 }
01271 void ChangeItem(char *p)
01272 {
01273 assert(data_type==EDIT_STRING);
01274 ptr= p;
01275 draw();
01276 }
01281 void ChangeItem(double *p)
01282 {
01283 assert(data_type==EDIT_DOUBLE);
01284 ptr = p;
01285 draw();
01286 }
01291 void SetRange(double mi, double ma)
01292 {
01293 assert(data_type==EDIT_DOUBLE);
01294 mind = mi;
01295 maxd = ma;
01296 TestRange();
01297 draw();
01298 }
01303 void SetRange(int mi, int ma)
01304 {
01305 assert(data_type==EDIT_INT);
01306 min = mi;
01307 max = ma;
01308 TestRange();
01309 draw();
01310 }
01314 void SetSize(int ns)
01315 {
01316 pos = offset = 0;
01317 if(ns>0 && ns<bufsize)
01318 {
01319 size = ns;
01320 draw();
01321 }
01322 }
01326 void Disable(void);
01330 FGEditBox(int xs, int ys, int ws1, int ws2, const char *nm, int key, FGWindow *w, int *pt, int ink, int paper, ControlCall f, int mn, int mx, int check, void* user_data);
01334 FGEditBox(int sz, int xs, int ys, int ws1, int ws2, const char *nm, int key, FGWindow *w, char *pt, int ink, int paper, ControlCall f, void* user_data);
01338 FGEditBox(int xs, int ys, int ws1, int ws2, const char *nm, int key, FGWindow *w, double *pt, int ink, int paper, ControlCall f, double mn, double mx, int check, void* user_data);
01339 };
01340
01349 class FGProgressBar : public FGControl
01350 {
01351 protected:
01352 int steps, value;
01353 int sirka;
01354 virtual ~FGProgressBar() { }
01355 public:
01356 void draw(void);
01360 void FGAPI setProgress(int a) { if (a>=0 && a<=steps) value = a; draw(); }
01364 int FGAPI progress(void) const { return value; }
01374 FGProgressBar(FGWindow *w, int xx, int yy, int ww, int hh, int s);
01375 };
01376
01382 class FGBaseMenu : public FGControl
01383 {
01384 protected:
01385 virtual ~FGBaseMenu() { }
01386 public:
01387
01388 virtual void draw(void);
01389 void DrawAsSelected(void);
01390 virtual void ClickUp(int a);
01391 FGBaseMenu(const char *nm, int key, FGWindow *w, ControlCall f, int font, void* user_data);
01392 virtual FGPixel GetColorOfFrame(void) const { return CYELLOW; }
01393 };
01394
01399 class FGBaseMenuItem : public FGControl
01400 {
01401 protected:
01402 virtual ~FGBaseMenuItem() { }
01403 public:
01404
01405 virtual void draw(void);
01406 void DrawAsSelected(void);
01407 virtual void ClickUp(int a);
01408 FGBaseMenuItem(const char *nm, int key, FGMenuWindow *w, ControlCall f, int font, void* user_data);
01409 virtual FGPixel GetColorOfFrame(void) const { return CScheme->pdmenu_color_of_frame; }
01410 };
01411
01415 class FGSlider : public FGControl
01416 {
01417 protected:
01418 virtual void draw(void) {}
01419 int minv,maxv,*val,steps,smer;
01420 void frame(int,int,int,int,int f=0);
01421 virtual void ClickDown(void);
01422 virtual void WheelSpin(int direction)
01423 {
01424 if (direction<0) StepDown();
01425 else if (direction>0) StepUp();
01426 }
01427 void StepDown(void)
01428 {
01429 modify(*val-minv-steps);
01430 }
01431 void StepUp(void)
01432 {
01433 modify(*val-minv+steps);
01434 }
01435 virtual ~FGSlider() { }
01436 public:
01437 void modify(int);
01438 void redraw(void)
01439 {
01440 ControlCall tmp = fnc;
01441 fnc = 0;
01442 draw();
01443 fnc = tmp;
01444 }
01445 FGSlider(FGWindow *win, int xs, int ys, int ws, int hs, int minimal, int maximal, int s, int *v, ControlCall f, void* user_data) :
01446 FGControl(xs, ys, ws, hs, 0, SLIDEBAR, 0, win, f, CWHITE, CBLACK, user_data), minv(0), maxv(0)
01447 {
01448 if (minimal>maximal)
01449 {
01450 minv = maximal;
01451 maxv = minimal;
01452 }
01453 else
01454 {
01455 minv = minimal;
01456 maxv = maximal;
01457 }
01458 if (*v<minv)
01459 *v=minv;
01460 if (*v>maxv)
01461 *v=maxv;
01462 val = v;
01463 steps= s;
01464 smer = h>w;
01465 }
01466 virtual const int ToInteger() const { return *val; }
01467 };
01468
01473 class FGSlideBarH : public FGSlider
01474 {
01475 protected:
01476 virtual ~FGSlideBarH() { }
01477
01478 public:
01479 FGSlideBarH(int x, int y, int min, int max, int step, int *val, FGWindow *win, ControlCall f, void* user_data):
01480 FGSlider(win,x,y,(max-min)/step+16+12+38,16,min,max,step,val,0,user_data)
01481 {
01482 draw();
01483 fnc = f;
01484 }
01485
01486 virtual void draw(void);
01487 };
01488
01493 class FGSlideBarV : public FGSlider
01494 {
01495 protected:
01496 virtual ~FGSlideBarV() { }
01497 public:
01498 FGSlideBarV(int x, int y, int min, int max, int step, int *val, FGWindow *win, ControlCall f, void* user_data):
01499 FGSlider(win,x,y,16,(max-min)/step+16+12+38,min,max,step,val,0,user_data)
01500 {
01501 draw();
01502 fnc = f;
01503 }
01504 virtual void draw(void);
01505 };
01506
01511 class FGControlContainer : public std::list<FGControl *>
01512 {
01513 FGControl* default_control;
01514 const char* idstring;
01515 int width, ypos, flag;
01516 public:
01517 FGControlContainer(const FGControlContainer& old);
01518 FGControlContainer(const char *s, int y);
01519 ~FGControlContainer();
01520
01521 const char *GetString(void) { return idstring; }
01522 int GetWidth(void) { return width; }
01523 int GetY(void) { return ypos; }
01524 int GetFlag(void) { return flag; }
01525 void SetFlag(int f) { flag = f; }
01526 void SetDefaultControl(FGControl* ctrl);
01527 FGControl* GetDefaultControl(void);
01528 void SetNextControl(void);
01529 void SetPreviousControl(void);
01530 void Rename(const char *);
01531 };
01532
01533 typedef FGControlContainer::iterator FGControlIterator;
01534
01535 typedef std::list<FGControlContainer> FGControlBox;
01536 typedef FGControlBox::iterator FGControlBoxIterator;
01537
01558 class FGWindow : public FGBaseGui
01559 {
01560 friend class FGControl;
01561 friend class FGPanel;
01562 friend class FGEditBox;
01563 friend class FGBaseMenu;
01564 friend class FGApp;
01565
01566 FGControlBox ctrl_list;
01567 FGControlBoxIterator Buttony;
01568 const char* current_tab_page;
01569 int c_menupos;
01570
01571 int ctrl_counter;
01572 unsigned first_draw:1,
01573 changed:1;
01574
01575 int xpos;
01576 int ypos;
01577
01578 void (*handler)(FGEvent *);
01579 FGControl *call_handler;
01580 void (*CallWindowHook)(int x, int y, int& nx, int& ny, int);
01581
01582
01583 FGMutex StateMutex;
01584 int state_locked;
01585 static FGMutex WindowListMutex;
01586
01587 FGPixel statuscolor;
01588 FGEditBox *ininput;
01589 int icon_x, icon_y;
01590 FGWindow **itself;
01591 FGWindow *iconized;
01592
01593 FGWindow(FGWindow **, FGPixel);
01594 virtual int iconize(int xs, int ys);
01595 int FGAPI Rozporcuj(int X1, int Y1, int X2, int Y2, int *in, int *out);
01596 void FGAPI Relocate(int xx, int yy);
01597 static void FindNextFindow(void);
01598 FGEditBox* FGAPI FindNextControl(void);
01599 int FGAPI TitleFind(FGEvent *e);
01600 void FGAPI WindowUpdate(int dx, int dy, int all=0);
01601 void FGAPI ResetActive(void)
01602 {
01603 call_handler = 0;
01604 }
01605 FGControl * FGAPI IsActive(void)
01606 {
01607 return call_handler;
01608 }
01609 int FGAPI IsInInput(void) const { return !!ininput; }
01610 void FGAPI SetInInput(FGEditBox *e)
01611 {
01612 ininput = e;
01613 }
01614 void FGAPI WindowInputChar(unsigned c)
01615 {
01616 ininput->inputproc(c);
01617 }
01618 void FGAPI WindowUpdateBlock(int x, int y, int w, int h);
01619
01620 void FGAPI SetNextTabPage(void);
01621 void FGAPI DrawTabPages(void);
01622 bool FGAPI ClickTabPage(int, int);
01623 void FGAPI RelocateTabPage(int xx, int yy);
01624
01625 void FGAPI puts(const char *s) { while(*s) wputc(*s++); }
01626 void FGAPI wputc(int);
01627 void FGAPI move(int x=0, int y=0) { wputc(-1); xpos=x; ypos=y; }
01629 int FGAPI GetXM(int);
01631 int FGAPI GetYM(void);
01633 FGControlContainer* GetBaseControls(void) { return & (*ctrl_list.begin()); }
01634 protected:
01635 FGDrawBuffer *icon;
01636
01637 virtual void FGAPI RepaintBlock(int x, int y, int w, int h);
01638 void FGAPI init(void);
01639 void FGAPI default_clipping(void);
01640 long FGAPI WindowStatus(long status);
01641 virtual void WindowPiktograms(int x, int y);
01642 virtual void WindowDrawTitle(int color);
01643 public:
01644
01645 virtual void draw(void);
01646 void FGAPI SetDefaultControl(FGControl* ctrl)
01647 {
01648 Buttony->SetDefaultControl(ctrl);
01649 }
01650 void SetNextControl(void)
01651 {
01652 Buttony->SetNextControl();
01653 }
01654 void SetPreviousControl(void)
01655 {
01656 Buttony->SetPreviousControl();
01657 }
01658 FGControl* GetDefaultControl(void)
01659 {
01660 return Buttony->GetDefaultControl();
01661 }
01663 void InstallWindowHook(void(*hook)(int, int, int&, int&, int))
01664 {
01665 CallWindowHook = hook;
01666 }
01668 void SetActive(FGControl *c);
01670 void RunHandler(void);
01672 static void ShowAll(void);
01673 static void FGAPI WindowVirtualRoot(int, int, int, int);
01674
01676 void StateLock(void)
01677 {
01678 StateMutex.Lock();
01679 state_locked++;
01680 }
01682 void StateUnlock(void)
01683 {
01684 StateMutex.Unlock();
01685 state_locked--;
01686 }
01687
01689 void FGAPI SetChange(void) { changed = 1; }
01691 void FGAPI ResetChange(void) { changed = 0; }
01692 bool FGAPI ShowNotify(void);
01693 void AbsToWindowPosition(int& _x, int& _y) { _x -= x; _y -= y; }
01695 void FGAPI SetIconPosition(int x, int y) { icon_x = x; icon_y = y; }
01697 int FGAPI IsIconized(void) const { return !!(int)iconized; }
01699 int FGAPI WindowIconize(void);
01701 int FGAPI WindowIconize(int, int);
01703 void FGAPI WindowAttachIcon(FGDrawBuffer *ico) { icon = ico; }
01704
01706 FGControlBoxIterator GetCurrentControls(void) { return Buttony; }
01707
01708 void FGAPI WindowRepaint(int xr, int yr, int w, int h);
01709 void FGAPI WindowRepaintUser(int xr, int yr, int w, int h);
01710
01711 FGWindow(FGWindow **, int xs, int ys, int ws, int hs, const char *nm, GuiHwnd=0, int i=IM, int p=PM, int flag=WTITLED|WFRAMED, void* user_data = UNDEFINED_USER_DATA);
01712 virtual ~FGWindow();
01713 bool WindowClose(void);
01718 bool FGAPI WindowFlushInput(void)
01719 {
01720 if (ininput)
01721 {
01722 WindowInputChar(CR);
01723 ininput = 0;
01724 return true;
01725 }
01726 return false;
01727 }
01728
01729 FGPushButton* AddPushButton(int xs, int ys, int ws, int hs, const char *nm, int key=0, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA);
01730 FGPushButton* AddPushButton(int xs, int ys, int ws, int hs, const char *nm, int key, FGDrawBuffer *bm, ControlCall f, void* user_data = UNDEFINED_USER_DATA);
01731 FGPushButton* AddPushButton(int xs, int ys, int key, FGDrawBuffer *bm, ControlCall f, void* user_data = UNDEFINED_USER_DATA);
01732 FGSlideBarH* AddSlideBarH(int xs, int ys, int min, int max, int step, int *val, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA);
01733 FGSlideBarV* AddSlideBarV(int xs, int ys, int min, int max, int step, int *val, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA);
01734 FGCheckBox* AddCheckBox(int xs, int ys, const char *nm, int key=0, int * variable=0, ControlCall=0, void* user_data = UNDEFINED_USER_DATA);
01735 FGCheckBox* AddCheckBox(int xs, int ys, const char *nm, int key, bool * variable, ControlCall=0, void* user_data = UNDEFINED_USER_DATA);
01736 FGRadioButton* AddRadioButton(int xs, int ys, const char *nm, int key=0, int * variable=0, ControlCall=0, void* user_data = UNDEFINED_USER_DATA);
01737 FGCheckBox* AddCheckBoxMask(int mask, int xs, int ys, const char *nm, int key=0, int * variable=0, ControlCall=0, void* user_data = UNDEFINED_USER_DATA);
01738 FGRadioButton* AddRadioButtonMask(int mask, int xs, int ys, const char *nm, int key=0, int * variable=0, ControlCall=0, void* user_data = UNDEFINED_USER_DATA);
01739 FGTwoStateButton* AddTwoStateButton(int xs, int ys, int w, int h, const char *nm, int key=0, int * variable=0, ControlCall=0, void* user_data = UNDEFINED_USER_DATA);
01740 FGEditBox* AddEditBox(int xs, int ys, int ws1, int ws2, const char *nm, int key, int *p, ControlCall f, int min, int max, void* user_data = UNDEFINED_USER_DATA);
01741 FGEditBox* AddEditBox(int xs, int ys, int ws1, int ws2, const char *nm, int key, int *p, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA);
01742 FGEditBox* AddEditBox(int xs, int ys, int ws1, int ws2, const char *nm, int key, char *p, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA);
01743 FGEditBox* AddEditBox(int sz, int xs, int ys, int ws1, int ws2, const char *nm, int key, char *p, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA);
01744 FGEditBox* AddEditBox(int xs, int ys, int ws1, int ws2, const char *nm, int key, double *p, ControlCall f, double min, double max, void* user_data = UNDEFINED_USER_DATA);
01745 FGEditBox* AddEditBox(int xs, int ys, int ws1, int ws2, const char *nm, int key, double *p, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA);
01746 FGBaseMenu* AddBaseMenu(const char *nm, int key=0, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA);
01747 FGProgressBar* AddProgressBar(int xs, int ys, int ws, int hs, int size);
01748 FGListBox* AddListBox(int xs, int ys, int w, int h, int dropdown, FGListBoxCallBack drawone=0, void* userdata = 0);
01749 FGLabel* AddLabel(int x, int y, const char *s, int key=0, ControlCall f=0, unsigned i = UNDEFINED_COLOR, unsigned p = UNDEFINED_COLOR, void* user_data = UNDEFINED_USER_DATA);
01750 FGPanel* AddPanel(int, int, int, int, const char *s=0, unsigned paper = UNDEFINED_COLOR, unsigned ink=CWHITED, unsigned ink2=CDARK);
01751 FGText* AddText(int x, int y, const char *s, unsigned ink = UNDEFINED_COLOR, unsigned paper = UNDEFINED_COLOR);
01752 FGImage* AddImage(int x, int y, FGDrawBuffer* img);
01753
01754 void FGAPI WindowText(int x, int y, const char *s, unsigned Ink = UNDEFINED_COLOR, unsigned Paper = UNDEFINED_COLOR);
01755
01756 void FGAPI WindowText(int x, int y, const char *s, FGFontProperty * f, unsigned color, unsigned bk);
01757 void FGAPI WindowTextUTF8(int x, int y, const char *s, FGFontProperty * f, unsigned color, unsigned bk);
01758 void FGAPI WindowTextUnicode(int x, int y, const unsigned short *s, FGFontProperty * f, unsigned color, unsigned bk);
01759
01760 void FGAPI WindowPanel(int, int, int, int, const char *s=0, int unsigned = CWHITED, unsigned ink2=CDARK);
01761
01762 void FGAPI WindowBox(int x, int y, int a, int b, unsigned color = UNDEFINED_COLOR);
01763
01764 void FGAPI WindowPixel(int x, int y, unsigned color = UNDEFINED_COLOR);
01765
01766 void FGAPI WindowRect(int x, int y, int a, int b, unsigned color = UNDEFINED_COLOR);
01767
01768 void FGAPI WindowPatternRect(int x, int y, int a, int b, FGPattern *);
01769
01770 void FGAPI WindowLine(int x, int y, int a, int b, unsigned color = UNDEFINED_COLOR);
01771 void FGAPI WindowPatternLine(int x, int y, int a, int b, FGPattern *p=&PatternDot);
01772
01773 void FGAPI WindowDrawCircle(int x, int y, int r, unsigned color = UNDEFINED_COLOR);
01774 void FGAPI WindowFillCircle(int x, int y, int r, unsigned color = UNDEFINED_COLOR);
01775
01776 void FGAPI WindowDrawEllipse(int x, int y, int rx, int ry, unsigned color = UNDEFINED_COLOR);
01777 void FGAPI WindowFillEllipse(int x, int y, int rx, int ry, unsigned color = UNDEFINED_COLOR);
01778
01779 void FGAPI WindowDrawArc(int x, int y, double ang1, double ang2, int r, unsigned color = UNDEFINED_COLOR);
01780
01781 FGRect FGAPI WindowFillPolygon(const FGPointArray& , unsigned col = UNDEFINED_COLOR);
01782 void FGAPI WindowDrawPolygon(const FGPointArray&, unsigned col = UNDEFINED_COLOR);
01783
01784 FGRect FGAPI WindowFillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, unsigned col = UNDEFINED_COLOR);
01785
01786 void FGAPI WindowSpline(FGPoint points[4], unsigned color = UNDEFINED_COLOR);
01787
01788 void FGAPI WindowScrollDown(int xx, int yy, int ww, int hh ,int about);
01789 void FGAPI WindowScrollUp(int xx, int yy, int ww, int hh ,int about);
01790 void FGAPI WindowScrollLeft(int xx, int yy, int ww, int hh ,int about);
01791 void FGAPI WindowScrollRight(int xx, int yy, int ww, int hh ,int about);
01792
01793 void FGAPI WindowStatusBar(int, const char *s, int c=CBLACK);
01794
01795 int printf(const char * , ... );
01796 int printf(int,int,const char *, ... );
01797
01799 void FGAPI SendEvent(int event, int key=0, int x=0, int y=0)
01800 {
01801 FGEvent e(event,key,x,y);
01802 SendToWindow(&e);
01803 }
01805 void FGAPI SendEvent(int event, int x, int y, int ww, int hh)
01806 {
01807 FGEvent e(event,0,x,y,ww,hh);
01808 SendToWindow(&e);
01809 }
01811 void FGAPI SendToWindow(FGEvent *p);
01812
01819 void FGAPI WindowLock(void) { status|=WLOCKED; }
01824 void FGAPI WindowUnLock(void);
01825 void FGAPI WindowResize(int, int);
01826 void FGAPI WindowMove(int,int);
01827 void FGAPI WindowFocus(void);
01828 void FGAPI WindowShape(int, int, int, int);
01829 void FGAPI WindowPutBitmap(int x, int y, int xs, int ys, int w, int h, FGDrawBuffer *p);
01830 #define WindowCopyFrom WindowPutBitmap
01831 void FGAPI WindowGetBitmap(int x, int y, int xs, int ys, int w, int h, FGDrawBuffer *p);
01832 MODAL_RETURN FGAPI ShowModal(void);
01833 bool FGAPI WindowSetWorkRect(int,int,int,int);
01834
01836 void FGAPI RedrawControls(void);
01838 void FGAPI RemoveControls(void);
01840 void FGAPI RemoveControls(FGControlBoxIterator iter);
01842 bool FGAPI RemoveControl(FGControlBoxIterator iter, FGControl* ctrl);
01844 void FGAPI RemoveControl(FGControl* ctrl);
01846 void FGAPI DisableControls(void);
01848 void FGAPI DisableControls(FGControlBoxIterator iter);
01850 void FGAPI EnableControls(void);
01852 void FGAPI EnableControls(FGControlBoxIterator iter);
01854 void FGAPI SetInk(FGPixel i)
01855 {
01856 state._ink = ink = i;
01857 }
01859 void FGAPI SetPaper(FGPixel p)
01860 {
01861 state._paper = paper = p;
01862 }
01864 void FGAPI SetName(const char *s);
01874 bool FGAPI AddTabPage(const char *name);
01879 const char* FGAPI GetCurrentTabPage(void)
01880 {
01881 return current_tab_page;
01882 }
01888 void FGAPI SetTabPage(const char *name);
01890 void FGAPI DeleteTabPages(void);
01892 void FGAPI DeleteTabPage(const char *name);
01894 int GetNumberOfTabPages(void);
01895
01896
01898 virtual void OnKeyPress(int akey) { }
01900 virtual void OnMouseMove(int x, int y) { }
01902 virtual void OnClick(int x, int y) { }
01904 virtual void OnDoubleClick(int x, int y) { }
01906 virtual void OnMiddleButton(int, int) { }
01908 virtual void OnContextPopup(int x, int y) { }
01910 virtual void OnWheel(int x, int y, int delta) { }
01912 virtual void OnPaint(void) { }
01914 virtual void OnStartDrag(int , int, int) {}
01916 virtual void OnEndDrag(int ,int, int, int, int) {}
01918 virtual void OnMove(int dx, int dy) { }
01920 virtual void OnResize(int dx, int dy) { }
01922 virtual void OnIconize(void) { }
01924 virtual void OnAccelerator(FGControl *which) { }
01926 virtual void OnTabSwitch(const char *) { }
01927 };
01928
01929 typedef std::list<FGWindow *> FGWindowContainer;
01930 typedef FGWindowContainer::iterator FGWindowIterator;
01931 typedef FGWindowContainer::reverse_iterator FGWindowRIterator;
01932
01938 class FGApp : public FGConnector
01939 {
01940 static const int pathsize = 256;
01941 friend class FGWindow;
01942 int mouseflag;
01943 static int fulldrag;
01945 static FGWindowContainer Windows;
01946 static FGWindow* Current;
01947 int XX, YY;
01948 bool locked;
01949 static FGInputDevice *user_input_drv;
01950 static int __fg_fps, __fg_fps_total;
01951 int mousefirst;
01952 static int current_mouse_x;
01953 static int current_mouse_y;
01954 int current_mouse_buttons;
01955 int old_mouse_x;
01956 int old_mouse_y;
01957 int old_mouse_buttons;
01958 int window_drag_in_action;
01959 int button_reached;
01960 int window_resize_in_action;
01961 int window_resize_width;
01962 int window_resize_height;
01963 int tmp_event;
01964 int drag_width, drag_height;
01965 int clickx, clicky, clickw, clickh;
01966 int selection_steps;
01967
01968 FGControl *idcb;
01969 FGControl *idc2;
01970 FGWindow *drag_window;
01971 static int repeat_status, repeat_delay1, repeat_delay2;
01972 FGEvent *hold_event;
01973 static bool is_ctrl, is_alt, is_shift;
01974
01975 enum { MAX_EVENT_QUEQUE=32 };
01976
01977 void blue_rect(int x, int y, int w, int h);
01978 void blue_rect2(int x, int y, int w, int h);
01979 void AutoRepeatStart(FGControl *);
01980 void AutoRepeatDo(void);
01981 void AutoRepeatEnd(void);
01982 void DoubleClick(int& event);
01983
01984 static FGEvent queque[MAX_EVENT_QUEQUE];
01985 static void (*DelayProc)(void);
01986 static void (*OnEverySecond)(int);
01987 static int quequeIndex;
01988 static FGWindow *Root;
01989 static MainHwnd appHandler;
01990 static unsigned long ticks;
01991 static int ctrl_break;
01992 static int startXdrag;
01993 static int startYdrag;
01994 static int endXdrag;
01995 static int endYdrag;
01996 static void (*DragShape)(int , int ,int , int );
01997 static FGPixel __p4[8];
01998 static FGPattern __patt;
01999 void CallDelayProc(void)
02000 {
02001 if (DelayProc)
02002 {
02003 DelayProc();
02004 return;
02005 }
02006 else if (OnIdle() == true)
02007 {
02008 return ;
02009 }
02010
02011 delay(10);
02012 }
02013 void GetUserEvent(FGEvent& e, int);
02014 void TranslateUserEvent(FGEvent& e);
02015 void ButtonClick(FGEvent& e, FGControl* ctrl);
02016 void Timer(void);
02017 int isgmkey(int k);
02018
02019 protected:
02020 static void SetCurrentWindow(FGWindow* novy) { Current = novy; }
02021 static void RemoveIterator(FGWindow* wnd);
02022 static FGWindowIterator GetIterator(FGWindow* Colise);
02023 static FGWindowRIterator GetRIterator(FGWindow* Colise);
02024 static FGWindow* WindowFind(FGEvent *e);
02025 static FGWindow* GetLastWindow(void)
02026 {
02027 return *(Windows.rbegin());
02028 }
02030 static FGWindow* WindowFind(int idw);
02031 static void FGAPI intersect(FGWindow* This, int, int, int, int);
02032 static FGAPI int _over(int, int, int, int, int xx, int yy, int ww, int hh);
02033 static FGWindow* OverSprite(FGWindowRIterator This, FGWindowRIterator _od, int x, int y, int w, int h);
02034 static FGWindow* FGAPI OdkryteOkno(FGWindowRIterator This, FGWindowRIterator pokial, int x, int y, int w, int h);
02035 static void FGAPI DestroyWindow(void);
02036 static int NumberOfWindow(void)
02037 {
02038 return Windows.size();
02039 }
02040 static void AddWindowToList(FGWindow* wnd, int where);
02041
02042 public:
02044 static FGWindow* GetCurrentWindow(void);
02045 int RemoveMousePointer(void);
02046 void ShowMousePointer(void);
02047 int get_key(void);
02048 static const FGMouseCursor *__fg_cursor;
02050 static int flags;
02052 static int video;
02054 static int background;
02056 static int Argc;
02058 static char **Argv;
02060 static char * name;
02062 static char *homedir;
02064 static char currdir[pathsize];
02066 static int ttf_support;
02075 void SetDelayProc(void (*fnc)(void))
02076 {
02077 DelayProc = fnc;
02078 }
02079 void UpdateMousePointer(void);
02080 static void SaveScreen(void);
02085 static void DisableCtrlBreak(void)
02086 {
02087 ctrl_break ^= 1;
02088 }
02092 static void SetWindowMoveStyle(int a)
02093 {
02094 fulldrag = a;
02095 }
02096 FGApp(int m, int& argc, char **& argv, int bck, int appFlags=APP_ENABLEALTX);
02097 virtual ~FGApp();
02102 static void FGAPI SendToApp(FGEvent *x);
02103 void FGAPI Run(MainHwnd hwnd=0);
02104 void FGAPI FGYield(void);
02110 static void AppDone(void)
02111 {
02112 FGEvent e(QUITEVENT);
02113 SendToApp(&e);
02114 }
02118 static void AppClose(void)
02119 {
02120 FGEvent e(CLOSEEVENT);
02121 SendToApp(&e);
02122 }
02132 void SetTimerProc(TimerProc p, int t=1000)
02133 {
02134 OnEverySecond = p;
02135 ticks = t;
02136 }
02146 static FGWindow * GetRootWindow(void)
02147 {
02148 return Root;
02149 }
02150 MODAL_RETURN FGAPI RunModal(FGWindow *which);
02152 static int GetMouseX(void)
02153 {
02154 return current_mouse_x;
02155 }
02157 static int GetMouseY(void)
02158 {
02159 return current_mouse_y;
02160 }
02162 static bool IsShift(void);
02164 static bool IsCtrl(void);
02166 static bool IsAlt(void);
02167
02168 static void set_mmx(void);
02169 static void reset_mmx(void);
02170 static int test_mmx(void);
02171
02172 static void SetCaption(char *new_name);
02173
02174 const FGMouseCursor * CursorLoad(const FGMouseCursor *cur);
02175
02176 int EnableBuffering(int mode);
02177 int Flip(void);
02178 void DisableBuffering(void);
02179
02180 ENUM_OS GetOS(void);
02181
02189 static void GetDragVector(int &x, int &y, int &w, int &h);
02196 static void SetDragShape(void(*a)(int,int,int,int)=0);
02197 static void SetRepeatDelay(int c1, int c2);
02198
02199 static void SetInputDevice(FGInputDevice *idev) { user_input_drv = idev; }
02200 void ResetInputDevice(void) { user_input_drv = 0; }
02201
02202 void LockInput(void) { locked = true; }
02203 void UnlockInput(void) { locked = false; }
02204
02205
02207 virtual void OnKeyPress(int) { }
02209 virtual void OnMouseMove(int , int) { }
02211 virtual void OnClick(int, int) { }
02213 virtual void OnDoubleClick(int, int) { }
02215 virtual void OnMiddleButton(int, int) { }
02217 virtual void OnContextPopup(int, int) { }
02219 virtual void OnWheel(int x, int y, int delta) { }
02221 virtual void OnStartDrag(int , int, int) {}
02223 virtual void OnEndDrag(int ,int, int, int, int) {}
02225 virtual void OnCursorOut(int)
02226 {
02227 }
02236 virtual bool OnIdle(void)
02237 {
02238 return false;
02239 }
02248 virtual void OnTimer(int secs)
02249 {
02250 }
02252 virtual void OnTabSwitch(const char *) { }
02253 };
02254
02259 extern FGApp *cApp;
02260
02265 class FGMenuWindow : public FGWindow
02266 {
02267 friend class FGWindow;
02268 friend class FGBaseMenuItem;
02269
02270 int offset;
02271
02272 static GuiHwnd Proc;
02273 static FGMenuWindow * CurrentMenu;
02274 static void MenuWindowHandler(FGEvent *p);
02275
02276 void _initmw(GuiHwnd proc)
02277 {
02278 offset = 0;
02279 Proc = proc;
02280 CurrentMenu = this;
02281 set_font(FGFONT_MENU);
02282 }
02283 int GetXM(void) const
02284 {
02285 return 4;
02286 }
02287 int GetYM(int a)
02288 {
02289 return (offset+=a,offset-a);
02290 }
02291 public:
02301 FGMenuWindow(int x, int y, int w, int h, GuiHwnd proc=0, void* user_data = UNDEFINED_USER_DATA ):
02302 FGWindow(0,x,y,w,h,"", MenuWindowHandler, CScheme->menuwindow_fore, CScheme->menuwindow_back,WFRAMED|WNOPICTO|WMENUWINDOWTYPE|WNODRAWFROMCONSTRUCTOR|WUSESELECTEDCONTROL, user_data)
02303 {
02304 draw();
02305 _initmw(proc);
02306 }
02314 FGMenuWindow(int w, int h, GuiHwnd proc=0, void* user_data = UNDEFINED_USER_DATA );
02315
02316 virtual ~FGMenuWindow()
02317 {
02318 CurrentMenu = 0;
02319 }
02320
02321 virtual void draw(void);
02322
02323 FGBaseMenuItem* AddMenu(char *nm, int key=0, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA );
02324 FGLabel* AddLabel(char *nm, int key=0, ControlCall f=0, unsigned i = UNDEFINED_COLOR, unsigned p = UNDEFINED_COLOR, void* user_data = UNDEFINED_USER_DATA );
02325 FGText* AddText(const char *s, unsigned ink = UNDEFINED_COLOR, unsigned paper = UNDEFINED_COLOR, void* user_data = UNDEFINED_USER_DATA );
02326 FGCheckBox* AddCheckBox(char *nm, int key=0, int * variable=0, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA );
02327 FGCheckBox* AddCheckBox(char *nm, int key=0, bool * variable=0, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA );
02328 FGRadioButton* AddRadioButton(char *nm, int key=0, int * variable=0, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA );
02329 FGRadioButton* AddRadioButton(char *nm, int key=0, bool * variable=0, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA );
02330 FGCheckBox* AddCheckBoxMask(int, char *nm, int key=0, int * variable=0, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA );
02331 FGRadioButton* AddRadioButtonMask(int, char *nm, int key=0, int * variable=0, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA );
02332 FGEditBox* AddEditBox(int ws1, int ws2, char *nm, int key, int *p,ControlCall f, int min, int max, void* user_data = UNDEFINED_USER_DATA );
02333 FGEditBox* AddEditBox(int ws1, int ws2, char *nm, int key, int *p, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA );
02334 FGEditBox* AddEditBox(int ws1, int ws2, char *nm, int key, char *p, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA );
02335 FGEditBox* AddEditBox(int sz, int ws1, int ws2, char *nm, int key, char *p, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA );
02336 FGEditBox* AddEditBox(int ws1, int ws2, char *nm, int key, double *p, ControlCall f, double min, double max, void* user_data = UNDEFINED_USER_DATA );
02337 FGEditBox* AddEditBox(int ws1, int ws2, char *nm, int key, double *p, ControlCall f=0, void* user_data = UNDEFINED_USER_DATA );
02338 void Separator(void);
02339 };
02340
02344 class FGDialog
02345 {
02346 FGWindow* wnd;
02347 FGControl* ctrl;
02348 unsigned width;
02349
02350 public:
02351 FGDialog(char* format, ...);
02352 FGDialog(unsigned ink, unsigned paper, const char* title, char* format, ...);
02353 ~FGDialog()
02354 {
02355 delete wnd;
02356 }
02357 FGWindow* GetWindow(void) { return wnd; }
02358 MODAL_RETURN ShowOk(void);
02359 MODAL_RETURN ShowYesNo(void);
02360 MODAL_RETURN ShowRetryIgnoreCancel(void);
02361 };
02362
02363
02364
02365 unsigned int CalculateCRC(unsigned StartCRC, void *Addr, unsigned Size);
02366
02371 extern ConfigInterface *cCfg;
02372
02373
02374
02379 typedef void ( * XUIEventHandler )(CallBack cb, void* user_data);
02380 typedef void ( * XUIEnterHandlerText )(CallBack cb, const char* text, void* user_data);
02381 typedef void ( * XUIEnterHandlerInteger )(CallBack cb, const int integer, void* user_data);
02382 typedef void ( * XUIEnterHandlerDouble )(CallBack cb, const double integer, void* user_data);
02383 typedef void ( * XUIWindowHandler )(FGEvent* event, void* user_data);
02391 struct FGClosure
02392 {
02393 static const int name_size = 48;
02394 enum { ON_CLICK, ON_INTEGER_CHANGE, ON_DOUBLE_CHANGE, ON_TEXT_CHANGE, HANDLER };
02395 char event_name[name_size];
02396 union {
02397 XUIEventHandler function;
02398 XUIWindowHandler handler;
02399 XUIEnterHandlerText text_handler;
02400 XUIEnterHandlerInteger int_handler;
02401 XUIEnterHandlerDouble dbl_handler;
02402 };
02403 void* user_data;
02404 int type;
02405
02406 FGClosure(const char* n, XUIEventHandler func = 0, void* user_data = 0);
02407 FGClosure(const char* n, XUIEnterHandlerText func = 0, void* user_data = 0);
02408 FGClosure(const char* n, XUIEnterHandlerInteger func = 0, void* user_data = 0);
02409 FGClosure(const char* n, XUIEnterHandlerDouble func = 0, void* user_data = 0);
02410 FGClosure(const char* n, XUIWindowHandler hwnd = 0, void* user_data = 0);
02411 };
02412
02413 typedef std::list<FGClosure> ClosureList;
02414 typedef ClosureList::iterator ClosureIterator;
02415
02416 void RegisterOnClickSignal(const char* signal_name, XUIEventHandler fnc, void* user_data = 0);
02417 void RegisterOnEnterSignal(const char* signal_name, XUIEnterHandlerText fnc, void* user_data = 0);
02418 void RegisterOnEnterSignal(const char* signal_name, XUIEnterHandlerInteger fnc, void* user_data = 0);
02419 void RegisterOnEnterSignal(const char* signal_name, XUIEnterHandlerDouble fnc, void* user_data = 0);
02420 void RegisterControl(FGControl* ctrl, XUIEventHandler fnc, void* user_data);
02421
02422 bool ChangeSignalData(const char* signal_name, void* func, void* user_data);
02423 bool DeregisterSignal(const char* signal_name, void* func);
02424 bool DeregisterSignal(const char* signal_name, void* func, void* data);
02425
02426 void RegisterWindowHandler(const char* handler_name, XUIWindowHandler fnc, void* user_data = 0);
02427
02428 void CallClosure(const char* signal_name, CallBack cb);
02429 void CallClosure(const char* signal_name, CallBack cb, int value);
02430 void CallClosure(const char* signal_name, FGEvent* e);
02431 void CallClosureDebug();
02432
02433 void GetTempName(char* buffer, int size);
02434
02435
02436
02437 #ifdef FG_NAMESPACE
02438 }
02439 #endif
02440
02441 #ifdef __BORLANDC__
02442 #pragma option pop
02443 #pragma option pop
02444 #endif
02445
02446 #endif