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 "csgeom/csrect.h" 00032 #include "csutil/parray.h" 00033 #include "csutil/array.h" 00034 #include "cstool/cspixmap.h" 00035 #include "cswspal.h" 00036 #include "ivideo/graph2d.h" 00037 #include "ivideo/fontserv.h" 00038 00039 class csApp; 00040 class csSkin; 00041 class csSkinSlice; 00042 struct iEvent; 00043 00044 // this is where we store all the csRect for calculating visible areas and clipping in 00045 typedef csPDelArray<csRect> cswsRectVector; 00046 00073 00074 #define CSS_VISIBLE 0x00000001 00075 00076 #define CSS_FOCUSED 0x00000002 00077 00078 #define CSS_DISABLED 0x00000004 00079 00080 #define CSS_SELECTABLE 0x00000008 00081 00082 #define CSS_GROUP 0x00000010 00083 00084 #define CSS_TOPSELECT 0x00000020 00085 00086 #define CSS_TRANSPARENT 0x00000040 00087 00088 #define CSS_MODAL 0x00000080 00089 00090 #define CSS_MAXIMIZED 0x00000100 00091 00092 #define CSS_DIRTY 0x00000200 00093 00094 #define CSS_RESTART_DIRTY_CHECK 0x00000400 00095 00134 enum 00135 { 00145 cscmdAreYouDefault = 0x80, 00155 cscmdActivate, 00159 cscmdHide, 00163 cscmdMaximize, 00167 cscmdClose, 00176 cscmdLimitMaximize, 00186 cscmdLoseFocus, 00196 cscmdReceiveFocus, 00201 cscmdOK, 00203 cscmdCancel, 00205 cscmdAbort, 00207 cscmdRetry, 00209 cscmdIgnore, 00218 cscmdColorSchemeChanged, 00231 cscmdSkinChanged, 00240 cscmdMoveClipChildren, 00244 cscmdStopModal 00245 }; 00246 00252 00253 #define CS_DRAG_XMIN 0x01 00254 00255 #define CS_DRAG_XMAX 0x02 00256 00257 #define CS_DRAG_YMIN 0x04 00258 00259 #define CS_DRAG_YMAX 0x08 00260 00261 #define CS_DRAG_MOVEABLE 0x10 00262 00263 #define CS_DRAG_SIZEABLE 0x20 00264 00265 #define CS_DRAG_ALL \ 00266 (CS_DRAG_XMIN | CS_DRAG_XMAX | CS_DRAG_YMIN | CS_DRAG_YMAX) 00267 00277 00278 #define CS_LOCK_XMIN 0x01 00279 00280 #define CS_LOCK_XMAX 0x02 00281 00282 #define CS_LOCK_YMIN 0x04 00283 00284 #define CS_LOCK_YMAX 0x08 00285 00286 #define CS_LOCK_ALL \ 00287 (CS_LOCK_XMIN | CS_LOCK_XMAX | CS_LOCK_YMIN | CS_LOCK_YMAX) 00288 00304 00305 #define CS_REPOS_HORIZONTAL 0x10 00306 00307 #define CS_REPOS_VERTICAL 0x20 00308 00309 #define CS_REPOS_H_MASK (CS_REPOS_HORIZONTAL | 0x3) 00310 00311 #define CS_REPOS_V_MASK (CS_REPOS_VERTICAL | 0xc) 00312 00313 #define CS_REPOS_LEFT (CS_REPOS_HORIZONTAL | 0x0) 00314 00315 #define CS_REPOS_RIGHT (CS_REPOS_HORIZONTAL | 0x1) 00316 00317 #define CS_REPOS_HCENTER (CS_REPOS_HORIZONTAL | 0x2) 00318 00319 #define CS_REPOS_HCENTERSIZE (CS_REPOS_HORIZONTAL | 0x3) 00320 00321 #define CS_REPOS_TOP (CS_REPOS_VERTICAL | 0x0) 00322 00323 #define CS_REPOS_BOTTOM (CS_REPOS_VERTICAL | 0x4) 00324 00325 #define CS_REPOS_VCENTER (CS_REPOS_VERTICAL | 0x8) 00326 00327 #define CS_REPOS_VCENTERSIZE (CS_REPOS_VERTICAL | 0xc) 00328 00349 class csComponent 00350 { 00351 protected: 00353 int state; 00355 csRect dirty; 00357 csRect clip; 00359 int *palette, palettesize; 00361 int *originalpalette; 00363 csRect OrgBound; 00365 char DragStyle; 00367 char ResizeMode; 00369 static int dragX, dragY, dragMode; 00371 static csRect *dragBound; 00373 csComponent *clipparent; 00375 char *text; 00377 iFont *Font; 00379 int FontSize; 00381 csArray<csComponent*> clipchildren; 00383 static cswsRectVector *visregion; 00384 00385 public: 00387 csComponent *focused; 00389 csComponent *top; 00391 csComponent *next, *prev; 00393 csComponent *parent; 00395 csApp *app; 00397 csSkinSlice *skinslice; 00399 void** skindata; 00401 unsigned int id; 00403 csRect bound; 00404 00406 csComponent (csComponent *iParent); 00408 virtual ~csComponent (); 00409 00411 virtual void Insert (csComponent *comp); 00412 00414 virtual void Delete (csComponent *comp); 00415 00417 void DeleteAll (); 00418 00420 void InsertClipChild (csComponent *clipchild); 00421 00423 void DeleteClipChild (csComponent *clipchild); 00424 00426 csComponent *GetClipParent () 00427 { return clipparent; } 00428 00430 virtual bool SetFocused (csComponent *comp); 00431 00433 csComponent *GetFocused () 00434 { return focused; } 00435 00437 bool Select (); 00438 00440 virtual csComponent *NextChild (csComponent *start = 0, bool disabled = false); 00441 00443 virtual csComponent *PrevChild (csComponent *start = 0, bool disabled = false); 00444 00446 virtual csComponent *NextControl (csComponent *start = 0); 00447 00449 virtual csComponent *PrevControl (csComponent *start = 0); 00450 00452 virtual csComponent *NextGroup (csComponent *start = 0); 00453 00455 virtual csComponent *PrevGroup (csComponent *start = 0); 00456 00458 bool FixFocused (); 00459 00464 bool SetZorder (csComponent *comp, csComponent *below); 00465 00467 csComponent *GetTop () 00468 { return top; } 00469 00480 void SetPalette (int *iPalette, int iPaletteSize); 00481 00483 void SetPalette (int iPaletteID) 00484 { SetPalette (cswsPalette [iPaletteID].Palette, cswsPalette [iPaletteID].Size); } 00485 00487 void ResetPalette (); 00488 00490 void SetColor (int Index, int Color); 00491 00493 int GetColor (int Index) 00494 { if (Index & 0x80000000) return Index; 00495 if (Index >= palettesize) return cs_Color_Red_L; else return palette[Index]; } 00496 00503 virtual void SetText (const char *iText); 00505 virtual void GetText (char *oText, int iTextSize) const; 00507 virtual const char *GetText () const { return text; } 00508 00515 csComponent *ForEach (bool (*func) (csComponent *child, void *param), 00516 void *param = 0, bool Zorder = false); 00517 00519 csComponent *GetChild (int find_id) const; 00520 00522 void SetApp (csApp *newapp); 00523 00525 virtual bool HandleEvent (iEvent &Event); 00526 00533 virtual bool PreHandleEvent (iEvent &Event); 00534 00536 virtual bool PostHandleEvent (iEvent &Event); 00537 00539 void *SendCommand (int CommandCode, void *Info = 0); 00541 void *SendBroadcast (int CommandCode, void *Info = 0); 00542 00544 csComponent *GetDefault (); 00545 00547 void Redraw (); 00548 00550 virtual void Draw (); 00551 00553 virtual void Show (bool focused = false); 00554 00556 virtual void Hide (); 00557 00559 virtual bool SetRect (int xmin, int ymin, int xmax, int ymax); 00560 00562 bool SetRect (csRect &rect) 00563 { return SetRect (rect.xmin, rect.ymin, rect.xmax, rect.ymax); } 00564 00566 bool SetDragRect (int xmin, int ymin, int xmax, int ymax); 00567 00569 void SetPos (int x, int y) 00570 { SetRect (x, y, x + bound.xmax - bound.xmin, y + bound.ymax - bound.ymin); } 00571 00573 void SetSize (int w, int h) 00574 { SetRect (bound.xmin, bound.ymin, bound.xmin + w, bound.ymin + h); } 00575 00577 void Center (bool iHoriz = true, bool iVert = true); 00578 00580 virtual bool Maximize (); 00581 00583 virtual bool Restore (); 00584 00593 void Invalidate (csRect &area, bool IncludeChildren = false, 00594 csComponent *below = 0); 00595 00597 void Invalidate (int xmin, int ymin, int xmax, int ymax, 00598 bool IncludeChildren = false, csComponent *below = 0) 00599 { 00600 csRect inv (xmin, ymin, xmax, ymax); 00601 Invalidate (inv, IncludeChildren, below); 00602 } 00603 00605 void Invalidate (bool IncludeChildren = false, csComponent *below = 0) 00606 { Invalidate (-99999, -99999, +99999, +99999, IncludeChildren, below); } 00607 00609 virtual void SetState (int mask, bool enable); 00610 00612 int GetState (int mask) 00613 { return (state & mask); } 00614 00616 void SetDragStyle (int iDragStyle) 00617 { DragStyle = iDragStyle; } 00618 00620 int GetDragStyle () 00621 { return DragStyle; } 00622 00624 void SetResizeMode (int iResizeMode) 00625 { ResizeMode = iResizeMode; } 00626 00628 int GetResizeMode () 00629 { return ResizeMode; } 00630 00632 void LocalToGlobal (int &x, int &y); 00633 00635 void GlobalToLocal (int &x, int &y); 00636 00642 void OtherToThis (csComponent *from, int &x, int &y); 00643 00645 void Drag (int x, int y, int DragMode); 00646 00648 void SetMouse (csMouseCursorID Cursor); 00649 00655 virtual void Close (); 00656 00667 csComponent *GetChildAt (int x, int y, 00668 bool (*func) (csComponent *, void *) = 0, void *data = 0); 00669 00674 void SetSizingCursor (int dragtype); 00675 00677 bool GetMousePosition (int &x, int &y); 00678 00701 bool HandleDragEvent (iEvent &Event, int BorderW, int BorderH); 00702 00704 virtual void FixPosition (int &newX, int &newY); 00705 00707 virtual void FixSize (int &newW, int &newH); 00708 00710 virtual void SuggestSize (int &w, int &h); 00711 00713 virtual void SetSuggestedSize (int dw, int dh); 00714 00716 void FindMaxFreeRect (csRect &area); 00717 00719 virtual char *GetSkinName (); 00720 00722 virtual csSkin *GetSkin (); 00723 00741 void SetClipRect (int xmin, int ymin, int xmax, int ymax) 00742 { clip.Set (xmin, ymin, xmax, ymax); } 00743 00745 void SetClipRect () 00746 { clip.MakeEmpty (); } 00747 00749 void SetFont (iFont *iNewFont, int iSize = -1); 00750 00752 virtual void GetFont (iFont *&oFont, int &oFontSize); 00753 00755 void Box (int xmin, int ymin, int xmax, int ymax, int colindx); 00756 00758 void Line (float x1, float y1, float x2, float y2, int colindx); 00759 00761 void Pixel (int x, int y, int colindx); 00762 00764 void Text (int x, int y, int fgindx, int bgindx, const char *s); 00765 00767 void Pixmap (csPixmap *s2d, int x, int y, int w, int h, uint8 Alpha = 0); 00769 void Pixmap (csPixmap *s2d, int x, int y, uint8 Alpha = 0) 00770 { Pixmap (s2d, x, y, s2d->Width (), s2d->Height (), Alpha); } 00772 void Pixmap (csPixmap *s2d, int x, int y, int w, int h, int orgx, int orgy, 00773 uint8 Alpha = 0); 00775 void Texture (iTextureHandle *tex, int x, int y, int w, int h, 00776 int orgx, int orgy, uint8 Alpha = 0); 00777 00779 int GetTextSize (const char *text, int *oHeight = 0); 00781 int GetTextChars (const char *text, int iWidth); 00782 00784 void Rect3D (int xmin, int ymin, int xmax, int ymax, int darkindx, int lightindx); 00785 00787 void ObliqueRect3D (int xmin, int ymin, int xmax, int ymax, int cornersize, 00788 int darkindx, int lightindx); 00789 00791 void Clear (int colindx) 00792 { Box (0, 0, bound.Width (), bound.Height (), colindx); } 00793 00795 void ClearZbuffer (int xmin, int ymin, int xmax, int ymax); 00796 00798 void ClearZbuffer () 00799 { ClearZbuffer (0, 0, bound.Width (), bound.Height ()); } 00800 00802 void Polygon3D (G3DPolygonDPFX &poly, uint mode); 00803 00805 00807 void DrawUnderline (int iX, int iY, const char *iText, int iUnderlinePos, 00808 int iColor); 00809 00810 protected: 00816 void Clip (cswsRectVector &rect, csComponent *last, bool forchild = false); 00817 00819 void ClipChild (cswsRectVector &rect, csComponent *child); 00820 00827 void FastClip (cswsRectVector &rect); 00828 00834 static void PrepareLabel (const char *iLabel, char * &oLabel, int &oUnderlinePos); 00835 00837 bool CheckHotKey (iEvent &iEvent, char iHotKey); 00838 00840 static int WordLeft (const char *iText, int StartPos); 00842 static int WordRight (const char *iText, int StartPos); 00843 00845 bool ApplySkin (csSkin *Skin); 00846 00855 void CheckDirtyTD (csRect &ioR); 00863 void CheckDirtyBU (csRect &ioR); 00864 00865 private: 00866 static bool do_handle_event (csComponent *child, void *param); 00867 }; 00868 00871 #endif // __CS_CSCOMP_H__
Generated for Crystal Space by doxygen 1.2.18