include/df/window.hpp

00001 //Window class
00002 
00003 struct WindowData;  //custom data for Window APIs
00004 
00005 //clr idx into clrs[] array
00006 #define _GUI_BLACK 0
00007 #define _GUI_GREY  1
00008 #define _GUI_WHITE 2
00009 #define _GUI_BLUE  3
00010 #define _GUI_DGREY 4  //dark grey
00011 #define _GUI_LGREY 5  //light grey
00012 
00013 //actual 24bit colours
00014 #define GUI_BLACK 0x010101  //all zeros could be transparent
00015 #define GUI_GREY  0xc0c0c0
00016 #define GUI_WHITE 0xf0f0f0
00017 #define GUI_BLUE  0x1010f0
00018 #define GUI_DGREY 0x777777  //dark grey
00019 #define GUI_LGREY 0xd8d8d8  //light grey
00020 
00021 class Window : public Element {
00022     friend class OSAPI;
00023     friend class MsgServerSession;
00024     friend class Network;
00025     friend class Element;    //GUI Element
00026     friend class Bitmap;
00027     friend class Timer;
00028     friend class Mouse;
00029     friend class MM;
00030     friend class Sound;
00031     friend class Font;
00032     friend class G3Scene;
00033     friend class G3Object;
00034     friend class G3Buffer;
00035     friend class G3ZBuffer;
00036     friend class SystemCode;
00037     friend class SpreadSheet;  //needs access to drawing
00038     friend class FindWindow;
00039 
00040   _PROTECTED_:       //share this info with derived class'es
00041 
00042     //I don't like doing this, but it makes things easier (avoid many pointer references)
00043     //NOTE:These header files may only include code (NO DATA!)
00044 #ifdef _DF_WINDOW_SRC_
00045 #ifdef DF_WIN
00046  #include <df/win32/window.hpp>
00047 #else
00048  #include <df/linux/window.hpp>
00049 #endif
00050 #endif
00051     //static data
00052     static uint32 bpp2bypp[33];
00053     static uint32 sx, sy;  //physical screen X/Y (in Windows Gfx mode)
00054     static uint32 sbpp;    //bits / pixel
00055     static uint32 sbypp;   //bytes / pixel
00056     //private data
00057     WindowData *wd;   //window data
00058     BOOL drawing;     //are we currently drawing
00059     BOOL wValid;      //is Window valid (becomes valid a little sooner than Valid)
00060     String WinTitle;  //window title
00061     BOOL mousevisible;
00062     Element *bFocus;  //backup focus (when program is switched away from)
00063     BOOL flgdraw;     //TRUE when a redraw is required (FlagDraw())
00064     BOOL flgflip;     //TRUE when a flip is required (FlagFlip())
00065     //coords
00066     int32 dix1, diy1, dix2, diy2;   //invalid rect (needs to be redrawn)
00067     int32 fix1, fiy1, fix2, fiy2;   //invalid rect (needs to be flip()ed)
00068     uint32 wx, wy;                  //Window X/Y size (x/y + titlebar/border size)
00069     int32 tpx, tpy;                 //turtle point (MoveTo() , LineTo(), etc.)
00070     int32 cwx1, cwx2, cwy1, cwy2;      //current clipping window
00071     int32 scwx1, scwx2, scwy1, scwy2;  //set clipping window (-1 = Max)
00072     //SwitchMode() stuff
00073     int wxpos, wypos;               //windowed x/y pos (not used during fullscreen mode)
00074     //real screen info
00075     BOOL child;                     //is a child of another window (makes many changes)
00076     Array<Window*> wlist;           //list of children Window's (see Element for elist)
00077 
00078     //private members
00079     void ProcessEvent(int msg, int x, int y, int flgs);
00080     BOOL UpdateInvalid();        //Updates window (draws invalid areas and flip()s)
00081     BOOL DrawInvalid();          //Draws Parent and all children to Working Buffer (Bitmap) (only area that is invalid)
00082     BOOL FlipInvalid();          //Flips Primary to Screen (Blt() operation)
00083     void AdjustWXY(uint32 *, uint32 *, int dir = 1);  //Adjust window x/y size (titlebar,etc.)
00084     void AdjustPOS(int32 *, int32 *, int dir = 1);  //Adjust window pos (titlebar,etc.)
00085     void winit();       //called by Window::Create() only
00086     void winitvalues(); //called at anytime to recalc values
00087     void attachWindow(Window *gfx);  //for child windows
00088     BOOL detachWindow(Window *gfx);
00089     static void _attachWindow(Window *gfx); //a list of ALL windows
00090     static BOOL _detachWindow(Window *gfx);
00091     void SetStyle(int s);
00092     void DisplayChange(int newx, int newy, int newbpp);
00093     virtual BOOL LockBuffer();
00094     virtual BOOL UnLockBuffer();
00095     RGB pal[256];
00096     void SizeChanged(uint _x, uint _y);
00097     void PosChanged(int _x, int _y);
00098 
00099   public:
00100     //public data
00101     Thread *This;
00102     Element *Focus;     //GUI element with current focus
00103     Mouse *mouse;       //each element can have it's own mouse
00104     uint32 clrs[6];     //GUI default clrs
00105     static uint8 _VGAPalette_[];
00106     String DropFilename;//WND_DROPFILES, MSG_DROPFILE
00107 
00108     //Ctor/dtor
00109     Window();
00110     void Init(char *title);
00111     ~Window();
00112 
00113     //size info
00114     uint32 bpp, bypp;
00115     uint32 xbypp, xybypp;
00116 
00117     //static public members
00118     static void GetMetrics(int style, int *_x, int *_y);  //size of window components
00119 
00120     //public members
00121     void SetTitle(char *newtitle);
00122 
00123     BOOL ExitFlag;
00124     BOOL GetExitFlag() { return ExitFlag;}
00125     void SetExitFlag() {ExitFlag = TRUE;}
00126     void ClrExitFlag() {ExitFlag = FALSE;}
00127 
00128     BOOL IsInvalid() { return (flgdraw || flgflip);}  //does it need redrawing?
00129 
00130     void SetGUIClr(uint32 idx, uint32 clr);
00131     uint32 GetGUIClr(uint32 idx);
00132 
00133     //Windowed functions only
00134     static BOOL GetDisplayMode(uint *x, uint *y, uint *bpp = (uint*)NULL);
00135     void GetScreenWorkArea(uint32 *x, uint32 *y);  //get work area (size of screen excluding system tray/menu)
00136     BOOL SetForeground();
00137 
00138     //mouse funcs (public)
00139     void ShowMouse();
00140     void HideMouse();
00141     void SetMouse(Mouse *);
00142 
00143     BOOL SwitchMode(int newbpp=0);  //switch between full/windowed mode
00144     BOOL Minimize();
00145     BOOL Maximize();
00146     BOOL Restore();
00147 
00148     BOOL NextFocus();  //TAB
00149     BOOL PrevFocus();  //SHIFT+TAB
00150 
00151     //Palette functions
00152     BOOL SetPal(RGB (*)[256]);  //set entire 256 colors palette
00153     BOOL GetPal(RGB (*)[256]);  //get entire 256 colors palette
00154 
00155     //multi-monitor (not implemented yet)
00156     int32 EnumDevices();  //fills in Screens //returns no devices (-1 on error)
00157     void FreeEnumDevices();
00158     BOOL FindFirstDevice(String &desc, String &name);
00159     BOOL FindNextDevice(String &desc, String &name);
00160     BOOL SelectDevice(int32 idx);  //-1=active screen
00161 
00162     void PutKeyClr(PTR,int,int,int,int,uint32);
00163     void Put(PTR,int,int,int,int);
00164 
00165 #ifdef DF_WIN
00166     static int32 Find(char *_class, char *_title);        //[Win32 only]find window matching class/title (returns hwnd)
00167 #endif
00168 
00169 //OpenGL members (DF/4.0)
00170     BOOL GLInit();    //call after calling Create()
00171     BOOL GLUnInit();  //call before calling Destroy()
00172     BOOL GLEnable();  //call before calling glBegin()
00173       //call OpenGL functions here
00174     BOOL GLDisable(); //call after calling glEnd()
00175     BOOL SwapBuffers();   //call to swap buffers
00176 
00177 //virtual members
00178     virtual void SetPos(int x, int y);
00179     virtual void SetSize(uint32 x, uint32 y);  //change window size (Can not change BPP!)
00180     virtual void GetSize(uint32 *_x, uint32 *_y);
00181     virtual void GetPos(int *_x, int *_y);
00182     virtual void SetPosSize(int _px, int _py, uint _sx, uint _sy);
00183     virtual void Enable();
00184     virtual void Disable();
00185     virtual BOOL Create(int _xpos, int _ypos, int _x, int _y, int _Style, Element *_Parent = (Element*)NULL);
00186     virtual void Destroy();
00187     virtual void Show();
00188     virtual void Hide();
00189     virtual void FlagFlip();
00190     virtual void FlagFlip(int _x1, int _y1, int _x2, int _y2);
00191     virtual void FlagDraw();
00192     virtual void FlagDraw(int _x1, int _y1, int _x2, int _y2);
00193     virtual void FlagEvent();
00194     virtual void MoveTo(int32 x, int32 y);   //move turtle graphics location to (x,y)
00195     virtual void Line(int32 x1, int32 y1, int32 x2, int32 y2, uint32 clr);  //draw line
00196     virtual void LineDash(int32 x1, int32 y1, int32 x2, int32 y2, uint32 clr);  //draw line dashed
00197     virtual void LineTo(int32 x, int32 y, uint32 clr);     //draw line from turtle loc.
00198     virtual void LineDashTo(int32 x, int32 y, uint32 clr);  //draw line dashed
00199     virtual void PutPixel(int32 x, int32 y, uint32 clr);  //OSAPI
00200     virtual uint32 GetPixel(int32 x, int32 y);  //OSAPI
00201     virtual void Box(int32 x1, int32 y1, int32 x2, int32 y2, uint32 clr);
00202     virtual void BoxDash(int32 x1, int32 y1, int32 x2, int32 y2, uint32 clr);
00203     virtual void BoxFill(int32 x1, int32 y1, int32 x2, int32 y2, uint32 clr);
00204     virtual BOOL DispatchEvent(Element *id,int msg,int x,int y,int flgs);
00205     virtual void GetFocus();
00206     virtual void KeyDown(int);
00207     //keyup (no override)
00208     //getkey (no override)
00209     //mouse... click dblclick exit (no override)
00210     virtual void Draw();
00211     virtual void LostFocus();
00212     virtual void SetFocus();   //Sets Window's Focus (not Element related, see Element::SetFocus())
00213     virtual void SetClipping(uint32 x1, uint32 y1, uint32 x2, uint32 y2);
00214     virtual void SetClipping();
00215     virtual void GetClipping(uint32 *x1, uint32 *y1, uint32 *x2, uint32 *y2);
00216     virtual uint32 MakePixel(uint32 clr);  //DF/1.9.0
00217 //DF/3.0.4 - Flip() is now virtual -> jWindow
00218     virtual BOOL Flip();
00219     virtual BOOL Flip(uint32 x1, uint32 y1, uint32 x2, uint32 y2);
00220 };
00221 
00222 class FindWindow {
00223   _PROTECTED_:
00224     uint32 Offset;
00225     int32 Dir;  //direction
00226     Array<Window*> *list;
00227     BOOL Eol;
00228   public:
00229     void Start(Array<Window*> *list, BOOL rev = FALSE);
00230     Window *Find(uint flgs);   //flgs == WND_...
00231 };
00232 

Generated on Mon Mar 5 09:49:14 2007 for DigiForce by  doxygen 1.4.7