CrystalSpace

Public API Reference

Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

csbutton.h

Go to the documentation of this file.
00001 /*
00002     Crystal Space Windowing System: button class
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 
00021 #ifndef __CS_CSBUTTON_H__
00022 #define __CS_CSBUTTON_H__
00023 
00032 #include "csextern.h"
00033  
00034 #include "cscomp.h"
00035 
00039 
00040 #define CSBS_SHIFT              0x00000001
00041 
00042 #define CSBS_DEFAULT            0x00000002
00043 
00044 #define CSBS_NODEFAULTBORDER    0x00000004
00045 
00046 #define CSBS_SELECTABLE         0x00000008
00047 
00048 #define CSBS_NOMOUSEFOCUS       0x00000010
00049 
00050 #define CSBS_NOKEYBOARDFOCUS    0x00000020
00051 
00057 #define CSBS_MULTICHOOSE        0x00000040
00058 
00059 #define CSBS_DISMISS            0x00000080
00060 
00061 #define CSBS_TEXTPLACEMENT      0x00030000
00062 
00063 #define CSBS_TEXTABOVE          0x00000000
00064 
00065 #define CSBS_TEXTBELOW          0x00010000
00066 
00067 #define CSBS_TEXTONTOP          0x00020000
00068 
00070 #define CSBS_DEFAULTVALUE       \
00071         (CSBS_SHIFT | CSBS_SELECTABLE | CSBS_TEXTBELOW)
00072 
00075 
00076 enum
00077 {
00086   cscmdButtonDown = 0x00000500,
00095   cscmdButtonUp,
00104   cscmdButtonRightClick,
00113   cscmdButtonDeselect
00114 };
00115 
00117 enum csButtonFrameStyle
00118 {
00120   csbfsNone,
00122   csbfsOblique,
00124   csbfsThickRect,
00126   csbfsThinRect,
00128   csbfsVeryThinRect,
00130   csbfsTextured,
00132   csbfsBitmap
00133 };
00134 
00139 class CS_CSWS_EXPORT csButton : public csComponent
00140 {
00141 protected:
00143   csPixmap *ImageNormal, *ImagePressed;
00144 
00149   csPixmap *FrameNormal, *FramePressed, *FrameHighlighted;
00150 
00152   bool delImages;
00154   bool delFrameImages;
00156   int CommandCode;
00158   size_t underline_pos;
00160   int ButtonStyle;
00162   csButtonFrameStyle FrameStyle;
00164   int TexOrgX, TexOrgY;
00166   uint8 ButtonAlpha;
00168   bool DrawTextOnHighlightOnly;
00169 
00170 public:
00172   bool Pressed;
00174   bool Highlighted;
00176   csButton (csComponent *iParent, int iCommandCode, int iButtonStyle =
00177     CSBS_DEFAULTVALUE, csButtonFrameStyle iFrameStyle = csbfsOblique);
00179   virtual ~csButton ();
00180 
00182   virtual void SetText (const char *iText)
00183   { PrepareLabel (iText, text, underline_pos); Invalidate (); }
00184 
00186  void SetDrawTextOnHighlightOnly(bool iTOHO)
00187  { DrawTextOnHighlightOnly = iTOHO; }
00188 
00190  bool GetDrawTextOnHighlightOnly()
00191  { return DrawTextOnHighlightOnly; }
00192 
00198   void SetBitmap (csPixmap *iNormal, csPixmap *iPressed, bool iDelete = true);
00199 
00205   void SetFrameBitmaps (csPixmap *iNormal, csPixmap *iPressed, csPixmap *iHighlighted, bool iDelete = true);
00206 
00212   void SetButtonTexture (csPixmap *iNormal, csPixmap *iPressed, bool iDelete = true);
00213 
00214 
00216   void GetBitmap (csPixmap **iNormal, csPixmap **iPressed);
00217 
00219   void GetFrameBitmaps (csPixmap **iNormal, csPixmap **iPressed, csPixmap **iHighlighted);
00220 
00222   void FreeBitmaps ();
00223 
00225   void FreeFrameBitmaps ();
00226 
00228   virtual bool HandleEvent (iEvent &Event);
00229 
00231   virtual bool PostHandleEvent (iEvent &Event);
00232 
00234   virtual void SetState (int mask, bool enable);
00235 
00237   virtual void SuggestSize (int &w, int &h);
00238 
00240   void SetCommandCode (int iCommandCode)
00241   { CommandCode = iCommandCode; }
00242 
00244   int GetCommandCode ()
00245   { return CommandCode; }
00246 
00248   virtual void SetPressed (bool state);
00249 
00251   inline int GetButtonStyle ()
00252   { return ButtonStyle; }
00253 
00255   inline csButtonFrameStyle GetFrameStyle ()
00256   { return FrameStyle; }
00257 
00259   inline size_t GetUnderlinePos ()
00260   { return underline_pos; }
00261 
00263   inline uint8 GetAlpha()
00264   { return ButtonAlpha; }
00265 
00267   void SetAlpha(uint8 iAlpha);
00268 
00270   void SetTextureOrigin(int iOrgX, int iOrgy);
00271 
00273   void GetTextureOrigin(int *iOrgx, int *iOrgy);
00274 
00276   virtual char *GetSkinName ()
00277   { return "Button"; }
00278 
00279 protected:
00281   virtual void Press ();
00282 
00284   bool HandleKeyPress (iEvent &Event);
00285 
00287   void DeselectNeighbours ();
00288 };
00289 
00292 #endif // __CS_CSBUTTON_H__

Generated for Crystal Space by doxygen 1.3.9.1