Changeset 85b5fec in opengl-game


Ignore:
Timestamp:
Mar 14, 2021, 2:10:20 AM (3 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
7865c5b
Parents:
d255d52
Message:

Use the new UI system in SDLGame as well

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • VulkanGame.vcxproj

    rd255d52 r85b5fec  
    143143    <ClCompile Include="game-gui-sdl.cpp" />
    144144    <ClCompile Include="gui\imgui\button-imgui.cpp" />
    145     <ClCompile Include="gui\imgui\ui-wdget.cpp" />
     145    <ClCompile Include="gui\imgui\ui-widget.cpp" />
    146146    <ClCompile Include="IMGUI\imgui.cpp" />
    147147    <ClCompile Include="IMGUI\imgui_demo.cpp" />
  • VulkanGame.vcxproj.filters

    rd255d52 r85b5fec  
    3232      <Filter>IMGUI SDL Reference</Filter>
    3333    </ClCompile>
    34     <ClCompile Include="gui\imgui\ui-wdget.cpp">
     34    <ClCompile Include="gui\imgui\ui-widget.cpp">
    3535      <Filter>gui\imgui</Filter>
    3636    </ClCompile>
  • sdl-game.cpp

    rd255d52 r85b5fec  
    88
    99#include "logger.hpp"
     10
     11#include "gui/imgui/button-imgui.hpp"
    1012
    1113using namespace std;
     
    343345      ImGui::NewFrame();
    344346
    345       (this->*currentRenderScreenFn)();
     347      (this->*currentRenderScreenFn)(gui->getWindowWidth(), gui->getWindowHeight());
    346348
    347349      ImGui::Render();
     
    10091011}
    10101012
    1011 void VulkanGame::renderMainScreen() {
    1012    unsigned int windowWidth = 640;
    1013    unsigned int windowHeight = 480;
    1014 
     1013void VulkanGame::renderMainScreen(int width, int height) {
    10151014   {
    10161015      int padding = 4;
    1017       ImGui::SetNextWindowPos(ImVec2(-padding, -padding), ImGuiCond_Once);
    1018       ImGui::SetNextWindowSize(ImVec2(windowWidth + 2 * padding, windowHeight + 2 * padding), ImGuiCond_Always);
     1016      ImGui::SetNextWindowPos(vec2(-padding, -padding), ImGuiCond_Once);
     1017      ImGui::SetNextWindowSize(vec2(width + 2 * padding, height + 2 * padding), ImGuiCond_Always);
    10191018      ImGui::Begin("WndMain", nullptr,
    10201019         ImGuiWindowFlags_NoTitleBar |
     
    10221021         ImGuiWindowFlags_NoMove);
    10231022
    1024       ImGui::InvisibleButton("", ImVec2(10, 80));
    1025       ImGui::InvisibleButton("", ImVec2(285, 18));
    1026       ImGui::SameLine();
    1027       if (ImGui::Button("New Game")) {
     1023      ButtonImGui btn("New Game");
     1024
     1025      ImGui::InvisibleButton("", vec2(10, height / 6));
     1026      if (btn.draw((width - btn.getWidth()) / 2)) {
    10281027         goToScreen(&VulkanGame::renderGameScreen);
    10291028      }
    10301029
    1031       ImGui::InvisibleButton("", ImVec2(10, 15));
    1032       ImGui::InvisibleButton("", ImVec2(300, 18));
    1033       ImGui::SameLine();
    1034       if (ImGui::Button("Quit")) {
     1030      ButtonImGui btn2("Quit");
     1031
     1032      ImGui::InvisibleButton("", vec2(10, 15));
     1033      if (btn2.draw((width - btn2.getWidth()) / 2)) {
    10351034         quitGame();
    10361035      }
     
    10401039}
    10411040
    1042 void VulkanGame::renderGameScreen() {
     1041void VulkanGame::renderGameScreen(int width, int height) {
    10431042   {
    1044       ImGui::SetNextWindowSize(ImVec2(130, 65), ImGuiCond_Once);
    1045       ImGui::SetNextWindowPos(ImVec2(10, 50), ImGuiCond_Once);
     1043      ImGui::SetNextWindowSize(vec2(130, 65), ImGuiCond_Once);
     1044      ImGui::SetNextWindowPos(vec2(10, 50), ImGuiCond_Once);
    10461045      ImGui::Begin("WndStats", nullptr,
    10471046         ImGuiWindowFlags_NoTitleBar |
     
    10561055
    10571056   {
    1058       ImGui::SetNextWindowSize(ImVec2(250, 35), ImGuiCond_Once);
    1059       ImGui::SetNextWindowPos(ImVec2(380, 10), ImGuiCond_Once);
     1057      ImGui::SetNextWindowSize(vec2(250, 35), ImGuiCond_Once);
     1058      ImGui::SetNextWindowPos(vec2(width - 260, 10), ImGuiCond_Always);
    10601059      ImGui::Begin("WndMenubar", nullptr,
    10611060         ImGuiWindowFlags_NoTitleBar |
    10621061         ImGuiWindowFlags_NoResize |
    10631062         ImGuiWindowFlags_NoMove);
    1064       ImGui::InvisibleButton("", ImVec2(155, 18));
     1063      ImGui::InvisibleButton("", vec2(155, 18));
    10651064      ImGui::SameLine();
    10661065      if (ImGui::Button("Main Menu")) {
     
    10711070
    10721071   {
    1073       ImGui::SetNextWindowSize(ImVec2(200, 200), ImGuiCond_Once);
    1074       ImGui::SetNextWindowPos(ImVec2(430, 60), ImGuiCond_Once);
     1072      ImGui::SetNextWindowSize(vec2(200, 200), ImGuiCond_Once);
     1073      ImGui::SetNextWindowPos(vec2(width - 210, 60), ImGuiCond_Always);
    10751074      ImGui::Begin("WndDebug", nullptr,
    10761075         ImGuiWindowFlags_NoTitleBar |
     
    10891088}
    10901089
     1090// TODO: Probably turn this into a UI widget class
    10911091void VulkanGame::renderGuiValueList(vector<UIValue>& values) {
    10921092   float maxWidth = 0.0f;
     
    11261126}
    11271127
    1128 void VulkanGame::goToScreen(void (VulkanGame::* renderScreenFn)()) {
     1128void VulkanGame::goToScreen(void (VulkanGame::* renderScreenFn)(int width, int height)) {
    11291129   currentRenderScreenFn = renderScreenFn;
     1130
     1131   // TODO: Maybe just set shouldRecreateSwapChain to true instead. Check this render loop logic
     1132   // to make sure there'd be no issues
     1133   //recreateSwapChain();
    11301134}
    11311135
  • sdl-game.hpp

    rd255d52 r85b5fec  
    109109      /*** High-level vars ***/
    110110
    111       void (VulkanGame::* currentRenderScreenFn)();
     111      // TODO: Just typedef the type of this function to RenderScreenFn or something since it's used in a few places
     112      void (VulkanGame::* currentRenderScreenFn)(int width, int height);
    112113
    113114      map<string, vector<UIValue>> valueLists;
     
    158159      /*** High-level functions ***/
    159160
    160       void renderMainScreen();
    161       void renderGameScreen();
     161      void renderMainScreen(int width, int height);
     162      void renderGameScreen(int width, int height);
    162163
    163164      void initGuiValueLists(map<string, vector<UIValue>>& valueLists);
    164165      void renderGuiValueList(vector<UIValue>& values);
    165166
    166       void goToScreen(void (VulkanGame::* renderScreenFn)());
     167      void goToScreen(void (VulkanGame::* renderScreenFn)(int width, int height));
    167168      void quitGame();
    168169
  • vulkan-game.cpp

    rd255d52 r85b5fec  
    1111
    1212#include "logger.hpp"
    13 
    1413#include "utils.hpp"
    1514
Note: See TracChangeset for help on using the changeset viewer.