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

pgwidget.h

Go to the documentation of this file.
00001 /*
00002     ParaGUI - crossplatform widgetset
00003     Copyright (C) 2000,2001,2002  Alexander Pipelka
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     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  
00019     Alexander Pipelka
00020     pipelka@teleweb.at
00021  
00022     Last Update:      $Author: mbickel $
00023     Update Date:      $Date: 2007-04-13 16:15:57 $
00024     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/include/pgwidget.h,v $
00025     CVS/RCS Revision: $Revision: 1.2 $
00026     Status:           $State: Exp $
00027 */
00028 
00033 #ifndef PG_WIDGET_H
00034 #define PG_WIDGET_H
00035 
00036 #include "pgmessageobject.h"
00037 #include "pgrectlist.h"
00038 #include "pgfont.h"
00039 #include "pgstring.h"
00040 
00041 #include MAP_INC
00042 
00043 class PG_Widget;
00044 class PG_WidgetDataInternal;
00045 
00081 class DECLSPEC PG_Widget : public PG_MessageObject, public PG_Rect  {
00082 public:
00083 
00084 
00086         typedef enum {
00087             ACT_ACTIVATE,       
00088             ACT_DEACTIVATE,     
00089             ACT_OK,     
00090             ACT_CANCEL, 
00091             ACT_LEFT,   
00092             ACT_RIGHT,  
00093             ACT_UP,     
00094             ACT_DOWN    
00095         } KeyAction;
00096 
00105         //PG_Widget(PG_Widget* parent, const PG_Rect& rect);
00106 
00114         PG_Widget(PG_Widget* parent, const PG_Rect& rect = PG_Rect::null, bool bObjectSurface = false);
00115 
00121         virtual ~PG_Widget();
00122 
00130         void LoadThemeStyle(const std::string& widgettype);
00131 
00140         virtual void LoadThemeStyle(const std::string& widgettype, const std::string& objectname);
00141 
00147         void StartWidgetDrag();
00148 
00155         void WidgetDrag(int x, int y);
00156 
00163         void EndWidgetDrag(int x, int y);
00164 
00175         bool MoveWidget(int x, int y, bool update = true);
00176 
00186         bool MoveWidget(const PG_Rect& r, bool update = true);
00187 
00198         virtual bool SizeWidget(Uint16 w, Uint16 h, bool update = true);
00199 
00207         PG_Point ClientToScreen(int x, int y);
00208 
00216         PG_Point ScreenToClient(int x, int y);
00217 
00223         SDL_Surface* GetWidgetSurface();
00224 
00229         bool IsVisible();
00230 
00236         PG_Widget* GetParent();
00237 
00243         virtual void AddChild(PG_Widget* child);
00244 
00255         virtual bool ProcessEvent(const SDL_Event* event, bool bModal = false);
00256 
00266         void SetID(int id);
00267 
00272         int GetID();
00273 
00280         PG_Widget* FindChild(int id, bool recursive = false );
00281 
00288         PG_Widget* FindChild(const std::string& name, bool recursive = false);
00289 
00294         bool IsMouseInside();
00295 
00301         bool Redraw(bool update = true);
00302 
00309         virtual void Blit(bool recursive = true, bool restore = true);
00310 
00315         void Update(bool doBlit = true);
00316 
00321         static void UpdateRect(const PG_Rect& r);
00322 
00326         static void UpdateScreen();
00327 
00332         virtual void Show(bool fade = false);
00333 
00338         virtual void Hide(bool fade = false);
00339 
00343         bool IsInFrontOf(PG_Widget*);
00344 
00348         void SendToBack();
00349 
00353         void BringToFront();
00354 
00358         PG_Widget* GetToplevelWidget();
00359 
00363         static void HideAll();
00364 
00365         void RecalcClipRect();
00366 
00372         virtual bool RestoreBackground(PG_Rect* clip = NULL, bool force = false);
00373 
00374         static PG_Widget* FindWidgetFromPos(int x, int y);
00375 
00380         void SetVisible(bool visible);
00381 
00386         void SetFadeSteps(int steps);
00387 
00392         void SetChildTransparency(Uint8 t);
00393 
00399         PG_RectList* GetChildList();
00400 
00406         int GetChildCount();
00407 
00409         void MoveRect(int x, int y);
00410 
00412         static void BulkBlit();
00413 
00414         // Navigation
00415 
00417         virtual bool Action(KeyAction action);
00418 
00423         static PG_RectList* GetWidgetList();
00424 
00429         void SetName(const std::string& name);
00430 
00435         const std::string& GetName();
00436 
00442         bool LoadLayout(const std::string& name);
00443 
00450         bool LoadLayout(const std::string& name, void (* WorkCallback)(int now, int max));
00451 
00459         bool LoadLayout(const std::string& name, void (* WorkCallback)(int now, int max), void *UserSpace);
00460 
00464         void RemoveAllChilds();
00465 
00471         void SetUserData(void *userdata, int size);
00472 
00477         virtual int GetUserDataSize();
00478 
00483         virtual void GetUserData(void *userdata);
00484 
00488         void ReleaseUserData();
00489 
00491         bool virtual RemoveChild(PG_Widget* child);
00492 
00498         virtual void SetText(const std::string& text);
00499 
00505         void AddText(const std::string& text, bool update = false);
00506 
00511         virtual void SetTextFormat(const char* text, ...);
00512 
00516         virtual const PG_String& GetText();
00517 
00518         void GetTextSize(Uint16& w, Uint16& h, const std::string& text = PG_NULLSTR);
00519 
00520         static void GetTextSize(Uint16& w, Uint16& h, const PG_String& text, PG_Font* font);
00521 
00522         int GetTextWidth();
00523 
00524         int GetTextHeight();
00525 
00526         int GetFontAscender();
00527 
00528         int GetFontHeight();
00529 
00534         PG_Color GetFontColor();
00535 
00536    PG_Color GetFontHighlightColor();
00537    
00543         void SetFontColor(const PG_Color& Color, bool bRecursive = false);
00544 
00545    void SetFontHighlightColor(const PG_Color& Color, bool bRecursive = false);
00546    
00552         void SetFontAlpha(int Alpha, bool bRecursive = false);
00553 
00559         void SetFontStyle(PG_Font::Style Style, bool bRecursive = false);
00560 
00566         void SetFontSize(int Size, bool bRecursive = false);
00567 
00573         void SetFontIndex(int Index, bool bRecursive = false);
00574 
00580         void SetFontName(const std::string& Name, bool bRecursive = false);
00581 
00588         void SetSizeByText(int Width = 0, int Height = 0, const std::string& Text = PG_NULLSTR);
00589 
00593         int GetFontSize();
00594 
00599         PG_Font* GetFont();
00600 
00605         void SetFont(PG_Font* font);
00606 
00612         void DrawText(const PG_Rect& rect, const PG_String& text);
00613 
00620         void DrawText(int x, int y, const PG_String& text);
00621 
00629         void DrawText(int x, int y, const PG_String& text, const PG_Rect& cliprect);
00630 
00637         void DrawText(const PG_Rect& rect, const PG_String& text, const PG_Color& c);
00638 
00646         void DrawText(int x, int y, const PG_String& text, const PG_Color& c);
00647 
00649         void DrawBorder(const PG_Rect& r, int size, bool up = true);
00650 
00656         virtual void SetTransparency(Uint8 t, bool bRecursive = false);
00657 
00662         Uint8 GetTransparency();
00663 
00668         void SetClipRect( const PG_Rect& r);
00669 
00674         PG_Rect* GetClipRect();
00675 
00680         bool IsClippingEnabled();
00681 
00683         void GetClipRects(PG_Rect& src, PG_Rect& dst);
00684 
00686         void GetClipRects(PG_Rect& src, PG_Rect& dst, const PG_Rect& displayrect);
00687 
00689         void SetPixel(int x, int y, const PG_Color& c);
00690 
00692         void DrawHLine(int x, int y, int w, const PG_Color& c);
00693 
00695         void DrawVLine(int x, int y, int h, const PG_Color& c);
00696 
00698         void DrawRectWH(int x, int y, int w, int h, const PG_Color& c);
00699 
00701         void DrawLine(Uint32 x0, Uint32 y0, Uint32 x1, Uint32 y1, const PG_Color& color, Uint8 width=1);
00702 
00706         virtual int RunModal();
00707 
00711         bool QuitModal();
00712 
00713         bool WillQuitModal();
00714 
00715         void StopQuitModal();
00716 
00725         void SetDirtyUpdate(bool bDirtyUpdate);
00726 
00734         void UpdateOverlappingSiblings( bool enable, bool recursive = true );
00735 
00740         bool GetDirtyUpdate();
00741 
00746         virtual void eventMouseLeave();
00747 
00752         virtual void eventMouseEnter();
00753 
00754         void SetHidden(bool hidden);
00755 
00756         bool IsHidden();
00757 
00763         void SetModalStatus(int status);
00764 
00765         void EnableReceiver(bool enable, bool bRecursive = false);
00766 
00767         template<class datatype = PG_Pointer>
00768 class SignalMouseEnter : public PG_Signal0<datatype> {}
00769         ;
00770 
00771         template<class datatype = PG_Pointer>
00772 class SignalMouseLeave : public PG_Signal0<datatype> {}
00773         ;
00774 
00775         SignalMouseEnter<> sigMouseEnter;
00776 
00777         SignalMouseLeave<> sigMouseLeave;
00778 
00786         void SetParent(PG_Widget* parent);
00787 
00792         void SetBorderSize(int b);
00793 
00798         int GetBorderSize();
00799 
00801    void activateHotkey( int keymodifier );
00802    int getHotkeyModifier();
00803    
00804 protected:
00805 
00812         //bool eventMessage(MSG_MESSAGE* msg);
00813 
00821         virtual void eventMoveWidget(int x, int y);
00822 
00830         virtual void eventSizeWidget(Uint16 w, Uint16 h);
00831 
00839         virtual void eventDraw(SDL_Surface* surface, const PG_Rect& rect);
00840 
00848         virtual void eventBlit(SDL_Surface* surface, const PG_Rect& src, const PG_Rect& dst);
00849 
00853         virtual void eventShow();
00854 
00858         virtual void eventHide();
00859 
00867         virtual bool eventQuitModal(int id, PG_MessageObject* widget, unsigned long data);
00868 
00870         void FadeOut();
00871 
00873         void FadeIn();
00874 
00876         bool AcceptEvent(const SDL_Event* event);
00877 
00879         void RemoveFromWidgetList();
00880 
00882         void AddToWidgetList();
00883 
00887         SDL_Surface* my_srfObject;
00888 
00892         PG_String my_text;
00893 
00901         PG_Color my_colorBorder[2][2];
00902 
00903         int my_bordersize;
00904 
00905    static bool RenderText(SDL_Surface *Surface, const PG_Rect& ClipRect, int BaseLineX, int BaseLineY, const PG_String& Text, PG_Font* ParamIn);
00906 
00907    PG_Char extractHotkey( const std::string& s );
00908    bool extractAndStoreHotkey( const std::string& s );
00909    bool checkForHotkey( const SDL_KeyboardEvent* key );
00910 
00911    
00912 private:
00913 
00914         PG_Widget(const PG_Widget&);
00915 
00916         PG_Widget& operator=(const PG_Widget&);
00917 
00918         static int my_ObjectCounter;
00919 
00920         static PG_RectList widgetList;
00921 
00922         // this is a bit rude but neccessary for future binary compatibility
00923         // because adding non-static data members would break the ABI.
00924         // For this we put all private data into a dynamically created struct.
00925         PG_WidgetDataInternal* _mid;
00926 };
00927 
00928 #endif // PG_WIDGET_H

Generated on Tue Jun 24 01:27:50 2008 for Advanced Strategic Command by  doxygen 1.4.2