summaryrefslogtreecommitdiff
path: root/vendor/vstsdk2.4/vstgui.sf/drawtest/source/pdrawtesteditor.cpp
blob: 7e7f3af47cad09dc08405371d30f025aa4f63e91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
//-------------------------------------------------------------------------------------------------------
//  VSTGUI Test View plugin
//  Copyright (c) 2004 Arne Scheffler. All rights reserved.
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//-------------------------------------------------------------------------------------------------------

#include "pdrawtesteditor.h"
#include "pdrawtestview.h"
#include "cscrollview.h"
#include "ctabview.h"
#include "controlsgui.h"
#include "pprimitivesviews.h"

enum {
	kBackgroundBitmap	= 1,
	kTabButtonBitmap	= 100,
	kTestBitmap			= 1000,
};

class MyTabView : public CTabView
{
public:
	MyTabView (const CRect& size, CFrame* parent, CBitmap* tabBitmap, CBitmap* background = 0, long tabPosition = kPositionTop, DrawTestEditor* editor = 0)
	: CTabView (size, parent, tabBitmap, background, tabPosition)
	, editor (editor) {}

	virtual void mouse (CDrawContext *pContext, CPoint &where, long button = -1)
	{
		if (button == kRButton)
		{
			CView* view = getViewAt (where);
			if (!view || view->isTypeOf ("CTabButton"))
			{
				CRect r;
				localToFrame (where);
				r.offset (where.x, where.y);
				r.offset (-size.left, -size.top);
				COptionMenu* menu = new COptionMenu (r, NULL, 0);
				menu->addEntry ("Tabs Left");
				menu->addEntry ("Tabs Right");
				menu->addEntry ("Tabs Top");
				menu->addEntry ("Tabs Bottom");
				menu->addEntry ("-");
				menu->addEntry ("Align Tabs Centered");
				menu->addEntry ("Align Tabs Left/Top");
				menu->addEntry ("Align Tabs Right/Bottom");
				getFrame ()->addView (menu);
				menu->takeFocus ();
				long res = menu->getLastResult ();
				getFrame ()->removeView (menu);
				if (res != -1)
				{
					if (res < 4)
					{
						r = size;
						editor->setTabView (getFrame (), r, res);
					}
					else
					{
						alignTabs (kAlignCenter + res - 5);
					}
				}
				return;
			}
		}
		CTabView::mouse (pContext, where, button);
	}

	virtual bool selectTab (long index)
	{
		bool result = CTabView::selectTab (index);
		#if DEBUG
		getFrame ()->dumpHierarchy ();
		#endif
		return result;
	}

protected:
	DrawTestEditor* editor;
};

class MyColoredView : public CView
{
public:
	MyColoredView (const CRect& size) : CView (size) {}

	void draw (CDrawContext* context)
	{
		context->setFillColor (backgroundColor);
		context->setFrameColor (kBlackCColor);
		context->drawRect (size, kDrawFilledAndStroked);
		setDirty (false);
	}

	void setBackgroundColor (const CColor& c) { backgroundColor = c; }

protected:	
	CColor backgroundColor;
};

DrawTestEditor::DrawTestEditor (void* effect)
#if AU
: AEffGUIEditor (effect)
#else
: AEffGUIEditor ((AudioEffect*)effect)
#endif
, controlsView (0)
{
	backgroundBitmap = new CBitmap (kBackgroundBitmap);
	// setup size of editor
	rect.left   = 0;
	rect.top    = 0;
	#if AU
	rect.right  = (short)backgroundBitmap->getWidth ();
	rect.bottom = (short)backgroundBitmap->getHeight ();
	#else
	rect.right  = (VstInt16)backgroundBitmap->getWidth ();
	rect.bottom = (VstInt16)backgroundBitmap->getHeight ();
	#endif
}

DrawTestEditor::~DrawTestEditor ()
{
	backgroundBitmap->forget ();
}

void DrawTestEditor::valueChanged (CDrawContext *pContext, CControl *pControl)
{
}

void DrawTestEditor::setTabView (CFrame* frame, const CRect& r, long position)
{
	frame->removeAll ();
	CBitmap* tabButtonBitmap = new CBitmap (kTabButtonBitmap);
	CTabView* tabView = new MyTabView (r, frame, tabButtonBitmap, NULL, position, this);
	tabView->setTransparency (true);
	frame->addView (tabView);
	CRect tabSize = tabView->getTabViewSize (tabSize);
//	tabSize.inset (1, 1);
	// add tabs
	CView* testView;
	CBitmap* testBitmap = new CBitmap (kTestBitmap);
	CRect containerSize;
	containerSize.right = testBitmap->getWidth ();
	containerSize.bottom = testBitmap->getHeight ();
	// the first tab is a scroll view with a movie bitmap
	CScrollView* scrollview = new CScrollView (tabSize, containerSize, frame, CScrollView::kHorizontalScrollbar|CScrollView::kVerticalScrollbar);
	CPoint p (0,0);
	testView = new CMovieBitmap (containerSize, NULL, 0, 1, testBitmap->getHeight (), testBitmap, p);
	testBitmap->forget ();
	scrollview->addView (testView);
	tabView->addTab (scrollview, "Scroll View");

	// the second tab is a draw primitives view
//	testView = new CDrawTestView (tabSize);
//	tabView->addTab (testView, "Primitives");
	testView = new PLinesView (tabSize);
	tabView->addTab (testView, "Lines");

	testView = new PRectsView (tabSize);
	tabView->addTab (testView, "Rects");

	testView = new PMiscView (tabSize);
	tabView->addTab (testView, "Misc");

	// the third tab is the old controlsgui view embeded into a container view
	CRect controlsGUISize (0, 0, 420, 210);
	controlsGUISize.offset (5, 5);
	testView = controlsView = new ControlsGUI (controlsGUISize, frame);

	CViewContainer* controlContainer = new CViewContainer (tabSize, frame);
	controlContainer->setTransparency (true);
	controlContainer->addView (testView);
	
	tabView->addTab (controlContainer, "Controls");

	CColor redColor = {255, 0, 0, 150};
	CColor greenColor = {0, 255, 0, 150};
	CColor blueColor = {0, 0, 255, 150};

	CViewContainer* clipView = new CViewContainer (tabSize, frame);
	clipView->setTransparency (true);
	CRect clipViewSize (0, 0, tabSize.getWidth () / 4, tabSize.getHeight () / 2);
	MyColoredView* cv = new MyColoredView (clipViewSize);
	cv->setBackgroundColor (redColor);
	clipView->addView (cv);
	clipViewSize.offset (clipViewSize.getWidth (), 0);
	cv = new MyColoredView (clipViewSize);
	cv->setBackgroundColor (greenColor);
	clipView->addView (cv);
	clipViewSize.offset (clipViewSize.getWidth (), 0);
	cv = new MyColoredView (clipViewSize);
	cv->setBackgroundColor (blueColor);
	clipView->addView (cv);
	clipViewSize.offset (clipViewSize.getWidth (), 0);
	cv = new MyColoredView (clipViewSize);
	cv->setBackgroundColor (redColor);
	clipView->addView (cv);
	clipViewSize (0, tabSize.getHeight () / 2, tabSize.getWidth () / 4, tabSize.getHeight ());
	cv = new MyColoredView (clipViewSize);
	cv->setBackgroundColor (greenColor);
	clipView->addView (cv);
	clipViewSize.offset (clipViewSize.getWidth (), 0);
	cv = new MyColoredView (clipViewSize);
	cv->setBackgroundColor (blueColor);
	clipView->addView (cv);
	clipViewSize.offset (clipViewSize.getWidth (), 0);
	cv = new MyColoredView (clipViewSize);
	cv->setBackgroundColor (redColor);
	clipView->addView (cv);
	clipViewSize.offset (clipViewSize.getWidth (), 0);
	cv = new MyColoredView (clipViewSize);
	cv->setBackgroundColor (greenColor);
	clipView->addView (cv);
	
	tabView->addTab (clipView, "Clip Test");
	tabView->alignTabs (CTabView::kAlignCenter);

	tabButtonBitmap->forget ();
	frame->setDirty ();
}

bool DrawTestEditor::open (void *ptr)
{
	AEffGUIEditor::open (ptr);
	CRect size (rect.left , rect.top, rect.right, rect.bottom);
	CFrame* frame = new CFrame (size, ptr, this);
	frame->setBackground (backgroundBitmap);
	size.inset (8, 8);
	size.top++; // the background bitmap is not correct
	size.left++; // the background bitmap is not correct
	setTabView (frame, size, CTabView::kPositionBottom);
	// last but not least set the class variable frame to our newly created frame
	this->frame = frame;
	return true;
}

void DrawTestEditor::close ()
{
	// don't forget to remove the frame !!
	if (frame)
		delete frame;
	frame = 0;
	controlsView = 0;
}

void DrawTestEditor::idle ()
{
	AEffGUIEditor::idle ();

	if(controlsView)
		controlsView->onIdle ();
}