Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

BWidget.h

Go to the documentation of this file.
00001 // BWidget.h (this is -*- C++ -*-)
00002 // 
00003 // \author: Bjoern Giesler <bjoern@giesler.de>
00004 // 
00005 // 
00006 // 
00007 // $Author: giesler $
00008 // $Locker$
00009 // $Revision$
00010 // $Date: 2002-08-19 10:41:28 +0200 (Mon, 19 Aug 2002) $
00011 
00012 #ifndef BWIDGET_H
00013 #define BWIDGET_H
00014 
00015 /* system includes */
00016 #include <nds.h>
00017 #include <vector>
00018 
00019 /* my includes */
00020 #include "BGraphics.h"
00021 #include "BImage.h"
00022 #include "BResponder.h"
00023 
00024 class BFont;
00025 class BScreen;
00026 
00032 class BWidget: public BResponder {
00033 public:
00035   typedef enum {
00036     STATE_DISABLED, 
00037     STATE_ENABLED,  
00038     STATE_SELECTED, 
00039     STATE_ACTIVE    
00040   } State;
00041 
00043   typedef enum {
00044     ROT_0 = 0,
00045     ROT_90 = 1,
00046     ROT_180 = 2,
00047     ROT_270 = 3
00048   } Rotation;
00049 
00051   typedef enum {
00052     DIR_LEFTTORIGHT = 0,
00053     DIR_TOPTOBOTTOM = 1,
00054     DIR_RIGHTTOLEFT = 2,
00055     DIR_BOTTOMTOTOP = 3
00056   } TextDirection;
00057 
00059   typedef enum {
00060     ALIGN_CENTER,
00061     ALIGN_LEFT,
00062     ALIGN_RIGHT
00063   } TextAlignment;
00064 
00066   typedef enum {
00067     RELIEF_NONE,   
00068     RELIEF_SIMPLE, 
00069     RELIEF_RAISED, 
00070     RELIEF_SUNKEN  
00071   } ReliefType;
00072 
00079   BWidget(BWidget* parent, const BRect& frame);
00080   virtual ~BWidget();
00081 
00083   const BRect& frame() const { return _frame; }
00085   virtual void setFrame(const BRect& frame);
00086 
00088   virtual State state() const { return _state; }
00090   virtual void setState(State state) { _state = state; _needsRedraw = true; }
00091 
00092   void setTag(int tag) { _tag = tag; }
00093   int tag() { return _tag; }
00094   
00095   virtual TextDirection textDirectionRelativeToScreen() const;
00096   virtual TextDirection textDirection() const { return _tdir; }
00097   virtual void setTextDirection(TextDirection dir) { _tdir = dir; _needsRedraw = true; }
00098 
00104   virtual Rotation rotation() const { return _rot; }
00105   virtual void setRotation(Rotation rot);
00106   virtual Rotation accumulatedRotation() const;
00107 
00114   inline BPoint transformUp(BPoint pt, bool global = true)
00115     const
00116   {
00117     BPoint pt1;
00118     switch(_rot) {
00119     case ROT_0:
00120       pt1.x = pt.x + _frame.pt.x;
00121       pt1.y = pt.y + _frame.pt.y;
00122       break;
00123 
00124     case ROT_90:
00125       pt1.x = _frame.pt.x - pt.y + _frame.sz.width;
00126       pt1.y = _frame.pt.y + pt.x;
00127       break;
00128 
00129     case ROT_180:
00130       pt1.x = _frame.pt.x - pt.x + _frame.sz.width;
00131       pt1.y = _frame.pt.y - pt.y + _frame.sz.height;
00132       break;
00133       
00134     case ROT_270:
00135       pt1.x = _frame.pt.x + pt.y;
00136       pt1.y = _frame.pt.y - pt.x + _frame.sz.height;
00137       break;
00138     }
00139 
00140     if(_parent && global)
00141       return _parent->transformUp(pt1);
00142     return pt1;
00143   }
00144 
00152   inline BPoint transformDown(const BPoint& pt, bool global = true)
00153     const
00154   {
00155     BPoint pt1 = pt, pt2;
00156 
00157     if(_parent && global)
00158       pt1 = _parent->transformDown(pt1);
00159 
00160     switch(_rot) {
00161     case ROT_0:
00162       pt2.x = pt1.x - _frame.pt.x;
00163       pt2.y = pt1.y - _frame.pt.y;
00164       break;
00165 
00166     case ROT_90:
00167       pt2.x = pt1.y - _frame.pt.y;
00168       pt2.y = _frame.pt.x + _frame.sz.width - pt1.x;
00169       break;
00170 
00171     case ROT_180:
00172       pt2.x = _frame.pt.x + _frame.sz.width - pt1.x;
00173       pt2.y = _frame.pt.y + _frame.sz.height - pt1.y;
00174       break;
00175       
00176     case ROT_270:
00177       pt2.x = _frame.pt.y + _frame.sz.height - pt1.y;
00178       pt2.y = pt1.x - _frame.pt.x;
00179       break;
00180     }
00181 
00182     return pt2;
00183   }
00184 
00191   inline BRect transformUp(const BRect& r, bool global = true)
00192     const
00193   {
00194     return BRect(transformUp(r.topLeft(), global),
00195                  transformUp(r.bottomRight(), global));
00196   }
00197 
00205   inline BRect transformDown(const BRect& r, bool global = true)
00206     const
00207   {
00208     return BRect(transformDown(r.topLeft(), global),
00209                  transformDown(r.bottomRight(), global));
00210   }
00211     
00216   TextAlignment textAlignment() const { return _align; }
00217   virtual void setTextAlignment(TextAlignment align);
00218 
00219   ReliefType reliefType() const { return _relief; }
00220   virtual void setReliefType(ReliefType relief);
00221 
00222   unsigned int vPadding() const { return _vpadding; }
00223   virtual void setVPadding(unsigned int padding);
00224 
00225   unsigned int hPadding() const { return _hpadding; }
00226   virtual void setHPadding(unsigned int padding);
00227 
00238   bool drawsDebugStuff() const { return _debug; }
00239   virtual void setDrawsDebugStuff(bool debug);
00240 
00245 
00246   virtual void draw(BImage& img);
00247 
00249   virtual void setNeedsRedraw(bool needs);
00250 
00252   virtual bool needsRedraw();
00253 
00254   virtual bool isShown() {
00255     if(_parent) return _parent->isShown() && _shown;
00256     return _shown;
00257   }
00258   virtual void hide() { _shown = false; }
00259   virtual void show();
00260 
00265   uint16 backgroundColor() const { return _bgcolor; }
00266   virtual void setBackgroundColor(uint16 color, bool recursive = false);
00267 
00268   uint8 backgroundAlpha() const { return _bgalpha; }
00269   virtual void setBackgroundAlpha(uint8 alpha);
00270   
00271   uint8 widgetAlpha() const { return _widgetalpha; }
00272   virtual void setWidgetAlpha(uint8 alpha);
00273 
00274   BFont *font() const { return _font; }
00275   virtual void setFont(BFont* font);
00276 
00277   uint16 textColor() { return _textcolor; }
00278   virtual void setTextColor(uint16 color, bool recursive = false);
00279 
00280   uint16 selectedTextColor() { return _selectedtextcolor; }
00281   virtual void setSelectedTextColor(uint16 color);
00282 
00287   void handleEvent(const BEvent& event);
00288 
00295 
00296   std::vector<BWidget*>& children() { return _children; }
00297 
00299   bool deletesChildren() { return _deleteChildren; }
00301   void setDeletesChildren(bool yesno) { _deleteChildren = yesno; }
00303   void deleteChildren();
00304 
00306   BWidget* parent() { return _parent; }
00307 
00309   BScreen* screen();
00311   void setScreen(BScreen* screen);
00312 
00316 protected:
00317   std::vector<BWidget*> _children;
00318   virtual void addChild(BWidget* w);
00319   virtual void removeChild(BWidget* w);
00320   
00321   BRect _frame;
00322   ReliefType _relief;
00323   unsigned int _vpadding, _hpadding;
00324   uint16 _bgcolor;
00325   uint16 _textcolor, _selectedtextcolor;
00326   uint8 _bgalpha;
00327   uint8 _widgetalpha;
00328   bool _needsRedraw;
00329   bool _debug;
00330   bool _shown;
00331 
00332   BFont *_font;
00333   BWidget *_parent;
00334   BScreen *_screen;
00335 
00336   State _state;
00337   TextDirection _tdir;
00338   Rotation _rot;
00339   TextAlignment _align;
00340   int _tag;
00341   bool _deleteChildren;
00342 };
00343 
00344 #endif /* BWIDGET_H */

Generated on Sat Dec 29 09:59:23 2007 for DSGUI by doxygen1.3-rc3