commit 0db513aa
Add Dear ImGui
Changed files
| M | CMakeLists.txt before |
| M | extra/docker/Dockerfile before |
| M | src/PuzzleSingleImageState.cpp before |
| M | src/sago_common.cpp before |
| M | src/sago_multi_scrambler_puzzle2.cpp before |
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ecb4c06..2adbcd0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,6 +18,10 @@ pkg_search_module(SDL2GFX REQUIRED SDL2_gfx)
include_directories(${SDL2GFX_INCLUDE_DIRS})
+pkg_search_module(IMGUI REQUIRED imgui)
+include_directories(${IMGUI_INCLUDE_DIRS})
+
+
include_directories(SYSTEM "src/Libs/include")
@@ -27,4 +31,5 @@ add_executable(sago_multi_scrambler_puzzle2 ${SOURCES})
TARGET_LINK_LIBRARIES( sago_multi_scrambler_puzzle2 ${Boost_LIBRARIES} )
target_link_libraries( sago_multi_scrambler_puzzle2 ${SDL2_LIBRARIES})
target_link_libraries( sago_multi_scrambler_puzzle2 physfs)
+target_link_libraries( sago_multi_scrambler_puzzle2 ${IMGUI_LIBRARIES})
target_link_libraries( sago_multi_scrambler_puzzle2 ${SDL2MIXER_LIBRARIES} ${SDL2IMAGE_LIBRARIES} ${SDL2TTF_LIBRARIES} ${SDL2GFX_LIBRARIES})
\ No newline at end of file
diff --git a/extra/docker/Dockerfile b/extra/docker/Dockerfile
index c3c3e82..e6d046b 100644
--- a/extra/docker/Dockerfile
+++ b/extra/docker/Dockerfile
@@ -1,11 +1,11 @@
-FROM ubuntu:22.04
+FROM ubuntu:24.04
# Set timezone to UTC. This prevents apt-get install SOME-PACKAGES from asking for timezone during setup
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update && apt-get install --no-install-recommends -y build-essential libphysfs-dev libboost-dev cmake libsdl2-dev libsdl2-image-dev \
-libsdl2-gfx-dev libsdl2-mixer-dev libsdl2-ttf-dev libboost-program-options-dev zip gettext
+libsdl2-gfx-dev libsdl2-mixer-dev libsdl2-ttf-dev libboost-program-options-dev libimgui-dev zip gettext
RUN mkdir -p /staging/game
diff --git a/src/PuzzleSingleImageState.cpp b/src/PuzzleSingleImageState.cpp
index 0079d82..0730377 100644
--- a/src/PuzzleSingleImageState.cpp
+++ b/src/PuzzleSingleImageState.cpp
@@ -27,6 +27,7 @@ https://github.com/sago007/saland
#include "globals.hpp"
#include <SDL2/SDL2_gfxPrimitives.h>
#include <time.h>
+#include "SagoImGui.hpp"
PuzzleSingleImageState::PuzzleSingleImageState() {
@@ -59,6 +60,7 @@ void PuzzleSingleImageState::ProcessInput(const SDL_Event& event, bool &processe
isActive = false;
processed = true;
}
+ ImGui_ImplSDL2_ProcessEvent(&event);
}
void PuzzleSingleImageState::Draw(SDL_Renderer* target) {
@@ -70,40 +72,54 @@ void PuzzleSingleImageState::Draw(SDL_Renderer* target) {
rect.w = resized_image_width;
if (!shuffeled) {
SDL_RenderCopy(target, this->pictureTex, NULL, &rect);
- return;
}
- for (size_t i = 0; i < pieces.size(); ++i) {
- SDL_Rect destination = pieces[i];
- destination.x += rect.x;
- destination.y += rect.y;
- SDL_Rect source = pieces.at(shuffeled_pieces[i]);
- double scale = double(source_image_height)/double(resized_image_height);
- source.x = double(source.x)*scale;
- source.y = double(source.y)*scale;
- source.w = double(source.w)*scale;
- source.h = double(source.h)*scale;
- int flip = static_cast<int>(SDL_FLIP_NONE);
- if (rotated_pieces[i] == 1 || rotated_pieces[i] == 3) {
- flip |= SDL_FLIP_HORIZONTAL;
+ else {
+ for (size_t i = 0; i < pieces.size(); ++i) {
+ SDL_Rect destination = pieces[i];
+ destination.x += rect.x;
+ destination.y += rect.y;
+ SDL_Rect source = pieces.at(shuffeled_pieces[i]);
+ double scale = double(source_image_height)/double(resized_image_height);
+ source.x = double(source.x)*scale;
+ source.y = double(source.y)*scale;
+ source.w = double(source.w)*scale;
+ source.h = double(source.h)*scale;
+ int flip = static_cast<int>(SDL_FLIP_NONE);
+ if (rotated_pieces[i] == 1 || rotated_pieces[i] == 3) {
+ flip |= SDL_FLIP_HORIZONTAL;
+ }
+ if (rotated_pieces[i] == 2 || rotated_pieces[i] == 3) {
+ flip |= SDL_FLIP_VERTICAL;
+ }
+ SDL_RenderCopyEx(target, this->pictureTex, &source, &destination, 0, nullptr, static_cast<SDL_RendererFlip>(flip) );
}
- if (rotated_pieces[i] == 2 || rotated_pieces[i] == 3) {
- flip |= SDL_FLIP_VERTICAL;
+ for (size_t i = 0; i < pieces.size(); ++i) {
+ const SDL_Rect& piece = pieces[i];
+ if (i == marked_piece) {
+ continue;
+ }
+ rectangleRGBA(target, rect.x+piece.x, rect.y+piece.y,
+ rect.x+piece.x + piece.w, rect.y+piece.y + piece.h, 255, 255, 0, 255);
}
- SDL_RenderCopyEx(target, this->pictureTex, &source, &destination, 0, nullptr, static_cast<SDL_RendererFlip>(flip) );
- }
- for (size_t i = 0; i < pieces.size(); ++i) {
- const SDL_Rect& piece = pieces[i];
- if (i == marked_piece) {
- continue;
+ if (marked_piece > -1 && marked_piece < pieces.size()) {
+ const SDL_Rect& piece = pieces.at(marked_piece);
+ rectangleRGBA(target, rect.x+piece.x, rect.y+piece.y,
+ rect.x+piece.x + piece.w, rect.y+piece.y + piece.h, 255, 0, 0, 255);
}
- rectangleRGBA(target, rect.x+piece.x, rect.y+piece.y,
- rect.x+piece.x + piece.w, rect.y+piece.y + piece.h, 255, 255, 0, 255);
}
- if (marked_piece > -1 && marked_piece < pieces.size()) {
- const SDL_Rect& piece = pieces.at(marked_piece);
- rectangleRGBA(target, rect.x+piece.x, rect.y+piece.y,
- rect.x+piece.x + piece.w, rect.y+piece.y + piece.h, 255, 0, 0, 255);
+
+
+ ImGui::BeginMainMenuBar();
+ if (ImGui::BeginMenu("File")) {
+ if (ImGui::MenuItem("Close")) {
+ isActive = false;
+ }
+ if (ImGui::MenuItem("Shuffle")) {
+ Shuffle();
+ }
+ ImGui::EndMenu();
}
+ ImGui::EndMainMenuBar();
}
diff --git a/src/sago_common.cpp b/src/sago_common.cpp
index e762901..cf9273b 100644
--- a/src/sago_common.cpp
+++ b/src/sago_common.cpp
@@ -27,6 +27,7 @@ https://github.com/sago007/saland
#include "sago/SagoTextField.hpp"
#include "globals.hpp"
#include "sago_common.hpp"
+#include "SagoImGui.hpp"
void InitSagoFS(int argc, const char* argv[]) {
PHYSFS_init(argv[0]);
@@ -37,8 +38,23 @@ void RunGameState(sago::GameStateInterface& state ) {
bool done = false; //We are done!
while (!done && !globalData.isShuttingDown) {
SDL_RenderClear(globalData.screen);
+ ImGui_ImplSDLRenderer2_NewFrame();
+ ImGui_ImplSDL2_NewFrame();
+ ImGui::NewFrame();
state.Draw(globalData.screen);
+ ImGui::Render();
+ ImGuiIO& io = ImGui::GetIO();
+ float x, y;
+ SDL_RenderGetScale(globalData.screen, &x, &y);
+ SDL_RenderSetScale(globalData.screen, io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y);
+ ImGui_ImplSDLRenderer2_RenderDrawData( ImGui::GetDrawData() );
+ SDL_RenderSetScale(globalData.screen, x, y);
+
+ //While using Dear ImGui we do not draw the mouse ourself. This is gone: globalData.mouse.Draw(globalData.screen, SDL_GetTicks(), globalData.mousex, globalData.mousey);
+ SDL_RenderPresent(globalData.screen);
+
+
SDL_Delay(5);
SDL_Event event;
@@ -62,8 +78,7 @@ void RunGameState(sago::GameStateInterface& state ) {
state.Update();
- globalData.mouse.Draw(globalData.screen, SDL_GetTicks(), globalData.mousex, globalData.mousey);
- SDL_RenderPresent(globalData.screen);
+
if (!state.IsActive()) {
done = true;
@@ -109,9 +124,11 @@ void InitGame() {
int rendererFlags = 0;
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
+ SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_SCALING, "1");
win = SDL_CreateWindow(GAMENAME, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_RESIZABLE);
globalData.screen = SDL_CreateRenderer(win, -1, rendererFlags);
- SDL_RenderSetLogicalSize(globalData.screen, globalData.xsize, globalData.ysize);
+ SDL_RenderSetLogicalSize(globalData.screen, width, height);
+ InitImGui(win, globalData.screen, width, height);
dataHolder.invalidateAll(globalData.screen);
globalData.spriteHolder.reset(new sago::SagoSpriteHolder(dataHolder));
diff --git a/src/sago_multi_scrambler_puzzle2.cpp b/src/sago_multi_scrambler_puzzle2.cpp
index b9f3b05..6f224e6 100644
--- a/src/sago_multi_scrambler_puzzle2.cpp
+++ b/src/sago_multi_scrambler_puzzle2.cpp
@@ -32,6 +32,7 @@ https://github.com/sago007/saland
#include "ImageSelectState.hpp"
#include "sago_common.hpp"
#include "MainGameState.hpp"
+#include "SagoImGui.hpp"
#ifndef VERSIONNUMBER
#define VERSIONNUMBER "0.1.0"