GUI: make it dockable

This commit is contained in:
tildearrow 2021-12-14 04:45:44 -05:00
parent 7a70ccfe2e
commit 9da9ed3cd7
2 changed files with 555 additions and 491 deletions

View File

@ -95,64 +95,9 @@ void FurnaceGUI::updateScroll(int amount) {
nextScroll=lineHeight*amount;
}
bool FurnaceGUI::loop() {
while (!quit) {
SDL_Event ev;
while (SDL_PollEvent(&ev)) {
ImGui_ImplSDL2_ProcessEvent(&ev);
switch (ev.type) {
case SDL_MOUSEMOTION:
if (macroDragActive) {
if (macroDragLen>0) {
int x=(ev.motion.x-macroDragStart.x)*macroDragLen/macroDragAreaSize.x;
if (x<0) x=0;
if (x>=macroDragLen) x=macroDragLen-1;
int y=round(macroDragMax-((ev.motion.y-macroDragStart.y)*(double(macroDragMax-macroDragMin)/(double)macroDragAreaSize.y)));
if (y>macroDragMax) y=macroDragMax;
if (y<macroDragMin) y=macroDragMin;
macroDragTarget[x]=y;
}
}
if (macroLoopDragActive) {
if (macroLoopDragLen>0) {
int x=(ev.motion.x-macroLoopDragStart.x)*macroLoopDragLen/macroLoopDragAreaSize.x;
if (x<0) x=0;
if (x>=macroLoopDragLen) x=-1;
*macroLoopDragTarget=x;
}
}
break;
case SDL_MOUSEBUTTONUP:
macroDragActive=false;
macroLoopDragActive=false;
break;
case SDL_QUIT:
quit=true;
return true;
break;
}
}
ImGui_ImplSDLRenderer_NewFrame();
ImGui_ImplSDL2_NewFrame(sdlWin);
ImGui::NewFrame();
ImGui::BeginMainMenuBar();
if (ImGui::BeginMenu("file")) {
ImGui::MenuItem("new");
ImGui::MenuItem("open...");
ImGui::Separator();
ImGui::MenuItem("save");
ImGui::MenuItem("save as...");
ImGui::Separator();
if (ImGui::MenuItem("exit")) {
quit=true;
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
if (ImGui::Begin("Playback")) {
void FurnaceGUI::drawSongInfo() {
if (!songInfoOpen) return;
if (ImGui::Begin("Song Information",&songInfoOpen)) {
ImGui::InputText("Name",&e->song.name);
ImGui::InputText("Author",&e->song.author);
ImGui::InputScalar("Speed 1",ImGuiDataType_U8,&e->song.speed1,&_ONE,&_THREE);
@ -172,9 +117,12 @@ bool FurnaceGUI::loop() {
}
}
ImGui::End();
}
void FurnaceGUI::drawOrders() {
char selID[16];
if (ImGui::Begin("Orders")) {
if (!ordersOpen) return;
if (ImGui::Begin("Orders",&ordersOpen)) {
if (ImGui::BeginTable("OrdersTable",1+e->getChannelCount(e->song.system))) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
@ -206,8 +154,11 @@ bool FurnaceGUI::loop() {
}
}
ImGui::End();
}
if (ImGui::Begin("Instruments")) {
void FurnaceGUI::drawInsList() {
if (!insListOpen) return;
if (ImGui::Begin("Instruments",&insListOpen)) {
for (int i=0; i<e->song.ins.size(); i++) {
DivInstrument* ins=e->song.ins[i];
if (ImGui::Selectable(fmt::sprintf("%d: %s##_INS%d\n",i,ins->name,i).c_str(),curIns==i)) {
@ -216,8 +167,11 @@ bool FurnaceGUI::loop() {
}
}
ImGui::End();
}
if (ImGui::Begin("Instrument Editor")) {
void FurnaceGUI::drawInsEdit() {
if (!insEditOpen) return;
if (ImGui::Begin("Instrument Editor",&insEditOpen,ImGuiWindowFlags_NoDocking)) {
if (curIns>=e->song.ins.size()) {
ImGui::Text("no instrument selected");
} else {
@ -514,8 +468,12 @@ bool FurnaceGUI::loop() {
}
}
ImGui::End();
}
if (ImGui::Begin("Pattern")) {
void FurnaceGUI::drawPattern() {
if (!patternOpen) return;
if (ImGui::Begin("Pattern",&patternOpen)) {
ImGui::SetWindowSize(ImVec2(scrW*dpiScale,scrH*dpiScale));
char id[32];
ImGui::PushFont(patFont);
unsigned char ord=e->getOrder();
@ -551,6 +509,12 @@ bool FurnaceGUI::loop() {
}
for (int i=0; i<e->song.patLen; i++) {
ImGui::TableNextRow(0,lineHeight);
if ((lineHeight*(i+dummyRows+1))-ImGui::GetScrollY()<0) {
continue;
}
if ((lineHeight*(i+dummyRows))-ImGui::GetScrollY()>ImGui::GetWindowSize().y) {
continue;
}
ImGui::TableNextColumn();
if (e->isPlaying() && oldRow==i) {
ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0,0x40ffffff);
@ -643,6 +607,88 @@ bool FurnaceGUI::loop() {
ImGui::PopFont();
}
ImGui::End();
}
bool FurnaceGUI::loop() {
while (!quit) {
SDL_Event ev;
while (SDL_PollEvent(&ev)) {
ImGui_ImplSDL2_ProcessEvent(&ev);
switch (ev.type) {
case SDL_MOUSEMOTION:
if (macroDragActive) {
if (macroDragLen>0) {
int x=(ev.motion.x-macroDragStart.x)*macroDragLen/macroDragAreaSize.x;
if (x<0) x=0;
if (x>=macroDragLen) x=macroDragLen-1;
int y=round(macroDragMax-((ev.motion.y-macroDragStart.y)*(double(macroDragMax-macroDragMin)/(double)macroDragAreaSize.y)));
if (y>macroDragMax) y=macroDragMax;
if (y<macroDragMin) y=macroDragMin;
macroDragTarget[x]=y;
}
}
if (macroLoopDragActive) {
if (macroLoopDragLen>0) {
int x=(ev.motion.x-macroLoopDragStart.x)*macroLoopDragLen/macroLoopDragAreaSize.x;
if (x<0) x=0;
if (x>=macroLoopDragLen) x=-1;
*macroLoopDragTarget=x;
}
}
break;
case SDL_MOUSEBUTTONUP:
macroDragActive=false;
macroLoopDragActive=false;
break;
case SDL_WINDOWEVENT:
switch (ev.window.event) {
case SDL_WINDOWEVENT_RESIZED:
scrW=ev.window.data1/dpiScale;
scrH=ev.window.data2/dpiScale;
break;
}
break;
case SDL_QUIT:
quit=true;
return true;
break;
}
}
ImGui_ImplSDLRenderer_NewFrame();
ImGui_ImplSDL2_NewFrame(sdlWin);
ImGui::NewFrame();
ImGui::BeginMainMenuBar();
if (ImGui::BeginMenu("file")) {
ImGui::MenuItem("new");
ImGui::MenuItem("open...");
ImGui::Separator();
ImGui::MenuItem("save");
ImGui::MenuItem("save as...");
ImGui::Separator();
if (ImGui::MenuItem("exit")) {
quit=true;
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("window")) {
if (ImGui::MenuItem("song information")) songInfoOpen=!songInfoOpen;
if (ImGui::MenuItem("instruments")) insListOpen=!insListOpen;
if (ImGui::MenuItem("instrument editor")) insEditOpen=!insEditOpen;
if (ImGui::MenuItem("orders")) ordersOpen=!ordersOpen;
if (ImGui::MenuItem("pattern")) patternOpen=!patternOpen;
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
ImGui::DockSpaceOverViewport();
drawSongInfo();
drawOrders();
drawInsList();
drawInsEdit();
drawPattern();
SDL_SetRenderDrawColor(sdlRend,uiColors[GUI_COLOR_BACKGROUND].x*255,
uiColors[GUI_COLOR_BACKGROUND].y*255,
@ -711,6 +757,11 @@ FurnaceGUI::FurnaceGUI():
curIns(0),
curOctave(3),
oldRow(0),
ordersOpen(true),
insListOpen(true),
songInfoOpen(true),
patternOpen(true),
insEditOpen(false),
arpMacroScroll(0),
macroDragStart(0,0),
macroDragAreaSize(0,0),

View File

@ -32,6 +32,11 @@ enum FurnaceGUIColors {
GUI_COLOR_MAX
};
struct SelectionPoint {
int xCoarse, xFine;
int y;
};
class FurnaceGUI {
DivEngine* e;
@ -50,6 +55,8 @@ class FurnaceGUI {
ImVec4 volColors[128];
int curIns, curOctave, oldRow;
bool ordersOpen, insListOpen, songInfoOpen, patternOpen, insEditOpen;
SelectionPoint selStart, selEnd;
int arpMacroScroll;
@ -68,6 +75,12 @@ class FurnaceGUI {
float nextScroll;
void drawSongInfo();
void drawOrders();
void drawInsList();
void drawPattern();
void drawInsEdit();
public:
const char* noteName(short note, short octave);
void bindEngine(DivEngine* eng);