Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members  

cscomp.h

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 __CSCOMP_H__
00021 #define __CSCOMP_H__
00022 
00023 #include "csgeom/csrect.h"
00024 #include "csutil/typedvec.h"
00025 #include "cstool/cspixmap.h"
00026 #include "cswspal.h"
00027 #include "ivideo/graph2d.h"
00028 #include "ivideo/fontserv.h"
00029 
00030 class csApp;
00031 class csSkin;
00032 class csSkinSlice;
00033 struct iEvent;
00034 
00035 // this is where we store all the csRect for calculating visible areas and clipping in
00036 CS_DECLARE_TYPED_VECTOR (cswsRectVector, csRect);
00037 
00064 
00065 #define CSS_VISIBLE             0x00000001
00066 
00067 #define CSS_FOCUSED             0x00000002
00068 
00069 #define CSS_DISABLED            0x00000004
00070 
00071 #define CSS_SELECTABLE          0x00000008
00072 
00073 #define CSS_GROUP               0x00000010
00074 
00075 #define CSS_TOPSELECT           0x00000020
00076 
00077 #define CSS_TRANSPARENT         0x00000040
00078 
00079 #define CSS_MODAL               0x00000080
00080 
00081 #define CSS_MAXIMIZED           0x00000100
00082 
00083 #define CSS_DIRTY               0x00000200
00084 
00085 #define CSS_RESTART_DIRTY_CHECK 0x00000400
00086 
00124 enum
00125 {
00135   cscmdAreYouDefault = 0x80,
00145   cscmdActivate,
00149   cscmdHide,
00153   cscmdMaximize,
00157   cscmdClose,
00166   cscmdLimitMaximize,
00176   cscmdLoseFocus,
00186   cscmdReceiveFocus,
00191   cscmdOK,
00193   cscmdCancel,
00195   cscmdAbort,
00197   cscmdRetry,
00199   cscmdIgnore,
00208   cscmdColorSchemeChanged,
00221   cscmdSkinChanged,
00230   cscmdMoveClipChildren,
00234   cscmdStopModal
00235 };
00236 
00241 
00242 #define CS_DRAG_XMIN            0x01
00243 
00244 #define CS_DRAG_XMAX            0x02
00245 
00246 #define CS_DRAG_YMIN            0x04
00247 
00248 #define CS_DRAG_YMAX            0x08
00249 
00250 #define CS_DRAG_MOVEABLE        0x10
00251 
00252 #define CS_DRAG_SIZEABLE        0x20
00253 
00254 #define CS_DRAG_ALL             (CS_DRAG_XMIN | CS_DRAG_XMAX | \
00255                                  CS_DRAG_YMIN | CS_DRAG_YMAX)
00256 
00265 
00266 #define CS_LOCK_XMIN            0x01
00267 
00268 #define CS_LOCK_XMAX            0x02
00269 
00270 #define CS_LOCK_YMIN            0x04
00271 
00272 #define CS_LOCK_YMAX            0x08
00273 
00274 #define CS_LOCK_ALL             (CS_LOCK_XMIN | CS_LOCK_XMAX | \
00275                                  CS_LOCK_YMIN | CS_LOCK_YMAX)
00276 
00289 
00290 #define CS_REPOS_HORIZONTAL     0x10
00291 
00292 #define CS_REPOS_VERTICAL       0x20
00293 
00294 #define CS_REPOS_H_MASK         (CS_REPOS_HORIZONTAL | 0x3)
00295 
00296 #define CS_REPOS_V_MASK         (CS_REPOS_VERTICAL | 0xc)
00297 
00298 #define CS_REPOS_LEFT           (CS_REPOS_HORIZONTAL | 0x0)
00299 
00300 #define CS_REPOS_RIGHT          (CS_REPOS_HORIZONTAL | 0x1)
00301 
00302 #define CS_REPOS_HCENTER        (CS_REPOS_HORIZONTAL | 0x2)
00303 
00304 #define CS_REPOS_HCENTERSIZE    (CS_REPOS_HORIZONTAL | 0x3)
00305 
00306 #define CS_REPOS_TOP            (CS_REPOS_VERTICAL | 0x0)
00307 
00308 #define CS_REPOS_BOTTOM         (CS_REPOS_VERTICAL | 0x4)
00309 
00310 #define CS_REPOS_VCENTER        (CS_REPOS_VERTICAL | 0x8)
00311 
00312 #define CS_REPOS_VCENTERSIZE    (CS_REPOS_VERTICAL | 0xc)
00313 
00333 class csComponent
00334 {
00335 protected:
00337   int state;
00339   csRect dirty;
00341   csRect clip;
00343   int *palette, palettesize;
00345   int *originalpalette;
00347   csRect OrgBound;
00349   char DragStyle;
00351   char ResizeMode;
00353   static int dragX, dragY, dragMode;
00355   static csRect *dragBound;
00357   csComponent *clipparent;
00359   char *text;
00361   iFont *Font;
00363   int FontSize;
00365   csVector clipchildren;
00367   static cswsRectVector *visregion;
00368 
00369 public:
00371   csComponent *focused;
00373   csComponent *top;
00375   csComponent *next, *prev;
00377   csComponent *parent;
00379   csApp *app;
00381   csSkinSlice *skinslice;
00383   csSome *skindata;
00385   unsigned int id;
00387   csRect bound;
00388 
00390   csComponent (csComponent *iParent);
00392   virtual ~csComponent ();
00393 
00395   virtual void Insert (csComponent *comp);
00396 
00398   virtual void Delete (csComponent *comp);
00399 
00401   void DeleteAll ();
00402 
00404   void InsertClipChild (csComponent *clipchild);
00405 
00407   void DeleteClipChild (csComponent *clipchild);
00408 
00410   csComponent *GetClipParent ()
00411   { return clipparent; }
00412 
00414   virtual bool SetFocused (csComponent *comp);
00415 
00417   csComponent *GetFocused ()
00418   { return focused; }
00419 
00421   bool Select ();
00422 
00424   virtual csComponent *NextChild (csComponent *start = NULL, bool disabled = false);
00425 
00427   virtual csComponent *PrevChild (csComponent *start = NULL, bool disabled = false);
00428 
00430   virtual csComponent *NextControl (csComponent *start = NULL);
00431 
00433   virtual csComponent *PrevControl (csComponent *start = NULL);
00434 
00436   virtual csComponent *NextGroup (csComponent *start = NULL);
00437 
00439   virtual csComponent *PrevGroup (csComponent *start = NULL);
00440 
00442   bool FixFocused ();
00443 
00448   bool SetZorder (csComponent *comp, csComponent *below);
00449 
00451   csComponent *GetTop ()
00452   { return top; }
00453 
00464   void SetPalette (int *iPalette, int iPaletteSize);
00465 
00467   void SetPalette (int iPaletteID)
00468   { SetPalette (cswsPalette [iPaletteID].Palette, cswsPalette [iPaletteID].Size); }
00469 
00471   void ResetPalette ();
00472 
00474   void SetColor (int Index, int Color);
00475 
00477   int GetColor (int Index)
00478    { if (Index & 0x80000000) return Index;
00479     if (Index >= palettesize) return cs_Color_Red_L; else return palette[Index]; }
00480 
00487   virtual void SetText (const char *iText);
00489   virtual void GetText (char *oText, int iTextSize) const;
00491   virtual const char *GetText () const { return text; }
00492 
00499   csComponent *ForEach (bool (*func) (csComponent *child, void *param),
00500     void *param = NULL, bool Zorder = false);
00501 
00503   csComponent *GetChild (int find_id) const;
00504 
00506   void SetApp (csApp *newapp);
00507 
00509   virtual bool HandleEvent (iEvent &Event);
00510 
00517   virtual bool PreHandleEvent (iEvent &Event);
00518 
00520   virtual bool PostHandleEvent (iEvent &Event);
00521 
00523   void *SendCommand (int CommandCode, void *Info = NULL);
00525   void *SendBroadcast (int CommandCode, void *Info = NULL);
00526 
00528   csComponent *GetDefault ();
00529 
00531   void Redraw ();
00532 
00534   virtual void Draw ();
00535 
00537   virtual void Show (bool focused = false);
00538 
00540   virtual void Hide ();
00541 
00543   virtual bool SetRect (int xmin, int ymin, int xmax, int ymax);
00544 
00546   bool SetRect (csRect &rect)
00547   { return SetRect (rect.xmin, rect.ymin, rect.xmax, rect.ymax); }
00548 
00550   bool SetDragRect (int xmin, int ymin, int xmax, int ymax);
00551 
00553   void SetPos (int x, int y)
00554   { SetRect (x, y, x + bound.xmax - bound.xmin, y + bound.ymax - bound.ymin); }
00555 
00557   void SetSize (int w, int h)
00558   { SetRect (bound.xmin, bound.ymin, bound.xmin + w, bound.ymin + h); }
00559 
00561   void Center (bool iHoriz = true, bool iVert = true);
00562 
00564   virtual bool Maximize ();
00565 
00567   virtual bool Restore ();
00568 
00577   void Invalidate (csRect &area, bool IncludeChildren = false,
00578     csComponent *below = NULL);
00579 
00581   void Invalidate (int xmin, int ymin, int xmax, int ymax,
00582     bool IncludeChildren = false, csComponent *below = NULL)
00583   {
00584     csRect inv (xmin, ymin, xmax, ymax);
00585     Invalidate (inv, IncludeChildren, below);
00586   }
00587 
00589   void Invalidate (bool IncludeChildren = false, csComponent *below = NULL)
00590   { Invalidate (-99999, -99999, +99999, +99999, IncludeChildren, below); }
00591 
00593   virtual void SetState (int mask, bool enable);
00594 
00596   int GetState (int mask)
00597   { return (state & mask); }
00598 
00600   void SetDragStyle (int iDragStyle)
00601   { DragStyle = iDragStyle; }
00602 
00604   int GetDragStyle ()
00605   { return DragStyle; }
00606 
00608   void SetResizeMode (int iResizeMode)
00609   { ResizeMode = iResizeMode; }
00610 
00612   int GetResizeMode ()
00613   { return ResizeMode; }
00614 
00616   void LocalToGlobal (int &x, int &y);
00617 
00619   void GlobalToLocal (int &x, int &y);
00620 
00626   void OtherToThis (csComponent *from, int &x, int &y);
00627 
00629   void Drag (int x, int y, int DragMode);
00630 
00632   void SetMouse (csMouseCursorID Cursor);
00633 
00639   virtual void Close ();
00640 
00651   csComponent *GetChildAt (int x, int y,
00652     bool (*func) (csComponent *, void *) = NULL, void *data = NULL);
00653 
00658   void SetSizingCursor (int dragtype);
00659 
00661   bool GetMousePosition (int &x, int &y);
00662 
00685   bool HandleDragEvent (iEvent &Event, int BorderW, int BorderH);
00686 
00688   virtual void FixPosition (int &newX, int &newY);
00689 
00691   virtual void FixSize (int &newW, int &newH);
00692 
00694   virtual void SuggestSize (int &w, int &h);
00695 
00697   virtual void SetSuggestedSize (int dw, int dh);
00698 
00700   void FindMaxFreeRect (csRect &area);
00701 
00703   virtual char *GetSkinName ();
00704 
00706   virtual csSkin *GetSkin ();
00707 
00725   void SetClipRect (int xmin, int ymin, int xmax, int ymax)
00726   { clip.Set (xmin, ymin, xmax, ymax); }
00727 
00729   void SetClipRect ()
00730   { clip.MakeEmpty (); }
00731 
00733   void SetFont (iFont *iNewFont, int iSize = -1);
00734 
00736   virtual void GetFont (iFont *&oFont, int &oFontSize);
00737 
00739   void Box (int xmin, int ymin, int xmax, int ymax, int colindx);
00740 
00742   void Line (float x1, float y1, float x2, float y2, int colindx);
00743 
00745   void Pixel (int x, int y, int colindx);
00746 
00748   void Text (int x, int y, int fgindx, int bgindx, const char *s);
00749 
00751   void Pixmap (csPixmap *s2d, int x, int y, int w, int h, uint8 Alpha = 0);
00753   void Pixmap (csPixmap *s2d, int x, int y, uint8 Alpha = 0)
00754   { Pixmap (s2d, x, y, s2d->Width (), s2d->Height (), Alpha); }
00756   void Pixmap (csPixmap *s2d, int x, int y, int w, int h, int orgx, int orgy,
00757     uint8 Alpha = 0);
00759   void Texture (iTextureHandle *tex, int x, int y, int w, int h,
00760     int orgx, int orgy, uint8 Alpha = 0);
00761 
00763   int GetTextSize (const char *text, int *oHeight = NULL);
00765   int GetTextChars (const char *text, int iWidth);
00766 
00768   void Rect3D (int xmin, int ymin, int xmax, int ymax, int darkindx, int lightindx);
00769 
00771   void ObliqueRect3D (int xmin, int ymin, int xmax, int ymax, int cornersize,
00772     int darkindx, int lightindx);
00773 
00775   void Clear (int colindx)
00776   { Box (0, 0, bound.Width (), bound.Height (), colindx); }
00777 
00779   void ClearZbuffer (int xmin, int ymin, int xmax, int ymax);
00780 
00782   void ClearZbuffer ()
00783   { ClearZbuffer (0, 0, bound.Width (), bound.Height ()); }
00784 
00786   void Polygon3D (G3DPolygonDPFX &poly, uint mode);
00787 
00789 
00791   void DrawUnderline (int iX, int iY, const char *iText, int iUnderlinePos,
00792     int iColor);
00793 
00794 protected:
00800   void Clip (cswsRectVector &rect, csComponent *last, bool forchild = false);
00801 
00803   void ClipChild (cswsRectVector &rect, csComponent *child);
00804 
00811   void FastClip (cswsRectVector &rect);
00812 
00818   static void PrepareLabel (const char *iLabel, char * &oLabel, int &oUnderlinePos);
00819 
00821   bool CheckHotKey (iEvent &iEvent, char iHotKey);
00822 
00824   static int WordLeft (const char *iText, int StartPos);
00826   static int WordRight (const char *iText, int StartPos);
00827 
00829   bool ApplySkin (csSkin *Skin);
00830 
00839   void CheckDirtyTD (csRect &ioR);
00847   void CheckDirtyBU (csRect &ioR);
00848 
00849 private:
00850   static bool do_handle_event (csComponent *child, void *param);
00851 };
00852 
00853 #endif // __CSCOMP_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000