GUI: possibly fix particles going out of bounds

This commit is contained in:
tildearrow 2023-02-20 16:35:02 -05:00
parent a8c04e80e3
commit ff7110cb05

View file

@ -1012,6 +1012,12 @@ void FurnaceGUI::drawPattern() {
ImDrawList* dl=ImGui::GetWindowDrawList();
ImVec2 off=ImVec2(0.0f,ImGui::GetWindowPos().y);
ImVec2 winMin=ImGui::GetWindowPos();
ImVec2 winMax=ImVec2(
winMin.x+ImGui::GetWindowSize().x,
winMin.y+ImGui::GetWindowSize().y
);
// commands
for (DivCommand& i: cmdStream) {
if (i.cmd==DIV_CMD_PITCH) continue;
@ -1133,11 +1139,18 @@ void FurnaceGUI::drawPattern() {
}
for (int j=0; j<num; j++) {
ImVec2 partPos=ImVec2(
off.x+patChanX[i.chan]+fmod(rand(),width)-scrollX,
off.y+(ImGui::GetWindowHeight()*0.5f)+randRange(0,patFont->FontSize)
);
if (partPos.x<winMin.x || partPos.y<winMin.y || partPos.x>winMax.x || partPos.y>winMax.y) continue;
particles.push_back(Particle(
color,
partIcon,
off.x+patChanX[i.chan]+fmod(rand(),width)-scrollX,
off.y+(ImGui::GetWindowHeight()*0.5f)+randRange(0,patFont->FontSize),
partPos.x,
partPos.y,
(speedX+randRange(-spread,spread))*0.5*dpiScale,
(speedY+randRange(-spread,spread))*0.5*dpiScale,
grav,
@ -1160,11 +1173,17 @@ void FurnaceGUI::drawPattern() {
col.w*=0.2;
float width=patChanX[i+1]-patChanX[i];
ImVec2 partPos=ImVec2(
off.x+patChanX[i]+fmod(rand(),width)-scrollX,
off.y+fmod(rand(),MAX(1,ImGui::GetWindowHeight()))
);
if (!(partPos.x<winMin.x || partPos.y<winMin.y || partPos.x>winMax.x || partPos.y>winMax.y)) {
particles.push_back(Particle(
pitchGrad,
(ch->portaNote<=ch->note)?ICON_FA_CHEVRON_DOWN:ICON_FA_CHEVRON_UP,
off.x+patChanX[i]+fmod(rand(),width)-scrollX,
off.y+fmod(rand(),MAX(1,ImGui::GetWindowHeight())),
partPos.x,
partPos.y,
0.0f,
(7.0f+(rand()%5)+pow(ch->portaSpeed,0.7f))*((ch->portaNote<=ch->note)?1:-1),
0.0f,
@ -1172,6 +1191,7 @@ void FurnaceGUI::drawPattern() {
255.0f,
15.0f
));
}
if (width>0.1) for (float j=-patChanSlideY[i]; j<ImGui::GetWindowHeight(); j+=width*0.7) {
ImVec2 tMin=ImVec2(off.x+patChanX[i]-scrollX,off.y+j);
@ -1210,11 +1230,17 @@ void FurnaceGUI::drawPattern() {
col.w*=0.2;
float width=patChanX[i+1]-patChanX[i];
ImVec2 partPos=ImVec2(
off.x+patChanX[i]+(width*0.5+0.5*sin(M_PI*(float)ch->vibratoPosGiant/64.0f)*width)-scrollX,
off.y+(ImGui::GetWindowHeight()*0.5f)+randRange(0,patFont->FontSize)
);
if (!(partPos.x<winMin.x || partPos.y<winMin.y || partPos.x>winMax.x || partPos.y>winMax.y)) {
particles.push_back(Particle(
pitchGrad,
ICON_FA_GLASS,
off.x+patChanX[i]+(width*0.5+0.5*sin(M_PI*(float)ch->vibratoPosGiant/64.0f)*width)-scrollX,
off.y+(ImGui::GetWindowHeight()*0.5f)+randRange(0,patFont->FontSize),
partPos.x,
partPos.y,
randRange(-4.0f,4.0f),
2.0f*(3.0f+(rand()%5)+ch->vibratoRate),
0.4f,
@ -1224,6 +1250,7 @@ void FurnaceGUI::drawPattern() {
));
}
}
}
// particle simulation
ImDrawList* fdl=ImGui::GetForegroundDrawList();