mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-27 06:53:01 +00:00
GUI: earliest ever GUI
This commit is contained in:
parent
e8ac2947ab
commit
9b850c1763
7 changed files with 3576 additions and 8 deletions
|
@ -20,12 +20,12 @@ if (WIN32)
|
|||
add_subdirectory(extern/zlib)
|
||||
set(HAVE_SDL2 SDL2-static)
|
||||
set(HAVE_Z zlibstatic)
|
||||
include_directories(extern/imgui extern/zlib ${CMAKE_CURRENT_BINARY_DIR}/extern/zlib)
|
||||
include_directories(extern/imgui extern/imgui/backends extern/zlib ${CMAKE_CURRENT_BINARY_DIR}/extern/zlib)
|
||||
else()
|
||||
if (BUILD_GUI)
|
||||
set(SDL_SHARED ON)
|
||||
add_subdirectory(extern/SDL)
|
||||
include_directories(extern/SDL/include extern/imgui)
|
||||
include_directories(extern/SDL/include extern/imgui extern/imgui/backends)
|
||||
set(HAVE_SDL2 SDL2)
|
||||
else()
|
||||
find_library(HAVE_SDL2 SDL2)
|
||||
|
@ -108,10 +108,13 @@ extern/imgui/backends/imgui_impl_sdlrenderer.cpp
|
|||
extern/imgui/backends/imgui_impl_sdl.cpp
|
||||
extern/igfd/ImGuiFileDialog.cpp
|
||||
|
||||
src/gui/font_main.cpp
|
||||
src/gui/font_pat.cpp
|
||||
src/gui/gui.cpp)
|
||||
|
||||
if (BUILD_GUI)
|
||||
add_executable(furnace ${ENGINE_SOURCES} ${AUDIO_SOURCES} ${GUI_SOURCES} src/main.cpp)
|
||||
target_compile_definitions(furnace PUBLIC HAVE_GUI)
|
||||
else()
|
||||
add_executable(furnace ${ENGINE_SOURCES} ${AUDIO_SOURCES} src/main.cpp)
|
||||
endif()
|
||||
|
|
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;
|
||||
}
|
||||
|
||||
FurnaceGUI::FurnaceGUI():
|
||||
e(NULL) {
|
||||
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),
|
||||
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();
|
||||
};
|
32
src/main.cpp
32
src/main.cpp
|
@ -11,12 +11,26 @@
|
|||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
#include "gui/gui.h"
|
||||
#endif
|
||||
|
||||
#define DIV_VERSION "dev10"
|
||||
|
||||
DivEngine e;
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
FurnaceGUI g;
|
||||
#endif
|
||||
|
||||
String outName;
|
||||
|
||||
#ifdef HAVE_GUI
|
||||
bool consoleMode=false;
|
||||
#else
|
||||
bool consoleMode=true;
|
||||
#endif
|
||||
|
||||
std::vector<TAParam> params;
|
||||
|
||||
bool pHelp(String) {
|
||||
|
@ -58,6 +72,11 @@ bool pView(String val) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool pConsole(String val) {
|
||||
consoleMode=true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pLogLevel(String val) {
|
||||
if (val=="debug") {
|
||||
logLevel=LOGLEVEL_DEBUG;
|
||||
|
@ -87,8 +106,10 @@ bool pVersion(String) {
|
|||
printf("- libsndfile by Erik de Castro Lopo and rest of libsndfile team (LGPLv2.1)\n");
|
||||
printf("- SDL2 by Sam Lantinga (zlib license)\n");
|
||||
printf("- zlib by Jean-loup Gailly and Mark Adler (zlib license)\n");
|
||||
printf("- Dear ImGui by Omar Cornut (MIT)\n");
|
||||
printf("- Nuked-OPM by Nuke.YKT (LGPLv2.1)\n");
|
||||
printf("- Nuked-OPN2 by Nuke.YKT (LGPLv2.1)\n");
|
||||
printf("- ymfm by Aaron Giles (BSD 3-clause)\n");
|
||||
printf("- MAME SN76496 emulation core by Nicola Salmoria (BSD 3-clause)\n");
|
||||
printf("- SameBoy by Lior Halphon (MIT)\n");
|
||||
printf("- Mednafen PCE by Mednafen Team (GPLv2)\n");
|
||||
|
@ -150,6 +171,7 @@ void initParams() {
|
|||
params.push_back(TAParam("o","output",true,pOutput,"<filename>","output audio to file"));
|
||||
params.push_back(TAParam("L","loglevel",true,pLogLevel,"debug|info|warning|error","set the log level (info by default)"));
|
||||
params.push_back(TAParam("v","view",true,pView,"pattern|commands|nothing","set visualization (pattern by default)"));
|
||||
params.push_back(TAParam("c","console",false,pConsole,"","enable console mode"));
|
||||
|
||||
params.push_back(TAParam("l","loops",true,pLoops,"<count>","set number of loops (-1 means loop forever)"));
|
||||
|
||||
|
@ -272,6 +294,8 @@ int main(int argc, char** argv) {
|
|||
return 1;
|
||||
}
|
||||
if (outName!="") return 0;
|
||||
|
||||
if (consoleMode) {
|
||||
logI("playing...\n");
|
||||
e.play();
|
||||
while (true) {
|
||||
|
@ -283,3 +307,11 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
g.bindEngine(&e);
|
||||
g.init();
|
||||
|
||||
g.loop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue