Skip to content

Commit

Permalink
SCUMM: Give Loom and Indy 3 their own Mac GUI header files
Browse files Browse the repository at this point in the history
  • Loading branch information
Torbjörn Andersson committed Dec 11, 2023
1 parent c2a2a8e commit e525613
Show file tree
Hide file tree
Showing 7 changed files with 367 additions and 293 deletions.
2 changes: 2 additions & 0 deletions engines/scumm/macgui/macgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "scumm/scumm.h"
#include "scumm/macgui/macgui.h"
#include "scumm/macgui/macgui_impl.h"
#include "scumm/macgui/macgui_indy3.h"
#include "scumm/macgui/macgui_loom.h"

namespace Scumm {

Expand Down
10 changes: 6 additions & 4 deletions engines/scumm/macgui/macgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,19 @@ class MacGui {
void drawBanner(char *message);
void undrawBanner();

Graphics::Surface *textArea() const;

bool runQuitDialog();
bool runRestartDialog();
void runDraftsInventory();

// Indiana Jones and the Last Crusade
bool isVerbGuiActive() const;

Graphics::Surface *textArea() const;
void clearTextArea();
void initTextAreaForActor(Actor *a, byte color);
void printCharToTextArea(int chr, int x, int y, int color);

bool isVerbGuiActive() const;
// Loom
void runDraftsInventory();
};

} // End of namespace Scumm
Expand Down
291 changes: 2 additions & 289 deletions engines/scumm/macgui/macgui_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*
*/

#ifndef SCUMM_GFX_MAC_H
#define SCUMM_GFX_MAC_H
#ifndef SCUMM_MACGUI_MACGUI_IMPL_H
#define SCUMM_MACGUI_MACGUI_IMPL_H

#define TEXT_END_MARKER { 0, 0, kStyleRegular, Graphics::kTextAlignLeft, nullptr }

Expand Down Expand Up @@ -622,293 +622,6 @@ class MacGuiImpl {
void drawBitmap(Graphics::Surface *s, Common::Rect r, const uint16 *bitmap, Color color) const;
};

class MacLoomGui : public MacGuiImpl {
public:
MacLoomGui(ScummEngine *vm, Common::String resourceFile);
~MacLoomGui();

const Common::String name() const { return "Loom"; }

bool handleEvent(Common::Event event);

const Graphics::Font *getFontByScummId(int32 id);

void setupCursor(int &width, int &height, int &hotspotX, int &hotspotY, int &animate);

void resetAfterLoad();
void update(int delta);

void runDraftsInventory();

protected:
bool getFontParams(FontId fontId, int &id, int &size, int &slant) const;

bool handleMenu(int id, Common::String &name);

void runAboutDialog();
bool runOpenDialog(int &saveSlotToHandle);
bool runSaveDialog(int &saveSlotToHandle, Common::String &name);
bool runOptionsDialog();

private:
Graphics::Surface *_practiceBox = nullptr;
Common::Point _practiceBoxPos;
int _practiceBoxNotes;
};

