Skip to content

Commit

Permalink
Migrate to latest Guichan.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarod42 committed Dec 5, 2023
1 parent 311a684 commit 58400e7
Show file tree
Hide file tree
Showing 23 changed files with 827 additions and 1,036 deletions.
21 changes: 10 additions & 11 deletions src/editor/editloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ static void EditorCallbackButtonUp(unsigned button)
GameMenuButtonClicked = false;
if (ButtonUnderCursor == ButtonUnderMenu) {
if (UI.MenuButton.Callback) {
UI.MenuButton.Callback->action("");
UI.MenuButton.Callback->action(gcn::ActionEvent{nullptr, ""});
}
}
}
Expand Down Expand Up @@ -1398,22 +1398,26 @@ static void EditorCallbackKeyDown(unsigned key, unsigned keychar)
case SDLK_PAGEUP:
if ((KeyModifiers & ModifierAlt) && KeyModifiers & ModifierControl) {
if (editorSlider->isVisible()) {
editorSlider->keyPress(gcn::Key::LEFT);
gcn::KeyEvent keyEvent{
nullptr, nullptr, false, false, false, false, 0, false, gcn::Key::Left};
editorSlider->keyPressed(keyEvent);
}
}
break;

case SDLK_PAGEDOWN:
if ((KeyModifiers & ModifierAlt) && KeyModifiers & ModifierControl) {
if (editorSlider->isVisible()) {
editorSlider->keyPress(gcn::Key::RIGHT);
gcn::KeyEvent keyEvent{
nullptr, nullptr, false, false, false, false, 0, false, gcn::Key::Right};
editorSlider->keyPressed(keyEvent);
}
}
break;

case 't':
toolDropdown->setSelected((toolDropdown->getSelected() + 1) % (toolDropdown->getListModel()->getNumberOfElements()));
toolDropdown->action("");
toolDropdown->action(gcn::ActionEvent{nullptr, ""});
break;

case 'f': // ALT+F, CTRL+F toggle fullscreen
Expand Down Expand Up @@ -2173,9 +2177,6 @@ void EditorMainLoop()
}

overlaysDropdown->setWidth(overlaysWidth);
overlaysDropdown->getScrollArea()->setWidth(overlaysWidth);
overlaysDropdown->getListBox()->setWidth(overlaysWidth);

overlaysDropdown->setBaseColor(gcn::Color(38, 38, 78));
overlaysDropdown->setForegroundColor(gcn::Color(200, 200, 120));
overlaysDropdown->setBackgroundColor(gcn::Color(200, 200, 120));
Expand Down Expand Up @@ -2205,8 +2206,6 @@ void EditorMainLoop()
}
toolDropdown->setListModel(new StringListModel(toolListStrings));
toolDropdown->setWidth(newW);
toolDropdown->getScrollArea()->setWidth(newW);
toolDropdown->getListBox()->setWidth(newW);

overlaysDropdown->setX(toolDropdown->getX() + toolDropdown->getWidth() + 10);

Expand Down Expand Up @@ -2241,7 +2240,7 @@ void EditorMainLoop()
toolDropdown->getAbsolutePosition(tbX, tbY);
tbX += CursorScreenPos.x;
tbY += CursorScreenPos.y;
if (!(toolDropdown->getDimension().isPointInRect(tbX, tbY))) {
if (!(toolDropdown->getDimension().isContaining(tbX, tbY))) {
DoScrollArea(MouseScrollState, 0, MouseScrollState == 0 && KeyScrollState > 0);
}
}
Expand All @@ -2259,7 +2258,7 @@ void EditorMainLoop()
if (start) {
start = false;
if (UI.MenuButton.Callback) {
UI.MenuButton.Callback->action("");
UI.MenuButton.Callback->action(gcn::ActionEvent(nullptr, ""));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/include/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class CFont : public gcn::Font
int getHeight() const override { return Height(); }
int getWidth(const std::string &text) const override { return Width(text); }
void drawString(gcn::Graphics *graphics, const std::string &text, int x, int y) override;
int getStringIndexAt(const std::string &text, int x) override;
int getStringIndexAt(const std::string &text, int x) const override;

// Set to false to reverse color when drawing string
void setIsNormal(bool value) { is_normal = value; }
Expand Down
15 changes: 9 additions & 6 deletions src/include/movie.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,20 @@ class Movie : public gcn::Image
Movie() = default;
~Movie();
bool Load(const std::string &filename, int w, int h);
bool IsPlaying() const { return is_dirty; }
bool IsPlaying() const { return true; }

// guichan
void *_getData() const override;
int getWidth() const override { return Width; }
int getHeight() const override { return Height; }
bool isDirty() const override { return is_dirty; }
void free() override { throw "unimplemented"; };
gcn::Color getPixel(int, int) override { throw "unimplemented"; };
void putPixel(int, int, const gcn::Color &) override { throw "unimplemented"; };
void convertToDisplayFormat() override { throw "unimplemented"; };

int Width = 0;
int Height = 0;
SDL_Surface *surface = nullptr;
CFile *f = nullptr;
mutable bool is_dirty = true;
mutable bool need_data = true;
mutable Uint32 start_time = 0;
mutable OggData *data = nullptr;
Expand Down Expand Up @@ -139,10 +140,12 @@ class Movie : public gcn::Image
bool IsPlaying() const { return false; }

// guichan
void *_getData() const override { return nullptr; }
int getWidth() const override { return 0; }
int getHeight() const override { return 0; }
bool isDirty() const override { return false; }
void free() override { throw "unimplemented"; };
gcn::Color getPixel(int, int) override { throw "unimplemented"; };
void putPixel(int, int, const gcn::Color &) override { throw "unimplemented"; };
void convertToDisplayFormat() override { throw "unimplemented"; };
};
#endif

Expand Down
29 changes: 19 additions & 10 deletions src/include/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

#include <SDL.h>
#include <guichan.hpp>
#include <guichan/sdl/sdlimage.hpp>

#include <string_view>
#include <vector>

Expand Down Expand Up @@ -92,7 +94,7 @@ class PixelModifier
/// Add more modifiers here
};

