From b7f8594bb3b6350e260c31f8f79cb167371bd7de Mon Sep 17 00:00:00 2001 From: Angel Xex Date: Tue, 8 Feb 2022 02:56:18 -0300 Subject: [PATCH] Border Color Selector --- include/apppopups.h | 1 + include/config.h | 11 +++- include/gui.h | 1 + include/libmpv.h | 2 +- source/UI/apppopups.cpp | 108 ++++++++++++++++++++++++++++++++++++ source/UI/playerWindows.cpp | 12 ++++ source/UI/settingsMenu.cpp | 3 + source/config.cpp | 55 ++++++++++++++++++ source/gui.cpp | 10 ++++ source/libmpv.cpp | 7 +++ 10 files changed, 208 insertions(+), 2 deletions(-) diff --git a/include/apppopups.h b/include/apppopups.h index a050e2c..5127999 100644 --- a/include/apppopups.h +++ b/include/apppopups.h @@ -18,6 +18,7 @@ namespace Popups { void SaveSettingsPopup(void); void ResumePopup(void); void SubFontColorPopup(void); + void SubBorderColorPopup(void); void PlaylistStartPlaylist(void); void DBUpdatedPopup(void); } diff --git a/include/config.h b/include/config.h index d00a6b3..dfd5ae1 100644 --- a/include/config.h +++ b/include/config.h @@ -53,6 +53,12 @@ class Config{ float * getSubFontColor(bool tmpvalue); std::string getSubFontColorHex(bool tmpvalue); void setSubFontColor(float *_color); + + //bordercolor + float * getSubBorderColor(bool tmpvalue); + std::string getSubBorderColorHex(bool tmpvalue); + void setSubBorderColor(float *_color); + //endbordercolor int getDeinterlace(bool tmpvalue); void setDeinterlace(int value); @@ -114,7 +120,10 @@ class Config{ float subfontcolor[4]; float tmpsubfontcolor[4]; - + //bordercolor + float subbordercolor[4]; + float tmpsubbordercolor[4]; + //end bordercolor int tmpstartresumeperc; int tmpstopresumeperc; diff --git a/include/gui.h b/include/gui.h index 0ba06ba..ac27c27 100644 --- a/include/gui.h +++ b/include/gui.h @@ -83,6 +83,7 @@ enum APP_POPUP_STATES { POPUP_STATE_ADDQUEUE, POPUP_STATE_STARTPLAYLIST, POPUP_STATE_SUBFONTCOLOR, + POPUP_STATE_SUBBORDERCOLOR, POPUP_STATE_DBUPDATED }; diff --git a/include/libmpv.h b/include/libmpv.h index 054989d..386b74e 100644 --- a/include/libmpv.h +++ b/include/libmpv.h @@ -82,7 +82,7 @@ class libMpv{ void setShadowIntensity(double value,bool osd); void setShadowOffset(int value,bool osd); void setSubFontColor(std::string hexcolor); - + void setSubBorderColor(std::string hexcolor); void setDeinterlace(int value); void setLoop(bool val); diff --git a/source/UI/apppopups.cpp b/source/UI/apppopups.cpp index 2883af2..d155a8e 100644 --- a/source/UI/apppopups.cpp +++ b/source/UI/apppopups.cpp @@ -211,6 +211,114 @@ namespace Popups{ } } + + static ImVec4 backup_color2; + static ImVec4 color2; + static bool saved_palette_init2 = true; + static ImVec4 saved_palette2[32] = {}; + + //bordercolor + void SubBorderColorPopup(void) { + if (saved_palette_init2) + { + for (int n = 0; n < IM_ARRAYSIZE(saved_palette2); n++) + { + ImGui::ColorConvertHSVtoRGB(n / 31.0f, 0.8f, 0.8f, + saved_palette2[n].x, saved_palette2[n].y, saved_palette2[n].z); + saved_palette2[n].w = 1.0f; // Alpha + } + saved_palette_init2 = false; + } + ImGui::SetNextWindowPos(ImVec2(0,0)); + ImGui::OpenPopup("subbordercolorpicker"); + + if (ImGui::BeginPopup("subbordercolorpicker")) { + float * tmpcolor = configini->getSubBorderColor(true); + float * tmpcolor_backup = configini->getSubBorderColor(false); + color2 = ImVec4(tmpcolor[0],tmpcolor[1],tmpcolor[2],tmpcolor[3]); + backup_color2 = ImVec4(tmpcolor_backup[0],tmpcolor_backup[1],tmpcolor_backup[2],tmpcolor_backup[3]); + ImGui::Separator(); + if(ImGui::ColorPicker3("##picker", (float*)&color2,ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoSmallPreview)){ + float setcolor[4]; + setcolor[0] = color2.x; + setcolor[1] = color2.y; + setcolor[2] = color2.z; + setcolor[3] = color2.w; + configini->setSubBorderColor(setcolor); + } + ImGui::SameLine(); + + ImGui::BeginGroup(); // Lock X position + ImGui::Text("Current"); + ImGui::ColorButton("##current", color2, ImGuiColorEditFlags_NoAlpha| ImGuiColorEditFlags_NoPicker , ImVec2(60, 40)); + ImGui::Text("Previous"); + if (ImGui::ColorButton("##previous", backup_color2, ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoPicker , ImVec2(60, 40))){ + float setcolor[4]; + setcolor[0] = backup_color2.x; + setcolor[1] = backup_color2.y; + setcolor[2] = backup_color2.z; + setcolor[3] = backup_color2.w; + configini->setSubBorderColor(setcolor); + } + ImGui::Separator(); + ImGui::Text("Palette"); + for (int n = 0; n < IM_ARRAYSIZE(saved_palette2); n++) + { + ImGui::PushID(n); + if ((n % 8) != 0) + ImGui::SameLine(0.0f, ImGui::GetStyle().ItemSpacing.y); + + ImGuiColorEditFlags palette_button_flags = ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoTooltip; + if (ImGui::ColorButton("##palette", saved_palette2[n], palette_button_flags, ImVec2(20, 20))){ + //color = ImVec4(saved_palette[n].x, saved_palette[n].y, saved_palette[n].z, color.w); // Preserve alpha! + float setcolor[4]; + setcolor[0] = saved_palette2[n].x; + setcolor[1] = saved_palette2[n].y; + setcolor[2] = saved_palette2[n].z; + setcolor[3] = color2.w; + configini->setSubBorderColor(setcolor); + } + + // Allow user to drop colors into each palette entry. Note that ColorButton() is already a + // drag source by default, unless specifying the ImGuiColorEditFlags_NoDragDrop flag. + if (ImGui::BeginDragDropTarget()) + { + if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F)) + memcpy((float*)&saved_palette2[n], payload->Data, sizeof(float) * 3); + if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F)) + memcpy((float*)&saved_palette2[n], payload->Data, sizeof(float) * 4); + ImGui::EndDragDropTarget(); + } + + ImGui::PopID(); + } + if(ImGui::Button("Use Color")){ + float setcolor[4]; + setcolor[0] = color2.x; + setcolor[1] = color2.y; + setcolor[2] = color2.z; + setcolor[3] = color2.w; + configini->setSubBorderColor(setcolor); + libmpv->setSubBorderColor(configini->getSubBorderColorHex(true)); + item.popupstate = POPUP_STATE_NONE; + } + ImGui::SameLine(); + if(ImGui::Button("Cancel")){ + item.popupstate = POPUP_STATE_NONE; + float setcolor[4]; + setcolor[0] = backup_color2.x; + setcolor[1] = backup_color2.y; + setcolor[2] = backup_color2.z; + setcolor[3] = backup_color2.w; + configini->setSubBorderColor(setcolor); + } + + ImGui::EndGroup(); + ImGui::EndPopup(); + } + } + //bordercolorend + void DBUpdatedPopup(void) { Popups::SetupPopup("Database Updated"); if (ImGui::BeginPopupModal("Database Updated", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { diff --git a/source/UI/playerWindows.cpp b/source/UI/playerWindows.cpp index 9dab417..33acb82 100644 --- a/source/UI/playerWindows.cpp +++ b/source/UI/playerWindows.cpp @@ -669,6 +669,14 @@ namespace playerWindows{ if(ImGui::ColorButton("##subfontcolor", ImVec4(subcolor[0],subcolor[1],subcolor[2],subcolor[3]), ImGuiColorEditFlags_NoAlpha| ImGuiColorEditFlags_NoPicker|ImGuiColorEditFlags_InputRGB , ImVec2(190, 40))){ item.popupstate = POPUP_STATE_SUBFONTCOLOR; } + + //bordercolor + ImGui::Text("Sub Border Color"); + float * subcolor2 = configini->getSubBorderColor(true); + if(ImGui::ColorButton("##subbordercolor", ImVec4(subcolor2[0],subcolor2[1],subcolor2[2],subcolor2[3]), ImGuiColorEditFlags_NoAlpha| ImGuiColorEditFlags_NoPicker|ImGuiColorEditFlags_InputRGB , ImVec2(190, 40))){ + item.popupstate = POPUP_STATE_SUBBORDERCOLOR; + } + //endbordercolor //ImGui::EndDisabled(); ImGui::SetCursorPosY(ImGui::GetWindowSize().y -50); @@ -691,6 +699,10 @@ namespace playerWindows{ libmpv->setSubFontSize(drag_subfontsize,false); configini->setSubFontColor(configini->getSubFontColor(false)); libmpv->setSubFontColor(configini->getSubFontColorHex(true)); + //bordercolor + configini->setSubBorderColor(configini->getSubBorderColor(false)); + libmpv->setSubBorderColor(configini->getSubBorderColorHex(true)); + //endbordercolor } } playerWindows::ExitWindow(); diff --git a/source/UI/settingsMenu.cpp b/source/UI/settingsMenu.cpp index 36feb74..47493ce 100644 --- a/source/UI/settingsMenu.cpp +++ b/source/UI/settingsMenu.cpp @@ -362,6 +362,9 @@ namespace Windows { configini->setSubFontSize(configini->getSubFontSize(false)); configini->setSubFontColor(configini->getSubFontColor(false)); + //bordercolor + configini->setSubBorderColor(configini->getSubBorderColor(false)); + //endbordercolor configini->setDbActive(configini->getDeinterlace(false)); diff --git a/source/config.cpp b/source/config.cpp index 96fac47..4512748 100644 --- a/source/config.cpp +++ b/source/config.cpp @@ -104,6 +104,25 @@ Config::Config(std::string inifile){ tmpsubfontcolor[1] = subfontcolor[1] = (float)tmpcolors[1]/255.0f; tmpsubfontcolor[2] = subfontcolor[2] = (float)tmpcolors[2]/255.0f; tmpsubfontcolor[3] = subfontcolor[3] = 1.0f; + + //bordercolor + + std::string fontcolorstring2 = "#000000"; + const char* fontcolorpv2; + fontcolorpv2 = ini->GetValue("Main", "subbordercolor"); + if(fontcolorpv2!= nullptr){ + fontcolorstring2 = fontcolorpv2; + } + if(fontcolorstring2 == ""){ + fontcolorstring2 = "#000000"; + } + int tmpcolors2[3]; + sscanf(fontcolorstring2.c_str(),"#%02X%02X%02X",&tmpcolors2[0],&tmpcolors2[1],&tmpcolors2[2]); + tmpsubbordercolor[0] = subbordercolor[0] = (float)tmpcolors2[0]/255.0f; + tmpsubbordercolor[1] = subbordercolor[1] = (float)tmpcolors2[1]/255.0f; + tmpsubbordercolor[2] = subbordercolor[2] = (float)tmpcolors2[2]/255.0f; + tmpsubbordercolor[3] = subbordercolor[3] = 1.0f; + //endbordercolor const char* deintpv; deintpv = ini->GetValue("Main", "deinterlace"); @@ -336,6 +355,28 @@ void Config::setSubFontColor(float *_color){ tmpsubfontcolor[2] = _color[2]; } +//bordercolor +float * Config::getSubBorderColor(bool tmpvalue){ + if(tmpvalue){ + return tmpsubbordercolor; + } + return subbordercolor; +} +std::string Config::getSubBorderColorHex(bool tmpvalue){ + char subfontcstr2[32]; + if(tmpvalue){ + sprintf(subfontcstr2,"#%02X%02X%02X",(unsigned int)(tmpsubbordercolor[0]*255.0f),(unsigned int)(tmpsubbordercolor[1]*255.0f),(unsigned int)(tmpsubbordercolor[2]*255.0f)); + return std::string(subfontcstr2); + } + sprintf(subfontcstr2,"#%02X%02X%02X",(unsigned int)(subbordercolor[0]*255.0f),(unsigned int)(subbordercolor[1]*255.0f),(unsigned int)(subbordercolor[2]*255.0f)); + return std::string(subfontcstr2); +} +void Config::setSubBorderColor(float *_color){ + tmpsubbordercolor[0] = _color[0]; + tmpsubbordercolor[1] = _color[1]; + tmpsubbordercolor[2] = _color[2]; +} +//endbordercolor void Config::setDeinterlace(int value){ tmpdeint = value; @@ -403,6 +444,12 @@ void Config::saveSettings(){ subfontcolor[1] = tmpsubfontcolor[1]; subfontcolor[2] = tmpsubfontcolor[2]; + //bordercolor + subbordercolor[0] = tmpsubbordercolor[0]; + subbordercolor[1] = tmpsubbordercolor[1]; + subbordercolor[2] = tmpsubbordercolor[2]; + //endbordercolor + themename = tmpthemename; @@ -443,6 +490,14 @@ void Config::saveSettings(){ sprintf(subfontcstr,"#%02X%02X%02X",(unsigned int)subfontcolor[0]*255,(unsigned int)subfontcolor[1]*255,(unsigned int)subfontcolor[2]*255); ini->SetValue("Main", "subfontcolor", subfontcstr); + //bordercolor + ini->Delete("Main", "subbordercolor"); + char subfontcstr2[32]; + sprintf(subfontcstr2,"#%02X%02X%02X",(unsigned int)subbordercolor[0]*255,(unsigned int)subbordercolor[1]*255,(unsigned int)subbordercolor[2]*255); + ini->SetValue("Main", "subbordercolor", subfontcstr2); + + //endbordercolor + std::vector deintopts = {"no","yes","auto"}; ini->Delete("Main", "deinterlace"); ini->SetValue("Main", "deinterlace", deintopts[deint].c_str()); diff --git a/source/gui.cpp b/source/gui.cpp index d6b86be..dbd44b9 100644 --- a/source/gui.cpp +++ b/source/gui.cpp @@ -612,6 +612,13 @@ namespace GUI { }else{ item.rightmenustate = PLAYER_RIGHT_MENU_HOME; } + //bordercolor + if(item.popupstate == POPUP_STATE_SUBBORDERCOLOR){ + item.popupstate = POPUP_STATE_NONE; + configini->setSubBorderColor(configini->getSubBorderColor(false)); + }else{ + item.rightmenustate = PLAYER_RIGHT_MENU_HOME; + } } else if(item.rightmenustate == PLAYER_AUDIOEQ){ item.rightmenustate = PLAYER_RIGHT_MENU_AUDIO; @@ -919,6 +926,9 @@ namespace GUI { if(item.popupstate == POPUP_STATE_SUBFONTCOLOR){ Popups::SubFontColorPopup(); } + if(item.popupstate == POPUP_STATE_SUBBORDERCOLOR){ + Popups::SubBorderColorPopup(); + } break; case PLAYER_RIGHT_MENU_SHADERMANIA: playerWindows::RightHomeShaderMania(); diff --git a/source/libmpv.cpp b/source/libmpv.cpp index 4d2f742..3672c79 100644 --- a/source/libmpv.cpp +++ b/source/libmpv.cpp @@ -134,6 +134,7 @@ void libMpv::loadFile(std::string _path){ setLoop(false); setSubFontSize(configini->getSubFontSize(false),false); setSubFontColor(configini->getSubFontColorHex(false)); + setSubBorderColor(configini->getSubBorderColorHex(false)); } @@ -609,6 +610,12 @@ void libMpv::setSubFontColor(std::string hexcolor){ } +void libMpv::setSubBorderColor(std::string hexcolor){ + std::string cmd = "no-osd set sub-border-color '" + hexcolor + std::string("'"); + mpv_command_string(handle, cmd.c_str()); + +} + void libMpv::setAudioEQ(int *eqval,bool osd){ char eqstring[1024]; sprintf(eqstring,"no-osd set af equalizer=f=64:width_type=o:w=3.3:g=%d,equalizer=f=400:width_type=o:w=2.0:g=%d,equalizer=f=1250:width_type=o:w=1.3:g=%d,equalizer=f=2830:width_type=o:w=1.0:g=%d,equalizer=f=5600:width_type=o:w=1.0:g=%d,equalizer=f=12500:width_type=o:w=1.3:g=%d",eqval[0],eqval[1],eqval[2],eqval[3],eqval[4],eqval[5]);