Skip to content

Commit 2ab953c

Browse files
committed
Merge pull request #109 from calband/improving_config
Improving config
2 parents e0c74f6 + 1aee11b commit 2ab953c

35 files changed

+1676
-1132
lines changed

build-macos/CalChart.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@
966966
E803363417EE27C500A58457 /* math_utils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = math_utils.cpp; sourceTree = "<group>"; };
967967
E803363517EE27C500A58457 /* math_utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = math_utils.h; sourceTree = "<group>"; };
968968
E803364117EE2E5400A58457 /* parse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = parse.h; sourceTree = "<group>"; };
969+
E803A0C7193BA54900C5F2D5 /* draw_utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = draw_utils.h; sourceTree = "<group>"; };
969970
E807BD5C17ED71F50052A53F /* calchart_cmd */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = calchart_cmd; sourceTree = BUILT_PRODUCTS_DIR; };
970971
E807BD5E17ED71F60052A53F /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
971972
E807BD6017ED71F60052A53F /* calchart_cmd.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = calchart_cmd.1; sourceTree = "<group>"; };
@@ -1192,6 +1193,7 @@
11921193
C7AFA97A117A6DBA00CC53E2 /* contscan.l */,
11931194
C7AFA97B117A6DBA00CC53E2 /* draw.cpp */,
11941195
E884F3A217A631BB00831301 /* draw.h */,
1196+
E803A0C7193BA54900C5F2D5 /* draw_utils.h */,
11951197
C7E047CA155F7B8900D8C71B /* field_canvas.cpp */,
11961198
C7E047CB155F7B8A00D8C71B /* field_canvas.h */,
11971199
C7E047CD155F892400D8C71B /* field_frame.cpp */,

src/animation_canvas.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,22 @@ void
6565
AnimationCanvas::OnPaint(wxPaintEvent& event)
6666
{
6767
wxBufferedPaintDC dc(this);
68+
auto& config = CalChartConfiguration::GetGlobalConfig();
6869

69-
dc.SetBackground(GetCalChartBrush(COLOR_FIELD));
70+
dc.SetBackground(config.Get_CalChartBrushAndPen(COLOR_FIELD).first);
7071
dc.Clear();
7172
dc.SetUserScale(mUserScale, mUserScale);
7273
dc.SetDeviceOrigin(mUserOriginX, 0);
7374
if (mMouseDown)
7475
{
7576
dc.SetBrush(*wxTRANSPARENT_BRUSH);
76-
dc.SetPen(GetCalChartPen(COLOR_SHAPES));
77+
dc.SetPen(config.Get_CalChartBrushAndPen(COLOR_SHAPES).second);
7778
dc.DrawRectangle(mMouseXStart, mMouseYStart,
7879
mMouseXEnd - mMouseXStart, mMouseYEnd - mMouseYStart);
7980
}
8081
if (mAnimationView)
8182
{
82-
mAnimationView->OnDraw(&dc);
83+
mAnimationView->OnDraw(&dc, config);
8384
}
8485
}
8586

src/animation_frame.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,14 @@ EVT_SIZE(AnimationFrame::OnSize)
7272
END_EVENT_TABLE()
7373

7474

75-
AnimationFrame::AnimationFrame(std::function<void ()> onClose, wxDocument *doc, wxView *view, wxFrame *parent, const wxSize& size) :
75+
AnimationFrame::AnimationFrame(std::function<void ()> onClose, wxDocument *doc, CalChartConfiguration& config_, wxView *view, wxFrame *parent, const wxSize& size) :
7676
#if defined(BUILD_FOR_VIEWER) && (BUILD_FOR_VIEWER != 0)
7777
wxDocChildFrame(doc, view, parent, wxID_ANY, wxT("CalChart Viewer"), wxDefaultPosition, size),
7878
#else
7979
wxFrame(parent, wxID_ANY, wxT("CalChart Viewer"), wxDefaultPosition, size),
8080
#endif
8181
mAnimationView(),
82+
config(config_),
8283
mCanvas(NULL),
8384
mOmniViewCanvas(NULL),
8485
mTimer(new wxTimer(this, CALCHART__anim_next_beat_timer)),
@@ -131,19 +132,19 @@ mWhenClosed(onClose)
131132
mSplitter->SetWindowStyleFlag(mSplitter->GetWindowStyleFlag() | wxSP_LIVE_UPDATE);
132133
mSplitter->SetMinSize(wxSize(300, 400));
133134

