22 #ifndef ULTIMA8_GUMPS_GUMP_H 23 #define ULTIMA8_GUMPS_GUMP_H 25 #include "ultima/ultima8/kernel/object.h" 26 #include "ultima/ultima8/misc/rect.h" 27 #include "ultima/ultima8/gfx/frame_id.h" 28 #include "ultima/shared/std/containers.h" 29 #include "ultima/ultima8/misc/classtype.h" 37 class GumpNotifyProcess;
40 typedef bool (*FindGumpPredicate)(
const Gump *g);
41 template<
class T>
inline bool IsOfType(
const Gump *g) {
return dynamic_cast<const T*
>(g) !=
nullptr; }
69 uint32 _processResult;
72 ENABLE_RUNTIME_CLASSTYPE()
74 Gump(
int x,
int y,
int width,
int height, uint16 owner = 0,
75 uint32 flags = 0, int32 layer = LAYER_NORMAL);
80 virtual
void CreateNotifier();
83 inline uint32 GetResult() {
84 return _processResult;
86 void SetResult(uint32 res) {
103 _frameNum = frameNum;
110 virtual void InitGump(
Gump *newparent,
bool take_focus =
true);
116 virtual Gump *
FindGump(FindGumpPredicate predicate,
bool recursive =
true);
123 return FindGump(&IsOfType<T>, recursive);
140 virtual void RenderSurfaceChanged();
186 static inline int32 ScaleCoord(int32 c, int32 factor) {
187 return ((c * factor) + (1 << 15)) >> 16;
189 static inline int32 UnscaleCoord(int32 c, int32 factor) {
190 return (c << 16) / factor;
197 virtual void Close(
bool no_del =
false);
201 return (_flags & FLAG_CLOSING) != 0;
205 virtual void Move(int32 x, int32 y) {
216 void getLocation(int32 &x, int32 &y)
const {
258 ROUND_BOTTOMRIGHT = 1
267 PointRoundDir r = ROUND_TOPLEFT);
271 PointRoundDir r = ROUND_TOPLEFT);
275 PointRoundDir r = ROUND_TOPLEFT);
279 PointRoundDir r = ROUND_TOPLEFT);
288 virtual uint16
TraceObjId(int32 mx, int32 my);
293 int32 lerp_factor = 256);
317 virtual Gump *onMouseDown(
int button, int32 mx, int32 my);
318 virtual void onMouseUp(
int button, int32 mx, int32 my) { }
319 virtual void onMouseClick(
int button, int32 mx, int32 my) { }
320 virtual void onMouseDouble(
int button, int32 mx, int32 my) { }
321 virtual Gump *onMouseMotion(int32 mx, int32 my);
325 virtual void onMouseOver() { };
326 virtual void onMouseLeft() { };
332 virtual bool OnKeyDown(
int key,
int mod);
333 virtual bool OnKeyUp(
int key);
334 virtual bool OnTextInput(
int unicode);
339 virtual void OnFocus(
bool ) { }
342 virtual void MakeFocus();
345 inline bool IsFocus() {
346 return _parent ? _parent->_focusChild == this :
false;
350 inline Gump *GetFocusChild() {
355 void FindNewFocusChild();
382 void SetIndex(int32 i) {
385 int32 GetIndex()
const {
392 virtual void onDragStop(int32 mx, int32 my);
393 virtual void onDrag(int32 mx, int32 my);
430 FLAG_DRAGGABLE = 0x0001,
431 FLAG_HIDDEN = 0x0002,
432 FLAG_CLOSING = 0x0004,
433 FLAG_CLOSE_AND_DEL = 0x0008,
434 FLAG_ITEM_DEPENDENT = 0x0010,
435 FLAG_DONT_SAVE = 0x0020,
436 FLAG_CORE_GUMP = 0x0040,
437 FLAG_KEEP_VISIBLE = 0x0080,
438 FLAG_PREVENT_SAVE = 0x0100
443 return (_flags & flags) != 0;
446 inline bool IsHidden()
const {
447 return (_flags & FLAG_HIDDEN) || (_parent && _parent->IsHidden());
449 bool IsDraggable()
const {
450 return _flags & FLAG_DRAGGABLE;
452 virtual void HideGump() {
453 _flags |= FLAG_HIDDEN;
455 virtual void UnhideGump() {
456 _flags &= ~FLAG_HIDDEN;
458 void SetVisibility(
bool visible) {
465 bool mustSave(
bool toplevel)
const;
474 LAYER_ABOVE_NORMAL = 8,
virtual void setRelativePosition(Position pos, int xoffset=0, int yoffset=0)
Moves this gump to a relative location on the parent gump.
virtual void Move(int32 x, int32 y)
Move this gump.
Definition: gump.h:205
virtual bool StartDraggingItem(Item *item, int mx, int my)
Definition: gump.h:397
virtual void DraggingItemLeftGump(Item *item)
Called when an item that was being dragged over the gump left the gump.
Definition: gump.h:409
Definition: gump_notify_process.h:33
virtual void InitGump(Gump *newparent, bool take_focus=true)
virtual void SetDims(const Rect &d)
Set the _dims.
Definition: gump.h:249
virtual void GumpRectToScreenSpace(Rect &gr, RectRoundDir r=ROUND_OUTSIDE)
Transform a rectangle to screenspace from gumpspace.
virtual void GumpToParent(int32 &gx, int32 &gy, PointRoundDir r=ROUND_TOPLEFT)
Convert a gump point to parent relative point.
virtual void PaintChildren(RenderSurface *surf, int32 lerp_factor, bool scaled)
Paint the Gumps Children (RenderSurface is relative to this)
virtual void PaintCompositing(RenderSurface *surf, int32 lerp_factor, int32 scalex, int32 scaley)
virtual void RemoveChild(Gump *)
Remove a gump from the child list.
Definition: render_surface.h:40
virtual void PaintThis(RenderSurface *surf, int32 lerp_factor, bool scaled)
Overloadable method to Paint just this Gump (RenderSurface is relative to this)
virtual void run()
Run the gump.
Definition: detection.h:27
Gump * GetParent()
Get the parent.
Definition: gump.h:372
virtual void ScreenSpaceToGumpRect(Rect &sr, RectRoundDir r=ROUND_OUTSIDE)
Transform a rectangle to gumpspace from screenspace.
void UpdateDimsFromShape()
Update the width/height to match the gump's current shape frame.
virtual void ParentToGump(int32 &px, int32 &py, PointRoundDir r=ROUND_TOPLEFT)
Convert a parent relative point to a gump point.
virtual void StopDraggingItem(Item *item, bool moved)
Definition: gump.h:415
virtual void AddChild(Gump *, bool take_focus=true)
Add a gump to the child list.
virtual void PaintComposited(RenderSurface *surf, int32 lerp_factor, int32 scalex, int32 scaley)
Overloadable method to Paint just this gumps unscaled components that require compositing (RenderSurf...
Gump * GetRootGump()
Get the root gump (or self)
Gump * FindGump(bool recursive=true)
Definition: gump.h:122
static bool FindByIndex(const Gump *g)
A predicate to find a ui element by its index.
Definition: gump.h:127
virtual void ChildNotify(Gump *child, uint32 message)
Definition: gump.h:381
virtual void ScreenSpaceToGump(int32 &sx, int32 &sy, PointRoundDir r=ROUND_TOPLEFT)
Convert a screen space point to a gump point.
virtual bool DraggingItem(Item *item, int mx, int my)
Definition: gump.h:404
void SetShape(const Shape *shape, uint32 frameNum)
Set the Gump's shape/frame.
Definition: gump.h:91
virtual bool onDragStart(int32 mx, int32 my)
virtual uint16 TraceObjId(int32 mx, int32 my)
Trace a click, and return ObjId.
bool hasFlags(uint flags) const
Does this gump have any of the given flags mask set.
Definition: gump.h:442
virtual bool GetLocationOfItem(uint16 itemid, int32 &gx, int32 &gy, int32 lerp_factor=256)
virtual void CloseItemDependents()
Definition: frame_id.h:30
virtual void MoveRelative(int x, int y)
Move this gump relative to its current position.
Definition: gump.h:211
Definition: containers.h:200
virtual void GumpToScreenSpace(int32 &gx, int32 &gy, PointRoundDir r=ROUND_TOPLEFT)
Convert a gump point to a screen space point.
virtual bool GetMouseCursor(int32 mx, int32 my, Shape &shape, int32 &frame)
virtual void DropItem(Item *item, int mx, int my)
Definition: gump.h:422
virtual void Paint(RenderSurface *surf, int32 lerp_factor, bool scaled)
virtual Gump * FindGump(FindGumpPredicate predicate, bool recursive=true)
virtual void MoveChildToFront(Gump *)
Move child to front (within its layer)
virtual void GetDims(Rect &d) const
Get the _dims.
Definition: gump.h:244
Std::list< Gump * > _children
Definition: gump.h:65
bool IsClosing() const
Check to see if a Gump is Closing.
Definition: gump.h:200
virtual bool PointOnGump(int mx, int my)
Detect if a point is on the gump.
void Set_frameNum(uint32 frameNum)
Set the Gump's frame.
Definition: gump.h:102
virtual void Close(bool no_del=false)