class MacIndy3Gui : public MacGuiImpl {
public:
enum ScrollDirection {
kScrollUp,
kScrollDown
};

MacIndy3Gui(ScummEngine *vm, Common::String resourceFile);
~MacIndy3Gui();

const Common::String name() const { return "Indy"; }

Graphics::Surface _textArea;

const Graphics::Font *getFontByScummId(int32 id);

void setupCursor(int &width, int &height, int &hotspotX, int &hotspotY, int &animate);

Graphics::Surface *textArea() { return &_textArea; }
void clearTextArea() { _textArea.fillRect(Common::Rect(_textArea.w, _textArea.h), kBlack); }
void initTextAreaForActor(Actor *a, byte color);
void printCharToTextArea(int chr, int x, int y, int color);

// There is a distinction between the GUI being allowed and being
// active. Allowed means that it's allowed to draw verbs, but not that
// it necessarily is. Active means that there are verbs on screen. From
// the outside, only the latter is relevant.
//
// One case where this makes a difference is when boxing with the
// coach. During the "10 minutes later" sign, the GUI is active but
// it's not drawing verbs, so the SCUMM engine is allowed to draw in
// the verb area to clear the power meters and text.

bool isVerbGuiActive() const;

void reset();
void resetAfterLoad();
void update(int delta);
bool handleEvent(Common::Event event);

protected:
bool getFontParams(FontId fontId, int &id, int &size, int &slant) const;

bool handleMenu(int id, Common::String &name);

void runAboutDialog();
bool runOpenDialog(int &saveSlotToHandle);
bool runSaveDialog(int &saveSlotToHandle, Common::String &name);
bool runOptionsDialog();
bool runIqPointsDialog();

private:
int _verbGuiTop = 0;
Graphics::Surface _verbGuiSurface;

bool _visible = false;

bool _leftButtonIsPressed = false;
Common::Point _leftButtonPressed;
Common::Point _leftButtonHeld;

int _timer = 0;

bool updateVerbs(int delta);
void updateMouseHeldTimer(int delta);
void drawVerbs();

void clearAboutDialog(MacDialogWindow *window);

int getInventoryScrollOffset() const;
void setInventoryScrollOffset(int n) const;

class Widget : public MacGuiObject {
private:
int _timer = 0;

public:
static ScummEngine *_vm;
static MacIndy3Gui *_gui;
static Graphics::Surface *_surface;

Widget(int x, int y, int width, int height);
virtual ~Widget() {}

void setEnabled(bool enabled) {
if (enabled != _enabled)
setRedraw(true);
if (!_enabled)
_timer = 0;
_enabled = enabled;
}

void setTimer(int t) { _timer = t; }
void clearTimer() { _timer = 0; }
bool hasTimer() const { return _timer > 0; }

bool getRedraw() const { return _redraw; }
virtual void setRedraw(bool redraw) { _redraw = redraw; }

virtual void reset();

virtual bool handleEvent(Common::Event &event) = 0;
virtual bool handleMouseHeld(Common::Point &pressed, Common::Point &held) { return false; }
virtual void updateTimer(int delta);
virtual void timeOut() {}

virtual void draw();
virtual void undraw();

byte translateChar(byte c) const;

// Primitives
void fill(Common::Rect r);
void drawBitmap(Common::Rect r, const uint16 *bitmap, Color color) const;
void drawShadowBox(Common::Rect r) const;
void drawShadowFrame(Common::Rect r, Color shadowColor, Color fillColor);

void markScreenAsDirty(Common::Rect r) const;
};

class VerbWidget : public Widget {
protected:
int _verbid = 0;
int _verbslot = -1;
bool _kill = false;

public:
VerbWidget(int x, int y, int width, int height) : Widget(x, y, width, height) {}

void setVerbid(int n) { _verbid = n; }
bool hasVerb() const { return _verbslot != -1; }
void threaten() { _kill = true; }
bool isDying() const { return _kill; }

void reset();

virtual void updateVerb(int verbslot);

void draw();
void undraw();
};

class Button : public VerbWidget {
private:
Common::String _text;

public:
Button(int x, int y, int width, int height);

bool handleEvent(Common::Event &event);

void reset();
void timeOut();
void updateVerb(int verbslot);

void draw();
};

class Inventory : public VerbWidget {
private:
class ScrollBar : public Widget {
private:
int _invCount = 0;
int _invOffset = 0;

public:
ScrollBar(int x, int y, int width, int height);

void setInventoryParameters(int invCount, int invOffset);
void scroll(ScrollDirection dir);
int getHandlePosition();

void reset();

bool handleEvent(Common::Event &event);

void draw();
};

class ScrollButton : public Widget {
public:
ScrollDirection _direction;

ScrollButton(int x, int y, int width, int height, ScrollDirection direction);

bool handleEvent(Common::Event &event);
bool handleMouseHeld(Common::Point &pressed, Common::Point &held);
void timeOut();

void draw();
};

class Slot : public Widget {
private:
Common::String _name;
int _slot = -1;
int _obj = -1;

public:
Slot(int slot, int x, int y, int width, int height);

void clearName() { _name.clear(); }
bool hasName() const { return !_name.empty(); }

void clearObject();
void setObject(int n);
int getObject() const { return _obj; }

void reset();

bool handleEvent(Common::Event &event);
void timeOut();

void draw();
};

Slot *_slots[6];
ScrollBar *_scrollBar;
ScrollButton *_scrollButtons[2];

static const uint16 _upArrow[16];
static const uint16 _downArrow[16];

public:
Inventory(int x, int y, int width, int height);
~Inventory();

void setRedraw(bool redraw);

void reset();

bool handleEvent(Common::Event &event);
bool handleMouseHeld(Common::Point &pressed, Common::Point &held);
void updateTimer(int delta);
void updateVerb(int verbslot);

void draw();
};

Common::HashMap<int, VerbWidget *> _widgets;
Common::Array<Common::Rect> _dirtyRects;

bool isVerbGuiAllowed() const;

void show();
void hide();

void fill(Common::Rect r);

void markScreenAsDirty(Common::Rect r);
void copyDirtyRectsToScreen();
};

} // End of namespace Scumm

#endif
1 change: 1 addition & 0 deletions engines/scumm/macgui/macgui_indy3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "scumm/actor.h"
#include "scumm/charset.h"
#include "scumm/macgui/macgui_impl.h"
#include "scumm/macgui/macgui_indy3.h"
#include "scumm/sound.h"
#include "scumm/verbs.h"

Expand Down
Loading

0 comments on commit e525613

Please sign in to comment.