134-
mOmniViewCanvas = new CCOmniView_Canvas(&mAnimationView, mSplitter);
135+
mOmniViewCanvas = new CCOmniView_Canvas(&mAnimationView, mSplitter, config);
135136
mCanvas = new AnimationCanvas(&mAnimationView, mSplitter);
136137

137138
mSplitA = mOmniViewCanvas;
138139
mSplitB = mCanvas;
139-
if (!GetConfiguration_AnimationFrameOmniAnimation())
140+
if (!config.Get_AnimationFrameOmniAnimation())
140141
{
141142
std::swap(mSplitA, mSplitB);
142143
}
143144
mSplitter->Initialize(mSplitA);
144-
if (GetConfiguration_AnimationFrameSplitScreen())
145+
if (config.Get_AnimationFrameSplitScreen())
145146
{
146-
if (GetConfiguration_AnimationFrameSplitVertical())
147+
if (config.Get_AnimationFrameSplitVertical())
147148
{
148149
mSplitter->SplitVertically(mSplitA, mSplitB);
149150
}
@@ -152,7 +153,7 @@ mWhenClosed(onClose)
152153
mSplitter->SplitHorizontally(mSplitA, mSplitB);
153154
}
154155
}
155-
mSplitter->SetSashPosition(GetConfiguration_AnimationFrameSashPosition());
156+
mSplitter->SetSashPosition(config.Get_AnimationFrameSashPosition());
156157

157158

158159
AddCoolToolBar(GetAnimationToolBar(), *this);
@@ -251,8 +252,8 @@ AnimationFrame::OnSize(wxSizeEvent& event)
251252
// HACK: Prevent width and height from growing out of control
252253
int w = event.GetSize().GetWidth();
253254
int h = event.GetSize().GetHeight();
254-
SetConfiguration_AnimationFrameWidth((w > 1200) ? 1200 : w);
255-
SetConfiguration_AnimationFrameHeight((h > 700) ? 700 : h);
255+
config.Set_AnimationFrameWidth((w > 1200) ? 1200 : w);
256+
config.Set_AnimationFrameHeight((h > 700) ? 700 : h);
256257
super::OnSize(event);
257258
}
258259

@@ -278,7 +279,7 @@ AnimationFrame::OnCmdClose(wxCloseEvent& event)
278279
{
279280
if (mSplitter)
280281
{
281-
SetConfiguration_AnimationFrameSashPosition(mSplitter->GetSashPosition());
282+
config.Set_AnimationFrameSashPosition(mSplitter->GetSashPosition());
282283
}
283284
// we should inform the parent frame we are closing
284285
if (mWhenClosed)
@@ -620,8 +621,8 @@ AnimationFrame::OnCmd_SplitViewHorizontal(wxCommandEvent& event)
620621
mSplitA->Show(true);
621622
mSplitB->Show(true);
622623
mSplitter->SplitHorizontally(mSplitA, mSplitB);
623-
SetConfiguration_AnimationFrameSplitScreen(true);
624-
SetConfiguration_AnimationFrameSplitVertical(false);
624+
config.Set_AnimationFrameSplitScreen(true);
625+
config.Set_AnimationFrameSplitVertical(false);
625626
}
626627

