Use a struct for the cached grid brushes rather than an array+enum
This commit is contained in:
parent
d5274b72d4
commit
909be4494a
2 changed files with 31 additions and 42 deletions
|
@ -27,11 +27,6 @@
|
||||||
//
|
//
|
||||||
// Aegisub Project http://www.aegisub.org/
|
// Aegisub Project http://www.aegisub.org/
|
||||||
|
|
||||||
/// @file base_grid.cpp
|
|
||||||
/// @brief Base for subtitle grid in main UI
|
|
||||||
/// @ingroup main_ui
|
|
||||||
///
|
|
||||||
|
|
||||||
#include "base_grid.h"
|
#include "base_grid.h"
|
||||||
|
|
||||||
#include "include/aegisub/context.h"
|
#include "include/aegisub/context.h"
|
||||||
|
@ -70,16 +65,6 @@ enum {
|
||||||
MENU_SHOW_COL = 1250 // Needs 15 IDs after this
|
MENU_SHOW_COL = 1250 // Needs 15 IDs after this
|
||||||
};
|
};
|
||||||
|
|
||||||
enum RowColor {
|
|
||||||
COLOR_DEFAULT = 0,
|
|
||||||
COLOR_HEADER,
|
|
||||||
COLOR_SELECTION,
|
|
||||||
COLOR_COMMENT,
|
|
||||||
COLOR_VISIBLE,
|
|
||||||
COLOR_SELECTED_COMMENT,
|
|
||||||
COLOR_LEFT_COL
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct hash<boost::flyweight<T>> {
|
struct hash<boost::flyweight<T>> {
|
||||||
|
@ -208,14 +193,13 @@ void BaseGrid::UpdateStyle() {
|
||||||
lineHeight = dc.GetTextExtent("#TWFfgGhH").GetHeight() + 4;
|
lineHeight = dc.GetTextExtent("#TWFfgGhH").GetHeight() + 4;
|
||||||
|
|
||||||
// Set row brushes
|
// Set row brushes
|
||||||
assert(sizeof(rowColors) / sizeof(rowColors[0]) >= COLOR_LEFT_COL);
|
row_colors.Default.SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Background")->GetColor()));
|
||||||
rowColors[COLOR_DEFAULT].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Background")->GetColor()));
|
row_colors.Header.SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Header")->GetColor()));
|
||||||
rowColors[COLOR_HEADER].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Header")->GetColor()));
|
row_colors.Selection.SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Selection")->GetColor()));
|
||||||
rowColors[COLOR_SELECTION].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Selection")->GetColor()));
|
row_colors.Comment.SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Comment")->GetColor()));
|
||||||
rowColors[COLOR_COMMENT].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Comment")->GetColor()));
|
row_colors.Visible.SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Inframe")->GetColor()));
|
||||||
rowColors[COLOR_VISIBLE].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Inframe")->GetColor()));
|
row_colors.SelectedComment.SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Selected Comment")->GetColor()));
|
||||||
rowColors[COLOR_SELECTED_COMMENT].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Selected Comment")->GetColor()));
|
row_colors.LeftCol.SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Left Column")->GetColor()));
|
||||||
rowColors[COLOR_LEFT_COL].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Left Column")->GetColor()));
|
|
||||||
|
|
||||||
// Set column widths
|
// Set column widths
|
||||||
std::vector<bool> column_array(OPT_GET("Subtitle/Grid/Column")->GetListBool());
|
std::vector<bool> column_array(OPT_GET("Subtitle/Grid/Column")->GetListBool());
|
||||||
|
@ -312,12 +296,12 @@ void BaseGrid::DrawImage(wxDC &dc, bool paint_columns[]) {
|
||||||
|
|
||||||
dc.SetFont(font);
|
dc.SetFont(font);
|
||||||
|
|
||||||
dc.SetBackground(rowColors[COLOR_DEFAULT]);
|
dc.SetBackground(row_colors.Default);
|
||||||
dc.Clear();
|
dc.Clear();
|
||||||
|
|
||||||
// Draw labels
|
// Draw labels
|
||||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||||
dc.SetBrush(rowColors[COLOR_LEFT_COL]);
|
dc.SetBrush(row_colors.LeftCol);
|
||||||
dc.DrawRectangle(0,lineHeight,colWidth[0],h-lineHeight);
|
dc.DrawRectangle(0,lineHeight,colWidth[0],h-lineHeight);
|
||||||
|
|
||||||
// Visible lines
|
// Visible lines
|
||||||
|
@ -348,12 +332,12 @@ void BaseGrid::DrawImage(wxDC &dc, bool paint_columns[]) {
|
||||||
|
|
||||||
for (int i = 0; i < nDraw + 1; i++) {
|
for (int i = 0; i < nDraw + 1; i++) {
|
||||||
int curRow = i + yPos - 1;
|
int curRow = i + yPos - 1;
|
||||||
RowColor curColor = COLOR_DEFAULT;
|
wxBrush curColor = row_colors.Default;
|
||||||
AssDialogue *curDiag = nullptr;
|
AssDialogue *curDiag = nullptr;
|
||||||
|
|
||||||
// Header
|
// Header
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
curColor = COLOR_HEADER;
|
curColor = row_colors.Header;
|
||||||
dc.SetTextForeground(text_standard);
|
dc.SetTextForeground(text_standard);
|
||||||
}
|
}
|
||||||
// Lines
|
// Lines
|
||||||
|
@ -362,15 +346,13 @@ void BaseGrid::DrawImage(wxDC &dc, bool paint_columns[]) {
|
||||||
|
|
||||||
bool inSel = !!selection.count(curDiag);
|
bool inSel = !!selection.count(curDiag);
|
||||||
if (inSel && curDiag->Comment)
|
if (inSel && curDiag->Comment)
|
||||||
curColor = COLOR_SELECTED_COMMENT;
|
curColor = row_colors.SelectedComment;
|
||||||
else if (inSel)
|
else if (inSel)
|
||||||
curColor = COLOR_SELECTION;
|
curColor = row_colors.Selection;
|
||||||
else if (curDiag->Comment)
|
else if (curDiag->Comment)
|
||||||
curColor = COLOR_COMMENT;
|
curColor = row_colors.Comment;
|
||||||
else if (OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame")->GetBool() && IsDisplayed(curDiag))
|
else if (OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame")->GetBool() && IsDisplayed(curDiag))
|
||||||
curColor = COLOR_VISIBLE;
|
curColor = row_colors.Visible;
|
||||||
else
|
|
||||||
curColor = COLOR_DEFAULT;
|
|
||||||
|
|
||||||
if (active_line != curDiag && curDiag->CollidesWith(active_line))
|
if (active_line != curDiag && curDiag->CollidesWith(active_line))
|
||||||
dc.SetTextForeground(text_collision);
|
dc.SetTextForeground(text_collision);
|
||||||
|
@ -384,9 +366,11 @@ void BaseGrid::DrawImage(wxDC &dc, bool paint_columns[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw row background color
|
// Draw row background color
|
||||||
if (curColor) {
|
if (curColor != row_colors.Default) {
|
||||||
dc.SetBrush(rowColors[curColor]);
|
dc.SetBrush(curColor);
|
||||||
dc.DrawRectangle((curColor == 1) ? 0 : colWidth[0],i*lineHeight+1,w,lineHeight);
|
dc.DrawRectangle(
|
||||||
|
(i == 0) ? 0 : colWidth[0], i * lineHeight + 1,
|
||||||
|
w, lineHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw text
|
// Draw text
|
||||||
|
|
|
@ -27,11 +27,6 @@
|
||||||
//
|
//
|
||||||
// Aegisub Project http://www.aegisub.org/
|
// Aegisub Project http://www.aegisub.org/
|
||||||
|
|
||||||
/// @file base_grid.h
|
|
||||||
/// @see base_grid.cpp
|
|
||||||
/// @ingroup main_ui
|
|
||||||
///
|
|
||||||
|
|
||||||
#include <libaegisub/signal.h>
|
#include <libaegisub/signal.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
@ -54,7 +49,17 @@ class BaseGrid final : public wxWindow {
|
||||||
wxFont font; ///< Current grid font
|
wxFont font; ///< Current grid font
|
||||||
wxScrollBar *scrollBar; ///< The grid's scrollbar
|
wxScrollBar *scrollBar; ///< The grid's scrollbar
|
||||||
bool byFrame = false; ///< Should times be displayed as frame numbers
|
bool byFrame = false; ///< Should times be displayed as frame numbers
|
||||||
wxBrush rowColors[7]; ///< Cached brushes used for row backgrounds
|
|
||||||
|
/// Cached brushes used for row backgrounds
|
||||||
|
struct {
|
||||||
|
wxBrush Default;
|
||||||
|
wxBrush Header;
|
||||||
|
wxBrush Selection;
|
||||||
|
wxBrush Comment;
|
||||||
|
wxBrush Visible;
|
||||||
|
wxBrush SelectedComment;
|
||||||
|
wxBrush LeftCol;
|
||||||
|
} row_colors;
|
||||||
|
|
||||||
/// Row from which the selection shrinks/grows from when selecting via the
|
/// Row from which the selection shrinks/grows from when selecting via the
|
||||||
/// keyboard, shift-clicking or dragging
|
/// keyboard, shift-clicking or dragging
|
||||||
|
|
Loading…
Reference in a new issue