GUI: earliest ever GUI
This commit is contained in:
parent
e8ac2947ab
commit
9b850c1763
7 changed files with 3576 additions and 8 deletions
1976
src/gui/font_main.cpp
Normal file
1976
src/gui/font_main.cpp
Normal file
File diff suppressed because it is too large
Load diff
1459
src/gui/font_pat.cpp
Normal file
1459
src/gui/font_pat.cpp
Normal file
File diff suppressed because it is too large
Load diff
7
src/gui/fonts.h
Normal file
7
src/gui/fonts.h
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef _FONTS_H
|
||||
#define _FONTS_H
|
||||
extern const unsigned int defFont_main_compressed_size;
|
||||
extern const unsigned int defFont_main_compressed_data[];
|
||||
extern const unsigned int defFont_pat_compressed_size;
|
||||
extern const unsigned int defFont_pat_compressed_data[];
|
||||
#endif
|
||||
|
|
@ -1,9 +1,82 @@
|
|||
#include "gui.h"
|
||||
#include "fonts.h"
|
||||
#include "../ta-log.h"
|
||||
#include "imgui.h"
|
||||
|
||||
void FurnaceGUI::bindEngine(DivEngine* eng) {
|
||||
e=eng;
|
||||
}
|
||||
|
||||
bool FurnaceGUI::loop() {
|
||||
while (!quit) {
|
||||
SDL_Event ev;
|
||||
while (SDL_PollEvent(&ev)) {
|
||||
ImGui_ImplSDL2_ProcessEvent(&ev);
|
||||
switch (ev.type) {
|
||||
case SDL_QUIT:
|
||||
quit=true;
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui_ImplSDLRenderer_NewFrame();
|
||||
ImGui_ImplSDL2_NewFrame(sdlWin);
|
||||
ImGui::NewFrame();
|
||||
|
||||
if (ImGui::Begin("Debug")) {
|
||||
ImGui::Text("Hello world!\n");
|
||||
ImGui::InputScalar("Speed 1",ImGuiDataType_U8,&e->song.speed1);
|
||||
ImGui::InputScalar("Speed 2",ImGuiDataType_U8,&e->song.speed2);
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
SDL_RenderClear(sdlRend);
|
||||
ImGui::Render();
|
||||
ImGui_ImplSDLRenderer_RenderDrawData(ImGui::GetDrawData());
|
||||
SDL_RenderPresent(sdlRend);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FurnaceGUI::init() {
|
||||
sdlWin=SDL_CreateWindow("Furnace",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,scrW*dpiScale,scrH*dpiScale,SDL_WINDOW_RESIZABLE|SDL_WINDOW_ALLOW_HIGHDPI);
|
||||
if (sdlWin==NULL) {
|
||||
logE("could not open window!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
sdlRend=SDL_CreateRenderer(sdlWin,-1,SDL_RENDERER_ACCELERATED|SDL_RENDERER_PRESENTVSYNC|SDL_RENDERER_TARGETTEXTURE);
|
||||
|
||||
if (sdlRend==NULL) {
|
||||
logE("could not init renderer! %s\n",SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
|
||||
ImGui::StyleColorsDark();
|
||||
ImGui_ImplSDL2_InitForSDLRenderer(sdlWin);
|
||||
ImGui_ImplSDLRenderer_Init(sdlRend);
|
||||
|
||||
ImGui::GetStyle().ScaleAllSizes(dpiScale);
|
||||
|
||||
if ((mainFont=ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(defFont_main_compressed_data,defFont_main_compressed_size,18*dpiScale))==NULL) {
|
||||
logE("could not load UI font!\n");
|
||||
return false;
|
||||
}
|
||||
if ((patFont=ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(defFont_pat_compressed_data,defFont_pat_compressed_size,18*dpiScale))==NULL) {
|
||||
logE("could not load pattern font!\n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
FurnaceGUI::FurnaceGUI():
|
||||
e(NULL) {
|
||||
e(NULL),
|
||||
quit(false),
|
||||
scrW(1280),
|
||||
scrH(800),
|
||||
dpiScale(2) {
|
||||
}
|
||||
|
|
@ -1,9 +1,27 @@
|
|||
#include "../engine/engine.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_sdl.h"
|
||||
#include "imgui_impl_sdlrenderer.h"
|
||||
#include <SDL.h>
|
||||
|
||||
class FurnaceGUI {
|
||||
DivEngine* e;
|
||||
|
||||
SDL_Window* sdlWin;
|
||||
SDL_Renderer* sdlRend;
|
||||
|
||||
bool quit;
|
||||
|
||||
int scrW, scrH;
|
||||
|
||||
double dpiScale;
|
||||
|
||||
ImFont* mainFont;
|
||||
ImFont* patFont;
|
||||
|
||||
public:
|
||||
void bindEngine(DivEngine* eng);
|
||||
bool loop();
|
||||
bool init();
|
||||
FurnaceGUI();
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue