csws/cscomp.h
Go to the documentation of this file.00001 /* 00002 Crystal Space Windowing System: Windowing System Component interface 00003 Copyright (C) 1998,1999 by Andrew Zabolotny <bit@eltech.ru> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_CSCOMP_H__ 00021 #define __CS_CSCOMP_H__ 00022 00031 #include "csextern.h" 00032 00033 #include "csgeom/csrect.h" 00034 #include "csutil/parray.h" 00035 #include "csutil/array.h" 00036 #include "cstool/cspixmap.h" 00037 #include "cswspal.h" 00038 #include "ivideo/graph2d.h" 00039 #include "ivideo/fontserv.h" 00040 00041 class csApp; 00042 class csSkin; 00043 class csSkinSlice; 00044 struct iEvent; 00045 00046 // this is where we store all the csRect for calculating visible areas and clipping in 00047 typedef csPDelArray<csRect> cswsRectVector; 00048 00075 00076 #define CSS_VISIBLE 0x00000001 00077 00078 #define CSS_FOCUSED 0x00000002 00079 00080 #define CSS_DISABLED 0x00000004 00081 00082 #define CSS_SELECTABLE 0x00000008 00083 00084 #define CSS_GROUP 0x00000010 00085 00086 #define CSS_TOPSELECT 0x00000020 00087 00088 #define CSS_TRANSPARENT 0x00000040 00089 00090 #define CSS_MODAL 0x00000080 00091 00092 #define CSS_MAXIMIZED 0x00000100 00093 00094 #define CSS_DIRTY 0x00000200 00095 00096 #define CSS_RESTART_DIRTY_CHECK 0x00000400 00097 00136 enum 00137 { 00147 cscmdAreYouDefault = 0x80, 00157 cscmdActivate, 00161 cscmdHide, 00165 cscmdMaximize, 00169 cscmdClose, 00178 cscmdLimitMaximize, 00188 cscmdLoseFocus, 00198 cscmdReceiveFocus, 00203 cscmdOK, 00205 cscmdCancel, 00207 cscmdAbort, 00209 cscmdRetry, 00211 cscmdIgnore, 00220 cscmdColorSchemeChanged, 00233 cscmdSkinChanged, 00242 cscmdMoveClipChildren, 00246 cscmdStopModal 00247 }; 00248 00254 00255 #define CS_DRAG_XMIN 0x01 00256 00257 #define CS_DRAG_XMAX 0x02 00258 00259 #define CS_DRAG_YMIN 0x04 00260 00261 #define CS_DRAG_YMAX 0x08 00262 00263 #define CS_DRAG_MOVEABLE 0x10 00264 00265 #define CS_DRAG_SIZEABLE 0x20 00266 00267 #define CS_DRAG_ALL \ 00268 (CS_DRAG_XMIN | CS_DRAG_XMAX | CS_DRAG_YMIN | CS_DRAG_YMAX) 00269 00279 00280 #define CS_LOCK_XMIN 0x01 00281 00282 #define CS_LOCK_XMAX 0x02 00283 00284 #define CS_LOCK_YMIN 0x04 00285 00286 #define CS_LOCK_YMAX 0x08 00287 00288 #define CS_LOCK_ALL \ 00289 (CS_LOCK_XMIN | CS_LOCK_XMAX | CS_LOCK_YMIN | CS_LOCK_YMAX) 00290 00306 00307 #define CS_REPOS_HORIZONTAL 0x10 00308 00309 #define CS_REPOS_VERTICAL 0x20 00310 00311 #define CS_REPOS_H_MASK (CS_REPOS_HORIZONTAL | 0x3) 00312 00313 #define CS_REPOS_V_MASK (CS_REPOS_VERTICAL | 0xc) 00314 00315 #define CS_REPOS_LEFT (CS_REPOS_HORIZONTAL | 0x0) 00316 00317 #define CS_REPOS_RIGHT (CS_REPOS_HORIZONTAL | 0x1) 00318 00319 #define CS_REPOS_HCENTER (CS_REPOS_HORIZONTAL | 0x2) 00320 00321 #define CS_REPOS_HCENTERSIZE (CS_REPOS_HORIZONTAL | 0x3) 00322 00323 #define CS_REPOS_TOP (CS_REPOS_VERTICAL | 0x0) 00324 00325 #define CS_REPOS_BOTTOM (CS_REPOS_VERTICAL | 0x4) 00326 00327 #define CS_REPOS_VCENTER (CS_REPOS_VERTICAL | 0x8) 00328 00329 #define CS_REPOS_VCENTERSIZE (CS_REPOS_VERTICAL | 0xc) 00330 00351 class CS_CSWS_EXPORT csComponent 00352 { 00353 protected: 00355 int state; 00357 csRect dirty; 00359 csRect clip; 00361 int *palette, palettesize; 00363 int *originalpalette; 00365 csRect OrgBound; 00367 char DragStyle; 00369 char ResizeMode; 00371 static int dragX; 00372 static int dragY; 00373 static int dragMode; 00375 static csRect *dragBound; 00377 csComponent *clipparent; 00379 char *text; 00381 iFont *Font; 00383 int FontSize; 00385 csArray<csComponent*> clipchildren; 00387 static cswsRectVector *visregion; 00388 00389 public: 00391 csComponent *focused; 00393 csComponent *top; 00395 csComponent *next, *prev; 00397 csComponent *parent; 00399 csApp *app; 00401 csSkinSlice *skinslice; 00403 void** skindata; 00405 unsigned int id; 00407 csRect bound; 00408 00410 csComponent (csComponent *iParent); 00412 virtual ~csComponent (); 00413 00415 virtual void Insert (csComponent *comp); 00416 00418 virtual void Delete (csComponent *comp); 00419 00421 void DeleteAll (); 00422 00424 void InsertClipChild (csComponent *clipchild); 00425 00427 void DeleteClipChild (csComponent *clipchild); 00428 00430 csComponent *GetClipParent () 00431 { return clipparent; } 00432 00434 virtual bool SetFocused (csComponent *comp); 00435 00437 csComponent *GetFocused () 00438 { return focused; } 00439 00441 bool Select (); 00442 00444 virtual csComponent *NextChild (csComponent *start = 0, bool disabled = false); 00445 00447 virtual csComponent *PrevChild (csComponent *start = 0, bool disabled = false); 00448 00450 virtual csComponent *NextControl (csComponent *start = 0); 00451 00453 virtual csComponent *PrevControl (csComponent *start = 0); 00454 00456 virtual csComponent *NextGroup (csComponent *start = 0); 00457 00459 virtual csComponent *PrevGroup (csComponent *start = 0); 00460 00462 bool FixFocused (); 00463 00468 bool SetZorder (csComponent *comp, csComponent *below); 00469 00471 csComponent *GetTop () 00472 { return top; } 00473 00484 void SetPalette (int *iPalette, int iPaletteSize); 00485 00487 void SetPalette (int iPaletteID) 00488 { SetPalette (cswsPalette [iPaletteID].Palette, cswsPalette [iPaletteID].Size); } 00489 00491 void ResetPalette (); 00492 00494 void SetColor (int Index, int Color); 00495 00497 int GetColor (int Index) 00498 { if (Index & 0x80000000) return Index; 00499 if (Index >= palettesize) return cs_Color_Red_L; else return palette[Index]; } 00500 00507 virtual void SetText (const char *iText); 00509 virtual void GetText (char *oText, int iTextSize) const; 00511 virtual const char *GetText () const { return text; } 00512 00519 csComponent *ForEach (bool (*func) (csComponent *child, void *param), 00520 void *param = 0, bool Zorder = false); 00521 00523 csComponent *GetChild (int find_id) const; 00524 00526 void SetApp (csApp *newapp); 00527 00529 virtual bool HandleEvent (iEvent &Event); 00530 00537 virtual bool PreHandleEvent (iEvent &Event); 00538 00540 virtual bool PostHandleEvent (iEvent &Event); 00541 00543 void *SendCommand (int CommandCode, void *Info = 0); 00545 void *SendBroadcast (int CommandCode, void *Info = 0); 00546 00548 csComponent *GetDefault (); 00549 00551 void Redraw (); 00552 00554 virtual void Draw (); 00555 00557 virtual void Show (bool focused = false); 00558 00560 virtual void Hide (); 00561 00563 virtual bool SetRect (int xmin, int ymin, int xmax, int ymax); 00564 00566 bool SetRect (csRect &rect) 00567 { return SetRect (rect.xmin, rect.ymin, rect.xmax, rect.ymax); } 00568 00570 bool SetDragRect (int xmin, int ymin, int xmax, int ymax); 00571 00573 void SetPos (int x, int y) 00574 { SetRect (x, y, x + bound.xmax - bound.xmin, y + bound.ymax - bound.ymin); } 00575 00577 void SetSize (int w, int h) 00578 { SetRect (bound.xmin, bound.ymin, bound.xmin + w, bound.ymin + h); } 00579 00581 void Center (bool iHoriz = true, bool iVert = true); 00582 00584 virtual bool Maximize (); 00585 00587 virtual bool Restore (); 00588 00597 void Invalidate (csRect &area, bool IncludeChildren = false, 00598 csComponent *below = 0); 00599 00601 void Invalidate (int xmin, int ymin, int xmax, int ymax, 00602 bool IncludeChildren = false, csComponent *below = 0) 00603 { 00604 csRect inv (xmin, ymin, xmax, ymax); 00605 Invalidate (inv, IncludeChildren, below); 00606 } 00607 00609 void Invalidate (bool IncludeChildren = false, csComponent *below = 0) 00610 { Invalidate (-99999, -99999, +99999, +99999, IncludeChildren, below); } 00611 00613 virtual void SetState (int mask, bool enable); 00614 00616 int GetState (int mask) 00617 { return (state & mask); } 00618 00620 void SetDragStyle (int iDragStyle) 00621 { DragStyle = iDragStyle; } 00622 00624 int GetDragStyle () 00625 { return DragStyle; } 00626 00628 void SetResizeMode (int iResizeMode) 00629 { ResizeMode = iResizeMode; } 00630 00632 int GetResizeMode () 00633 { return ResizeMode; } 00634 00636 void LocalToGlobal (int &x, int &y); 00637 00639 void GlobalToLocal (int &x, int &y); 00640 00646 void OtherToThis (csComponent *from, int &x, int &y); 00647 00649 void Drag (int x, int y, int DragMode); 00650 00652 void SetMouse (csMouseCursorID Cursor); 00653 00659 virtual void Close (); 00660 00671 csComponent *GetChildAt (int x, int y, 00672 bool (*func) (csComponent *, void *) = 0, void *data = 0); 00673 00678 void SetSizingCursor (int dragtype); 00679 00681 bool GetMousePosition (int &x, int &y); 00682 00705 bool HandleDragEvent (iEvent &Event, int BorderW, int BorderH); 00706 00708 virtual void FixPosition (int &newX, int &newY); 00709 00711 virtual void FixSize (int &newW, int &newH); 00712 00714 virtual void SuggestSize (int &w, int &h); 00715 00717 virtual void SetSuggestedSize (int dw, int dh); 00718 00720 void FindMaxFreeRect (csRect &area); 00721 00723 virtual char *GetSkinName (); 00724 00726 virtual csSkin *GetSkin (); 00727 00745 void SetClipRect (int xmin, int ymin, int xmax, int ymax) 00746 { clip.Set (xmin, ymin, xmax, ymax); } 00747 00749 void SetClipRect () 00750 { clip.MakeEmpty (); } 00751 00753 void SetFont (iFont *iNewFont); 00754 00756 virtual void GetFont (iFont *&oFont); 00757 00759 void Box (int xmin, int ymin, int xmax, int ymax, int colindx); 00760 00762 void Line (float x1, float y1, float x2, float y2, int colindx); 00763 00765 void Pixel (int x, int y, int colindx); 00766 00768 void Text (int x, int y, int fgindx, int bgindx, const char *s); 00769 00771 void Pixmap (csPixmap *s2d, int x, int y, int w, int h, uint8 Alpha = 0); 00773 void Pixmap (csPixmap *s2d, int x, int y, uint8 Alpha = 0) 00774 { Pixmap (s2d, x, y, s2d->Width (), s2d->Height (), Alpha); } 00776 void Pixmap (csPixmap *s2d, int x, int y, int w, int h, int orgx, int orgy, 00777 uint8 Alpha = 0); 00779 void Texture (iTextureHandle *tex, int x, int y, int w, int h, 00780 int orgx, int orgy, uint8 Alpha = 0); 00781 00783 int GetTextSize (const char *text, int *oHeight = 0); 00785 int GetTextChars (const char *text, int iWidth); 00786 00788 void Rect3D (int xmin, int ymin, int xmax, int ymax, int darkindx, int lightindx); 00789 00791 void ObliqueRect3D (int xmin, int ymin, int xmax, int ymax, int cornersize, 00792 int darkindx, int lightindx); 00793 00795 void Clear (int colindx) 00796 { Box (0, 0, bound.Width (), bound.Height (), colindx); } 00797 00799 void ClearZbuffer (int xmin, int ymin, int xmax, int ymax); 00800 00802 void ClearZbuffer () 00803 { ClearZbuffer (0, 0, bound.Width (), bound.Height ()); } 00804 00806 void Polygon3D (G3DPolygonDPFX &poly, uint mode); 00807 00809 00811 void DrawUnderline (int iX, int iY, const char *iText, int iUnderlinePos, 00812 int iColor); 00813 00814 protected: 00820 void Clip (cswsRectVector &rect, csComponent *last, bool forchild = false); 00821 00823 void ClipChild (cswsRectVector &rect, csComponent *child); 00824 00831 void FastClip (cswsRectVector &rect); 00832 00838 static void PrepareLabel (const char *iLabel, char * &oLabel, int &oUnderlinePos); 00839 00841 bool CheckHotKey (iEvent &iEvent, char iHotKey); 00842 00844 static int WordLeft (const char *iText, int StartPos); 00846 static int WordRight (const char *iText, int StartPos); 00847 00849 bool ApplySkin (csSkin *Skin); 00850 00859 void CheckDirtyTD (csRect &ioR); 00867 void CheckDirtyBU (csRect &ioR); 00868 00869 private: 00870 static bool do_handle_event (csComponent *child, void *param); 00871 }; 00872 00875 #endif // __CS_CSCOMP_H__
Generated for Crystal Space by doxygen 1.2.18