forked from gerritvoss/OpenSGToolbox
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path04Background.cpp
More file actions
618 lines (471 loc) · 24.6 KB
/
04Background.cpp
File metadata and controls
618 lines (471 loc) · 24.6 KB
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
/*************************************************
Welcome to the 04Background tutorial. In this
tutorial, you will see how to use the
different Backgrounds available and add them
to components. The following Backgrounds
are introduced:
ColorLayer
CompoundLayer
EmptyLayer
GradientLayer
MaterialLayer
TextureLayer
PatternLayer
Backgrounds are used simply to provide a background
for various components. Using combinations, very
complex possibilities exist. As with 03Border, the
easiest way to understand the base differences
is to simply run this tutorial.
The following all are shown and explained
within this tutorial (note the specific
requirements of each Border are not listed
here):
All Backgrounds:
Creating Background
Setting Color
Specifying style
Adding Backgrounds to components
These tutorials contain potentially relevant
information:
*************************************************/
// OpenSG Tutorial Example: Creating a Layer
//
// This tutorial explains how to implement the
// Layers offered by the OSG User Interface
// library and how to modify their features.
//
// Includes: explanations and examples of how to create
// and use the six different backgrounds included in the
// OSG User Interface library.
//
// Note that the Active Border and Layer are not set,
// meaning that if pressed, the Buttons revert to the default
// settings for Layer and Border.
// General OpenSG configuration, needed everywhere
#include "OSGConfig.h"
// Methods to create simple geometry: boxes, spheres, tori etc.
#include "OSGSimpleGeometry.h"
// A little helper to simplify scene management and interaction
#include "OSGSimpleSceneManager.h"
#include "OSGNode.h"
#include "OSGGroup.h"
#include "OSGViewport.h"
// The general scene file loading handler
#include "OSGSceneFileHandler.h"
// Input
#include "OSGWindowUtils.h"
//Text Foreground
#include "OSGSimpleTextForeground.h"
//Animation
#include "OSGKeyframeSequences.h"
#include "OSGKeyframeAnimator.h"
#include "OSGFieldAnimation.h"
// UserInterface Headers
#include "OSGUIForeground.h"
#include "OSGInternalWindow.h"
#include "OSGUIDrawingSurface.h"
#include "OSGGraphics2D.h"
#include "OSGLookAndFeelManager.h"
// 04Layer Headers
#include "OSGLayers.h"
#include "OSGButton.h"
#include "OSGLineBorder.h"
#include "OSGFlowLayout.h"
#include "OSGLookAndFeelManager.h"
// Include Layer header files
#include "OSGChunkMaterial.h"
#include "OSGMaterialChunk.h"
#include "OSGTextureObjChunk.h"
#include "OSGImageFileHandler.h"
// Activate the OpenSG namespace
OSG_USING_NAMESPACE
// Forward declaration so we can have the interesting stuff upfront
void display(SimpleSceneManager *mgr);
void reshape(Vec2f Size, SimpleSceneManager *mgr);
//Ctrl+q handler
void keyTyped(KeyEventDetails* const details)
{
if(details->getKey() == KeyEventDetails::KEY_Q && details->getModifiers() &
KeyEventDetails::KEY_MODIFIER_COMMAND)
{
dynamic_cast<WindowEventProducer*>(details->getSource())->closeWindow();
}
}
class SimpleScreenDoc
{
public:
SimpleScreenDoc(SimpleSceneManager* SceneManager,
WindowEventProducer* MainWindow);
private:
SimpleTextForegroundRecPtr _DocForeground;
SimpleTextForegroundRecPtr _DocShowForeground;
FieldAnimationRecPtr _ShowDocFadeOutAnimation;
SimpleScreenDoc(void);
SimpleScreenDoc(const SimpleScreenDoc& );
SimpleTextForegroundTransitPtr makeDocForeground(void);
SimpleTextForegroundTransitPtr makeDocShowForeground(void);
void keyTyped(KeyEventDetails* const details);
};
/******************************************************
Documentation Foreground
******************************************************/
SimpleTextForegroundTransitPtr SimpleScreenDoc::makeDocForeground(void)
{
SimpleTextForegroundRecPtr DocForeground = SimpleTextForeground::create();
DocForeground->addLine("This tutorial is a simple demonstration of the use");
DocForeground->addLine("of the different \\{\\color=AAAA00FF Layer} types used for the");
DocForeground->addLine("backgrounds of these buttons.");
DocForeground->addLine("");
DocForeground->addLine("\\{\\color=AAAAAAFF Key Commands}:");
DocForeground->addLine(" \\{\\color=AAAAFFFF Cmd+q}: Close the application");
DocForeground->addLine(" \\{\\color=AAAAFFFF ?}: Show/hide this documentation");
return SimpleTextForegroundTransitPtr(DocForeground);
}
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
// Create the SimpleSceneManager helper
SimpleSceneManagerRefPtr sceneManager = SimpleSceneManager::create();
TutorialWindow->setDisplayCallback(boost::bind(display, sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, sceneManager));
// Tell the Manager what to manage
sceneManager->setWindow(TutorialWindow);
TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1));
// Make Torus Node (creates Torus in background of scene)
NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);
// Make Main Scene Node and add the Torus
NodeRefPtr scene = OSG::Node::create();
scene->setCore(OSG::Group::create());
scene->addChild(TorusGeometryNode);
// Create the Graphics
GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create();
// Initialize the LookAndFeelManager to enable default settings
LookAndFeelManager::the()->getLookAndFeel()->init();
/******************************************************
Create the Layers.
******************************************************/
ColorLayerRefPtr ExampleColorLayer = OSG::ColorLayer::create();
CompoundLayerRefPtr ExampleCompoundLayer = OSG::CompoundLayer::create();
EmptyLayerRefPtr ExampleEmptyLayer = OSG::EmptyLayer::create();
GradientLayerRefPtr ExampleGradientLayer = OSG::GradientLayer::create();
MaterialLayerRefPtr ExampleMaterialLayer = OSG::MaterialLayer::create();
TextureLayerRefPtr ExampleTextureLayer = OSG::TextureLayer::create();
PatternLayerRefPtr ExamplePatternLayer = OSG::PatternLayer::create();
GlassLayerRefPtr ExampleGlassLayer = OSG::GlassLayer::create();
CompoundLayerRefPtr ExampleGlassCompoundLayer = OSG::CompoundLayer::create();
/******************************************************
The ColorLayer is a simple Layer
having just a Color to it.
-setColor(Color4f): Determine the Color of
the Layer.
******************************************************/
ExampleColorLayer->setColor(Color4f(1.0,0.0,0.0,1.0));
/******************************************************
The CompoundLayer allows you to
combine multiple Backgrounds into one.
The Backgrounds are added sequentially;
so in this example the
ExampleTextureLayer would be added
first, and the ExampleGradientLayer
rendered on top of it.
-getBackgrounds().push_back(BackgroundName):
Adds a Background to the
CompoundBackground.
******************************************************/
ExampleCompoundLayer->pushToBackgrounds(ExampleTextureLayer);
ExampleCompoundLayer->pushToBackgrounds(ExampleGradientLayer);
/******************************************************
The EmptyLayer is a Background
with no attributes.
******************************************************/
// Nothing!
/******************************************************
The GradientLayer is a Background
which displays a gradient of Color.
-getColors().push_back(Color4f): Determines the
starting Color for the gradient.
-getColors().push_back(Color4f): Determines the
ending Color for the gradient.
-setOrientation(ENUM): Determines the
gradient alignment. Takes
HORIZONTAL_ORIENTATION or
VERTICAL_ORIENTATION arguments.
******************************************************/
ExampleGradientLayer->editMFColors()->push_back(Color4f(1.0, 0.0, 0.0, 1.0));
ExampleGradientLayer->editMFStops()->push_back(0.0);
ExampleGradientLayer->editMFColors()->push_back(Color4f(0.0, 1.0, 0.0, 0.75));
ExampleGradientLayer->editMFStops()->push_back(0.5);
ExampleGradientLayer->editMFColors()->push_back(Color4f(0.0, 0.0, 1.0, 0.5));
ExampleGradientLayer->editMFStops()->push_back(1.0);
ExampleGradientLayer->setStartPosition(Vec2f(0.2f,0.2f));
ExampleGradientLayer->setEndPosition(Vec2f(.6f,0.6f));
ExampleGradientLayer->setSpreadMethod(GradientLayer::SPREAD_REFLECT);
/******************************************************
The MaterialLayer is a Background
which is created using a Material (also
created here).
-setMaterial(MaterialName): Determine
which Material will be used to
create the Background.
******************************************************/
// Creates Material
ChunkMaterialRefPtr LayerMaterial = ChunkMaterial::create();
MaterialChunkRefPtr LayerMaterialChunk = MaterialChunk::create();
LayerMaterialChunk->setAmbient(Color4f(1.0,0.0,0.0,1.0));
LayerMaterialChunk->setDiffuse(Color4f(0.0,1.0,0.0,1.0));
LayerMaterialChunk->setSpecular(Color4f(0.0,0.0,1.0,1.0));
LayerMaterial->addChunk(LayerMaterialChunk);
// Edit MaterialLayer
ExampleMaterialLayer->setMaterial(LayerMaterial);
/******************************************************
The TextureLayer is a Background
which is created using a Texture (also
created here).
-setTexture(TextureName): Determine
which Texture will be used to
create the Background.
******************************************************/
// Creates Texture from Image
TextureObjChunkRefPtr LayerTextureObjChunk = TextureObjChunk::create();
ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Checker.jpg");
LayerTextureObjChunk->setImage(LoadedImage);
// Edit TextureLayer
ExampleTextureLayer->setTexture(LayerTextureObjChunk);
/******************************************************
The PatternLayer is a Background
which is created using a Texture (also
created here).
-setTexture(TextureName): Determine
which Texture will be used to
create the Background.
-setPatternSize(Vec2f):
-setVerticalAlignment():
-setHorizontalAlignment():
-setHorizontalRepeat():
-setVerticalRepeat():
-setHorizontalRepeatValue():
-setVerticalRepeatValue():
******************************************************/
TextureObjChunkRefPtr LayerPatternChunk = TextureObjChunk::create();
//ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Checker.jpg");
LayerPatternChunk->setImage(LoadedImage);
LayerPatternChunk->setWrapS(GL_REPEAT);
LayerPatternChunk->setWrapT(GL_CLAMP_TO_EDGE);
ExamplePatternLayer->setTexture(LayerPatternChunk);
ExamplePatternLayer->setPatternSize(Vec2f(50.0f,50.0f));
ExamplePatternLayer->setVerticalAlignment(0.5);
ExamplePatternLayer->setHorizontalAlignment(0.0);
ExamplePatternLayer->setHorizontalRepeat(PatternLayer::PATTERN_REPEAT_BY_POINT);
ExamplePatternLayer->setVerticalRepeat(PatternLayer::PATTERN_REPEAT_ABSOLUTE);
ExamplePatternLayer->setHorizontalRepeatValue(1.0);
ExamplePatternLayer->setVerticalRepeatValue(2.0);
/******************************************************
******************************************************/
ExampleGlassLayer->setCenterColor(Color4f(1.0f,1.0f,1.0f,0.0f));
ExampleGlassLayer->setEdgeColor(Color4f(1.0f,1.0f,1.0f,0.7f));
/******************************************************
******************************************************/
ExampleGlassCompoundLayer->pushToBackgrounds(ExampleColorLayer);
ExampleGlassCompoundLayer->pushToBackgrounds(ExampleGlassLayer);
/******************************************************
Create and edit Button Components to
display the Layers.
******************************************************/
ButtonRefPtr ExampleColorLayerButton = OSG::Button::create();
ButtonRefPtr ExampleCompoundLayerButton = OSG::Button::create();
ButtonRefPtr ExampleEmptyLayerButton = OSG::Button::create();
ButtonRefPtr ExampleGradientLayerButton = OSG::Button::create();
ButtonRefPtr ExampleMaterialLayerButton = OSG::Button::create();
ButtonRefPtr ExampleTextureLayerButton = OSG::Button::create();
ButtonRefPtr ExamplePatternLayerButton = OSG::Button::create();
ButtonRefPtr ExampleGlassLayerButton = OSG::Button::create();
ButtonRefPtr ExampleGlassCompoundLayerButton = OSG::Button::create();
ExampleColorLayerButton->setText("Color Layer");
ExampleColorLayerButton->setBackground(ExampleColorLayer);
ExampleColorLayerButton->setActiveBackground(ExampleColorLayer);
ExampleColorLayerButton->setRolloverBackground(ExampleColorLayer);
ExampleColorLayerButton->setPreferredSize(Vec2f(150,50));
ExampleCompoundLayerButton->setText("Compound Layer");
ExampleCompoundLayerButton->setBackground(ExampleCompoundLayer);
ExampleCompoundLayerButton->setActiveBackground(ExampleCompoundLayer);
ExampleCompoundLayerButton->setRolloverBackground(ExampleCompoundLayer);
ExampleCompoundLayerButton->setPreferredSize(Vec2f(150,50));
ExampleEmptyLayerButton->setText("Empty Layer");
ExampleEmptyLayerButton->setBackground(ExampleEmptyLayer);
ExampleEmptyLayerButton->setActiveBackground(ExampleEmptyLayer);
ExampleEmptyLayerButton->setRolloverBackground(ExampleEmptyLayer);
ExampleEmptyLayerButton->setPreferredSize(Vec2f(150,50));
ExampleGradientLayerButton->setText("Gradient Layer");
ExampleGradientLayerButton->setBackground(ExampleGradientLayer);
ExampleGradientLayerButton->setActiveBackground(ExampleGradientLayer);
ExampleGradientLayerButton->setRolloverBackground(ExampleGradientLayer);
ExampleGradientLayerButton->setPreferredSize(Vec2f(150,50));
ExampleMaterialLayerButton->setText("Material Layer");
ExampleMaterialLayerButton->setBackground(ExampleMaterialLayer);
ExampleMaterialLayerButton->setActiveBackground(ExampleMaterialLayer);
ExampleMaterialLayerButton->setRolloverBackground(ExampleMaterialLayer);
ExampleMaterialLayerButton->setPreferredSize(Vec2f(150,50));
ExampleMaterialLayerButton->setTextColor(Color4f(1.0,1.0,1.0,1.0));
ExampleMaterialLayerButton->setRolloverTextColor(Color4f(1.0,1.0,1.0,1.0));
ExampleMaterialLayerButton->setActiveTextColor(Color4f(1.0,1.0,1.0,1.0));
ExampleTextureLayerButton->setText("Texture Layer");
ExampleTextureLayerButton->setBackground(ExampleTextureLayer);
ExampleTextureLayerButton->setActiveBackground(ExampleTextureLayer);
ExampleTextureLayerButton->setRolloverBackground(ExampleTextureLayer);
ExampleTextureLayerButton->setPreferredSize(Vec2f(150,50));
ExampleTextureLayerButton->setTextColor(Color4f(0.0,1.0,0.0,1.0));
ExampleTextureLayerButton->setRolloverTextColor(Color4f(0.0,1.0,0.0,1.0));
ExampleTextureLayerButton->setActiveTextColor(Color4f(0.0,1.0,0.0,1.0));
ExamplePatternLayerButton->setText("Pattern Layer");
ExamplePatternLayerButton->setBackground(ExamplePatternLayer);
ExamplePatternLayerButton->setActiveBackground(ExamplePatternLayer);
ExamplePatternLayerButton->setRolloverBackground(ExamplePatternLayer);
ExamplePatternLayerButton->setPreferredSize(Vec2f(150,50));
ExamplePatternLayerButton->setTextColor(Color4f(0.0,1.0,0.0,1.0));
ExamplePatternLayerButton->setRolloverTextColor(Color4f(0.0,1.0,0.0,1.0));
ExamplePatternLayerButton->setActiveTextColor(Color4f(0.0,1.0,0.0,1.0));
ExampleGlassLayerButton->setText("Glass Layer");
ExampleGlassLayerButton->setBackground(ExampleGlassLayer);
ExampleGlassLayerButton->setActiveBackground(ExampleGlassLayer);
ExampleGlassLayerButton->setRolloverBackground(ExampleGlassLayer);
ExampleGlassLayerButton->setPreferredSize(Vec2f(150,50));
ExampleGlassLayerButton->setTextColor(Color4f(0.0,0.0,0.0,1.0));
ExampleGlassLayerButton->setRolloverTextColor(Color4f(0.0,0.0,0.0,1.0));
ExampleGlassLayerButton->setActiveTextColor(Color4f(0.0,0.0,0.0,1.0));
ExampleGlassCompoundLayerButton->setText("GlassCompound Layer");
ExampleGlassCompoundLayerButton->setBackground(ExampleGlassCompoundLayer);
ExampleGlassCompoundLayerButton->setActiveBackground(ExampleGlassCompoundLayer);
ExampleGlassCompoundLayerButton->setRolloverBackground(ExampleGlassCompoundLayer);
ExampleGlassCompoundLayerButton->setPreferredSize(Vec2f(150,50));
ExampleGlassCompoundLayerButton->setTextColor(Color4f(0.0,0.0,0.0,1.0));
ExampleGlassCompoundLayerButton->setRolloverTextColor(Color4f(0.0,0.0,0.0,1.0));
ExampleGlassCompoundLayerButton->setActiveTextColor(Color4f(0.0,0.0,0.0,1.0));
/******************************************************
Create a MainFrameBackground. For almost
all Tutorials, this is simply a
ColorLayer with a semi-transparent
white Background.
******************************************************/
// Create The Main InternalWindow
// Create Background to be used with the Main InternalWindow
ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create();
MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
//InternalWindow Layout
LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create();
InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create();
MainInternalWindow->pushToChildren(ExampleColorLayerButton);
MainInternalWindow->pushToChildren(ExampleCompoundLayerButton);
MainInternalWindow->pushToChildren(ExampleEmptyLayerButton);
MainInternalWindow->pushToChildren(ExampleGradientLayerButton);
MainInternalWindow->pushToChildren(ExampleMaterialLayerButton);
MainInternalWindow->pushToChildren(ExampleTextureLayerButton);
MainInternalWindow->pushToChildren(ExamplePatternLayerButton);
MainInternalWindow->pushToChildren(ExampleGlassLayerButton);
MainInternalWindow->pushToChildren(ExampleGlassCompoundLayerButton);
MainInternalWindow->setLayout(MainInternalWindowLayout);
MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f));
MainInternalWindow->setDrawTitlebar(false);
MainInternalWindow->setResizable(false);
// Create the Drawing Surface
UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create();
TutorialDrawingSurface->setGraphics(TutorialGraphics);
TutorialDrawingSurface->setEventProducer(TutorialWindow);
TutorialDrawingSurface->openWindow(MainInternalWindow);
// Create the UI Foreground Object
UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create();
TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);
// Create the SimpleSceneManager helper
sceneManager->setRoot(scene);
// Add the UI Foreground Object to the Scene
ViewportRefPtr TutorialViewport = sceneManager->getWindow()->getPort(0);
TutorialViewport->addForeground(TutorialUIForeground);
//Create the Documentation Foreground and add it to the viewport
SimpleScreenDoc TheSimpleScreenDoc(sceneManager, TutorialWindow);
// Show the whole Scene
sceneManager->showAll();
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"04Background");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}
// Callback functions
// Redraw the window
void display(SimpleSceneManager *mgr)
{
mgr->redraw();
}
// React to size changes
void reshape(Vec2f Size, SimpleSceneManager *mgr)
{
mgr->resize(Size.x(), Size.y());
}
SimpleTextForegroundTransitPtr SimpleScreenDoc::makeDocShowForeground(void)
{
SimpleTextForegroundRecPtr DocShowForeground = SimpleTextForeground::create();
DocShowForeground->setSize(20.0f);
DocShowForeground->setBgColor(Color4f(0.0f,0.0f,0.0f,0.0f));
DocShowForeground->setShadowColor(Color4f(0.0f,0.0f,0.0f,0.0f));
DocShowForeground->setBorderColor(Color4f(1.0f,1.0f,1.0f,0.0f));
DocShowForeground->setHorizontalAlign(SimpleTextForeground::Middle);
DocShowForeground->setVerticalAlign(SimpleTextForeground::Top);
DocShowForeground->addLine("Press ? for help.");
return SimpleTextForegroundTransitPtr(DocShowForeground);
}
SimpleScreenDoc::SimpleScreenDoc(SimpleSceneManager* SceneManager,
WindowEventProducer* MainWindow)
{
_DocForeground = makeDocForeground();
_DocForeground->setBgColor(Color4f(0.0f,0.0f,0.0f,0.8f));
_DocForeground->setBorderColor(Color4f(1.0f,1.0f,1.0f,1.0f));
_DocForeground->setTextMargin(Vec2f(5.0f,5.0f));
_DocForeground->setHorizontalAlign(SimpleTextForeground::Left);
_DocForeground->setVerticalAlign(SimpleTextForeground::Top);
_DocForeground->setActive(false);
_DocShowForeground = makeDocShowForeground();
ViewportRefPtr TutorialViewport = SceneManager->getWindow()->getPort(0);
TutorialViewport->addForeground(_DocForeground);
TutorialViewport->addForeground(_DocShowForeground);
MainWindow->connectKeyTyped(boost::bind(&SimpleScreenDoc::keyTyped,
this,
_1));
//Color Keyframe Sequence
KeyframeColorSequenceRecPtr ColorKeyframes = KeyframeColorSequenceColor4f::create();
ColorKeyframes->addKeyframe(Color4f(1.0f,1.0f,1.0f,1.0f),0.0f);
ColorKeyframes->addKeyframe(Color4f(1.0f,1.0f,1.0f,1.0f),5.0f);
ColorKeyframes->addKeyframe(Color4f(1.0f,1.0f,1.0f,0.0f),7.0f);
//Animator
KeyframeAnimatorRecPtr TheAnimator = KeyframeAnimator::create();
TheAnimator->setKeyframeSequence(ColorKeyframes);
//Animation
_ShowDocFadeOutAnimation = FieldAnimation::create();
_ShowDocFadeOutAnimation->setAnimator(TheAnimator);
_ShowDocFadeOutAnimation->setInterpolationType(TBAnimator::LINEAR_INTERPOLATION);
_ShowDocFadeOutAnimation->setCycling(1);
_ShowDocFadeOutAnimation->setAnimatedField(_DocShowForeground,
SimpleTextForeground::ColorFieldId);
_ShowDocFadeOutAnimation->attachUpdateProducer(MainWindow);
_ShowDocFadeOutAnimation->start();
}
void SimpleScreenDoc::keyTyped(KeyEventDetails* const details)
{
switch(details->getKeyChar())
{
case '?':
_DocForeground->setActive(!_DocForeground->getActive());
break;
}
}