00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GUMP_H_INCLUDED
00020 #define GUMP_H_INCLUDED
00021
00022 #include "Object.h"
00023 #include "Rect.h"
00024 #include "FrameID.h"
00025 #include <list>
00026
00027 class RenderSurface;
00028 class Shape;
00029 class Item;
00030 class GumpNotifyProcess;
00031
00032
00033
00034
00035
00036
00037
00038 class Gump : public Object
00039 {
00040 protected:
00041
00042 friend class GumpList;
00043
00044 uint16 owner;
00045 Gump * parent;
00046 sint32 x, y;
00047
00048
00049 Pentagram::Rect dims;
00050 uint32 flags;
00051 sint32 layer;
00052
00053 sint32 index;
00054
00055 Shape *shape;
00056 uint32 framenum;
00057
00060 std::list<Gump*> children;
00061 Gump * focus_child;
00062
00063 uint16 notifier;
00064 uint32 process_result;
00065
00066 public:
00067 ENABLE_RUNTIME_CLASSTYPE();
00068 Gump();
00069 Gump(int x, int y, int width, int height, uint16 owner = 0,
00070 uint32 _Flags = 0, sint32 layer = LAYER_NORMAL);
00071 virtual ~Gump();
00072
00073 public:
00074
00075 virtual void CreateNotifier();
00076 void SetNotifyProcess(GumpNotifyProcess* proc);
00077 GumpNotifyProcess* GetNotifyProcess();
00078 inline uint32 GetResult() { return process_result; }
00079
00081 inline void SetShape(Shape *_shape, uint32 _framenum)
00082 { shape = _shape; framenum = _framenum; }
00083
00084 void SetShape(FrameID frame, bool adjustsize=false);
00085
00087 inline void SetFramenum(uint32 _framenum)
00088 { framenum = _framenum; }
00089
00094 virtual void InitGump(Gump* newparent,bool take_focus=true);
00095
00101 virtual Gump * FindGump(const RunTimeClassType& t,
00102 bool recursive=true,
00103 bool no_inheritance=false);
00104
00110 template<class T> Gump * FindGump(bool recursive=true,
00111 bool no_inheritance=false)
00112 { return FindGump(T::ClassType, recursive, no_inheritance); }
00113
00116 virtual Gump * FindGump(int mx, int my);
00117
00122 virtual bool GetMouseCursor(int mx, int my, Shape &shape,
00123 sint32 &frame);
00124
00125
00126 virtual void RenderSurfaceChanged();
00127
00130 virtual bool Run(const uint32 framenum);
00131
00135 virtual void CloseItemDependents(void);
00136
00139
00140
00141
00142 virtual void Paint(RenderSurface* surf, sint32 lerp_factor, bool scaled);
00143
00146
00147
00148
00149
00150 virtual void PaintCompositing(RenderSurface* surf, sint32 lerp_factor, sint32 scalex, sint32 scaley);
00151
00152 protected:
00153
00155
00156
00157
00158 virtual void PaintThis(RenderSurface* surf, sint32 lerp_factor, bool scaled);
00159
00161
00162
00163
00164 virtual void PaintChildren(RenderSurface* surf, sint32 lerp_factor, bool scaled);
00165
00167
00168
00169
00170
00171 virtual void PaintComposited(RenderSurface* surf, sint32 lerp_factor, sint32 scalex, sint32 scaley);
00172
00173 static inline sint32 ScaleCoord(sint32 c, sint32 factor) { return ((c*factor)+(1<<15))>>16; }
00174 static inline sint32 UnscaleCoord(sint32 c, sint32 factor) { return (c<<16)/factor; }
00175
00176 public:
00177
00180 virtual void Close(bool no_del = false);
00181
00183 bool IsClosing() { return (flags&FLAG_CLOSING)!=0; }
00184
00186 virtual void Move(int x_, int y_) { x = x_; y = y_; }
00187
00189 virtual void MoveRelative(int x_, int y_) { x += x_; y += y_; }
00190
00191 enum Position {
00192 CENTER = 1,
00193 TOP_LEFT = 2,
00194 TOP_RIGHT = 3,
00195 BOTTOM_LEFT = 4,
00196 BOTTOM_RIGHT = 5,
00197 TOP_CENTER = 6,
00198 BOTTOM_CENTER = 7
00199 };
00200
00202
00203
00204
00205 virtual void setRelativePosition(Position pos, int xoffset=0, int yoffset=0);
00206
00207
00208
00209
00210
00212 virtual void GetDims(Pentagram::Rect &d) { d = dims; }
00213
00215 virtual bool PointOnGump(int mx, int my);
00216
00217 enum PointRoundDir {
00218 ROUND_TOPLEFT = 0,
00219 ROUND_BOTTOMRIGHT = 1
00220 };
00221 enum RectRoundDir {
00222 ROUND_INSIDE,
00223 ROUND_OUTSIDE
00224 };
00225
00227 virtual void ScreenSpaceToGump(int &sx, int &sy,
00228 PointRoundDir r = ROUND_TOPLEFT);
00229
00231 virtual void GumpToScreenSpace(int &gx, int &gy,
00232 PointRoundDir r = ROUND_TOPLEFT);
00233
00235 virtual void ParentToGump(int &px, int &py,
00236 PointRoundDir r = ROUND_TOPLEFT);
00237
00239 virtual void GumpToParent(int &gx, int &gy,
00240 PointRoundDir r = ROUND_TOPLEFT);
00241
00243 virtual void GumpRectToScreenSpace(int &gx,int &gy, int &gw,int &gh,
00244 RectRoundDir r = ROUND_OUTSIDE);
00245
00247 virtual void ScreenSpaceToGumpRect(int &sx,int &sy, int &sw,int &sh,
00248 RectRoundDir r = ROUND_OUTSIDE);
00249
00251 virtual uint16 TraceObjId(int mx, int my);
00252
00255 virtual bool GetLocationOfItem(uint16 itemid, int &gx, int &gy,
00256 sint32 lerp_factor = 256);
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 virtual Gump * OnMouseDown(int button, int mx, int my);
00278 virtual void OnMouseUp(int button, int mx, int my) { }
00279 virtual void OnMouseClick(int button, int mx, int my) { }
00280 virtual void OnMouseDouble(int button, int mx, int my) { }
00281 virtual Gump * OnMouseMotion(int mx, int my);
00282
00283
00284
00285 virtual void OnMouseOver() { };
00286 virtual void OnMouseLeft() { };
00287
00288
00289
00290
00291
00292 virtual bool OnKeyDown(int key, int mod);
00293 virtual bool OnKeyUp(int key);
00294 virtual bool OnTextInput(int unicode);
00295
00296
00297
00298
00299 virtual void OnFocus(bool ) { }
00300
00301
00302 virtual void MakeFocus();
00303
00304
00305 inline bool IsFocus()
00306 { return parent?parent->focus_child==this:false; }
00307
00308
00309 inline Gump * GetFocusChild() { return focus_child; }
00310
00311
00312 void FindNewFocusChild();
00313
00314
00315
00316
00317
00318
00320 virtual void AddChild(Gump *, bool take_focus = true);
00321
00323 virtual void RemoveChild(Gump *);
00324
00326 virtual void MoveChildToFront(Gump *);
00327
00329 inline Gump * GetParent() { return parent; }
00330
00332 Gump * GetRootGump();
00333
00336 virtual void ChildNotify(Gump *child, uint32 message) { }
00337 void SetIndex(sint32 i) { index = i; }
00338 sint32 GetIndex() { return index; }
00339
00340
00343 virtual bool StartDraggingChild(Gump* gump, int mx, int my);
00344 virtual void DraggingChild(Gump* gump, int mx, int my);
00345 virtual void StopDraggingChild(Gump* gump);
00346
00349 virtual bool StartDraggingItem(Item* item, int mx, int my)
00350 { return false; }
00351
00355 virtual bool DraggingItem(Item* item, int mx, int my)
00356 { return false; }
00357
00359 virtual void DraggingItemLeftGump(Item* item) { }
00360
00365 virtual void StopDraggingItem(Item* item, bool moved) { }
00366
00372 virtual void DropItem(Item* item, int mx, int my) { }
00373
00374 public:
00375
00376
00377
00378
00379 enum GumpFlags {
00380 FLAG_DRAGGABLE = 0x01,
00381 FLAG_HIDDEN = 0x02,
00382 FLAG_CLOSING = 0x04,
00383 FLAG_CLOSE_AND_DEL = 0x08,
00384 FLAG_ITEM_DEPENDENT = 0x10,
00385 FLAG_DONT_SAVE = 0x20,
00386
00387 FLAG_CORE_GUMP = 0x40,
00388 FLAG_KEEP_VISIBLE = 0x80
00389
00390 };
00391
00392 inline bool IsHidden()
00393 { return (flags&FLAG_HIDDEN) || (parent && parent->IsHidden()); }
00394 bool IsDraggable() { return flags&FLAG_DRAGGABLE; }
00395 virtual void HideGump() { flags |= FLAG_HIDDEN; }
00396 virtual void UnhideGump() { flags &= ~FLAG_HIDDEN; }
00397
00398 bool mustSave(bool toplevel);
00399
00400
00401
00402
00403 enum GumpLayers {
00404 LAYER_DESKTOP = -16,
00405 LAYER_GAMEMAP = -8,
00406 LAYER_NORMAL = 0,
00407 LAYER_ABOVE_NORMAL = 8,
00408 LAYER_MODAL = 12,
00409 LAYER_CONSOLE = 16
00410 };
00411
00412 bool loadData(IDataSource* ids, uint32 version);
00413 protected:
00414 virtual void saveData(ODataSource* ods);
00415 };
00416
00417 #endif //GUMP_H_INCLUDED