widget_type.h

Go to the documentation of this file.
00001 /* $Id: widget_type.h 21448 2010-12-10 17:47:11Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #ifndef WIDGET_TYPE_H
00013 #define WIDGET_TYPE_H
00014 
00015 #include "core/alloc_type.hpp"
00016 #include "core/bitmath_func.hpp"
00017 #include "core/math_func.hpp"
00018 #include "strings_type.h"
00019 #include "gfx_type.h"
00020 #include "window_type.h"
00021 
00022 static const int WIDGET_LIST_END = -1; 
00023 
00025 enum MatrixWidgetValues {
00026   /* Number of column bits of the WWT_MATRIX widget data. */
00027   MAT_COL_START = 0, 
00028   MAT_COL_BITS  = 8, 
00029 
00030   /* Number of row bits of the WWT_MATRIX widget data. */
00031   MAT_ROW_START = 8, 
00032   MAT_ROW_BITS  = 8, 
00033 };
00034 
00036 enum ArrowWidgetValues {
00037   AWV_DECREASE, 
00038   AWV_INCREASE, 
00039   AWV_LEFT,     
00040   AWV_RIGHT,    
00041 };
00042 
00046 enum WidgetType {
00047   /* Window widget types. */
00048   WWT_EMPTY,      
00049 
00050   WWT_PANEL,      
00051   WWT_INSET,      
00052   WWT_IMGBTN,     
00053   WWT_IMGBTN_2,   
00054   WWT_ARROWBTN,   
00055   WWT_TEXTBTN,    
00056   WWT_TEXTBTN_2,  
00057   WWT_LABEL,      
00058   WWT_TEXT,       
00059   WWT_MATRIX,     
00060   WWT_FRAME,      
00061   WWT_CAPTION,    
00062 
00063   WWT_SHADEBOX,   
00064   WWT_STICKYBOX,  
00065   WWT_DEBUGBOX,   
00066   WWT_RESIZEBOX,  
00067   WWT_CLOSEBOX,   
00068   WWT_DROPDOWN,   
00069   WWT_EDITBOX,    
00070   WWT_LAST,       
00071 
00072   /* Nested widget types. */
00073   NWID_HORIZONTAL,      
00074   NWID_HORIZONTAL_LTR,  
00075   NWID_VERTICAL,        
00076   NWID_MATRIX,          
00077   NWID_SPACER,          
00078   NWID_SELECTION,       
00079   NWID_VIEWPORT,        
00080   NWID_BUTTON_DROPDOWN, 
00081   NWID_HSCROLLBAR,      
00082   NWID_VSCROLLBAR,      
00083 
00084   /* Nested widget part types. */
00085   WPT_RESIZE,       
00086   WPT_MINSIZE,      
00087   WPT_MINTEXTLINES, 
00088   WPT_FILL,         
00089   WPT_DATATIP,      
00090   WPT_PADDING,      
00091   WPT_PIPSPACE,     
00092   WPT_ENDCONTAINER, 
00093   WPT_FUNCTION,     
00094   WPT_SCROLLBAR,    
00095 
00096   /* Pushable window widget types. */
00097   WWT_MASK = 0x7F,
00098 
00099   WWB_PUSHBUTTON    = 1 << 7,
00100 
00101   WWT_PUSHBTN       = WWT_PANEL    | WWB_PUSHBUTTON,
00102   WWT_PUSHTXTBTN    = WWT_TEXTBTN  | WWB_PUSHBUTTON,
00103   WWT_PUSHIMGBTN    = WWT_IMGBTN   | WWB_PUSHBUTTON,
00104   WWT_PUSHARROWBTN  = WWT_ARROWBTN | WWB_PUSHBUTTON,
00105 };
00106 
00108 enum SizingType {
00109   ST_SMALLEST, 
00110   ST_RESIZE,   
00111 };
00112 
00113 /* Forward declarations. */
00114 class NWidgetCore;
00115 class Scrollbar;
00116 
00123 class NWidgetBase : public ZeroedMemoryAllocator {
00124 public:
00125   NWidgetBase(WidgetType tp);
00126 
00127   virtual void SetupSmallestSize(Window *w, bool init_array) = 0;
00128   virtual void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) = 0;
00129 
00130   virtual void FillNestedArray(NWidgetBase **array, uint length) = 0;
00131 
00132   virtual NWidgetCore *GetWidgetFromPos(int x, int y) = 0;
00133   virtual NWidgetBase *GetWidgetOfType(WidgetType tp);
00134 
00142   FORCEINLINE void SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
00143   {
00144     this->padding_top = top;
00145     this->padding_right = right;
00146     this->padding_bottom = bottom;
00147     this->padding_left = left;
00148   };
00149 
00150   FORCEINLINE uint GetHorizontalStepSize(SizingType sizing) const;
00151   FORCEINLINE uint GetVerticalStepSize(SizingType sizing) const;
00152 
00153   virtual void Draw(const Window *w) = 0;
00154   virtual void SetDirty(const Window *w) const;
00155 
00156   WidgetType type;      
00157   uint fill_x;          
00158   uint fill_y;          
00159   uint resize_x;        
00160   uint resize_y;        
00161   /* Size of the widget in the smallest window possible.
00162    * Computed by #SetupSmallestSize() followed by #AssignSizePosition().
00163    */
00164   uint smallest_x;      
00165   uint smallest_y;      
00166   /* Current widget size (that is, after resizing). */
00167   uint current_x;       
00168   uint current_y;       
00169 
00170   uint pos_x;           
00171   uint pos_y;           
00172 
00173   NWidgetBase *next;    
00174   NWidgetBase *prev;    
00175 
00176   uint8 padding_top;    
00177   uint8 padding_right;  
00178   uint8 padding_bottom; 
00179   uint8 padding_left;   
00180 
00181 protected:
00182   FORCEINLINE void StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height);
00183 };
00184 
00189 FORCEINLINE uint NWidgetBase::GetHorizontalStepSize(SizingType sizing) const
00190 {
00191   return (sizing == ST_RESIZE) ? this->resize_x : this->fill_x;
00192 }
00193 
00198 FORCEINLINE uint NWidgetBase::GetVerticalStepSize(SizingType sizing) const
00199 {
00200   return (sizing == ST_RESIZE) ? this->resize_y : this->fill_y;
00201 }
00202 
00211 FORCEINLINE void NWidgetBase::StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height)
00212 {
00213   this->pos_x = x;
00214   this->pos_y = y;
00215   if (sizing == ST_SMALLEST) {
00216     this->smallest_x = given_width;
00217     this->smallest_y = given_height;
00218   }
00219   this->current_x = given_width;
00220   this->current_y = given_height;
00221 }
00222 
00223 
00228 class NWidgetResizeBase : public NWidgetBase {
00229 public:
00230   NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y);
00231 
00232   void SetMinimalSize(uint min_x, uint min_y);
00233   void SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size);
00234   void SetFill(uint fill_x, uint fill_y);
00235   void SetResize(uint resize_x, uint resize_y);
00236 
00237   void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl);
00238 
00239   uint min_x; 
00240   uint min_y; 
00241 };
00242 
00244 enum NWidgetDisplay {
00245   /* Generic. */
00246   NDB_LOWERED         = 0, 
00247   NDB_DISABLED        = 1, 
00248   /* Viewport widget. */
00249   NDB_NO_TRANSPARENCY = 2, 
00250   NDB_SHADE_GREY      = 3, 
00251   NDB_SHADE_DIMMED    = 4, 
00252   /* Button dropdown widget. */
00253   NDB_DROPDOWN_ACTIVE = 5, 
00254   /* Scrollbar widget. */
00255   NDB_SCROLLBAR_UP    = 6, 
00256   NDB_SCROLLBAR_DOWN  = 7, 
00257 
00258   ND_LOWERED  = 1 << NDB_LOWERED,                
00259   ND_DISABLED = 1 << NDB_DISABLED,               
00260   ND_NO_TRANSPARENCY = 1 << NDB_NO_TRANSPARENCY, 
00261   ND_SHADE_GREY      = 1 << NDB_SHADE_GREY,      
00262   ND_SHADE_DIMMED    = 1 << NDB_SHADE_DIMMED,    
00263   ND_DROPDOWN_ACTIVE = 1 << NDB_DROPDOWN_ACTIVE, 
00264   ND_SCROLLBAR_UP    = 1 << NDB_SCROLLBAR_UP,    
00265   ND_SCROLLBAR_DOWN  = 1 << NDB_SCROLLBAR_DOWN,  
00266   ND_SCROLLBAR_BTN   = ND_SCROLLBAR_UP | ND_SCROLLBAR_DOWN, 
00267 };
00268 DECLARE_ENUM_AS_BIT_SET(NWidgetDisplay)
00269 
00270 
00274 class NWidgetCore : public NWidgetResizeBase {
00275 public:
00276   NWidgetCore(WidgetType tp, Colours colour, uint fill_x, uint fill_y, uint16 widget_data, StringID tool_tip);
00277 
00278   void SetIndex(int index);
00279   void SetDataTip(uint16 widget_data, StringID tool_tip);
00280 
00281   inline void SetLowered(bool lowered);
00282   inline bool IsLowered() const;
00283   inline void SetDisabled(bool disabled);
00284   inline bool IsDisabled() const;
00285 
00286   /* virtual */ void FillNestedArray(NWidgetBase **array, uint length);
00287   /* virtual */ NWidgetCore *GetWidgetFromPos(int x, int y);
00288 
00289   NWidgetDisplay disp_flags; 
00290   Colours colour;            
00291   int index;                 
00292   uint16 widget_data;        
00293   StringID tool_tip;         
00294   int scrollbar_index;       
00295 };
00296 
00301 inline void NWidgetCore::SetLowered(bool lowered)
00302 {
00303   this->disp_flags = lowered ? SETBITS(this->disp_flags, ND_LOWERED) : CLRBITS(this->disp_flags, ND_LOWERED);
00304 }
00305 
00307 inline bool NWidgetCore::IsLowered() const
00308 {
00309   return HasBit(this->disp_flags, NDB_LOWERED);
00310 }
00311 
00316 inline void NWidgetCore::SetDisabled(bool disabled)
00317 {
00318   this->disp_flags = disabled ? SETBITS(this->disp_flags, ND_DISABLED) : CLRBITS(this->disp_flags, ND_DISABLED);
00319 }
00320 
00322 inline bool NWidgetCore::IsDisabled() const
00323 {
00324   return HasBit(this->disp_flags, NDB_DISABLED);
00325 }
00326 
00327 
00332 class NWidgetContainer : public NWidgetBase {
00333 public:
00334   NWidgetContainer(WidgetType tp);
00335   ~NWidgetContainer();
00336 
00337   void Add(NWidgetBase *wid);
00338   /* virtual */ void FillNestedArray(NWidgetBase **array, uint length);
00339 
00341   inline bool IsEmpty() { return head == NULL; };
00342 
00343   /* virtual */ NWidgetBase *GetWidgetOfType(WidgetType tp);
00344 
00345 protected:
00346   NWidgetBase *head; 
00347   NWidgetBase *tail; 
00348 };
00349 
00351 enum StackedZeroSizePlanes {
00352   SZSP_VERTICAL = INT_MAX / 2, 
00353   SZSP_HORIZONTAL,             
00354   SZSP_NONE,                   
00355 
00356   SZSP_BEGIN = SZSP_VERTICAL,  
00357 };
00358 
00369 class NWidgetStacked : public NWidgetContainer {
00370 public:
00371   NWidgetStacked();
00372 
00373   void SetIndex(int index);
00374 
00375   void SetupSmallestSize(Window *w, bool init_array);
00376   void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl);
00377   /* virtual */ void FillNestedArray(NWidgetBase **array, uint length);
00378 
00379   /* virtual */ void Draw(const Window *w);
00380   /* virtual */ NWidgetCore *GetWidgetFromPos(int x, int y);
00381 
00382   void SetDisplayedPlane(int plane);
00383 
00384   int shown_plane; 
00385   int index;       
00386 };
00387 
00389 enum NWidContainerFlags {
00390   NCB_EQUALSIZE = 0, 
00391 
00392   NC_NONE = 0,                       
00393   NC_EQUALSIZE = 1 << NCB_EQUALSIZE, 
00394 };
00395 DECLARE_ENUM_AS_BIT_SET(NWidContainerFlags)
00396 
00397 
00398 class NWidgetPIPContainer : public NWidgetContainer {
00399 public:
00400   NWidgetPIPContainer(WidgetType tp, NWidContainerFlags flags = NC_NONE);
00401 
00402   void SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post);
00403 
00404   /* virtual */ void Draw(const Window *w);
00405   /* virtual */ NWidgetCore *GetWidgetFromPos(int x, int y);
00406 
00407 protected:
00408   NWidContainerFlags flags; 
00409   uint8 pip_pre;            
00410   uint8 pip_inter;          
00411   uint8 pip_post;           
00412 };
00413 
00418 class NWidgetHorizontal : public NWidgetPIPContainer {
00419 public:
00420   NWidgetHorizontal(NWidContainerFlags flags = NC_NONE);
00421 
00422   void SetupSmallestSize(Window *w, bool init_array);
00423   void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl);
00424 };
00425 
00430 class NWidgetHorizontalLTR : public NWidgetHorizontal {
00431 public:
00432   NWidgetHorizontalLTR(NWidContainerFlags flags = NC_NONE);
00433 
00434   void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl);
00435 };
00436 
00441 class NWidgetVertical : public NWidgetPIPContainer {
00442 public:
00443   NWidgetVertical(NWidContainerFlags flags = NC_NONE);
00444 
00445   void SetupSmallestSize(Window *w, bool init_array);
00446   void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl);
00447 };
00448 
00457 class NWidgetMatrix : public NWidgetPIPContainer {
00458 public:
00459   NWidgetMatrix();
00460 
00461   void SetIndex(int index);
00462   void SetColour(Colours colour);
00463   void SetClicked(int clicked);
00464   void SetCount(int count);
00465   void SetScrollbar(Scrollbar *sb);
00466 
00467   void SetupSmallestSize(Window *w, bool init_array);
00468   void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl);
00469   /* virtual */ void FillNestedArray(NWidgetBase **array, uint length);
00470 
00471   /* virtual */ NWidgetCore *GetWidgetFromPos(int x, int y);
00472   /* virtual */ void Draw(const Window *w);
00473 protected:
00474   int index;      
00475   Colours colour; 
00476   int clicked;    
00477   int count;      
00478   Scrollbar *sb;  
00479 private:
00480   int widget_w;   
00481   int widget_h;   
00482   int widgets_x;  
00483   int widgets_y;  
00484 
00485   void GetScrollOffsets(int &start_x, int &start_y, int &base_offs_x, int &base_offs_y);
00486 };
00487 
00488 
00493 class NWidgetSpacer : public NWidgetResizeBase {
00494 public:
00495   NWidgetSpacer(int length, int height);
00496 
00497   void SetupSmallestSize(Window *w, bool init_array);
00498   /* virtual */ void FillNestedArray(NWidgetBase **array, uint length);
00499 
00500   /* virtual */ void Draw(const Window *w);
00501   /* virtual */ void SetDirty(const Window *w) const;
00502   /* virtual */ NWidgetCore *GetWidgetFromPos(int x, int y);
00503 };
00504 
00509 class NWidgetBackground : public NWidgetCore {
00510 public:
00511   NWidgetBackground(WidgetType tp, Colours colour, int index, NWidgetPIPContainer *child = NULL);
00512   ~NWidgetBackground();
00513 
00514   void Add(NWidgetBase *nwid);
00515   void SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post);
00516 
00517   void SetupSmallestSize(Window *w, bool init_array);
00518   void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl);
00519 
00520   /* virtual */ void FillNestedArray(NWidgetBase **array, uint length);
00521 
00522   /* virtual */ void Draw(const Window *w);
00523   /* virtual */ NWidgetCore *GetWidgetFromPos(int x, int y);
00524   /* virtual */ NWidgetBase *GetWidgetOfType(WidgetType tp);
00525 
00526 private:
00527   NWidgetPIPContainer *child; 
00528 };
00529 
00539 class NWidgetViewport : public NWidgetCore {
00540 public:
00541   NWidgetViewport(int index);
00542 
00543   /* virtual */ void SetupSmallestSize(Window *w, bool init_array);
00544   /* virtual */ void Draw(const Window *w);
00545 
00546   void InitializeViewport(Window *w, uint32 follow_flags, ZoomLevel zoom);
00547   void UpdateViewportCoordinates(Window *w);
00548 };
00549 
00553 class Scrollbar {
00554 private:
00555   const bool is_vertical; 
00556   uint16 count;           
00557   uint16 cap;             
00558   uint16 pos;             
00559 
00560 public:
00561   Scrollbar(bool is_vertical) : is_vertical(is_vertical)
00562   {
00563   }
00564 
00569   FORCEINLINE uint16 GetCount() const
00570   {
00571     return this->count;
00572   }
00573 
00578   FORCEINLINE uint16 GetCapacity() const
00579   {
00580     return this->cap;
00581   }
00582 
00587   FORCEINLINE uint16 GetPosition() const
00588   {
00589     return this->pos;
00590   }
00591 
00597   FORCEINLINE bool IsVisible(uint16 item) const
00598   {
00599     return IsInsideBS(item, this->GetPosition(), this->GetCapacity());
00600   }
00601 
00606   FORCEINLINE bool IsVertical() const
00607   {
00608     return this->is_vertical;
00609   }
00610 
00616   void SetCount(int num)
00617   {
00618     assert(num >= 0);
00619     assert(num <= MAX_UVALUE(uint16));
00620 
00621     this->count = num;
00622     num -= this->cap;
00623     if (num < 0) num = 0;
00624     if (num < this->pos) this->pos = num;
00625   }
00626 
00632   void SetCapacity(int capacity)
00633   {
00634     assert(capacity > 0);
00635     assert(capacity <= MAX_UVALUE(uint16));
00636 
00637     this->cap = capacity;
00638     if (this->cap + this->pos > this->count) this->pos = max(0, this->count - this->cap);
00639   }
00640 
00641   void SetCapacityFromWidget(Window *w, int widget, int padding = 0);
00642 
00647   void SetPosition(int position)
00648   {
00649     assert(position >= 0);
00650     assert(this->count <= this->cap ? (position == 0) : (position + this->cap <= this->count));
00651     this->pos = position;
00652   }
00653 
00659   void UpdatePosition(int difference)
00660   {
00661     if (difference == 0) return;
00662     this->SetPosition(Clamp(this->pos + difference, 0, max(this->count - this->cap, 0)));
00663   }
00664 
00671   void ScrollTowards(int position)
00672   {
00673     if (position < this->GetPosition()) {
00674       /* scroll up to the item */
00675       this->SetPosition(position);
00676     } else if (position >= this->GetPosition() + this->GetCapacity()) {
00677       /* scroll down so that the item is at the bottom */
00678       this->SetPosition(position - this->GetCapacity() + 1);
00679     }
00680   }
00681 
00682   int GetScrolledRowFromWidget(int clickpos, const Window * const w, int widget, int padding = 0, int line_height = -1) const;
00683 };
00684 
00690 class NWidgetScrollbar : public NWidgetCore, public Scrollbar {
00691 public:
00692   NWidgetScrollbar(WidgetType tp, Colours colour, int index);
00693 
00694   /* virtual */ void SetupSmallestSize(Window *w, bool init_array);
00695   /* virtual */ void Draw(const Window *w);
00696 };
00697 
00702 class NWidgetLeaf : public NWidgetCore {
00703 public:
00704   NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data, StringID tip);
00705 
00706   /* virtual */ void SetupSmallestSize(Window *w, bool init_array);
00707   /* virtual */ void Draw(const Window *w);
00708 
00709   bool ButtonHit(const Point &pt);
00710 
00711   static void InvalidateDimensionCache();
00712 private:
00713   static Dimension shadebox_dimension;  
00714   static Dimension debugbox_dimension;  
00715   static Dimension stickybox_dimension; 
00716   static Dimension resizebox_dimension; 
00717   static Dimension closebox_dimension;  
00718 };
00719 
00727 static FORCEINLINE uint ComputeMaxSize(uint base, uint max_space, uint step)
00728 {
00729   if (base >= max_space || step == 0) return base;
00730   if (step == 1) return max_space;
00731   uint increment = max_space - base;
00732   increment -= increment % step;
00733   return base + increment;
00734 }
00735 
00787 struct NWidgetPartDataTip {
00788   uint16 data;      
00789   StringID tooltip; 
00790 };
00791 
00796 struct NWidgetPartWidget {
00797   Colours colour; 
00798   int16 index;    
00799 };
00800 
00805 struct NWidgetPartPaddings {
00806   uint8 top, right, bottom, left; 
00807 };
00808 
00813 struct NWidgetPartPIP {
00814   uint8 pre, inter, post; 
00815 };
00816 
00821 struct NWidgetPartTextLines {
00822   uint8 lines;   
00823   uint8 spacing; 
00824   FontSize size; 
00825 };
00826 
00833 typedef NWidgetBase *NWidgetFunctionType(int *biggest_index);
00834 
00839 struct NWidgetPart {
00840   WidgetType type;                         
00841   union {
00842     Point xy;                        
00843     NWidgetPartDataTip data_tip;     
00844     NWidgetPartWidget widget;        
00845     NWidgetPartPaddings padding;     
00846     NWidgetPartPIP pip;              
00847     NWidgetPartTextLines text_lines; 
00848     NWidgetFunctionType *func_ptr;   
00849     NWidContainerFlags cont_flags;   
00850   } u;
00851 };
00852 
00859 static inline NWidgetPart SetResize(int16 dx, int16 dy)
00860 {
00861   NWidgetPart part;
00862 
00863   part.type = WPT_RESIZE;
00864   part.u.xy.x = dx;
00865   part.u.xy.y = dy;
00866 
00867   return part;
00868 }
00869 
00876 static inline NWidgetPart SetMinimalSize(int16 x, int16 y)
00877 {
00878   NWidgetPart part;
00879 
00880   part.type = WPT_MINSIZE;
00881   part.u.xy.x = x;
00882   part.u.xy.y = y;
00883 
00884   return part;
00885 }
00886 
00894 static inline NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSize size = FS_NORMAL)
00895 {
00896   NWidgetPart part;
00897 
00898   part.type = WPT_MINTEXTLINES;
00899   part.u.text_lines.lines = lines;
00900   part.u.text_lines.spacing = spacing;
00901   part.u.text_lines.size = size;
00902 
00903   return part;
00904 }
00905 
00912 static inline NWidgetPart SetFill(uint fill_x, uint fill_y)
00913 {
00914   NWidgetPart part;
00915 
00916   part.type = WPT_FILL;
00917   part.u.xy.x = fill_x;
00918   part.u.xy.y = fill_y;
00919 
00920   return part;
00921 }
00922 
00928 static inline NWidgetPart EndContainer()
00929 {
00930   NWidgetPart part;
00931 
00932   part.type = WPT_ENDCONTAINER;
00933 
00934   return part;
00935 }
00936 
00943 static inline NWidgetPart SetDataTip(uint16 data, StringID tip)
00944 {
00945   NWidgetPart part;
00946 
00947   part.type = WPT_DATATIP;
00948   part.u.data_tip.data = data;
00949   part.u.data_tip.tooltip = tip;
00950 
00951   return part;
00952 }
00953 
00963 static inline NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
00964 {
00965   NWidgetPart part;
00966 
00967   part.type = WPT_PADDING;
00968   part.u.padding.top = top;
00969   part.u.padding.right = right;
00970   part.u.padding.bottom = bottom;
00971   part.u.padding.left = left;
00972 
00973   return part;
00974 }
00975 
00981 static inline NWidgetPart SetPadding(uint8 padding)
00982 {
00983   return SetPadding(padding, padding, padding, padding);
00984 }
00985 
00993 static inline NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
00994 {
00995   NWidgetPart part;
00996 
00997   part.type = WPT_PIPSPACE;
00998   part.u.pip.pre = pre;
00999   part.u.pip.inter = inter;
01000   part.u.pip.post = post;
01001 
01002   return part;
01003 }
01004 
01012 static inline NWidgetPart SetScrollbar(int index)
01013 {
01014   NWidgetPart part;
01015 
01016   part.type = WPT_SCROLLBAR;
01017   part.u.widget.index = index;
01018 
01019   return part;
01020 }
01021 
01031 static inline NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx = -1)
01032 {
01033   NWidgetPart part;
01034 
01035   part.type = tp;
01036   part.u.widget.colour = col;
01037   part.u.widget.index = idx;
01038 
01039   return part;
01040 }
01041 
01048 static inline NWidgetPart NWidget(WidgetType tp, NWidContainerFlags cont_flags = NC_NONE)
01049 {
01050   NWidgetPart part;
01051 
01052   part.type = tp;
01053   part.u.cont_flags = cont_flags;
01054 
01055   return part;
01056 }
01057 
01063 static inline NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
01064 {
01065   NWidgetPart part;
01066 
01067   part.type = WPT_FUNCTION;
01068   part.u.func_ptr = func_ptr;
01069 
01070   return part;
01071 }
01072 
01073 NWidgetContainer *MakeNWidgets(const NWidgetPart *parts, int count, int *biggest_index, NWidgetContainer *container);
01074 NWidgetContainer *MakeWindowNWidgetTree(const NWidgetPart *parts, int count, int *biggest_index, NWidgetStacked **shade_select);
01075 
01076 NWidgetBase *MakeCompanyButtonRows(int *biggest_index, int widget_first, int widget_last, int max_length, StringID button_tooltip);
01077 
01078 #endif /* WIDGET_TYPE_H */

Generated on Fri Dec 31 17:15:42 2010 for OpenTTD by  doxygen 1.6.1