From faf7d811989dc07d0eaae0e080e95ec0971981ab Mon Sep 17 00:00:00 2001 From: IXtreme Date: Sun, 22 Dec 2024 02:03:29 -0500 Subject: [PATCH] Add Next and Prev ops to menu. I think it is done now. --- src/main.cpp | 118 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 85 insertions(+), 33 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d3a928f..6af0a68 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -141,6 +141,66 @@ void DrawPlay(Vector2 Pos, float scale, Color color) { DrawTriangle(backtop, backbot, front, color); } +void DrawNext(Vector2 Pos, float scale, Color color) { + Vector2 backtop = (Vector2) { .x=-0.35f, .y=-0.35f }; + Vector2 backbot = (Vector2) { .x=-0.35f, .y=0.35f}; + Vector2 front = (Vector2) {.x = 0.28f, .y=0}; + + backtop = Vector2Scale(backtop, scale); + backbot = Vector2Scale(backbot, scale); + front = Vector2Scale(front, scale); + + backtop = Vector2Add(backtop, Pos); + backbot = Vector2Add(backbot, Pos); + front = Vector2Add(front, Pos); + + DrawTriangle(backtop, backbot, front, color); + + Vector2 topleft = (Vector2) {.x = -0.29f, .y = -0.4f }; + + + + Vector2 bar2topleft = Vector2Add(topleft, (Vector2) {0.706f*0.6f, .y=0}); + bar2topleft = Vector2Scale(bar2topleft, scale); + bar2topleft = Vector2Add(bar2topleft, Pos); + + Vector2 size = (Vector2) {.x=0.706f *0.2f, .y = 0.8f }; + size = Vector2Scale(size, scale); + + + DrawRectangleV(bar2topleft, size, color); +} + + +void DrawBack(Vector2 Pos, float scale, Color color) { + Vector2 backtop = (Vector2) { .x=0.35f, .y=-0.35f }; + Vector2 backbot = (Vector2) { .x=0.35f, .y=0.35f}; + Vector2 front = (Vector2) {.x = -0.28f, .y=0}; + + backtop = Vector2Scale(backtop, scale); + backbot = Vector2Scale(backbot, scale); + front = Vector2Scale(front, scale); + + backtop = Vector2Add(backtop, Pos); + backbot = Vector2Add(backbot, Pos); + front = Vector2Add(front, Pos); + + //DrawTriangle(backtop, backbot, front, color); + DrawTriangle(front, backbot, backtop, color); + + Vector2 topleft = (Vector2) {.x = -0.29f, .y = -0.4f }; + + + Vector2 bar1topleft = Vector2Scale(topleft, scale); + bar1topleft = Vector2Add(bar1topleft, Pos); + + Vector2 size = (Vector2) {.x=0.706f *0.2f, .y = 0.8f }; + size = Vector2Scale(size, scale); + + + DrawRectangleV(bar1topleft, size, color); +} + void DrawStop(Vector2 Pos, float scale, Color color) { Vector2 topleft = (Vector2) {.x = -0.353f, .y = -0.353f }; Vector2 botright = (Vector2) {.x = 0.353f, .y = 0.353f }; @@ -204,38 +264,6 @@ int main(int argc, char *argv[]) { std::vector serviceList = GetMprisServices(); auto current_player = MprisPlayer("org.mpris.MediaPlayer2.playerctld"); - // current_player.pp(); - /* - auto connection = sdbus::createSessionBusConnection(); - - sdbus::ServiceName dest{"org.freedesktop.DBus"}; - sdbus::ObjectPath objec{"/org/freedesktop/DBus"}; - - auto prox = sdbus::createProxy(dest, objec); - sdbus::InterfaceName interfaceName{"org.freedesktop.DBus"}; - sdbus::MethodName introspect("ListNames"); - - auto method = prox->createMethodCall(interfaceName, introspect); - auto reply = prox->callMethod(method); - std::vector res; - reply >> res; - for (std::string item : res) { - std::cout << item << std::endl; - } - - */ - - // if the linked ImGui has docking, enable it. - // this will only be true if you use the docking branch of ImGui. -#ifdef IMGUI_HAS_DOCK - ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable; -#endif - - // for (json::iterator it = course_info.begin(); it != course_info.end(); ++it) { - // std::cout << *it << std::endl; - // } - - double lasttime = 0.0; // Main game loop while (!WindowShouldClose() && @@ -276,16 +304,35 @@ int main(int argc, char *argv[]) { } else { DrawPlay(centerline, 0.1*GetScreenWidth(), WHITE); } + + Vector2 next = Vector2Add(centerline, (Vector2) {screen.x * 0.2f, 0.0f}); + DrawCircleV(next, 0.05*GetScreenWidth(), transblack); + DrawNext(next, 0.1*GetScreenWidth(), WHITE); + + Vector2 back = Vector2Add(centerline, (Vector2) {screen.x * -0.2f, 0.0f}); + DrawCircleV(back, 0.05*GetScreenWidth(), transblack); + DrawBack(back, 0.1*GetScreenWidth(), WHITE); + if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && CheckCollisionPointCircle(GetMousePosition(), centerline, 0.05*GetScreenWidth()) ) { current_player.PausePlay(); current_player.playstate = current_player.playstate == "Playing" ? "Paused" : "Playing"; } + if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && CheckCollisionPointCircle(GetMousePosition(), next, 0.05*GetScreenWidth()) ) { + current_player.Next(); + current_player.playstate = current_player.playstate == "Playing" ? "Paused" : "Playing"; + } + + if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && CheckCollisionPointCircle(GetMousePosition(), back, 0.05*GetScreenWidth()) ) { + current_player.Prev(); + current_player.playstate = current_player.playstate == "Playing" ? "Paused" : "Playing"; + } + } - if (IsKeyPressed(KEY_SLASH)) { + if (IsKeyPressed(KEY_SLASH) || IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) { showIMgui = !showIMgui; } @@ -327,15 +374,20 @@ int main(int argc, char *argv[]) { if (ImGui::Begin("Player Control")) { ImGui::Text("%s", current_player.GetIdentity().c_str()); + + if (ImGui::Button("Prev")) { current_player.Prev(); } + ImGui::SameLine(); if (ImGui::Button("Play/Pause")) { current_player.PausePlay(); } + ImGui::SameLine(); if (ImGui::Button("Next")) { current_player.Next(); } + ImGui::SameLine(); if (ImGui::Button("Refresh")) { current_player.Refresh(); current_player.UpdateTexture();