1 /*
2  *  tracker/SectionSwitcher.cpp
3  *
4  *  Copyright 2009 Peter Barth
5  *
6  *  This file is part of Milkytracker.
7  *
8  *  Milkytracker is free software: you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation, either version 3 of the License, or
11  *  (at your option) any later version.
12  *
13  *  Milkytracker is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with Milkytracker.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 /*
24  *  SectionSwitcher.cpp
25  *  MilkyTracker
26  *
27  *  Created by Peter Barth on 09.04.08.
28  *
29  */
30 
31 #include "SectionSwitcher.h"
32 #include "Tracker.h"
33 #include "Screen.h"
34 #include "Container.h"
35 #include "SectionInstruments.h"
36 #include "SectionSamples.h"
37 #include "ScopesControl.h"
38 #include "PatternEditorControl.h"
39 
40 #include "ControlIDs.h"
41 
SectionSwitcher(Tracker & tracker)42 SectionSwitcher::SectionSwitcher(Tracker& tracker) :
43 	tracker(tracker),
44 	bottomSection(ActiveBottomSectionNone),
45 #ifdef __LOWRES__
46 	lowerSectionPage(ActiveLowerSectionPageMain),
47 #endif
48 	currentUpperSection(NULL)
49 {
50 }
51 
52 // General bottom sections show/hide
showBottomSection(ActiveBottomSections section,bool paint)53 void SectionSwitcher::showBottomSection(ActiveBottomSections section, bool paint/* = true*/)
54 {
55 	switch (bottomSection)
56 	{
57 		case ActiveBottomSectionInstrumentEditor:
58 			tracker.sectionInstruments->show(false);
59 			break;
60 		case ActiveBottomSectionSampleEditor:
61 			tracker.sectionSamples->show(false);
62 			break;
63 		case ActiveBottomSectionNone:
64 			break;
65 	}
66 
67 	if (bottomSection != section)
68 		bottomSection = section;
69 	else
70 		bottomSection = ActiveBottomSectionNone;
71 
72 	switch (bottomSection)
73 	{
74 		case ActiveBottomSectionInstrumentEditor:
75 			tracker.sectionInstruments->show(true);
76 			break;
77 		case ActiveBottomSectionSampleEditor:
78 			tracker.sectionSamples->show(true);
79 			break;
80 		case ActiveBottomSectionNone:
81 			tracker.rearrangePatternEditorControl();
82 			break;
83 	}
84 
85 	if (paint)
86 		tracker.screen->paint();
87 }
88 
showUpperSection(SectionAbstract * section,bool hideSIP)89 void SectionSwitcher::showUpperSection(SectionAbstract* section, bool hideSIP/* = true*/)
90 {
91 	tracker.screen->pauseUpdate(true);
92 	if (currentUpperSection)
93 	{
94 		currentUpperSection->show(false);
95 	}
96 	if (section)
97 	{
98 		if (hideSIP)
99 			tracker.hideInputControl();
100 
101 		section->show(true);
102 	}
103 	tracker.screen->pauseUpdate(false);
104 	tracker.screen->update();
105 	currentUpperSection = section;
106 }
107 
108 #ifdef __LOWRES__
showSubMenu(ActiveLowerSectionPages section,bool repaint)109 void SectionSwitcher::showSubMenu(ActiveLowerSectionPages section, bool repaint/* = true*/)
110 {
111 	// Hide everything first
112 	tracker.showSongSettings(false);
113 	tracker.showMainOptions(false);
114 	tracker.screen->getControlByID(CONTAINER_INSTRUMENTLIST)->show(false);
115 	tracker.screen->getControlByID(CONTAINER_LOWRES_TINYMENU)->show(false);
116 	tracker.screen->getControlByID(CONTAINER_LOWRES_JAMMENU)->show(false);
117 
118 	tracker.scopesControl->show(false);
119 	tracker.screen->getControlByID(CONTAINER_SCOPECONTROL)->show(false);
120 
121 	// Last active page was the "Jam"-section so the pattern editor has probably been resized
122 	// Check if it was resized and if so, restore original size
123 	if (lastLowerSectionPage == ActiveLowerSectionPageJam &&
124 		section != ActiveLowerSectionPageJam &&
125 		patternEditorSize != tracker.getPatternEditorControl()->getSize())
126 	{
127 		tracker.getPatternEditorControl()->setSize(patternEditorSize);
128 	}
129 
130 	switch (section)
131 	{
132 		case ActiveLowerSectionPageMain:
133 			tracker.showMainOptions(true);
134 			tracker.hideInputControl(false);
135 			break;
136 		case ActiveLowerSectionPageSong:
137 			tracker.showSongSettings(true);
138 			tracker.hideInputControl(false);
139 			break;
140 		case ActiveLowerSectionPageInstruments:
141 			tracker.screen->getControlByID(CONTAINER_INSTRUMENTLIST)->show(true);
142 			tracker.screen->getControlByID(CONTAINER_LOWRES_TINYMENU)->show(true);
143 			tracker.hideInputControl(false);
144 			break;
145 		case ActiveLowerSectionPageScopes:
146 			tracker.scopesControl->show(true);
147 			tracker.screen->getControlByID(CONTAINER_SCOPECONTROL)->show(true);
148 			tracker.updateScopesControlButtons();
149 			tracker.hideInputControl(false);
150 			break;
151 		case ActiveLowerSectionPageJam:
152 		{
153 			PPControl* control = tracker.screen->getControlByID(CONTAINER_LOWRES_JAMMENU);
154 			ASSERT(control);
155 			patternEditorSize = tracker.getPatternEditorControl()->getSize();
156 			PPSize size(tracker.screen->getWidth(), control->getLocation().y);
157 			if (tracker.getPatternEditorControl()->getSize() != size)
158 				tracker.getPatternEditorControl()->setSize(size);
159 			tracker.hideInputControl();
160 			tracker.screen->getControlByID(CONTAINER_LOWRES_JAMMENU)->show(true);
161 			break;
162 		}
163 	}
164 
165 	if (repaint)
166 		tracker.screen->paint();
167 }
168 
169 
switchToSubMenu(ActiveLowerSectionPages lsPageNew)170 void SectionSwitcher::switchToSubMenu(ActiveLowerSectionPages lsPageNew)
171 {
172 	// same page, nothing to do
173 	if (lsPageNew == lowerSectionPage)
174 		return;
175 
176 	// remember what was currently active
177 	lastLowerSectionPage = lowerSectionPage;
178 	// apply new page
179 	lowerSectionPage = lsPageNew;
180 
181 	updateSubMenusButtons(false);
182 	// make it visible
183 	showSubMenu(lowerSectionPage);
184 }
185 
hideBottomSection()186 void SectionSwitcher::hideBottomSection()
187 {
188 	if (bottomSection != ActiveBottomSectionNone)
189 		showBottomSection(ActiveBottomSectionNone, false);
190 }
191 
updateSubMenusButtons(bool repaint)192 void SectionSwitcher::updateSubMenusButtons(bool repaint/* = true*/)
193 {
194 	PPContainer* container = static_cast<PPContainer*>(tracker.screen->getControlByID(CONTAINER_LOWRES_MENUSWITCH));
195 
196 	for (pp_int32 i = 0; i < tracker.NUMSUBMENUS(); i++)
197 		static_cast<PPButton*>(container->getControlByID(BUTTON_0+i))->setPressed(false);
198 
199 	static_cast<PPButton*>(container->getControlByID(BUTTON_0+lowerSectionPage))->setPressed(true);
200 
201 	if (repaint)
202 		tracker.screen->paintControl(container);
203 }
204 
205 #endif
206