mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-23 21:15:11 +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)
|
add_subdirectory(extern/zlib)
|
||||||
set(HAVE_SDL2 SDL2-static)
|
set(HAVE_SDL2 SDL2-static)
|
||||||
set(HAVE_Z zlibstatic)
|
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()
|
else()
|
||||||
if (BUILD_GUI)
|
if (BUILD_GUI)
|
||||||
set(SDL_SHARED ON)
|
set(SDL_SHARED ON)
|
||||||
add_subdirectory(extern/SDL)
|
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)
|
set(HAVE_SDL2 SDL2)
|
||||||
else()
|
else()
|
||||||
find_library(HAVE_SDL2 SDL2)
|
find_library(HAVE_SDL2 SDL2)
|
||||||
|
@ -108,10 +108,13 @@ extern/imgui/backends/imgui_impl_sdlrenderer.cpp
|
||||||
extern/imgui/backends/imgui_impl_sdl.cpp
|
extern/imgui/backends/imgui_impl_sdl.cpp
|
||||||
extern/igfd/ImGuiFileDialog.cpp
|
extern/igfd/ImGuiFileDialog.cpp
|
||||||
|
|
||||||
|
src/gui/font_main.cpp
|
||||||
|
src/gui/font_pat.cpp
|
||||||
src/gui/gui.cpp)
|
src/gui/gui.cpp)
|
||||||
|
|
||||||
if (BUILD_GUI)
|
if (BUILD_GUI)
|
||||||
add_executable(furnace ${ENGINE_SOURCES} ${AUDIO_SOURCES} ${GUI_SOURCES} src/main.cpp)
|
add_executable(furnace ${ENGINE_SOURCES} ${AUDIO_SOURCES} ${GUI_SOURCES} src/main.cpp)
|
||||||
|
target_compile_definitions(furnace PUBLIC HAVE_GUI)
|
||||||
else()
|
else()
|
||||||
add_executable(furnace ${ENGINE_SOURCES} ${AUDIO_SOURCES} src/main.cpp)
|
add_executable(furnace ${ENGINE_SOURCES} ${AUDIO_SOURCES} src/main.cpp)
|
||||||
endif()
|
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 "gui.h"
|
||||||
|
#include "fonts.h"
|
||||||
|
#include "../ta-log.h"
|
||||||
|
#include "imgui.h"
|
||||||
|
|
||||||
void FurnaceGUI::bindEngine(DivEngine* eng) {
|
void FurnaceGUI::bindEngine(DivEngine* eng) {
|
||||||
e=eng;
|
e=eng;
|
||||||
}
|
}
|
||||||
|
|
||||||
FurnaceGUI::FurnaceGUI():
|
bool FurnaceGUI::loop() {
|
||||||
e(NULL) {
|
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 "../engine/engine.h"
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_impl_sdl.h"
|
||||||
|
#include "imgui_impl_sdlrenderer.h"
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
class FurnaceGUI {
|
class FurnaceGUI {
|
||||||
DivEngine* e;
|
DivEngine* e;
|
||||||
|
|
||||||
|
SDL_Window* sdlWin;
|
||||||
|
SDL_Renderer* sdlRend;
|
||||||
|
|
||||||
|
bool quit;
|
||||||
|
|
||||||
|
int scrW, scrH;
|
||||||
|
|
||||||
|
double dpiScale;
|
||||||
|
|
||||||
|
ImFont* mainFont;
|
||||||
|
ImFont* patFont;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void bindEngine(DivEngine* eng);
|
void bindEngine(DivEngine* eng);
|
||||||
|
bool loop();
|
||||||
|
bool init();
|
||||||
FurnaceGUI();
|
FurnaceGUI();
|
||||||
};
|
};
|
42
src/main.cpp
42
src/main.cpp
|
@ -11,12 +11,26 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_GUI
|
||||||
|
#include "gui/gui.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define DIV_VERSION "dev10"
|
#define DIV_VERSION "dev10"
|
||||||
|
|
||||||
DivEngine e;
|
DivEngine e;
|
||||||
|
|
||||||
|
#ifdef HAVE_GUI
|
||||||
|
FurnaceGUI g;
|
||||||
|
#endif
|
||||||
|
|
||||||
String outName;
|
String outName;
|
||||||
|
|
||||||
|
#ifdef HAVE_GUI
|
||||||
|
bool consoleMode=false;
|
||||||
|
#else
|
||||||
|
bool consoleMode=true;
|
||||||
|
#endif
|
||||||
|
|
||||||
std::vector<TAParam> params;
|
std::vector<TAParam> params;
|
||||||
|
|
||||||
bool pHelp(String) {
|
bool pHelp(String) {
|
||||||
|
@ -58,6 +72,11 @@ bool pView(String val) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool pConsole(String val) {
|
||||||
|
consoleMode=true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool pLogLevel(String val) {
|
bool pLogLevel(String val) {
|
||||||
if (val=="debug") {
|
if (val=="debug") {
|
||||||
logLevel=LOGLEVEL_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("- libsndfile by Erik de Castro Lopo and rest of libsndfile team (LGPLv2.1)\n");
|
||||||
printf("- SDL2 by Sam Lantinga (zlib license)\n");
|
printf("- SDL2 by Sam Lantinga (zlib license)\n");
|
||||||
printf("- zlib by Jean-loup Gailly and Mark Adler (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-OPM by Nuke.YKT (LGPLv2.1)\n");
|
||||||
printf("- Nuked-OPN2 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("- MAME SN76496 emulation core by Nicola Salmoria (BSD 3-clause)\n");
|
||||||
printf("- SameBoy by Lior Halphon (MIT)\n");
|
printf("- SameBoy by Lior Halphon (MIT)\n");
|
||||||
printf("- Mednafen PCE by Mednafen Team (GPLv2)\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("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("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("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)"));
|
params.push_back(TAParam("l","loops",true,pLoops,"<count>","set number of loops (-1 means loop forever)"));
|
||||||
|
|
||||||
|
@ -272,14 +294,24 @@ int main(int argc, char** argv) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (outName!="") return 0;
|
if (outName!="") return 0;
|
||||||
logI("playing...\n");
|
|
||||||
e.play();
|
if (consoleMode) {
|
||||||
while (true) {
|
logI("playing...\n");
|
||||||
|
e.play();
|
||||||
|
while (true) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
Sleep(500);
|
Sleep(500);
|
||||||
#else
|
#else
|
||||||
usleep(500000);
|
usleep(500000);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g.bindEngine(&e);
|
||||||
|
g.init();
|
||||||
|
|
||||||
|
g.loop();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue