mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-02 10:55:05 +00:00
GUI: more sample editor work
scrollbar and some layout changes
This commit is contained in:
parent
20799402c8
commit
b83b46aa2c
3 changed files with 108 additions and 31 deletions
|
@ -1364,6 +1364,7 @@ void FurnaceGUI::actualSampleList() {
|
|||
ImGui::TableNextColumn();
|
||||
if (ImGui::Selectable(fmt::sprintf("%d: %s##_SAM%d",i,sample->name,i).c_str(),curSample==i)) {
|
||||
curSample=i;
|
||||
samplePos=0;
|
||||
updateSampleTex=true;
|
||||
}
|
||||
if (ImGui::IsItemHovered()) {
|
||||
|
@ -2052,6 +2053,8 @@ void FurnaceGUI::drawNewSong() {
|
|||
curNibble=false;
|
||||
orderNibble=false;
|
||||
orderCursor=-1;
|
||||
samplePos=0;
|
||||
updateSampleTex=true;
|
||||
selStart=SelectionPoint();
|
||||
selEnd=SelectionPoint();
|
||||
cursor=SelectionPoint();
|
||||
|
@ -4946,6 +4949,8 @@ int FurnaceGUI::load(String path) {
|
|||
curNibble=false;
|
||||
orderNibble=false;
|
||||
orderCursor=-1;
|
||||
samplePos=0;
|
||||
updateSampleTex=true;
|
||||
selStart=SelectionPoint();
|
||||
selEnd=SelectionPoint();
|
||||
cursor=SelectionPoint();
|
||||
|
@ -5042,10 +5047,14 @@ void FurnaceGUI::processDrags(int dragX, int dragY) {
|
|||
}
|
||||
}
|
||||
if (sampleDragActive) {
|
||||
int x=samplePos+(int)(double(dragX-sampleDragStart.x)*sampleZoom);
|
||||
int x1=samplePos+(int)(double(dragX-sampleDragStart.x+1)*sampleZoom);
|
||||
int x=samplePos+round(double(dragX-sampleDragStart.x)*sampleZoom);
|
||||
int x1=samplePos+round(double(dragX-sampleDragStart.x+1)*sampleZoom);
|
||||
if (x<0) x=0;
|
||||
if (x>=(int)sampleDragLen) x=sampleDragLen-1;
|
||||
if (sampleDragMode) {
|
||||
if (x>=(int)sampleDragLen) x=sampleDragLen-1;
|
||||
} else {
|
||||
if (x>(int)sampleDragLen) x=sampleDragLen;
|
||||
}
|
||||
if (x1<0) x1=0;
|
||||
if (x1>=(int)sampleDragLen) x1=sampleDragLen-1;
|
||||
double y=0.5-double(dragY-sampleDragStart.y)/sampleDragAreaSize.y;
|
||||
|
@ -6660,6 +6669,10 @@ void FurnaceGUI::applyUISettings() {
|
|||
sty.Colors[ImGuiCol_PlotHistogram]=uiColors[GUI_COLOR_MACRO_OTHER];
|
||||
sty.Colors[ImGuiCol_PlotHistogramHovered]=uiColors[GUI_COLOR_MACRO_OTHER];
|
||||
|
||||
/*sty.WindowRounding=8.0f;
|
||||
sty.FrameRounding=6.0f;
|
||||
sty.PopupRounding=8.0f;*/
|
||||
|
||||
sty.ScaleAllSizes(dpiScale);
|
||||
|
||||
ImGui::GetStyle()=sty;
|
||||
|
@ -7143,6 +7156,7 @@ FurnaceGUI::FurnaceGUI():
|
|||
randomMode(false),
|
||||
oldOrdersLen(0),
|
||||
sampleZoom(1.0),
|
||||
prevSampleZoom(1.0),
|
||||
samplePos(0),
|
||||
resizeSize(1024),
|
||||
resampleTarget(32000),
|
||||
|
@ -7153,6 +7167,7 @@ FurnaceGUI::FurnaceGUI():
|
|||
sampleDragActive(false),
|
||||
sampleDragMode(false),
|
||||
sampleDrag16(false),
|
||||
sampleZoomAuto(true),
|
||||
sampleDragTarget(NULL),
|
||||
sampleDragStart(0,0),
|
||||
sampleDragAreaSize(0,0) {
|
||||
|
|
|
@ -737,13 +737,14 @@ class FurnaceGUI {
|
|||
|
||||
// sample editor specific
|
||||
double sampleZoom;
|
||||
double prevSampleZoom;
|
||||
int samplePos;
|
||||
int resizeSize;
|
||||
double resampleTarget;
|
||||
int resampleStrat;
|
||||
float amplifyVol;
|
||||
int sampleSelStart, sampleSelEnd;
|
||||
bool sampleDragActive, sampleDragMode, sampleDrag16;
|
||||
bool sampleDragActive, sampleDragMode, sampleDrag16, sampleZoomAuto;
|
||||
void* sampleDragTarget;
|
||||
ImVec2 sampleDragStart;
|
||||
ImVec2 sampleDragAreaSize;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
#include "gui.h"
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <math.h>
|
||||
#include "../ta-log.h"
|
||||
#include "IconsFontAwesome4.h"
|
||||
|
@ -110,28 +111,12 @@ void FurnaceGUI::drawSampleEdit() {
|
|||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
if (ImGui::InputDouble("Zoom",&sampleZoom,0.1,2.0)) {
|
||||
if (sampleZoom<0.01) sampleZoom=0.01;
|
||||
updateSampleTex=true;
|
||||
}
|
||||
if (ImGui::InputInt("Pos",&samplePos,1,10)) {
|
||||
if (samplePos>=(int)sample->samples) samplePos=sample->samples-1;
|
||||
if (samplePos<0) samplePos=0;
|
||||
updateSampleTex=true;
|
||||
}
|
||||
|
||||
/*
|
||||
if (ImGui::Button("Apply")) {
|
||||
e->renderSamplesP();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(ICON_FA_VOLUME_UP "##PreviewSample")) {
|
||||
e->previewSample(curSample);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(ICON_FA_VOLUME_OFF "##StopSample")) {
|
||||
e->stopSamplePreview();
|
||||
}*/
|
||||
*/
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::Button(ICON_FA_I_CURSOR "##SSelect")) {
|
||||
|
@ -274,13 +259,71 @@ void FurnaceGUI::drawSampleEdit() {
|
|||
ImGui::SetTooltip("Apply filter");
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::Dummy(ImVec2(4.0*dpiScale,dpiScale));
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(ICON_FA_VOLUME_UP "##PreviewSample")) {
|
||||
e->previewSample(curSample);
|
||||
}
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::SetTooltip("Preview sample");
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(ICON_FA_VOLUME_OFF "##StopSample")) {
|
||||
e->stopSamplePreview();
|
||||
}
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::SetTooltip("Stop sample preview");
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
double zoomPercent=100.0/sampleZoom;
|
||||
ImGui::Text("Zoom");
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(150.0f*dpiScale);
|
||||
if (ImGui::InputDouble("##SZoom",&zoomPercent,5.0,20.0,"%g%%")) {
|
||||
if (zoomPercent>10000.0) zoomPercent=10000.0;
|
||||
if (zoomPercent<1.0) zoomPercent=1.0;
|
||||
sampleZoom=100.0/zoomPercent;
|
||||
if (sampleZoom<0.01) sampleZoom=0.01;
|
||||
sampleZoomAuto=false;
|
||||
updateSampleTex=true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (sampleZoomAuto) {
|
||||
if (ImGui::Button("100%")) {
|
||||
sampleZoom=1.0;
|
||||
sampleZoomAuto=false;
|
||||
updateSampleTex=true;
|
||||
}
|
||||
} else {
|
||||
if (ImGui::Button("Auto")) {
|
||||
sampleZoomAuto=true;
|
||||
updateSampleTex=true;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
ImVec2 avail=ImGui::GetContentRegionAvail();
|
||||
avail.y-=ImGui::GetFontSize()+ImGui::GetStyle().ItemSpacing.y;
|
||||
avail.y-=ImGui::GetFontSize()+ImGui::GetStyle().ItemSpacing.y+ImGui::GetStyle().ScrollbarSize;
|
||||
int availX=avail.x;
|
||||
int availY=avail.y;
|
||||
|
||||
|
||||
if (sampleZoomAuto) {
|
||||
samplePos=0;
|
||||
if (sample->samples<1 || avail.x<=0) {
|
||||
sampleZoom=1.0;
|
||||
} else {
|
||||
sampleZoom=(double)sample->samples/avail.x;
|
||||
}
|
||||
if (sampleZoom!=prevSampleZoom) {
|
||||
prevSampleZoom=sampleZoom;
|
||||
updateSampleTex=true;
|
||||
}
|
||||
}
|
||||
|
||||
if (sampleTex==NULL || sampleTexW!=avail.x || sampleTexH!=avail.y) {
|
||||
if (sampleTex!=NULL) {
|
||||
SDL_DestroyTexture(sampleTex);
|
||||
|
@ -359,10 +402,15 @@ void FurnaceGUI::drawSampleEdit() {
|
|||
}
|
||||
|
||||
ImGui::ImageButton(sampleTex,avail,ImVec2(0,0),ImVec2(1,1),0);
|
||||
|
||||
ImVec2 rectMin=ImGui::GetItemRectMin();
|
||||
ImVec2 rectMax=ImGui::GetItemRectMax();
|
||||
ImVec2 rectSize=ImGui::GetItemRectSize();
|
||||
|
||||
if (ImGui::IsItemClicked()) {
|
||||
if (sample->samples>0 && (sample->depth==16 || sample->depth==8)) {
|
||||
sampleDragStart=ImGui::GetItemRectMin();
|
||||
sampleDragAreaSize=ImGui::GetItemRectSize();
|
||||
sampleDragStart=rectMin;
|
||||
sampleDragAreaSize=rectSize;
|
||||
sampleDrag16=(sample->depth==16);
|
||||
sampleDragTarget=(sample->depth==16)?((void*)sample->data16):((void*)sample->data8);
|
||||
sampleDragLen=sample->samples;
|
||||
|
@ -393,14 +441,14 @@ void FurnaceGUI::drawSampleEdit() {
|
|||
int posX=-1;
|
||||
int posY=0;
|
||||
ImVec2 pos=ImGui::GetMousePos();
|
||||
pos.x-=ImGui::GetItemRectMin().x;
|
||||
pos.y-=ImGui::GetItemRectMin().y;
|
||||
pos.x-=rectMin.x;
|
||||
pos.y-=rectMin.y;
|
||||
|
||||
if (sampleZoom>0) {
|
||||
posX=samplePos+pos.x*sampleZoom;
|
||||
if (posX>(int)sample->samples) posX=-1;
|
||||
}
|
||||
posY=(0.5-pos.y/ImGui::GetItemRectSize().y)*((sample->depth==8)?255:32767);
|
||||
posY=(0.5-pos.y/rectSize.y)*((sample->depth==8)?255:32767);
|
||||
if (posX>=0) {
|
||||
statusBar+=fmt::sprintf(" | (%d, %d)",posX,posY);
|
||||
}
|
||||
|
@ -415,15 +463,28 @@ void FurnaceGUI::drawSampleEdit() {
|
|||
start^=end;
|
||||
}
|
||||
ImDrawList* dl=ImGui::GetWindowDrawList();
|
||||
ImVec2 p1=ImGui::GetItemRectMin();
|
||||
ImVec2 p1=rectMin;
|
||||
p1.x+=start/sampleZoom-samplePos;
|
||||
|
||||
ImVec2 p2=ImVec2(ImGui::GetItemRectMin().x+end/sampleZoom-samplePos,ImGui::GetItemRectMax().y);
|
||||
ImVec2 p2=ImVec2(rectMin.x+end/sampleZoom-samplePos,rectMax.y);
|
||||
ImVec4 selColor=uiColors[GUI_COLOR_ACCENT_SECONDARY];
|
||||
selColor.w*=0.25;
|
||||
|
||||
// TODO: color
|
||||
dl->AddRectFilled(p1,p2,0xc0c0c0c0);
|
||||
dl->AddRectFilled(p1,p2,ImGui::GetColorU32(selColor));
|
||||
}
|
||||
|
||||
ImS64 scrollV=samplePos;
|
||||
ImS64 availV=round(rectSize.x*sampleZoom);
|
||||
ImS64 contentsV=MAX(sample->samples,MAX(availV,1));
|
||||
|
||||
if (ImGui::ScrollbarEx(ImRect(ImVec2(rectMin.x,rectMax.y),ImVec2(rectMax.x,rectMax.y+ImGui::GetStyle().ScrollbarSize)),ImGui::GetID("sampleScroll"),ImGuiAxis_X,&scrollV,availV,contentsV,0)) {
|
||||
if (!sampleZoomAuto && samplePos!=scrollV) {
|
||||
samplePos=scrollV;
|
||||
updateSampleTex=true;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY()+ImGui::GetStyle().ScrollbarSize);
|
||||
ImGui::Text("%s",statusBar.c_str());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue