This repository has been archived by the owner on Dec 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Gorilla.h
3028 lines (2609 loc) · 83.7 KB
/
Gorilla.h
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
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Gorilla
-------
Copyright (c) 2010 Robin Southern
Additional contributions by:
- Murat Sari
- Nigel Atkinson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef GORILLA_H
#define GORILLA_H
#include "OGRE/Ogre.h"
#ifndef GORILLA_USES_EXCEPTIONS
# define GORILLA_USES_EXCEPTIONS 0
#endif
#if OGRE_COMP == OGRE_COMPILER_GNUC
# define __FUNC__ __PRETTY_FUNCTION__
#elif OGRE_COMP != OGRE_COMPILER_BORL
# define __FUNC__ "No function name info"
#endif
namespace Gorilla
{
class Silverback;
class TextureAtlas;
class LayerContainer;
class Screen;
class ScreenRenderable;
class Layer;
class Rectangle;
class Polygon;
class LineList;
class QuadList;
class Caption;
class MarkupText;
template<typename T> struct VectorType
{
#if OGRE_VERSION <= 67077 // If the version is less than or equal to 1.6.5
typedef std::vector<T> type;
#else
typedef typename Ogre::vector<T>::type type;
#endif
};
namespace Colours
{
enum Colour
{
None = 0, // No Colour.
AliceBlue=0xf0f8ff, Gainsboro=0xdcdcdc, MistyRose=0xffe4e1,
AntiqueWhite=0xfaebd7, GhostWhite=0xf8f8ff, Moccasin=0xffe4b5,
Aqua=0x00ffff, Gold=0xffd700, NavajoWhite=0xffdead,
Aquamarine=0x7fffd4, Goldenrod=0xdaa520, Navy=0x000080,
Azure=0xf0ffff, Gray=0x808080, OldLace=0xfdf5e6,
Beige=0xf5f5dc, Green=0x008000, Olive=0x808000,
Bisque=0xffe4c4, GreenYellow=0xadff2f, OliveDrab=0x6b8e23,
Black=0x000000, Grey=0x808080, Orange=0xffa500,
BlanchedAlmond=0xffebcd, Honeydew=0xf0fff0, OrangeRed=0xff4500,
Blue=0x0000ff, HotPink=0xff69b4, Orchid=0xda70d6,
BlueViolet=0x8a2be2, IndianRed=0xcd5c5c, PaleGoldenrod=0xeee8aa,
Brown=0xa52a2a, Indigo=0x4b0082, PaleGreen=0x98fb98,
Burlywood=0xdeb887, Ivory=0xfffff0, PaleTurquoise=0xafeeee,
CadetBlue=0x5f9ea0, Khaki=0xf0e68c, PaleVioletRed=0xdb7093,
Chartreuse=0x7fff00, Lavender=0xe6e6fa, PapayaWhip=0xffefd5,
Chocolate=0xd2691e, LavenderBlush=0xfff0f5, PeachPuff=0xffdab9,
Coral=0xff7f50, LawnGreen=0x7cfc00, Peru=0xcd853f,
CornflowerBlue=0x6495ed, LemonChiffon=0xfffacd, Pink=0xffc0cb,
Cornsilk=0xfff8dc, LightBlue=0xadd8e6, Plum=0xdda0dd,
Crimson=0xdc143c, LightCoral=0xf08080, PowderBlue=0xb0e0e6,
Cyan=0x00ffff, LightCyan=0xe0ffff, Purple=0x800080,
DarkBlue=0x00008b, LightGoldenrodyellow=0xfafad2, Red=0xff0000,
DarkCyan=0x008b8b, LightGray=0xd3d3d3, RosyBrown=0xbc8f8f,
DarkGoldenrod=0xb8860b, LightGreen=0x90ee90, RoyalBlue=0x4169e1,
DarkGray=0xa9a9a9, LightGrey=0xd3d3d3, SaddleBrown=0x8b4513,
DarkGreen=0x006400, LightPink=0xffb6c1, Salmon=0xfa8072,
DarkGrey=0xa9a9a9, LightSalmon=0xffa07a, SandyBrown=0xf4a460,
DarkKhaki=0xbdb76b, LightSeagreen=0x20b2aa, SeaGreen=0x2e8b57,
DarkMagenta=0x8b008b, LightSkyblue=0x87cefa, SeaShell=0xfff5ee,
DarkOlivegreen=0x556b2f, LightSlategray=0x778899, Sienna=0xa0522d,
DarkOrange=0xff8c00, LightSlategrey=0x778899, Silver=0xc0c0c0,
DarkOrchid=0x9932cc, LightSteelblue=0xb0c4de, SkyBlue=0x87ceeb,
DarkRed=0x8b0000, LightYellow=0xffffe0, SlateBlue=0x6a5acd,
DarkSalmon=0xe9967a, Lime=0x00ff00, SlateGray=0x708090,
DarkSeagreen=0x8fbc8f, LimeGreen=0x32cd32, SlateGrey=0x708090,
DarkSlateblue=0x483d8b, Linen=0xfaf0e6, Snow=0xfffafa,
DarkSlategray=0x2f4f4f, Magenta=0xff00ff, SpringGreen=0x00ff7f,
DarkSlategrey=0x2f4f4f, Maroon=0x800000, SteelBlue=0x4682b4,
DarkTurquoise=0x00ced1, MediumAquamarine=0x66cdaa, Tan=0xd2b48c,
DarkViolet=0x9400d3, MediumBlue=0x0000cd, Teal=0x008080,
DeepPink=0xff1493, MediumOrchid=0xba55d3, Thistle=0xd8bfd8,
DeepSkyblue=0x00bfff, MediumPurple=0x9370db, Tomato=0xff6347,
DimGray=0x696969, MediumSeaGreen=0x3cb371, Turquoise=0x40e0d0,
DimGrey=0x696969, MediumSlateBlue=0x7b68ee, Violet=0xee82ee,
DodgerBlue=0x1e90ff, MediumSpringGreen=0x00fa9a, Wheat=0xf5deb3,
FireBrick=0xb22222, MediumTurquoise=0x48d1cc, White=0xffffff,
FloralWhite=0xfffaf0, MediumBioletRed=0xc71585, WhiteSmoke=0xf5f5f5,
ForestGreen=0x228b22, MidnightBlue=0x191970, Yellow=0xffff00,
Fuchsia=0xff00ff, MintCream=0xf5fffa, YellowGreen=0x9acd32
}; // Colour
} // namespace Colours
/*! function. rgb
desc.
Convert three/four RGBA values into an Ogre::ColourValue
*/
Ogre::ColourValue rgb(Ogre::uchar r, Ogre::uchar g, Ogre::uchar b, Ogre::uchar a = 255);
/*! function. webcolour
desc.
Turn a webcolour from the Gorilla::Colours::Colour enum into an Ogre::ColourValue
*/
Ogre::ColourValue webcolour(Colours::Colour, Ogre::Real alpha = 1.0);
/*! enum. Gradient
desc.
Directions for background gradients
*/
enum Gradient
{
Gradient_NorthSouth,
Gradient_WestEast,
Gradient_Diagonal
};
/*! enum. Border
desc.
Border Directions
+---------------------+
|\ NORTH /|
| \ / |
| +---------------+ |
| | | |
| W| |E |
| E| |A |
| S| |S |
| T| |T |
| | | |
| +---------------+ |
| / SOUTH \ |
|/ \|
+---------------------+
*/
enum Border
{
Border_North = 0,
Border_South = 1,
Border_East = 2,
Border_West = 3
};
/*! enum. QuadCorner
desc.
Names of each corner/vertex of a Quad
*/
enum QuadCorner
{
TopLeft = 0,
TopRight = 1,
BottomRight = 2,
BottomLeft = 3
};
/*! enum. TextAlignment
desc.
Horizontal text alignment for captions.
*/
enum TextAlignment
{
TextAlign_Left, // Place the text to where left is (X = left)
TextAlign_Right, // Place the text to the right of left (X = left - text_width)
TextAlign_Centre, // Place the text centered at left (X = left - (text_width / 2 ) )
};
/*! enum. VerticalAlignment
desc.
Vertical text alignment for captions.
*/
enum VerticalAlignment
{
VerticalAlign_Top,
VerticalAlign_Middle,
VerticalAlign_Bottom
};
/*! enum. buffer<T>
desc.
Internal container class that is similar to std::vector
*/
template<typename T> class buffer
{
public:
inline buffer() : mBuffer(0), mUsed(0), mCapacity(0)
{ // no code.
}
inline ~buffer()
{
if (mBuffer && mCapacity)
OGRE_FREE(mBuffer, Ogre::MEMCATEGORY_GEOMETRY);
}
inline size_t size() const
{
return mUsed;
}
inline size_t capacity() const
{
return mCapacity;
}
inline T& operator[](size_t index)
{
return *(mBuffer + index);
}
inline const T& operator[](size_t index) const
{
return *(mBuffer + index);
}
inline T& at(size_t index)
{
return *(mBuffer + index);
}
inline const T& at(size_t index) const
{
return *(mBuffer + index);
}
inline void remove_all()
{
mUsed = 0;
}
inline void resize(size_t new_capacity)
{
T* new_buffer = (T*) OGRE_MALLOC(sizeof(T) * new_capacity, Ogre::MEMCATEGORY_GEOMETRY);
if (mUsed != 0)
{
if (mUsed < new_capacity) // Copy all
std::copy(mBuffer, mBuffer + mUsed, new_buffer);
else if (mUsed >= new_capacity) // Copy some
std::copy(mBuffer, mBuffer + new_capacity, new_buffer);
}
OGRE_FREE(mBuffer, Ogre::MEMCATEGORY_GEOMETRY);
mCapacity = new_capacity;
mBuffer = new_buffer;
}
inline void push_back(const T& value)
{
if (mUsed == mCapacity)
resize(mUsed == 0 ? 1 : mUsed * 2);
*(mBuffer + mUsed) = value;
mUsed++;
}
inline void pop_back()
{
if (mUsed != 0)
mUsed--;
}
inline void erase(size_t index)
{
*(mBuffer + index) = *(mBuffer + mUsed - 1);
mUsed--;
}
inline T* first()
{
return mBuffer;
}
inline T* last()
{
return mBuffer + mUsed;
}
protected:
T* mBuffer;
size_t mUsed, mCapacity;
};
/*! struct. Vertex
desc.
Structure for a single vertex.
*/
struct Vertex
{
Ogre::Vector3 position;
Ogre::ColourValue colour;
Ogre::Vector2 uv;
};
/*! struct. Kerning
desc.
Distances between two characters next to each other.
*/
struct Kerning
{
Kerning(Ogre::uint c, Ogre::Real k) : character(c), kerning(k) {}
Ogre::uint character;
Ogre::Real kerning;
};
/*! struct. Glyph
desc.
Texture and size information about a single character loaded from a TextureAtlas.
*/
class Glyph : public Ogre::GeneralAllocatedObject
{
public:
Glyph() : uvTop(0), uvBottom(0), uvWidth(0), uvHeight(0), uvLeft(0), uvRight(0), glyphWidth(0), glyphHeight(0), glyphAdvance(0), verticalOffset(0) {}
~Glyph() {}
Ogre::Vector2 texCoords[4];
Ogre::Real uvTop, uvBottom, uvWidth, uvHeight, uvLeft, uvRight,
glyphWidth, glyphHeight, glyphAdvance, verticalOffset;
buffer<Kerning> kerning;
// Get kerning value of a character to the right of another.
// Ab -- get the kerning value of b, pass on A.
inline const Ogre::Real getKerning(unsigned char left_of) const
{
if (kerning.size() == 0)
return 0;
for (size_t i=0;i < kerning.size();i++)
{
if (kerning[i].character == left_of)
return kerning[i].kerning;
}
return 0;
}
};
/*! class. Sprite
desc.
Portions of a texture from a TextureAtlas.
*/
class Sprite : public Ogre::GeneralAllocatedObject
{
public:
Sprite() {}
~Sprite() {}
Ogre::Real uvTop, uvLeft, uvRight, uvBottom, spriteWidth, spriteHeight;
Ogre::Vector2 texCoords[4];
};
/* class. Silverback
desc.
Main singleton class for Gorilla
*/
class Silverback : public Ogre::Singleton<Silverback>, public Ogre::GeneralAllocatedObject, public Ogre::FrameListener
{
public:
/*! constructor. Silverback
desc.
Silverback constructor.
*/
Silverback();
/*! destructor. Silverback
desc.
Silverback destructor.
*/
~Silverback();
/*! function. loadAtlas
desc.
Create a TextureAtlas from a ".gorilla" file.
Name is the name of the TextureAtlas, as well as the first part of the filename
of the gorilla file; i.e. name.gorilla, the gorilla file can be loaded from a different
resource group if you give that name as the second argument, otherwise it will assume
to be "General".
*/
void loadAtlas(const Ogre::String& name, const Ogre::String& group = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
/*! function. createScreen
desc.
Create a Screen using a Viewport and a name of a previously loaded TextureAtlas.
Both must exist. The screen will register itself as a RenderQueueListener to the
SceneManager that has the Camera which is tied to the Viewport.
note.
Each screen is considered a new batch. To reduce your batch count in Gorilla,
reduce the number of screens you use.
*/
Screen* createScreen(Ogre::Viewport*, const Ogre::String& atlas);
Screen* createScreen(Ogre::Viewport* viewport, TextureAtlas* atlas);
/*! function. destroyScreen
desc.
Destroy an existing screen, its layers and the contents of those layers.
*/
void destroyScreen(Screen*);
/*! function. createScreenRenderable
*/
ScreenRenderable* createScreenRenderable(const Ogre::Vector2& maxSize, const Ogre::String& atlas);
/*! function. destroyScreen
desc.
Destroy an existing screen, its layers and the contents of those layers.
*/
void destroyScreenRenderable(ScreenRenderable*);
/*! function. frameStarted
desc.
Call ScreenRenderable draw
*/
bool frameStarted(const Ogre::FrameEvent& evt);
protected:
std::map<Ogre::String, TextureAtlas*> mAtlases;
std::vector<Screen*> mScreens;
std::vector<ScreenRenderable*> mScreenRenderables;
};
/*! class. GlyphData
desc.
Collection of glyphs of the same size.
*/
class GlyphData : public Ogre::GeneralAllocatedObject
{
friend class TextureAtlas;
public:
GlyphData();
~GlyphData();
/*! function. getGlyph
desc.
Get a glyph (character information) from a specific character.
note.
If the character doesn't exist then a null pointer is returned.
Do not delete the Glyph pointer.
*/
inline Glyph* getGlyph(Ogre::uint character) const
{
Ogre::uint safe_character = character - mRangeBegin;
if (safe_character >= 0 && safe_character <= mGlyphs.size())
return mGlyphs[safe_character];
return 0;
}
std::vector<Glyph*> mGlyphs;
Ogre::uint mRangeBegin, mRangeEnd;
Ogre::Real mSpaceLength,
mLineHeight,
mBaseline,
mLineSpacing,
mLetterSpacing,
mMonoWidth;
};
/*! class. TextureAtlas
desc.
The TextureAtlas file represents a .gorilla file which contains all the needed information that
describes the portions of a single texture. Such as Glyph and Sprite information, text kerning,
line heights and so on. It isn't typically used by the end-user.
*/
class TextureAtlas : public Ogre::GeneralAllocatedObject
{
friend class Silverback;
public:
Ogre::MaterialPtr createOrGet2DMasterMaterial();
Ogre::MaterialPtr createOrGet3DMasterMaterial();
/*! function. getTexture
desc.
Get the texture assigned to this TextureAtlas
*/
inline Ogre::TexturePtr getTexture() const
{
return mTexture;
}
/*! function. getMaterial
desc.
Get the material assigned to this TextureAtlas
*/
inline Ogre::MaterialPtr get2DMaterial() const
{
return m2DMaterial;
}
/*! function. getMaterial
desc.
Get the material assigned to this TextureAtlas
*/
inline Ogre::MaterialPtr get3DMaterial() const
{
return m3DMaterial;
}
/*! function. getMaterialName
desc.
Get the name of the material assigned to this TextureAtlas
*/
inline Ogre::String get2DMaterialName() const
{
return m2DMaterial->getName();
}
/*! function. getMaterialName
desc.
Get the name of the material assigned to this TextureAtlas
*/
inline Ogre::String get3DMaterialName() const
{
return m3DMaterial->getName();
}
inline GlyphData* getGlyphData(Ogre::uint index) const
{
std::map<Ogre::uint, GlyphData*>::const_iterator it = mGlyphData.find(index);
if (it == mGlyphData.end())
return 0;
return (*it).second;
}
/*! function. getSprite
desc.
Get a sprite (portion of a texture) from a name.
note.
If the sprite doesn't exist then a null pointer is returned.
Do not delete the Sprite pointer.
*/
inline Sprite* getSprite(const Ogre::String& name) const
{
std::map<Ogre::String, Sprite*>::const_iterator it = mSprites.find(name);
if (it == mSprites.end())
return 0;
return (*it).second;
}
/*! function. getGlyphKerning
desc.
Get the UV information for a designated white pixel in the texture.
note.
Units are in relative coordinates (0..1)
*/
inline Ogre::Vector2 getWhitePixel() const
{
return mWhitePixel;
}
/*! function. getGlyphKerning
desc.
Get the X coordinate for a designated white pixel in the texture.
note.
Units are in relative coordinates (0..1)
*/
inline Ogre::Real getWhitePixelX() const
{
return mWhitePixel.x;
}
/*! function. getGlyphKerning
desc.
Get the Y coordinate for a designated white pixel in the texture.
note.
Units are in relative coordinates (0..1)
*/
inline Ogre::Real getWhitePixelY() const
{
return mWhitePixel.y;
}
/*! function. getTextureSize
desc.
Get the size of the texture.
*/
inline Ogre::Vector2 getTextureSize() const
{
return Ogre::Vector2(Ogre::Real(mTexture->getWidth()), Ogre::Real(mTexture->getHeight()));
}
/*! function. getTextureSize
desc.
Get the reciprocal of the width of the texture.
*/
inline Ogre::Real getInvTextureCoordsX() const
{
return 1.0f / Ogre::Real(mTexture->getWidth());
}
/*! function. getTextureSize
desc.
Get the reciprocal of the height of the texture.
*/
inline Ogre::Real getInvTextureCoordsY() const
{
return 1.0f / Ogre::Real(mTexture->getHeight());
}
/*! function. getPass
desc.
Get the first pass of the material used by this TextureAtlas
*/
inline Ogre::Pass* get2DPass() const
{
return m2DPass;
}
/*! function. getGlyphMonoWidth
desc.
Reset the ten markup colours used in the MarkupText, by default these are:
0 = 255, 255, 255
1 = 0, 0, 0
2 = 204, 204, 204
3 = 254, 220, 129
4 = 254, 138, 129
5 = 123, 236, 110
6 = 44, 192, 171
7 = 199, 93, 142
8 = 254, 254, 254
9 = 13, 13, 13
*/
void refreshMarkupColours();
/*! function. setMarkupColour
desc.
Change one of the ten markup colours.
note.
colour_palette_index must be between or equal to 0 and 9.
*/
void setMarkupColour(Ogre::uint colour_palette_index, const Ogre::ColourValue&);
/*! function. getMarkupColour
desc.
Get one of the ten markup colours.
note.
colour_palette_index must be between or equal to 0 and 9.
*/
const Ogre::ColourValue &getMarkupColour(Ogre::uint colour_palette_index) const;
protected:
TextureAtlas(const Ogre::String& gorillaFile, const Ogre::String& group);
~TextureAtlas();
void _reset();
void _load(const Ogre::String& gorillaFile, const Ogre::String& groupName);
void _loadTexture(Ogre::ConfigFile::SettingsMultiMap*);
void _loadGlyphs(Ogre::ConfigFile::SettingsMultiMap*, GlyphData*);
void _loadKerning(Ogre::ConfigFile::SettingsMultiMap*, GlyphData*);
void _loadVerticalOffsets(Ogre::ConfigFile::SettingsMultiMap*, GlyphData*);
void _loadSprites(Ogre::ConfigFile::SettingsMultiMap*);
void _create2DMaterial();
void _create3DMaterial();
void _calculateCoordinates();
Ogre::TexturePtr mTexture;
Ogre::MaterialPtr m2DMaterial, m3DMaterial;
Ogre::Pass* m2DPass, *m3DPass;
std::map<Ogre::uint, GlyphData*> mGlyphData;
std::map<Ogre::String, Sprite*> mSprites;
Ogre::Vector2 mWhitePixel;
Ogre::Vector2 mInverseTextureSize;
Ogre::ColourValue mMarkupColour[10];
};
class LayerContainer
{
public:
LayerContainer(TextureAtlas*);
virtual ~LayerContainer();
/*! function. createLayer
desc.
Create a layer for drawing on to.
Index represents the z-order, 0 being the layer drawn first and 15
the layer drawn last. Layers drawn after another layer will appear
to be top than the other.
note.
Index must be between or equal to 0 and 15. Any other value will cause
a very nasty crash.
*/
Layer* createLayer(Ogre::uint index = 0);
/*! function. destroyLayer
desc.
Destroy a layer and it's contents.
*/
void destroy(Layer* layer);
/*! function. getAtlas
desc.
Get atlas assigned to this LayerContainer
*/
TextureAtlas* getAtlas() const { return mAtlas; }
virtual Ogre::Real getTexelOffsetX() const { return 0.0f; }
virtual Ogre::Real getTexelOffsetY() const { return 0.0f; }
/*! function. _createVertexBuffer
desc.
Create the vertex buffer
*/
void _createVertexBuffer(size_t initialSize);
/*! function. _destroyVertexBuffer
desc.
Destroy the vertex buffer
*/
void _destroyVertexBuffer();
/*! function. _resizeVertexBuffer
desc.
Resize the vertex buffer to the greatest nearest power
of 2 of requestedSize.
*/
void _resizeVertexBuffer(size_t requestedSize);
/* function. _recalculateIndexes
desc.
Clear mIndexes, mIndexVertices and mIndexRedraw,
and from mLayers fill them out again. A full redraw
is required.
*/
void _recalculateIndexes();
/*! function. _redrawIndex
desc.
Redraw all layers of an index.
If force is true, then all elements of that layer
will be redrawn regardless of anything has changed
or not.
*/
void _redrawIndex(Ogre::uint id, bool force);
/*! function. _redrawAllIndexes
desc.
Redraw all layers of all indexes
If force is true, then all elements of all layers
will be redrawn regardless of anything has changed
or not.
*/
void _redrawAllIndexes(bool force = false);
/*! function. _redrawAllIndexes
desc.
Redraw a redraw of an index on the next call of _renderVertices
*/
void _requestIndexRedraw(Ogre::uint index);
/*! function. _renderVertices
desc.
Bundle up mIndexData (redraw any if needed) then copy them
into mVertexBuffer, and update mRenderOpPtr with the new
vertex count.
*/
void _renderVertices(bool force = false);
/*! function. renderOnce
desc.
Draw the vertices from mVertexBuffer into Ogre.
*/
virtual void renderOnce() = 0;
virtual void _transform(buffer<Vertex>& vertices, size_t begin, size_t end) {}
protected:
/// mLayers -- Master copy of all layers of this Target.
std::vector<Layer*> mLayers;
struct IndexData : public Ogre::GeneralAllocatedObject
{
std::vector<Layer*> mLayers;
buffer<Vertex> mVertices;
bool mRedrawNeeded;
};
/// mIndexes -- Copies pointers to Layers arranged their index.
std::map< Ogre::uint, IndexData* > mIndexData;
/// mIndexRedrawNeeded -- An index (not sure what) needs to be redrawn.
bool mIndexRedrawNeeded;
/// mRedrawAll -- All indexes need to be redrawn regardless of state.
bool mIndexRedrawAll;
/// mVertexBuffer -- Compiled layers of all indexes go into here for rendering directly to the screen or scene.
Ogre::HardwareVertexBufferSharedPtr mVertexBuffer;
/// mVertexBufferSize -- How much the VertexBuffer can hold.
size_t mVertexBufferSize;
/// mRenderOpPtr -- Pointer to the RenderOperation (Not owned by LayerContainer)
Ogre::RenderOperation* mRenderOpPtr;
/// Atlas assigned to this LayerContainer
TextureAtlas* mAtlas;
};
class Screen : public LayerContainer, public Ogre::RenderQueueListener, public Ogre::GeneralAllocatedObject
{
public:
friend class Silverback;
friend class Layer;
/*! desc. getTexelOffsetX
Helper function to get horizontal texel offset.
*/
inline Ogre::Real getTexelOffsetX() const { return mRenderSystem->getHorizontalTexelOffset(); }
/*! desc. getTexelOffsetY
Helper function to get vertical texel offset.
*/
inline Ogre::Real getTexelOffsetY() const { return mRenderSystem->getVerticalTexelOffset(); }
/*! desc. getWidth
Get screen height in pixels.
*/
inline Ogre::Real getWidth() const { return mWidth; }
/*! desc. getHeight
Get screen height in pixels.
*/
inline Ogre::Real getHeight() const { return mHeight; }
/*! desc. isVisible
Is the screen and it's contents visible or not?
note.
If the screen is hidden, then it is not rendered which decrease the batch count by one.
*/
inline bool isVisible() const { return mIsVisible; }
/*! desc. setVisible
Show or hide the screen.
*/
inline void setVisible(bool value) { mIsVisible = value;}
/*! desc. hide
Hide the screen and the all of layers within it.
*/
inline void hide() { mIsVisible = false;}
/*! desc. show
Show the screen and the visible layers within it.
*/
inline void show() { mIsVisible = true;}
#if OGRE_NO_VIEWPORT_ORIENTATIONMODE == 1
inline void setOrientation(Ogre::OrientationMode o)
{
mOrientation = o; mOrientationChanged = true;
if (mOrientation == Ogre::OR_DEGREE_90 || mOrientation == Ogre::OR_DEGREE_270)
{
std::swap(mWidth, mHeight);
std::swap(mInvWidth, mInvHeight);
}
}
#endif
protected:
/*! constructor. Screen
desc.
Use Silverback::createScreen
*/
Screen(Ogre::Viewport*, TextureAtlas*);
/*! destructor. Screen
desc.
Use Silverback::destroyScreen
*/
~Screen();
// Internal -- Not used, but required by renderQueueListener
void renderQueueStarted(Ogre::uint8, const Ogre::String&, bool&) {}
// Internal -- Called by Ogre to render the screen.
void renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& repeatThisInvocation);
// Internal -- Prepares RenderSystem for rendering.
void _prepareRenderSystem();
// Internal -- Renders mVertexData to screen.
void renderOnce();
// Internal -- Used to transform vertices using units of pixels into screen coordinates.
void _transform(buffer<Vertex>& vertices, size_t begin, size_t end);
Ogre::RenderOperation mRenderOp;
Ogre::SceneManager* mSceneMgr;
Ogre::RenderSystem* mRenderSystem;
Ogre::Viewport* mViewport;
Ogre::Real mWidth, mHeight, mInvWidth, mInvHeight;
Ogre::OrientationMode mOrientation;
#if OGRE_NO_VIEWPORT_ORIENTATIONMODE == 1
bool mOrientationChanged;
#endif
Ogre::Vector3 mScale;
bool mIsVisible;
bool mCanRender;
Ogre::Matrix4 mVertexTransform;
};
class ScreenRenderable : public LayerContainer, public Ogre::SimpleRenderable
{
public:
ScreenRenderable(const Ogre::Vector2& maxSize, TextureAtlas*);
~ScreenRenderable();
void frameStarted();
void renderOnce();
void _transform(buffer<Vertex>& vertices, size_t begin, size_t end);
void calculateBoundingBox();
Ogre::Real getBoundingRadius(void) const { return mBox.getMaximum().squaredLength(); }
Ogre::Real getSquaredViewDepth(const Ogre::Camera* cam) const
{
Ogre::Vector3 min, max, mid, dist;
min = mBox.getMinimum();
max = mBox.getMaximum();
mid = ((max - min) * 0.5) + min;
dist = cam->getDerivedPosition() - mid;
return dist.squaredLength();
}
protected: