From af5d34cc1d96ab43764ff976c41c61d796f09795 Mon Sep 17 00:00:00 2001 From: Ryan Lucia Date: Sun, 15 Apr 2018 17:59:32 -0400 Subject: [PATCH] Add configuration options for colors in visual typesetting tools --- src/libresrc/default_config.json | 7 +++++++ src/libresrc/osx/default_config.json | 7 +++++++ src/options.h | 2 ++ src/preferences.cpp | 10 ++++++++++ src/visual_tool.cpp | 28 ++++++++++++++++------------ src/visual_tool.h | 9 +++++++-- src/visual_tool_clip.cpp | 14 ++++++++++---- src/visual_tool_drag.cpp | 8 ++++++-- src/visual_tool_rotatexy.cpp | 16 +++++++++++----- src/visual_tool_rotatez.cpp | 19 +++++++++++++------ src/visual_tool_scale.cpp | 18 +++++++++++++----- src/visual_tool_vector_clip.cpp | 27 +++++++++++++++++---------- 12 files changed, 119 insertions(+), 46 deletions(-) diff --git a/src/libresrc/default_config.json b/src/libresrc/default_config.json index 0134efb94..35f870950 100644 --- a/src/libresrc/default_config.json +++ b/src/libresrc/default_config.json @@ -266,6 +266,13 @@ }, "Video Dummy" : { "Last Colour" : "rgb(47, 163, 254)" + }, + "Visual Tools" : { + "Highlight Primary" : "rgb(255, 169, 40)", + "Highlight Secondary" : "rgb(255, 253, 185)", + "Lines Primary" : "rgb(187, 0, 0)", + "Lines Secondary" : "rgb(106, 32, 19)", + "Shaded Area Alpha" : 0.5 } }, diff --git a/src/libresrc/osx/default_config.json b/src/libresrc/osx/default_config.json index c230c7460..5ad7be7d0 100644 --- a/src/libresrc/osx/default_config.json +++ b/src/libresrc/osx/default_config.json @@ -266,6 +266,13 @@ }, "Video Dummy" : { "Last Colour" : "rgb(47, 163, 254)" + }, + "Visual Tools" : { + "Highlight Primary" : "rgb(255, 169, 40)", + "Highlight Secondary" : "rgb(255, 253, 185)", + "Lines Primary" : "rgb(187, 0, 0)", + "Lines Secondary" : "rgb(106, 32, 19)", + "Shaded Area Alpha" : 0.5 } }, diff --git a/src/options.h b/src/options.h index 8f0240334..77e6676a2 100644 --- a/src/options.h +++ b/src/options.h @@ -14,6 +14,8 @@ // // Aegisub Project http://www.aegisub.org/ +#pragma once + #include #include #include diff --git a/src/preferences.cpp b/src/preferences.cpp index 1986a6132..7850af5f9 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -288,6 +288,16 @@ void Interface_Colours(wxTreebook *book, Preferences *parent) { p->OptionAdd(grid, _("Lines"), "Colour/Subtitle Grid/Lines"); p->OptionAdd(grid, _("CPS Error"), "Colour/Subtitle Grid/CPS Error"); + auto visual_tools = p->PageSizer(_("Visual Typesetting Tools")); + p->OptionAdd(visual_tools, _("Primary Lines"), "Colour/Visual Tools/Lines Primary"); + p->OptionAdd(visual_tools, _("Secondary Lines"), "Colour/Visual Tools/Lines Secondary"); + p->OptionAdd(visual_tools, _("Primary Highlight"), "Colour/Visual Tools/Highlight Primary"); + p->OptionAdd(visual_tools, _("Secondary Highlight"), "Colour/Visual Tools/Highlight Secondary"); + + // Separate sizer to prevent the colors in the visual tools section from getting resized + auto visual_tools_alpha = p->PageSizer(_("Visual Typesetting Tools Alpha")); + p->OptionAdd(visual_tools_alpha, _("Shaded Area"), "Colour/Visual Tools/Shaded Area Alpha", 0, 1, 0.1); + p->sizer = main_sizer; p->SetSizerAndFit(p->sizer); diff --git a/src/visual_tool.cpp b/src/visual_tool.cpp index bdbc4e813..13009127c 100644 --- a/src/visual_tool.cpp +++ b/src/visual_tool.cpp @@ -23,7 +23,9 @@ #include "ass_dialogue.h" #include "ass_file.h" #include "ass_style.h" +#include "compat.h" #include "include/aegisub/context.h" +#include "options.h" #include "selection_controller.h" #include "video_controller.h" #include "video_display.h" @@ -37,17 +39,15 @@ #include -const wxColour VisualToolBase::colour[] = { - wxColour(106,32,19), - wxColour(255,169,40), - wxColour(255,253,185), - wxColour(187,0,0) -}; - VisualToolBase::VisualToolBase(VideoDisplay *parent, agi::Context *context) : c(context) , parent(parent) , frame_number(c->videoController->GetFrameN()) +, highlight_color_primary_opt(OPT_GET("Colour/Visual Tools/Highlight Primary")) +, highlight_color_secondary_opt(OPT_GET("Colour/Visual Tools/Highlight Secondary")) +, line_color_primary_opt(OPT_GET("Colour/Visual Tools/Lines Primary")) +, line_color_secondary_opt(OPT_GET("Colour/Visual Tools/Lines Secondary")) +, shaded_area_alpha_opt(OPT_GET("Colour/Visual Tools/Shaded Area Alpha")) , file_changed_connection(c->ass->AddCommitListener(&VisualToolBase::OnCommit, this)) { int script_w, script_h; @@ -273,14 +273,18 @@ void VisualTool::OnMouseEvent(wxMouseEvent &event) { template void VisualTool::DrawAllFeatures() { - gl.SetLineColour(colour[0], 1.0f, 1); + wxColour grid_color = to_wx(line_color_secondary_opt->GetColor()); + gl.SetLineColour(grid_color, 1.0f, 1); + wxColour base_fill = to_wx(line_color_primary_opt->GetColor()); + wxColour active_fill = to_wx(highlight_color_secondary_opt->GetColor()); + wxColour alt_fill = to_wx(line_color_primary_opt->GetColor()); for (auto& feature : features) { - int fill = 1; + wxColour fill = base_fill; if (&feature == active_feature) - fill = 2; + fill = active_fill; else if (sel_features.count(&feature)) - fill = 3; - gl.SetFillColour(colour[fill], 0.3f); + fill = alt_fill; + gl.SetFillColour(fill, 0.3f); feature.Draw(gl); } } diff --git a/src/visual_tool.h b/src/visual_tool.h index d1af51f02..72eec4224 100644 --- a/src/visual_tool.h +++ b/src/visual_tool.h @@ -22,6 +22,7 @@ #include "gl_wrap.h" #include "vector2d.h" +#include "options.h" #include #include @@ -85,8 +86,6 @@ protected: /// Called when the user double-clicks virtual void OnDoubleClick() { } - static const wxColour colour[4]; - agi::Context *c; VideoDisplay *parent; @@ -106,6 +105,12 @@ protected: Vector2D video_pos; ///< Top-left corner of the video in the display area Vector2D video_res; ///< Video resolution + const agi::OptionValue *highlight_color_primary_opt; + const agi::OptionValue *highlight_color_secondary_opt; + const agi::OptionValue *line_color_primary_opt; + const agi::OptionValue *line_color_secondary_opt; + const agi::OptionValue *shaded_area_alpha_opt; + agi::signal::Connection file_changed_connection; int commit_id = -1; ///< Last used commit id for coalescing diff --git a/src/visual_tool_clip.cpp b/src/visual_tool_clip.cpp index b9e41f3c1..52a1024b2 100644 --- a/src/visual_tool_clip.cpp +++ b/src/visual_tool_clip.cpp @@ -21,7 +21,9 @@ #include "visual_tool_clip.h" #include "ass_dialogue.h" +#include "compat.h" #include "include/aegisub/context.h" +#include "options.h" #include "selection_controller.h" #include @@ -66,14 +68,18 @@ void VisualToolClip::Draw() { DrawAllFeatures(); + // Load colors from options + wxColour line_color = to_wx(line_color_primary_opt->GetColor()); + float shaded_alpha = static_cast(shaded_area_alpha_opt->GetDouble()); + // Draw rectangle - gl.SetLineColour(colour[3], 1.0f, 2); - gl.SetFillColour(colour[3], 0.0f); + gl.SetLineColour(line_color, 1.0f, 2); + gl.SetFillColour(line_color, 0.0f); gl.DrawRectangle(cur_1, cur_2); // Draw outside area - gl.SetLineColour(colour[3], 0.0f); - gl.SetFillColour(*wxBLACK, 0.5f); + gl.SetLineColour(line_color, 0.0f); + gl.SetFillColour(*wxBLACK, shaded_alpha); if (inverse) { gl.DrawRectangle(cur_1, cur_2); } diff --git a/src/visual_tool_drag.cpp b/src/visual_tool_drag.cpp index 63236dc7f..9d8aa6594 100644 --- a/src/visual_tool_drag.cpp +++ b/src/visual_tool_drag.cpp @@ -22,6 +22,7 @@ #include "ass_dialogue.h" #include "ass_file.h" +#include "compat.h" #include "include/aegisub/context.h" #include "libresrc/libresrc.h" #include "options.h" @@ -182,6 +183,9 @@ void VisualToolDrag::OnSelectedSetChanged() { void VisualToolDrag::Draw() { DrawAllFeatures(); + // Load colors from options + wxColour line_color = to_wx(line_color_primary_opt->GetColor()); + // Draw connecting lines for (auto& feature : features) { if (feature.type == DRAG_START) continue; @@ -203,7 +207,7 @@ void VisualToolDrag::Draw() { Vector2D end = p2->pos - direction * (10 + arrow_len); if (has_arrow) { - gl.SetLineColour(colour[3], 0.8f, 2); + gl.SetLineColour(line_color, 0.8f, 2); // Arrow line gl.DrawLine(start, end); @@ -214,7 +218,7 @@ void VisualToolDrag::Draw() { } // Draw dashed line else { - gl.SetLineColour(colour[3], 0.5f, 2); + gl.SetLineColour(line_color, 0.5f, 2); gl.DrawDashedLine(start, end, 6); } } diff --git a/src/visual_tool_rotatexy.cpp b/src/visual_tool_rotatexy.cpp index 0a6949c22..acb389acd 100644 --- a/src/visual_tool_rotatexy.cpp +++ b/src/visual_tool_rotatexy.cpp @@ -20,7 +20,9 @@ #include "visual_tool_rotatexy.h" +#include "compat.h" #include "include/aegisub/context.h" +#include "options.h" #include "selection_controller.h" #include @@ -41,17 +43,21 @@ void VisualToolRotateXY::Draw() { DrawAllFeatures(); + // Load colors from options + wxColour line_color_primary = to_wx(line_color_primary_opt->GetColor()); + wxColour line_color_secondary = to_wx(line_color_secondary_opt->GetColor()); + // Transform grid gl.SetOrigin(org->pos); gl.SetRotation(angle_x, angle_y, angle_z); gl.SetShear(fax, fay); // Draw grid - gl.SetLineColour(colour[0], 0.5f, 2); + gl.SetLineColour(line_color_secondary, 0.5f, 2); gl.SetModeLine(); - float r = colour[0].Red() / 255.f; - float g = colour[0].Green() / 255.f; - float b = colour[0].Blue() / 255.f; + float r = line_color_secondary.Red() / 255.f; + float g = line_color_secondary.Green() / 255.f; + float b = line_color_secondary.Blue() / 255.f; // Number of lines on each side of each axis static const int radius = 15; @@ -103,7 +109,7 @@ void VisualToolRotateXY::Draw() { gl.DrawLines(2, points, 4, colors); // Draw vectors - gl.SetLineColour(colour[3], 1.f, 2); + gl.SetLineColour(line_color_primary, 1.f, 2); float vectors[] = { 0.f, 0.f, 0.f, 50.f, 0.f, 0.f, diff --git a/src/visual_tool_rotatez.cpp b/src/visual_tool_rotatez.cpp index 9e7e1f8e6..0d8bf2a9c 100644 --- a/src/visual_tool_rotatez.cpp +++ b/src/visual_tool_rotatez.cpp @@ -20,7 +20,9 @@ #include "visual_tool_rotatez.h" +#include "compat.h" #include "include/aegisub/context.h" +#include "options.h" #include "selection_controller.h" #include @@ -44,6 +46,11 @@ void VisualToolRotateZ::Draw() { DrawAllFeatures(); + // Load colors from options + wxColour line_color_primary = to_wx(line_color_primary_opt->GetColor()); + wxColour line_color_secondary = to_wx(line_color_secondary_opt->GetColor()); + wxColour highlight_color = to_wx(highlight_color_primary_opt->GetColor()); + float radius = (pos - org->pos).Len(); float oRadius = radius; if (radius < 50) @@ -55,8 +62,8 @@ void VisualToolRotateZ::Draw() { gl.SetScale(scale); // Draw the circle - gl.SetLineColour(colour[0]); - gl.SetFillColour(colour[1], 0.3f); + gl.SetLineColour(line_color_secondary); + gl.SetFillColour(highlight_color, 0.3f); gl.DrawRing(Vector2D(0, 0), radius + 4, radius - 4); // Draw markers around circle @@ -70,7 +77,7 @@ void VisualToolRotateZ::Draw() { // Draw the baseline through the origin showing current rotation Vector2D angle_vec(Vector2D::FromAngle(angle * deg2rad)); - gl.SetLineColour(colour[3], 1, 2); + gl.SetLineColour(line_color_primary, 1, 2); gl.DrawLine(angle_vec * -radius, angle_vec * radius); if (org->pos != pos) { @@ -84,8 +91,8 @@ void VisualToolRotateZ::Draw() { } // Draw the fake features on the ring - gl.SetLineColour(colour[0], 1.f, 1); - gl.SetFillColour(colour[1], 0.3f); + gl.SetLineColour(line_color_secondary, 1.f, 1); + gl.SetFillColour(highlight_color, 0.3f); gl.DrawCircle(angle_vec * radius, 4); gl.DrawCircle(angle_vec * -radius, 4); @@ -94,7 +101,7 @@ void VisualToolRotateZ::Draw() { // Draw line to mouse if it isn't over the origin feature if (mouse_pos && (mouse_pos - org->pos).SquareLen() > 100) { - gl.SetLineColour(colour[0]); + gl.SetLineColour(line_color_secondary); gl.DrawLine(org->pos, mouse_pos); } } diff --git a/src/visual_tool_scale.cpp b/src/visual_tool_scale.cpp index 045352048..10468d3a9 100644 --- a/src/visual_tool_scale.cpp +++ b/src/visual_tool_scale.cpp @@ -20,6 +20,9 @@ #include "visual_tool_scale.h" +#include "compat.h" +#include "options.h" + #include VisualToolScale::VisualToolScale(VideoDisplay *parent, agi::Context *context) @@ -35,6 +38,11 @@ void VisualToolScale::Draw() { // The width of the y scale guide/height of the x scale guide static const int guide_size = 10; + // Load colors from options + wxColour line_color_primary = to_wx(line_color_primary_opt->GetColor()); + wxColour line_color_secondary = to_wx(line_color_secondary_opt->GetColor()); + wxColour highlight_color = to_wx(highlight_color_primary_opt->GetColor()); + // Ensure that the scaling UI is comfortably visible on screen Vector2D base_point = pos .Max(Vector2D(base_len / 2 + guide_size, base_len / 2 + guide_size)) @@ -54,13 +62,13 @@ void VisualToolScale::Draw() { Vector2D y_p2(scale_half_length.X(), minor_dim_offset); // Current scale amount lines - gl.SetLineColour(colour[3], 1.f, 2); + gl.SetLineColour(line_color_primary, 1.f, 2); gl.DrawLine(x_p1, x_p2); gl.DrawLine(y_p1, y_p2); // Fake features at the end of the lines - gl.SetLineColour(colour[0], 1.f, 1); - gl.SetFillColour(colour[1], 0.3f); + gl.SetLineColour(line_color_secondary, 1.f, 1); + gl.SetFillColour(highlight_color, 0.3f); gl.DrawCircle(x_p1, 4); gl.DrawCircle(x_p2, 4); gl.DrawCircle(y_p1, 4); @@ -68,12 +76,12 @@ void VisualToolScale::Draw() { // Draw the guides int half_len = base_len / 2; - gl.SetLineColour(colour[0], 1.f, 1); + gl.SetLineColour(line_color_secondary, 1.f, 1); gl.DrawRectangle(Vector2D(half_len, -half_len), Vector2D(half_len + guide_size, half_len)); gl.DrawRectangle(Vector2D(-half_len, half_len), Vector2D(half_len, half_len + guide_size)); // Draw the feet - gl.SetLineColour(colour[0], 1.f, 2); + gl.SetLineColour(line_color_secondary, 1.f, 2); gl.DrawLine(Vector2D(half_len + guide_size, -half_len), Vector2D(half_len + guide_size + guide_size / 2, -half_len)); gl.DrawLine(Vector2D(half_len + guide_size, half_len), Vector2D(half_len + guide_size + guide_size / 2, half_len)); gl.DrawLine(Vector2D(-half_len, half_len + guide_size), Vector2D(-half_len, half_len + guide_size + guide_size / 2)); diff --git a/src/visual_tool_vector_clip.cpp b/src/visual_tool_vector_clip.cpp index cc04eddca..bbe00d8e9 100644 --- a/src/visual_tool_vector_clip.cpp +++ b/src/visual_tool_vector_clip.cpp @@ -17,6 +17,7 @@ #include "visual_tool_vector_clip.h" #include "ass_dialogue.h" +#include "compat.h" #include "include/aegisub/context.h" #include "libresrc/libresrc.h" #include "options.h" @@ -92,8 +93,14 @@ void VisualToolVectorClip::Draw() { assert(!start.empty()); assert(!count.empty()); - gl.SetLineColour(colour[3], .5f, 2); - gl.SetFillColour(wxColour(0, 0, 0), 0.5f); + // Load colors from options + wxColour line_color = to_wx(line_color_primary_opt->GetColor()); + wxColour highlight_color_primary = to_wx(highlight_color_primary_opt->GetColor()); + wxColour highlight_color_secondary = to_wx(highlight_color_secondary_opt->GetColor()); + float shaded_alpha = static_cast(shaded_area_alpha_opt->GetDouble()); + + gl.SetLineColour(line_color, .5f, 2); + gl.SetFillColour(*wxBLACK, shaded_alpha); // draw the shade over clipped out areas and line showing the clip gl.DrawMultiPolygon(points, start, count, video_pos, video_res, !inverse); @@ -117,13 +124,13 @@ void VisualToolVectorClip::Draw() { if ((mode == 3 || mode == 4) && !active_feature && points.size() > 2) { auto highlighted_points = spline.GetPointList(highlighted_curve); if (!highlighted_points.empty()) { - gl.SetLineColour(colour[2], 1.f, 2); + gl.SetLineColour(highlight_color_secondary, 1.f, 2); gl.DrawLineStrip(2, highlighted_points); } } // Draw lines connecting the bicubic features - gl.SetLineColour(colour[3], 0.9f, 1); + gl.SetLineColour(line_color, 0.9f, 1); for (auto const& curve : spline) { if (curve.type == SplineCurve::BICUBIC) { gl.DrawDashedLine(curve.p1, curve.p2, 6); @@ -133,19 +140,19 @@ void VisualToolVectorClip::Draw() { // Draw features for (auto& feature : features) { - int color = 3; + wxColour feature_color = line_color; if (&feature == active_feature) - color = 1; + feature_color = highlight_color_primary; else if (sel_features.count(&feature)) - color = 2; - gl.SetFillColour(colour[color], .6f); + feature_color = highlight_color_secondary; + gl.SetFillColour(feature_color, .6f); if (feature.type == DRAG_SMALL_SQUARE) { - gl.SetLineColour(colour[3], .5f, 1); + gl.SetLineColour(line_color, .5f, 1); gl.DrawRectangle(feature.pos - 3, feature.pos + 3); } else { - gl.SetLineColour(colour[color], .5f, 1); + gl.SetLineColour(feature_color, .5f, 1); gl.DrawCircle(feature.pos, 2.f); } }