class CGraphic : public gcn::Image
class CGraphic : public gcn::SDLImage
{
public:
struct frame_pos_t {
Expand All @@ -101,7 +103,7 @@ class CGraphic : public gcn::Image
};

protected:
CGraphic() = default;
CGraphic() : gcn::SDLImage(nullptr, false) {}
~CGraphic() {}

public:
Expand Down Expand Up @@ -174,20 +176,24 @@ class CGraphic : public gcn::Image
// minor programmatic editing features
void OverlayGraphic(CGraphic *other, bool mask = false);

bool IsLoaded(bool flipped = false) const { return Surface != nullptr && (!flipped || SurfaceFlip != nullptr); }
bool IsLoaded(bool flipped = false) const { return mSurface != nullptr && (!flipped || SurfaceFlip != nullptr); }

//guichan
void *_getData() const override { return Surface; }
int getWidth() const override { return Width; }
int getHeight() const override { return Height; }
void free() override { gcn::SDLImage::free(); }
gcn::Color getPixel(int x, int y) override { return gcn::SDLImage::getPixel(x, y); }
void putPixel(int x, int y, const gcn::Color &color) override{ gcn::SDLImage::putPixel(x, y, color); }
void convertToDisplayFormat() override { gcn::SDLImage::convertToDisplayFormat(); }

void setSurface(SDL_Surface *surface) { mSurface = surface; }

private:
void ExpandFor(const uint16_t numOfFramesToAdd);

public:
fs::path File; /// Filename
std::string HashFile; /// Filename used in hash
SDL_Surface *Surface = nullptr; /// Surface
SDL_Surface *SurfaceFlip = nullptr; /// Flipped surface
frame_pos_t *frame_map = nullptr;
frame_pos_t *frameFlip_map = nullptr;
Expand Down Expand Up @@ -251,14 +257,15 @@ class Mng : public gcn::Image
void Draw(int x, int y);

//guichan
void *_getData() const override;
int getWidth() const override { return surface->w; }
int getHeight() const override { return surface->h; }
bool isDirty() const override { return true; }
void free() override { throw "unimplemented"; }
gcn::Color getPixel(int x, int y) override { throw "unimplemented"; }
void putPixel(int x, int y, const gcn::Color &color) override { throw "unimplemented"; }
void convertToDisplayFormat() override { throw "unimplemented"; }

static uint32_t MaxFPS;

mutable bool is_dirty = false;
std::string name;
FILE *fd = nullptr;
mng_handle handle = nullptr;
Expand All @@ -281,10 +288,12 @@ class Mng : public gcn::Image
void Draw(int x, int y) {}

//guichan
void *_getData() const override { return nullptr; }
int getWidth() const override { return 0; }
int getHeight() const override { return 0; }
bool isDirty() const override { return false; }
void free() override { throw "unimplemented"; }
gcn::Color getPixel(int x, int y) override { throw "unimplemented"; }
void putPixel(int x, int y, const gcn::Color &color) override { throw "unimplemented"; }
void convertToDisplayFormat() override { throw "unimplemented"; }

static inline uint32_t MaxFPS = 15;
};
Expand Down
Loading

0 comments on commit 58400e7

Please sign in to comment.