Debian Codegraph @

src/gui/clock.cpp

raw
1 /**
2 * Furnace Tracker - multi-system chiptune tracker
3 * Copyright (C) 2021-2025 tildearrow and contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "gui.h"
21 #include "imgui_internal.h"
22 #include "imgui.h"
23
24 void FurnaceGUI::drawClock() {
25 if (nextWindow==GUI_WINDOW_CLOCK) {
26 clockOpen=true;
27 ImGui::SetNextWindowFocus();
28 nextWindow=GUI_WINDOW_NOTHING;
29 }
30 if (!clockOpen) return;
31 if (ImGui::Begin("Clock",&clockOpen,globalWinFlags,_("Clock"))) {
32 int row=oldRow;
33 int elapsedBars=e->getElapsedBars();
34 int elapsedBeats=e->getElapsedBeats();
35 bool playing=e->isPlaying();
36 if (clockShowRow) {
37 ImGui::PushFont(bigFont);
38 ImGui::Text("%.3d:%.3d",playOrder,row);
39 ImGui::PopFont();
40 }
41 if (clockShowBeat) {
42 ImGui::PushFont(bigFont);
43 ImGui::Text("%.3d:%.1d",elapsedBars,elapsedBeats+1);
44 ImGui::PopFont();
45 }
46 if (clockShowMetro) {
47 ImDrawList* dl=ImGui::GetWindowDrawList();
48 ImGuiWindow* window=ImGui::GetCurrentWindow();
49 ImVec2 size=ImGui::GetContentRegionAvail();
50 size.y=12.0f*dpiScale;
51
52 ImVec2 minArea=window->DC.CursorPos;
53 ImVec2 maxArea=ImVec2(
54 minArea.x+size.x,
55 minArea.y+size.y
56 );
57 ImRect rect=ImRect(minArea,maxArea);
58 /*ImRect inRect=rect;
59 inRect.Min.x+=dpiScale;
60 inRect.Min.y+=dpiScale;
61 inRect.Max.x-=dpiScale;
62 inRect.Max.y-=dpiScale;*/
63 ImGuiStyle& style=ImGui::GetStyle();
64 ImGui::ItemSize(size,style.FramePadding.y);
65 if (ImGui::ItemAdd(rect,ImGui::GetID("metroQ"))) {
66 int h1=e->curSubSong->hilightA;
67 int h2=e->curSubSong->hilightB;
68 if (h1>0 && h2>0) {
69 int beats=(h2+(h1-1))/h1;
70 if (beats<0) beats=1;
71 if (beats>16) beats=16;
72 if (playing) {
73 if (elapsedBeats!=oldBeat || elapsedBars!=oldBar) {
74 if (elapsedBeats>15) elapsedBeats=15;
75 clockMetroTick[elapsedBeats]=1.0f;
76 oldBeat=elapsedBeats;
77 oldBar=elapsedBars;
78 }
79 } else {
80 oldBeat=-1;
81 oldBar=-1;
82 }
83 for (int i=0; i<beats; i++) {
84 ImVec2 minB=ImLerp(minArea,maxArea,ImVec2((float)i/(float)beats,0.0f));
85 ImVec2 maxB=ImLerp(minArea,maxArea,ImVec2((float)(i+1)/(float)beats,1.0f));
86 ImVec4 col=ImLerp(uiColors[GUI_COLOR_CLOCK_BEAT_LOW],uiColors[GUI_COLOR_CLOCK_BEAT_HIGH],clockMetroTick[i]);
87 dl->AddQuadFilled(
88 ImLerp(minB,maxB,ImVec2(0.35f,0.0f)),
89 ImLerp(minB,maxB,ImVec2(0.9f,0.0f)),
90 ImLerp(minB,maxB,ImVec2(0.65f,1.0f)),
91 ImLerp(minB,maxB,ImVec2(0.1f,1.0f)),
92 ImGui::GetColorU32(col)
93 );
94
95 if (elapsedBeats==i && playing) {
96 clockMetroTick[i]-=0.1f*ImGui::GetIO().DeltaTime*60.0f;
97 if (clockMetroTick[i]<0.3f) clockMetroTick[i]=0.3f;
98 } else {
99 clockMetroTick[i]-=0.1f*ImGui::GetIO().DeltaTime*60.0f;
100 if (clockMetroTick[i]<0.0f) clockMetroTick[i]=0.0f;
101 }
102 }
103 }
104 }
105 }
106 if (clockShowTime) {
107 int totalTicks=e->getTotalTicks();
108 int totalSeconds=e->getTotalSeconds();
109 ImGui::PushFont(bigFont);
110 ImGui::Text("%.2d:%.2d.%.2d",(totalSeconds/60),totalSeconds%60,totalTicks/10000);
111 ImGui::PopFont();
112 }
113 }
114 if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_SPOILER;
115 ImGui::End();
116 }