627628
void
@@ -634,8 +635,8 @@ AnimationFrame::OnCmd_SplitViewVertical(wxCommandEvent& event)
634635
mSplitA->Show(true);
635636
mSplitB->Show(true);
636637
mSplitter->SplitVertically(mSplitA, mSplitB);
637-
SetConfiguration_AnimationFrameSplitScreen(true);
638-
SetConfiguration_AnimationFrameSplitVertical(true);
638+
config.Set_AnimationFrameSplitScreen(true);
639+
config.Set_AnimationFrameSplitVertical(true);
639640
}
640641

641642
void
@@ -645,7 +646,7 @@ AnimationFrame::OnCmd_SplitViewUnsplit(wxCommandEvent& event)
645646
{
646647
mSplitter->Unsplit();
647648
}
648-
SetConfiguration_AnimationFrameSplitScreen(false);
649+
config.Set_AnimationFrameSplitScreen(false);
649650
}
650651

651652
void
@@ -658,7 +659,7 @@ AnimationFrame::OnCmd_SwapAnimateAndOmni(wxCommandEvent& event)
658659
mSplitter->Unsplit();
659660
}
660661
std::swap(mSplitA, mSplitB);
661-
SetConfiguration_AnimationFrameOmniAnimation(!GetConfiguration_AnimationFrameOmniAnimation());
662+
config.Set_AnimationFrameOmniAnimation(!config.Get_AnimationFrameOmniAnimation());
662663
if (mode == wxSPLIT_HORIZONTAL)
663664
{
664665
mSplitter->SplitHorizontally(mSplitA, mSplitB);

src/animation_frame.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class AnimationCanvas;
3636
class CCOmniView_Canvas;
3737
class FancyTextWin;
3838
class wxSplitterWindow;
39+
class CalChartConfiguration;
3940

4041
#if defined(BUILD_FOR_VIEWER) && (BUILD_FOR_VIEWER != 0)
4142
typedef wxDocChildFrame AnimationFrameParent;
@@ -48,7 +49,7 @@ class AnimationFrame : public AnimationFrameParent
4849
public:
4950
typedef AnimationFrameParent super;
5051

51-
AnimationFrame(std::function<void ()> onClose, wxDocument *doc, wxView *view, wxFrame *parent, const wxSize& size);
52+
AnimationFrame(std::function<void ()> onClose, wxDocument *doc, CalChartConfiguration& config, wxView *view, wxFrame *parent, const wxSize& size);
5253
~AnimationFrame();
5354

5455
void OnSize(wxSizeEvent& event);
@@ -107,7 +108,8 @@ class AnimationFrame : public AnimationFrameParent
107108
void TransitionToNextSheet();
108109

109110
AnimationView mAnimationView;
110-
// we really do need one of each. We can't do inheritance because they have different base classes
111+
CalChartConfiguration& config;
112+
// we really do need one of each. We can't do inheritance because they have different base classes
111113
AnimationCanvas *mCanvas;
112114
CCOmniView_Canvas *mOmniViewCanvas;
113115
wxSlider *mSheetSlider;

src/animation_view.cpp

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,15 @@ AnimationView::~AnimationView()
5454
void
5555
AnimationView::OnDraw(wxDC *dc)
5656
{
57-
GetShow()->GetMode().DrawMode(*dc, ShowMode::kAnimation);
57+
auto& config = CalChartConfiguration::GetGlobalConfig();
58+
OnDraw(dc, config);
59+
}
60+
61+
void
62+
AnimationView::OnDraw(wxDC *dc, const CalChartConfiguration& config)
63+
{
64+
dc->SetPen(config.Get_CalChartBrushAndPen(COLOR_FIELD_DETAIL).second);
65+
GetShow()->GetMode().DrawMode(*dc, config, ShowMode::kAnimation);
5866
const bool checkForCollision = mCollisionWarningType != COLLISION_RESPONSE_NONE;
5967
if (mAnimation)
6068
{
@@ -65,13 +73,14 @@ AnimationView::OnDraw(wxDC *dc)
6573
if (checkForCollision && info.mCollision)
6674
{
6775
if (info.mCollision == COLLISION_WARNING) {
68-
dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_COLLISION_WARNING));
69-
dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_COLLISION_WARNING));
76+
auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_COLLISION_WARNING);
77+
dc->SetBrush(brushAndPen.first);
78+
dc->SetPen(brushAndPen.second);
7079
} else if (info.mCollision == COLLISION_INTERSECT) {
71-
dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_COLLISION));
72-
dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_COLLISION));
80+
auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_COLLISION);
81+
dc->SetBrush(brushAndPen.first);
82+
dc->SetPen(brushAndPen.second);
7383
}
74-
7584
}
7685
else if (GetShow()->IsSelected(i))
7786
{
@@ -80,18 +89,27 @@ AnimationView::OnDraw(wxDC *dc)
8089
case ANIMDIR_SW:
8190
case ANIMDIR_W:
8291
case ANIMDIR_NW:
83-
dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_HILIT_BACK));
84-
dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_HILIT_BACK));
92+
{
93+
auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_HILIT_BACK);
94+
dc->SetBrush(brushAndPen.first);
95+
dc->SetPen(brushAndPen.second);
96+
}
8597
break;
8698
case ANIMDIR_SE:
8799
case ANIMDIR_E:
88100
case ANIMDIR_NE:
89-
dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_HILIT_FRONT));
90-
dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_HILIT_FRONT));
101+
{
102+
auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_HILIT_FRONT);
103+
dc->SetBrush(brushAndPen.first);
104+
dc->SetPen(brushAndPen.second);
105+
}
91106
break;
92107
default:
93-
dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_HILIT_SIDE));
94-
dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_HILIT_SIDE));
108+
{
109+
auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_HILIT_SIDE);
110+
dc->SetBrush(brushAndPen.first);
111+
dc->SetPen(brushAndPen.second);
112+
}
95113
}
96114
}
97115
else
@@ -101,18 +119,27 @@ AnimationView::OnDraw(wxDC *dc)
101119
case ANIMDIR_SW:
102120
case ANIMDIR_W:
103121
case ANIMDIR_NW:
104-
dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_BACK));
105-
dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_BACK));
122+
{
123+
auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_BACK);
124+
dc->SetBrush(brushAndPen.first);
125+
dc->SetPen(brushAndPen.second);
126+
}
106127
break;
107128
case ANIMDIR_SE:
108129
case ANIMDIR_E:
109130
case ANIMDIR_NE:
110-
dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_FRONT));
111-
dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_FRONT));
131+
{
132+
auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_FRONT);
133+
dc->SetBrush(brushAndPen.first);
134+
dc->SetPen(brushAndPen.second);
135+
}
112136
break;
113137
default:
114-
dc->SetPen(GetCalChartPen(COLOR_POINT_ANIM_SIDE));
115-
dc->SetBrush(GetCalChartBrush(COLOR_POINT_ANIM_SIDE));
138+
{
139+
auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_SIDE);
140+
dc->SetBrush(brushAndPen.first);
141+
dc->SetPen(brushAndPen.second);
142+
}
116143
}
117144
}
118145
CC_coord position = info.mPosition;

