the go back commit

This commit is contained in:
IXtreme 2025-01-12 01:56:55 -05:00
parent 2869533db9
commit ebfb6e239a
4 changed files with 118 additions and 18 deletions

View file

@ -58,8 +58,15 @@ CPP_SRC += $(wildcard $(SRC_DIR)/material-colors/cpp/quantize/wsmeans.cpp)
CPP_SRC += $(wildcard $(SRC_DIR)/material-colors/cpp/quantize/wu.cpp)
CPP_SRC += $(wildcard $(SRC_DIR)/material-colors/cpp/quantize/lab.cpp)
CPP_SRC += $(wildcard $(SRC_DIR)/material-colors/cpp/utils/utils.cpp)
CPP_SRC += $(wildcard $(SRC_DIR)/material-colors/cpp/cam/cam.cpp)
CPP_SRC += $(wildcard $(SRC_DIR)/material-colors/cpp/cam/hct.cpp)
CPP_SRC += $(wildcard $(SRC_DIR)/material-colors/cpp/cam/hct_solver.cpp)
CPP_SRC += $(wildcard $(SRC_DIR)/material-colors/cpp/cam/viewing_conditions.cpp)
CPP_SRC += $(wildcard $(SRC_DIR)/material-colors/cpp/score/score.cpp)
EXTRA_DIRS += $(OBJ_DIR)/material-colors/cpp/quantize
EXTRA_DIRS += $(OBJ_DIR)/material-colors/cpp/utils
EXTRA_DIRS += $(OBJ_DIR)/material-colors/cpp/score
EXTRA_DIRS += $(OBJ_DIR)/material-colors/cpp/cam
ifeq ($(IMGUI_MODE), BUILD)
CPP_SRC += $(wildcard $(SRC_DIR)/imgui/*.cpp) #GET LIST OF ALL CPP FILES

View file

@ -7,8 +7,8 @@
#include <sdbus-c++/Types.h>
#define IMGUI_DEFINE_MATH_OPERATORS
#include "raylib.h"
#include "rlgl.h"
#include "raymath.h"
#include "rlgl.h"
#include <optional>
#include <unordered_map>
#include <vector>
@ -233,18 +233,22 @@ float ScaleToFit(Vector2 src, Vector2 dst) {
// return Vector2Scale(src, ratio);
}
void GenCircleOverlay(RenderTexture tex, bool trans) {
void GenCircleOverlay(MprisPlayer *current_player, RenderTexture tex, bool trans, bool accent) {
BeginTextureMode(tex);
if (trans) {
ClearBackground(WHITE);
} else {
if (accent) {
ClearBackground(current_player->GetPrimaryColor());
} else {
ClearBackground(BLACK);
}
}
BeginBlendMode(BLEND_SUBTRACT_COLORS);
if (trans) {
DrawCircle(GetScreenWidth()/2, GetScreenHeight()/2, std::min(GetScreenWidth()/2, GetScreenHeight()/2), WHITE);
DrawCircle(GetScreenWidth() / 2, GetScreenHeight() / 2, std::min(GetScreenWidth() / 2, GetScreenHeight() / 2), WHITE);
} else {
DrawCircle(GetScreenWidth()/2, GetScreenHeight()/2, std::min(GetScreenWidth()/2, GetScreenHeight()/2), (Color{0,0,0,0}));
DrawCircle(GetScreenWidth() / 2, GetScreenHeight() / 2, std::min(GetScreenWidth() / 2, GetScreenHeight() / 2), (Color{0, 0, 0, 0}));
}
EndBlendMode();
EndTextureMode();
@ -257,13 +261,13 @@ int main(int argc, char *argv[]) {
int screenHeight = 800;
// SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE);
//SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE);
SetConfigFlags(FLAG_WINDOW_TRANSPARENT | FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE);
// SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE);
SetConfigFlags(FLAG_WINDOW_TRANSPARENT | FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT);
InitWindow(screenWidth, screenHeight, "raylib-Extras [ImGui] example - Docking");
SetTargetFPS(244);
rlImGuiSetup(true);
ImGui::GetStyle().AntiAliasedLinesUseTex = false;
//SetWindowState(FLAG_WINDOW_UNDECORATED);
// SetWindowState(FLAG_WINDOW_UNDECORATED);
TestC();
TestCPPFunc();
@ -284,17 +288,28 @@ int main(int argc, char *argv[]) {
// Main game loop
bool goodstate = false;
bool trans = false;
bool accent = true;
long imagecount = -1;
bool showMetricsWindow = false;
RenderTexture recordoverlay = LoadRenderTexture(screenWidth, screenHeight);
GenCircleOverlay(recordoverlay, trans);
GenCircleOverlay(&current_player, recordoverlay, trans, accent);
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, trans);
GenCircleOverlay(&current_player, recordoverlay, trans, accent);
}
if (current_player.imagecount > imagecount) {
imagecount = current_player.imagecount;
GenCircleOverlay(&current_player, recordoverlay, trans, accent);
}
if (GetTime() > lasttime + 3) {
lasttime = GetTime();
current_player.Refresh();
@ -302,7 +317,7 @@ int main(int argc, char *argv[]) {
BeginDrawing();
if (trans) {
ClearBackground((Color) {0,0,0,0});
ClearBackground((Color){0, 0, 0, 0});
} else {
ClearBackground(BLACK);
}
@ -353,7 +368,7 @@ int main(int argc, char *argv[]) {
} 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)) {
} else if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) && disc.enabled) {
float initmouserot;
Vector2 initmousepos;
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
@ -386,10 +401,10 @@ int main(int argc, char *argv[]) {
if (disc.active) {
if (trans) {
rlSetBlendFactors(1,1, 0x800B);
rlSetBlendFactors(1, 1, 0x800B);
BeginBlendMode(BLEND_CUSTOM);
}
DrawTexture(recordoverlay.texture, 0, 0 , WHITE);
DrawTexture(recordoverlay.texture, 0, 0, WHITE);
if (trans) {
EndBlendMode();
}
@ -402,6 +417,7 @@ int main(int argc, char *argv[]) {
// start ImGui content
if (showIMgui) {
disc.enabled = false;
rlImGuiBegin();
// if you want windows to dock to the viewport, call this.
@ -421,6 +437,9 @@ int main(int argc, char *argv[]) {
current_player = MprisPlayer(item);
}
}
if (ImGui::MenuItem("Refresh")) {
serviceList = GetMprisServices();
}
ImGui::EndMenu();
}
@ -432,11 +451,26 @@ int main(int argc, char *argv[]) {
}
if (ImGui::MenuItem("Trans Mode !!", nullptr, trans)) {
trans = !trans;
GenCircleOverlay(recordoverlay, trans);
GenCircleOverlay(&current_player, recordoverlay, trans, accent);
}
if (ImGui::MenuItem("Accent Mode !!", nullptr, accent)) {
accent = !accent;
GenCircleOverlay(&current_player, recordoverlay, trans, accent);
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Tools")) {
if (ImGui::MenuItem("Debug Window", nullptr, showMetricsWindow)) {
showMetricsWindow = !showMetricsWindow;
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
if (showMetricsWindow) {
ImGui::ShowMetricsWindow();
}
}
// show some windows
@ -466,6 +500,18 @@ int main(int argc, char *argv[]) {
ImGui::Separator();
ImGui::LabelText("Disc Info", "P: %f, V: %f, A: %f", disc.pos, disc.velo, disc.accel);
rlImGuiImageSize(&current_player.tex.tex, 300, 300);
ImGui::Separator();
int inc = 0;
for (auto obj : current_player.accent_colors) {
float col[3] = {0, 0, 0};
col[0] = ((float)obj.r) / 255;
col[1] = ((float)obj.g) / 255;
col[2] = ((float)obj.b) / 255;
ImGui::ColorEdit3(("lf" + std::to_string(inc)).c_str(), col);
inc++;
}
}
ImGui::End();
@ -474,6 +520,8 @@ int main(int argc, char *argv[]) {
// end ImGui Content
rlImGuiEnd();
} else {
disc.enabled = true;
}
EndDrawing();

View file

@ -5,6 +5,7 @@
#define IMGUI_DEFINE_MATH_OPERATORS
#include "imgui.h"
#include <cpp/score/score.h>
#include <curl/curl.h>
#include <fstream>
#include <iostream>
@ -19,6 +20,7 @@ MprisPlayer::MprisPlayer(std::string servicename) {
image_path_cache = "NULL";
PlayerProxy = sdbus::createProxy(dest, objec);
mp2 = "org.mpris.MediaPlayer2.Player";
imagecount = 0;
Refresh();
}
@ -62,6 +64,33 @@ void MprisPlayer::Refresh() {
if (current_metadata["mpris:artUrl"].get<std::string>() != image_path_cache) {
image_path_cache = current_metadata["mpris:artUrl"].get<std::string>();
UpdateTexture();
auto img = LoadImageFromTexture(tex.tex);
std::vector <material_color_utilities::Argb> argbs;
material_color_utilities::QuantizerResult res;
if (img.format == PIXELFORMAT_UNCOMPRESSED_R8G8B8A8) {
auto data = (char*) img.data;
for (int i = 0; i < img.width * img.height * 4; i += 4) {
material_color_utilities::Argb color = (data[i] << 16) | (data[i + 1] << 8) | (data[i + 2]) | (data[i + 3] << 24);
argbs.push_back(color);
}
res = material_color_utilities::QuantizeCelebi(argbs, 16);
} else if (img.format == PIXELFORMAT_UNCOMPRESSED_R8G8B8) {
auto data = (char*) img.data;
for (int i = 0; i < img.width * img.height * 3; i += 3) {
material_color_utilities::Argb color = (data[i] << 16) | (data[i + 1] << 8) | (data[i + 2] | (0xFF << 24));
argbs.push_back(color);
}
res = material_color_utilities::QuantizeCelebi(argbs, 16);
}
auto colors = material_color_utilities::RankedSuggestions(res.color_to_count, material_color_utilities::ScoreOptions());
accent_colors.clear();
for (auto obj : colors) {
accent_colors.push_back((Color) {.r=(unsigned char) ((obj >> 16) & 0xFF), .g=(unsigned char)( (obj >> 8) & 0xFF ), .b=(unsigned char)((obj >> 0) & 0xFF), .a=(unsigned char)((obj>>24) & 0xFF) });
}
imagecount = imagecount + 1;
}
} catch (const std::exception& e) {}
return;
@ -177,6 +206,16 @@ void MprisPlayer::UpdateTexture() {
}
}
Color MprisPlayer::GetPrimaryColor() {
if (accent_colors.empty()) {
return BLACK;
} else {
std::cout << "here" << std::endl;
return accent_colors[0];
}
}
DiscObject::DiscObject(float ia) {
pos = 0;
prevouspos = 0;
@ -184,6 +223,7 @@ DiscObject::DiscObject(float ia) {
accel = 0;
target = ia;
active = true;
enabled = true;
}
void DiscObject::Activate() {

View file

@ -10,6 +10,7 @@
#include <sdbus-c++/IConnection.h>
#include <sdbus-c++/IProxy.h>
#include <string>
#include "cpp/quantize/celebi.h"
class RayTexture {
public:
@ -30,6 +31,7 @@ public:
float accel;
float target;
bool active;
bool enabled;
DiscObject(float ia);
void UpdatePos(float dtime);
void UpdatePos(float pos, float dtime);
@ -45,7 +47,9 @@ class MprisPlayer {
sdbus::InterfaceName mp2;
sdbus::MethodName playpause;
RayTexture tex;
std::vector<Color> accent_colors;
std::string image_path_cache;
long imagecount;
explicit MprisPlayer(std::string servicename);
void PausePlay();
void Refresh();
@ -57,6 +61,7 @@ class MprisPlayer {
std::string GetIdentity();
std::unordered_map<std::string, sdbus::Variant> current_metadata;
std::unordered_map<std::string, sdbus::Variant> GetCurrentMetadata();
Color GetPrimaryColor();
};