Add cool record spin feature
This commit is contained in:
parent
4e3f3e1325
commit
d05147fa69
90
src/main.cpp
90
src/main.cpp
|
@ -20,11 +20,11 @@
|
|||
|
||||
#include "stdio.h"
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sdbus-c++/sdbus-c++.h>
|
||||
#include <string>
|
||||
#include <curl/curl.h>
|
||||
extern "C" {
|
||||
#include "testc.h"
|
||||
}
|
||||
|
@ -158,8 +158,6 @@ void DrawNext(Vector2 Pos, float scale, Color 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);
|
||||
|
@ -167,11 +165,9 @@ void DrawNext(Vector2 Pos, float scale, Color color) {
|
|||
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};
|
||||
|
@ -190,14 +186,12 @@ void DrawBack(Vector2 Pos, float scale, Color 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);
|
||||
}
|
||||
|
||||
|
@ -215,7 +209,6 @@ void DrawStop(Vector2 Pos, float scale, Color color) {
|
|||
void DrawPause(Vector2 Pos, float scale, Color color) {
|
||||
Vector2 topleft = (Vector2){.x = -0.353f, .y = -0.353f};
|
||||
|
||||
|
||||
Vector2 bar1topleft = Vector2Scale(topleft, scale);
|
||||
bar1topleft = Vector2Add(bar1topleft, Pos);
|
||||
|
||||
|
@ -238,6 +231,16 @@ float ScaleToFit(Vector2 src, Vector2 dst) {
|
|||
// return Vector2Scale(src, ratio);
|
||||
}
|
||||
|
||||
void GenCircleOverlay(RenderTexture tex) {
|
||||
BeginTextureMode(tex);
|
||||
ClearBackground(BLACK);
|
||||
BeginBlendMode(BLEND_SUBTRACT_COLORS);
|
||||
DrawCircle(GetScreenWidth()/2, GetScreenHeight()/2, std::min(GetScreenWidth()/2, GetScreenHeight()/2), (Color{0,0,0,0}));
|
||||
EndBlendMode();
|
||||
EndTextureMode();
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
@ -265,10 +268,21 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
auto current_player = MprisPlayer("org.mpris.MediaPlayer2.playerctld");
|
||||
double lasttime = 0.0;
|
||||
bool discmode = false;
|
||||
DiscObject disc(0);
|
||||
// Main game loop
|
||||
while (!WindowShouldClose() &&
|
||||
run) // Detect window close button or ESC key, or a quit from the menu
|
||||
bool goodstate = false;
|
||||
|
||||
RenderTexture recordoverlay = LoadRenderTexture(screenWidth, screenHeight);
|
||||
GenCircleOverlay(recordoverlay);
|
||||
|
||||
while (!WindowShouldClose() && run) // Detect window close button or ESC key, or a quit from the menu
|
||||
{
|
||||
if (IsWindowResized()) {
|
||||
UnloadRenderTexture(recordoverlay);
|
||||
recordoverlay = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());
|
||||
GenCircleOverlay(recordoverlay);
|
||||
}
|
||||
if (GetTime() > lasttime + 3) {
|
||||
lasttime = GetTime();
|
||||
current_player.Refresh();
|
||||
|
@ -284,9 +298,11 @@ int main(int argc, char *argv[]) {
|
|||
Vector2 fpos;
|
||||
fpos.x = (winwidth.x * 0.5) - (scaledsize.x * 0.5f);
|
||||
fpos.y = (winwidth.y * 0.5) - (scaledsize.y * 0.5f);
|
||||
DrawTextureEx(current_player.tex.tex, fpos, 0, ScaleToFit(imagesize, winwidth), WHITE);
|
||||
|
||||
// DrawTextureEx(current_player.tex.tex, fpos, 0, ScaleToFit(imagesize, winwidth), WHITE);
|
||||
Rectangle src = (Rectangle){0, 0, (float)current_player.tex.tex.width, (float)current_player.tex.tex.height};
|
||||
Rectangle dst = (Rectangle){fpos.x + scaledsize.x / 2, fpos.y + scaledsize.y / 2, scaledsize.x, scaledsize.y};
|
||||
|
||||
DrawTexturePro(current_player.tex.tex, src, dst, (Vector2){dst.width / 2, dst.height / 2}, disc.pos, WHITE);
|
||||
|
||||
if (IsWindowFocused()) {
|
||||
const float buttonsize = 0.1;
|
||||
|
@ -316,22 +332,47 @@ int main(int argc, char *argv[]) {
|
|||
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()) ) {
|
||||
} else 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()) ) {
|
||||
} else if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && CheckCollisionPointCircle(GetMousePosition(), back, 0.05 * GetScreenWidth())) {
|
||||
current_player.Prev();
|
||||
current_player.playstate = current_player.playstate == "Playing" ? "Paused" : "Playing";
|
||||
} else if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
||||
float initmouserot;
|
||||
Vector2 initmousepos;
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||
initmouserot = disc.pos;
|
||||
initmousepos = GetMousePosition();
|
||||
initmousepos = Vector2Add(initmousepos, (Vector2){-screen.x / 2, -screen.y / 2});
|
||||
goodstate = true;
|
||||
}
|
||||
if (goodstate) {
|
||||
Vector2 mouse = GetMousePosition();
|
||||
Vector2 mousecentered = Vector2Add(mouse, (Vector2){-screen.x / 2, -screen.y / 2});
|
||||
disc.velo = 0;
|
||||
disc.UpdatePos(initmouserot + (((180.0f * atan2(mousecentered.y, mousecentered.x)) / M_PI) - ((180.0f * atan2(initmousepos.y, initmousepos.x)) / M_PI)), GetFrameTime());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!goodstate) {
|
||||
disc.UpdatePos(GetFrameTime());
|
||||
// Ease from velo to target
|
||||
if (current_player.playstate == "Playing") {
|
||||
disc.target = 100;
|
||||
} else {
|
||||
disc.target = 0;
|
||||
}
|
||||
disc.accel = disc.target - disc.velo;
|
||||
}
|
||||
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
|
||||
goodstate = false;
|
||||
}
|
||||
|
||||
|
||||
if (disc.active) {
|
||||
DrawTexture(recordoverlay.texture, 0, 0 , WHITE);
|
||||
}
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_SLASH) || IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) {
|
||||
showIMgui = !showIMgui;
|
||||
}
|
||||
|
@ -364,7 +405,9 @@ int main(int argc, char *argv[]) {
|
|||
if (ImGui::BeginMenu("Window")) {
|
||||
if (ImGui::MenuItem("Demo Window", nullptr, showDemoWindow))
|
||||
showDemoWindow = !showDemoWindow;
|
||||
|
||||
if (ImGui::MenuItem("Record Spin !!", nullptr, disc.active)) {
|
||||
disc.Activate();
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMainMenuBar();
|
||||
|
@ -375,7 +418,6 @@ 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();
|
||||
}
|
||||
|
@ -392,7 +434,11 @@ int main(int argc, char *argv[]) {
|
|||
current_player.Refresh();
|
||||
current_player.UpdateTexture();
|
||||
}
|
||||
|
||||
// ImGui::SliderFloat("erm", &rotation, -180, 180, "Rotation");
|
||||
// rlImGuiImage(¤t_player.tex.tex);
|
||||
ImGui::Separator();
|
||||
ImGui::LabelText("Disc Info", "P: %f, V: %f, A: %f", disc.pos, disc.velo, disc.accel);
|
||||
rlImGuiImageSize(¤t_player.tex.tex, 300, 300);
|
||||
}
|
||||
ImGui::End();
|
||||
|
|
|
@ -177,6 +177,49 @@ void MprisPlayer::UpdateTexture() {
|
|||
}
|
||||
}
|
||||
|
||||
DiscObject::DiscObject(float ia) {
|
||||
pos = 0;
|
||||
prevouspos = 0;
|
||||
velo = 0;
|
||||
accel = 0;
|
||||
target = ia;
|
||||
active = true;
|
||||
}
|
||||
|
||||
void DiscObject::Activate() {
|
||||
active = !active;
|
||||
pos = 0;
|
||||
prevouspos = 0;
|
||||
velo = 0;
|
||||
accel = 0;
|
||||
target = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DiscObject::UpdatePos(float dtime) {
|
||||
if (active) {
|
||||
prevouspos = pos;
|
||||
pos = pos + velo * dtime;
|
||||
velo = velo + accel * dtime;
|
||||
accel = target;
|
||||
}
|
||||
}
|
||||
|
||||
void DiscObject::UpdatePos(float new_pos, float dtime) {
|
||||
if (active) {
|
||||
prevouspos = pos;
|
||||
pos = new_pos;
|
||||
velo = (pos - prevouspos) / dtime;
|
||||
accel = target;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DiscObject::AddAccel(float ac) {
|
||||
accel = accel + ac;
|
||||
}
|
||||
|
||||
RayTexture::RayTexture() {
|
||||
auto rtex = LoadRenderTexture(300,300);
|
||||
BeginTextureMode(rtex);
|
||||
|
|
|
@ -22,6 +22,22 @@ class RayTexture {
|
|||
~RayTexture();
|
||||
};
|
||||
|
||||
class DiscObject {
|
||||
public:
|
||||
float prevouspos;
|
||||
float pos;
|
||||
float velo;
|
||||
float accel;
|
||||
float target;
|
||||
bool active;
|
||||
DiscObject(float ia);
|
||||
void UpdatePos(float dtime);
|
||||
void UpdatePos(float pos, float dtime);
|
||||
void AddAccel(float ac);
|
||||
void Activate();
|
||||
};
|
||||
|
||||
|
||||
class MprisPlayer {
|
||||
public:
|
||||
std::unique_ptr<sdbus::IConnection> bus_connection;
|
||||
|
|
Loading…
Reference in a new issue