src/animation_view.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
class AnimationFrame;
3333
class FieldView;
34+
class CalChartConfiguration;
3435

3536
class AnimationView : public wxView
3637
{
@@ -41,6 +42,7 @@ class AnimationView : public wxView
4142
// virtual bool OnCreate(wxDocument *doc, long flags);
4243
// virtual bool OnClose(bool deleteWindow = true);
4344
virtual void OnDraw(wxDC *dc);
45+
void OnDraw(wxDC *dc, const CalChartConfiguration& config);
4446
virtual void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL);
4547

4648
void RefreshFrame();

src/calchartapp.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ void CalChartApp::InitAppAsServer() {
9999
gPrintDialogData = new wxPrintDialogData();
100100
mHelpController = std::unique_ptr<wxHtmlHelpController>(new wxHtmlHelpController());
101101

102-
// setup the configuration.
103-
ReadConfig();
104-
105102
//// Create the main frame window
106103
wxFrame *frame = new TopFrame(mDocManager, (wxFrame *)NULL, _T("CalChart"));
107104

@@ -158,6 +155,8 @@ void CalChartApp::ProcessArguments() {
158155

159156

160157
void CalChartApp::ExitAppAsServer() {
158+
// Flush out the other commands
159+
CalChartConfiguration::GetGlobalConfig().FlushWriteQueue();
161160
// Get the file history
162161
wxConfigBase *config = wxConfigBase::Get();
163162
config->SetPath(wxT("/FileHistory"));
@@ -172,5 +171,12 @@ void CalChartApp::ExitAppAsServer() {
172171
mHelpController.reset();
173172
}
174173

174+
std::unique_ptr<ShowMode>
175+
CalChartApp::GetMode(const wxString& which)
176+
{
177+
return ShowMode::GetMode(which);
178+
}
179+
175180
void CalChartApp::ExitAppAsClient() {
176-
}
181+
}
182+

src/calchartapp.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class CalChartApp : public wxApp
4545
virtual void MacOpenFiles(const wxArrayString &fileNames);
4646
int OnExit();
4747

48-
ShowModeList& GetModeList() { return mModeList; }
48+
std::unique_ptr<ShowMode> GetMode(const wxString& which);
4949

5050
// the global help system:
5151
wxHtmlHelpController& GetGlobalHelpController();
@@ -60,8 +60,6 @@ class CalChartApp : public wxApp
6060
void ExitAppAsServer();
6161
void ExitAppAsClient();
6262

63-
ShowModeList mModeList;
64-
6563
wxDocManager* mDocManager;
6664
std::unique_ptr<wxHtmlHelpController> mHelpController;
6765

src/calchartdoc.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ IMPLEMENT_DYNAMIC_CLASS(CalChartDoc, wxDocument);
5252
// Create a new show
5353
CalChartDoc::CalChartDoc() :
5454
mShow(CC_show::Create_CC_show()),
55-
mMode(wxGetApp().GetModeList().front().get()),
55+
mMode(wxGetApp().GetMode(kShowModeStrings[0])),
5656
mTimer(*this)
5757
{
58-
mTimer.Start(GetConfiguration_AutosaveInterval()*1000);
58+
mTimer.Start(CalChartConfiguration::GetGlobalConfig().Get_AutosaveInterval()*1000);
5959
}
6060

6161
// When a file is opened, we first check to see if there is a temporary
@@ -511,13 +511,13 @@ CalChartDoc::GetMode() const
511511
}
512512

513513
void
514-
CalChartDoc::SetMode(const ShowMode* m)
514+
CalChartDoc::SetMode(std::unique_ptr<const ShowMode> m)
515515
{
516516
if (!m)
517517
{
518518
throw std::runtime_error("Cannot use NULL ShowMode");
519519
}
520-
mMode = m;
520+
std::swap(mMode, m);
521521
UpdateAllViews();
522522
}
523523

src/calchartdoc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class CalChartDoc : public wxDocument
159159
const SelectionList& GetSelectionList() const;
160160

161161
const ShowMode& GetMode() const;
162-
void SetMode(const ShowMode* m);
162+
void SetMode(std::unique_ptr<const ShowMode> m);
163163

164164
bool AlreadyHasPrintContinuity() const;
165165

@@ -193,7 +193,7 @@ class CalChartDoc : public wxDocument
193193
void RestoreSnapShot(const CC_show& snapshot);
194194

195195
std::unique_ptr<CC_show> mShow;
196-
const ShowMode* mMode;
196+
std::unique_ptr<const ShowMode> mMode;
197197
AutoSaveTimer mTimer;
198198
};
199199

0 commit comments

Comments
 (0)