diff --git a/engines/ultima/ultima8/gumps/book_gump.cpp b/engines/ultima/ultima8/gumps/book_gump.cpp index fa6afea5b60..6e6fc5e2667 100644 --- a/engines/ultima/ultima8/gumps/book_gump.cpp +++ b/engines/ultima/ultima8/gumps/book_gump.cpp @@ -73,12 +73,7 @@ void BookGump::InitGump(Gump *newparent, bool take_focus) { Shape *shapeP = GameData::get_instance()->getGumps()->getShape(6); SetShape(shapeP, 0); - - const ShapeFrame *sf = shapeP->getFrame(0); - assert(sf); - - _dims.w = sf->_width; - _dims.h = sf->_height; + UpdateDimsFromShape(); } void BookGump::NextText() { diff --git a/engines/ultima/ultima8/gumps/container_gump.cpp b/engines/ultima/ultima8/gumps/container_gump.cpp index 2172fc24cd0..fc80e8a9c60 100644 --- a/engines/ultima/ultima8/gumps/container_gump.cpp +++ b/engines/ultima/ultima8/gumps/container_gump.cpp @@ -66,11 +66,7 @@ ContainerGump::~ContainerGump() { } void ContainerGump::InitGump(Gump *newparent, bool take_focus) { - const ShapeFrame *sf = _shape->getFrame(_frameNum); - assert(sf); - - _dims.w = sf->_width; - _dims.h = sf->_height; + UpdateDimsFromShape(); // Wait with ItemRelativeGump initialization until we calculated our size. ItemRelativeGump::InitGump(newparent, take_focus); diff --git a/engines/ultima/ultima8/gumps/gump.cpp b/engines/ultima/ultima8/gumps/gump.cpp index a75bc422644..6d9351b602f 100644 --- a/engines/ultima/ultima8/gumps/gump.cpp +++ b/engines/ultima/ultima8/gumps/gump.cpp @@ -82,12 +82,16 @@ void Gump::SetShape(FrameID frame, bool adjustsize) { _frameNum = frame._frameNum; if (adjustsize && _shape) { - const ShapeFrame *sf = _shape->getFrame(_frameNum); - _dims.w = sf->_width; - _dims.h = sf->_height; + UpdateDimsFromShape(); } } +void Gump::UpdateDimsFromShape() { + const ShapeFrame *sf = _shape->getFrame(_frameNum); + assert(sf); + _dims.w = sf->_width; + _dims.h = sf->_height; +} void Gump::CreateNotifier() { assert(_notifier == 0); diff --git a/engines/ultima/ultima8/gumps/gump.h b/engines/ultima/ultima8/gumps/gump.h index 169c1281b1f..59fd92ba0a2 100644 --- a/engines/ultima/ultima8/gumps/gump.h +++ b/engines/ultima/ultima8/gumps/gump.h @@ -94,6 +94,9 @@ public: void SetShape(FrameID frame, bool adjustsize = false); + //! Update the width/height to match the gump's current shape frame + void UpdateDimsFromShape(); + //! Set the Gump's frame inline void Set_frameNum(uint32 frameNum) { _frameNum = frameNum; diff --git a/engines/ultima/ultima8/gumps/menu_gump.cpp b/engines/ultima/ultima8/gumps/menu_gump.cpp index e18899dd8d1..d78e926142f 100644 --- a/engines/ultima/ultima8/gumps/menu_gump.cpp +++ b/engines/ultima/ultima8/gumps/menu_gump.cpp @@ -108,15 +108,11 @@ void MenuGump::InitGump(Gump *newparent, bool take_focus) { ModalGump::InitGump(newparent, take_focus); _shape = GameData::get_instance()->getGumps()->getShape(gumpShape); - const ShapeFrame *sf = _shape->getFrame(0); - assert(sf); - - _dims.w = sf->_width; - _dims.h = sf->_height; + UpdateDimsFromShape(); Shape *logoShape; logoShape = GameData::get_instance()->getGumps()->getShape(paganShape); - sf = logoShape->getFrame(0); + const ShapeFrame *sf = logoShape->getFrame(0); assert(sf); Gump *logo = new Gump(42, 10, sf->_width, sf->_height); diff --git a/engines/ultima/ultima8/gumps/mini_stats_gump.cpp b/engines/ultima/ultima8/gumps/mini_stats_gump.cpp index 7fee623ba4b..52893a1d80e 100644 --- a/engines/ultima/ultima8/gumps/mini_stats_gump.cpp +++ b/engines/ultima/ultima8/gumps/mini_stats_gump.cpp @@ -66,11 +66,7 @@ void MiniStatsGump::InitGump(Gump *newparent, bool take_focus) { Gump::InitGump(newparent, take_focus); _shape = GameData::get_instance()->getGumps()->getShape(gumpshape); - const ShapeFrame *sf = _shape->getFrame(0); - assert(sf); - - _dims.w = sf->_width; - _dims.h = sf->_height; + UpdateDimsFromShape(); } void MiniStatsGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool scaled) { diff --git a/engines/ultima/ultima8/gumps/paged_gump.cpp b/engines/ultima/ultima8/gumps/paged_gump.cpp index d0e6bd53733..70bf894d8d1 100644 --- a/engines/ultima/ultima8/gumps/paged_gump.cpp +++ b/engines/ultima/ultima8/gumps/paged_gump.cpp @@ -60,11 +60,7 @@ void PagedGump::InitGump(Gump *newparent, bool take_focus) { ModalGump::InitGump(newparent, take_focus); _shape = GameData::get_instance()->getGumps()->getShape(_gumpShape); - const ShapeFrame *sf = _shape->getFrame(0); - assert(sf); - - _dims.w = sf->_width; - _dims.h = sf->_height; + UpdateDimsFromShape(); FrameID buttonleft(GameData::GUMPS, pageOverShape, 0); FrameID buttonright(GameData::GUMPS, pageOverShape, 1); diff --git a/engines/ultima/ultima8/gumps/quit_gump.cpp b/engines/ultima/ultima8/gumps/quit_gump.cpp index 2eee406550e..c518c7cb5ce 100644 --- a/engines/ultima/ultima8/gumps/quit_gump.cpp +++ b/engines/ultima/ultima8/gumps/quit_gump.cpp @@ -57,17 +57,13 @@ void QuitGump::InitGump(Gump *newparent, bool take_focus) { ModalGump::InitGump(newparent, take_focus); _shape = GameData::get_instance()->getGumps()->getShape(gumpShape); - const ShapeFrame *sf = _shape->getFrame(0); - assert(sf); - - _dims.w = sf->_width; - _dims.h = sf->_height; + UpdateDimsFromShape(); FrameID askshape(GameData::GUMPS, askShapeId, 0); askshape = _TL_SHP_(askshape); Shape *askShape = GameData::get_instance()->getShape(askshape); - sf = askShape->getFrame(askshape._frameNum); + const ShapeFrame *sf = askShape->getFrame(askshape._frameNum); assert(sf); Gump *ask = new Gump(0, 0, sf->_width, sf->_height); diff --git a/engines/ultima/ultima8/gumps/readable_gump.cpp b/engines/ultima/ultima8/gumps/readable_gump.cpp index 3a0ed1b7ea5..ba11a79c365 100644 --- a/engines/ultima/ultima8/gumps/readable_gump.cpp +++ b/engines/ultima/ultima8/gumps/readable_gump.cpp @@ -63,11 +63,7 @@ void ReadableGump::InitGump(Gump *newparent, bool take_focus) { SetShape(shape_, 0); - const ShapeFrame *sf = shape_->getFrame(0); - assert(sf); - - _dims.w = sf->_width; - _dims.h = sf->_height; + UpdateDimsFromShape(); if (CoreApp::get_instance()->getGameInfo()->_language == GameInfo::GAMELANG_JAPANESE) { diff --git a/engines/ultima/ultima8/gumps/scroll_gump.cpp b/engines/ultima/ultima8/gumps/scroll_gump.cpp index d6e9267b9a6..151cbae502b 100644 --- a/engines/ultima/ultima8/gumps/scroll_gump.cpp +++ b/engines/ultima/ultima8/gumps/scroll_gump.cpp @@ -66,12 +66,7 @@ void ScrollGump::InitGump(Gump *newparent, bool take_focus) { Shape *shape_ = GameData::get_instance()->getGumps()->getShape(19); SetShape(shape_, 0); - - const ShapeFrame *sf = shape_->getFrame(0); - assert(sf); - - _dims.w = sf->_width; - _dims.h = sf->_height; + UpdateDimsFromShape(); } void ScrollGump::NextText() { diff --git a/engines/ultima/ultima8/gumps/slider_gump.cpp b/engines/ultima/ultima8/gumps/slider_gump.cpp index 2d8d960f503..16b7c6504b3 100644 --- a/engines/ultima/ultima8/gumps/slider_gump.cpp +++ b/engines/ultima/ultima8/gumps/slider_gump.cpp @@ -125,11 +125,7 @@ void SliderGump::InitGump(Gump *newparent, bool take_focus) { ModalGump::InitGump(newparent, take_focus); _shape = GameData::get_instance()->getGumps()->getShape(gumpshape); - const ShapeFrame *sf = _shape->getFrame(0); - assert(sf); - - _dims.w = sf->_width; - _dims.h = sf->_height; + UpdateDimsFromShape(); Shape *childshape = GameData::get_instance()-> getGumps()->getShape(slidershape); diff --git a/engines/ultima/ultima8/gumps/widgets/button_widget.cpp b/engines/ultima/ultima8/gumps/widgets/button_widget.cpp index 8b9deb99eaf..955b6d924b9 100644 --- a/engines/ultima/ultima8/gumps/widgets/button_widget.cpp +++ b/engines/ultima/ultima8/gumps/widgets/button_widget.cpp @@ -79,13 +79,8 @@ void ButtonWidget::InitGump(Gump *newparent, bool take_focus) { assert(_shapeUp != nullptr); assert(_shapeDown != nullptr); - _shape = _shapeUp; - _frameNum = _frameNumUp; - - const ShapeFrame *sf = _shape->getFrame(_frameNum); - assert(sf); - _dims.w = sf->_width; - _dims.h = sf->_height; + SetShape(_shapeUp, _frameNumUp); + UpdateDimsFromShape(); } } diff --git a/engines/ultima/ultima8/gumps/widgets/sliding_widget.cpp b/engines/ultima/ultima8/gumps/widgets/sliding_widget.cpp index 48b6cdc3851..686688b005f 100644 --- a/engines/ultima/ultima8/gumps/widgets/sliding_widget.cpp +++ b/engines/ultima/ultima8/gumps/widgets/sliding_widget.cpp @@ -49,11 +49,7 @@ SlidingWidget::~SlidingWidget() { void SlidingWidget::InitGump(Gump *newparent, bool take_focus) { Gump::InitGump(newparent, take_focus); - const ShapeFrame *sf = _shape->getFrame(_frameNum); - assert(sf); - - _dims.w = sf->_width; - _dims.h = sf->_height; + UpdateDimsFromShape(); } uint16 SlidingWidget::TraceObjId(int32 mx, int32 my) {