-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCarnegieMellonGraphics.h
executable file
·1944 lines (1717 loc) · 63.6 KB
/
CarnegieMellonGraphics.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
/* CarnegieMellonGraphics Library Version 2.1.4a
$Id: CarnegieMellonGraphics.h,v 1.11 2003/01/07 20:24:01 jsaks Exp $
Copyright (c) 1999-2000 by Geoffrey Alan Washburn <[email protected]>
Some portions may be copyright by others. See AUTHORS file.
If this library is distributed in a precompiled binary form:
Portions of the supplied binary may be copyrighted by other individuals
and as such subject to their own license. If modifications were
necessary to their code, these changes will be made available upon
request or in a separate source release. Currently, this may include
some subset of the following:
FreeType : Copyright (c) 1996-1998 by David Turner, Rober Wilhem, and
Werner Lemberg (Use approved under FreeType custom license)
GLTT : Copyright (c) 1998-1999 by Stephane Rehel (LGPL License)
JPEGlib : Copyright (c) 1991-1998 by Thomas G. Lane
(Use approved under IJG custom license)
libPNG : Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
Copyright (c) 1996, 1997 Andreas Dilger
Copyright (c) 1998, 1999 Glenn Randers-Pehrson
Also copyright by "Contributing Authors":
John Bowler
Kevin Bracey
Sam Bushell
Andreas Dilger
Magnus Holmgren
Tom Lane
Dave Martindale
Glenn Randers-Pehrson
Greg Roelofs
Guy Eric Schalnat
Paul Schmidt
Tom Tanner
Willem van Schaik
Tim Wegner
(Use approved under custom license)
Pthreads-Win32 : Copyright (c) 1998 by FSF? (LGPL License)
Redistribution and use of this library in source and binary form, with or
without modification, are permitted provided that the following conditions
are met:
1. Redistribution of source code must retain the above copyright
notices, this list of conditions and the following disclaimer.
2. Redistribution in binary form must reproduce the above copyright
notices, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. When redistributing a modified version of this library it must carry
prominent notices stating the name of the individuals(s) that altered
the files, the nature of the modifications, and the date they were
performed.
4. None of the above copyright holders may be used to endore or promote
products derived from this software without specific prior written
notice.
5. No fee is charge for redistribution or use without specific
prior written permission of the copyright holders.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
This code is not yet certified for mission critical applications,
such as navigation and/or control of aircraft.
*/
#ifndef __CARNEGIEMELLONGRAPHICS_H__
#define __CARNEGIEMELLONGRAPHICS_H__
#ifdef _MSC_VER
#pragma warning (disable : 4786)
#endif
#include <queue>
#include <list>
#include <map>
#include <string>
#include <vector>
// if your compiler understands namespaces, this is all good
//#define string std::string
//#define vector std::vector
//#define map std::map
//using namespace std;
/******************************************************************************
* The KeyModifiers objects act as a "set" whose domain is that of the
* modifier keys that are available on a given system (usually control, shift,
* and alt).
* <!--
* This is not as intutitive as I would like, but this is the best I have come
* up with so far. However, the more complicated functionality associated with
* this is currently only expected to be employed by more advanced users, so
* it is not too problematic.
* -->
* <P>Users can only work with the named sets provided, and only operate on them
* through the overloaded operators : | = Union, & = Intersection, and
* ~ = Compliment. Equality and stream output support are also provided.
*
* <P>So for example, the set of modifers associated with holding down the control
* key would simply be KeyModifiers::CONTROL. If you were to hold down both
* the shift and alt keys, the modifier set would be equal to
*
* <pre> KeyModifiers::SHIFT | KeyModifiers::ALT </pre>
*
* <p>(union of the two singletons) or
*
* <pre> KeyModifiers::SHIFT_AND_ALT </pre>
*
* or
*
* <pre> KeyModifiers::ALT_AND_SHIFT </pre>
*
* <p>Predefined names have been provided for all subsets (the powerset!) of the
* entire domain, since it is a small set this is reasonable.
*****************************************************************************/
class KeyModifiers {
public:
KeyModifiers();
////// Pre-defined modifier sets //////
/**
* Matches if there are no active modifiers
*/
static const KeyModifiers NO_MODIFIERS;
/**
* Matches "control" key
*/
static const KeyModifiers CONTROL;
/**
* Matches the "shift" key
*/
static const KeyModifiers SHIFT;
/**
* Matches the "alt" key
*/
static const KeyModifiers ALT;
/**
* Matches if both "control" and "alt" are active
*/
static const KeyModifiers CONTROL_AND_ALT;
/**
* Matches if both "control" and "alt" are active
*/
static const KeyModifiers ALT_AND_CONTROL;
/**
* Matches if both "control" and "shift" are active
*/
static const KeyModifiers CONTROL_AND_SHIFT;
/**
* Matches if both "control" and "shift" are active
*/
static const KeyModifiers SHIFT_AND_CONTROL;
/**
* Matches if both "shift" and "alt" are active
*/
static const KeyModifiers SHIFT_AND_ALT;
/**
* Matches if both "shift" and "alt" are active
*/
static const KeyModifiers ALT_AND_SHIFT;
/**
* Matches when all modifiers are active
*/
static const KeyModifiers ALL_MODIFIERS;
/**
* Matches any set of modifiers
*/
static const KeyModifiers ANY_MODIFIERS;
////// Overloaded operators //////
/**
* ~ Compliment operator on KeyModifiers
*/
KeyModifiers& operator~();
/**
* |= Union-Assignment operator on KeyModifiers
*/
KeyModifiers& operator|=(const KeyModifiers& rhs);
/**
* &= Intersection-Assignment operator on KeyModifiers
*/
KeyModifiers& operator&=(const KeyModifiers& rhs);
/**
* == Equality tests on KeyModifiers
*/
bool operator==(const KeyModifiers& rhs) const;
/**
* != Inequality tests on KeyModifiers
*/
bool operator!=(const KeyModifiers& rhs) const;
/**
* | Union operator on KeyModifiers
*/
friend KeyModifiers operator|(const KeyModifiers& lhs, const KeyModifiers& rhs);
/**
* & Intersection operator on KeyModifiers
*/
friend KeyModifiers operator&(const KeyModifiers& lhs, const KeyModifiers& rhs);
private:
// Ignore these
int value;
KeyModifiers(int v);
};
// Declare the existance of operator<< on modifiers
std::ostream& operator<<(std::ostream& s, const KeyModifiers& mod);
/******************************************************************************
* MouseEvents are generated whenever the user performs some action with the
* mouse. The types of MouseEvents that can occur are listed below as
* part of the MouseEvent::Event enumeration.
*
* <P>MouseEvents are designed to work in a manner so that a user can easily
* "match" and filter out events in which they have interest. Basically
* the user constructs a new event to match against the event they currently
* have. The MouseEvent constructor has several default parameters
* so the user doesn't need to specify more detail about the event than they
* need.
*
* <P>It is also possible to simply obtain pertinent information about an
* event through the accessor member functions.
*
* <P>For example, if the user has just removed a mouse event from the mouse input
* queue, and they want to see if the mouse was clicked they can do the
* following:
*
* <pre>
* if(MouseEvent(MouseEvent::BUTTON_CLICK_EVENT) == an_event)
* // do something
* </pre>
*
* <p>Or a more complicated example would be if the user wanted to check to
* see if the mouse has was moved over position (x, y) while holding down the
* left button they would do this:
*
* <pre>
* if(MouseEvent(MouseEvent::MOUSE_MOVE_EVENT, MouseEvent::LEFT_BUTTON, x, y) == an_event)
* // do something else
* </pre>
*
* <p>Finally, if you wanted to check to see if the right mouse buton has been
* pressed down while holding down the shift key, you would do the following:
*
* <pre>
* if(MouseEvent(MouseEvent::ButtonDown, MouseEvent::RIGHT_BUTTON, -1, -1,
* KeyModifiers::SHIFT) == an_event)
* // do more of something else
* </pre>
*
* <p>In this case the coordinate of (-1, -1) indicates the location at which
* the button press occurred does not matter.
*
* <p>Note that on some platforms, certain mouse and modifier combinations will be
* trapped by the operating system/window manager and will not be reported
* as having taken place.
*****************************************************************************/
class MouseEvent {
public:
/**
* These are the buttons that CMG recognizes. A mouse event only ever contains one button.
* To find out if two buttons are down at the same time, use {@link Window#isButtonDown}.
* <table>
* <tr><td>NO_BUTTON</td> <td>Matches if no button was pressed</td></tr>
* <tr><td>LEFT_BUTTON</td> <td>Matches if the left button was pressed</td></tr>
* <tr><td>RIGHT_BUTTON</td> <td>Matches if the right button was pressed</td></tr>
* <tr><td>MIDDLE_BUTTON</td> <td>Matches if the middle button was pressed</td></tr>
* <tr><td>ANY_BUTTON</td> <td>Matches if any button was pressed</td></tr>
* </table>
* @see Window#isButtonDown
*/
typedef enum {
NO_BUTTON, // Matches if no button was pressed
LEFT_BUTTON, // Matches if the left button was pressed
RIGHT_BUTTON, // Matches if the right button was pressed
MIDDLE_BUTTON, // Matches if the middle button was pressed
ANY_BUTTON // Matches if any button was pressed
} Button;
/**
* These are the events that CMG reports.
* <table>
* <tr><td>NULL_EVENT</td> <td>For creating "NULL" mouse events</td></tr>
* <tr><td>MOUSE_MOVE_EVENT</td> <td>Event generated if the mouse was moved</td></tr>
* <tr><td>ENTER_WINDOW_EVENT</td> <td>Event generated if the mouse has entered the window</td></tr>
* <tr><td>EXIT_WINDOW_EVENT</td> <td>Event generated if the mouse has exited the window</td></tr>
* <tr><td>BUTTON_CLICK_EVENT</td> <td>Event generated if a mouse button has been clicked (Will always follow a ButtonUp event)</td></tr>
* <tr><td>BUTTON_DOWN_EVENT</td> <td>Event generated when a mouse button is pressed</td></tr>
* <tr><td>BUTTON_UP_EVENT</td> <td>Event generated when a mouse button is released</td></tr>
* </table>
*/
typedef enum {
NULL_EVENT, // For creating "NULL" mouse events
MOUSE_MOVE_EVENT, // Event generated if the mouse was moved
ENTER_WINDOW_EVENT, // Event generated if the mouse has entered the window
EXIT_WINDOW_EVENT, // Event generated if the mouse has exited the window
BUTTON_CLICK_EVENT, // Event generated if a mouse button has been clicked
// (Will always follow a ButtonUp event)
BUTTON_DOWN_EVENT, // Event generated when a mouse button is pressed
BUTTON_UP_EVENT // Event generated when a mouse button is released
} Event;
/**
* Constructor for a mouse event from a set of parameters.
*/
MouseEvent(const Event e, // Default values
const Button b = ANY_BUTTON,
const int x = -1, // Location not applicable
const int y = -1, // Location not applicable
const KeyModifiers km = KeyModifiers::ANY_MODIFIERS);
/**
* Copy constructor
*/
MouseEvent(const MouseEvent &me);
/**
* Default constructor
*/
MouseEvent();
/**
* Comparison operator for equality on events.
*/
bool operator==(const MouseEvent& rhs) const;
/**
* Comparison operator for inequality on events.
*/
bool operator!=(const MouseEvent& rhs) const;
////// Accessors //////
/**
* @return The actual event information for the mouse event.
*/
const Event getEvent() const;
/**
* @return Which button(s), if any, were involved with this event.
*/
const Button getButton() const;
/**
* @return The X coordinate that this event occurred, if relevant, otherwise returns -1.
*/
const int getX() const;
/**
* @return The Y coordinate that this event occurred, if relevant, otherwise returns -1
*/
const int getY() const;
/**
* @return set of modifiers active at the time of the event, if relevant.
*/
const KeyModifiers getModifiers() const;
private:
// Ignore these
Event event;
Button button;
int ex, ey;
KeyModifiers modifiers;
};
// Declare the existance of operator<< on mouse events
std::ostream& operator<<(std::ostream& s, const MouseEvent& event);
/******************************************************************************
* KeyboardEvents are generated whenever the user presses a key.
* KeyboardEvents operate in a manner very similar to that of {@link .MouseEvent}. So
* in the interest of brevity, I won't repeat much of the similar information.
* As before, they use default parameters, so the user only need specify as
* much detail as they have interest in matching.
*
* <p>As before it is also, possible to simply extract the pertinent information
* from an event using the accessor membor fuctions.
*
* <p>So for example if the user simply wants to see if the "G" key has been
* pressed they can do the following:
*
* <pre>
* if(KeyboardEvent('g') == some_event)
* // do something
* </pre>
*
* <p>Note, that if they wanted a capital G they should do the following:
*
* <pre>
* if(KeyboardEvent('G') == some_event)
* // do something
* </pre>
*
* <p>rather than
*
* <pre>
* if(KeyboardEvent('g', KeyModifiers::SHIFT) == some_event)
* // do something
* </pre>
*
* <p>One final example would be if the user wants to detect if the Alt and
* Escape keys have been pressed simultaneously they would do:
*
* <pre>
* if(KeyboardEvent(NamedKey::ESCAPE, KeyModifiers::ALT) == some_event)
* // do something else
* </pre>
*
* <p>Note that on some platforms, certain keyboard and modifier combinations
* will a) be trapped by the operating system/window manager and will not be
* reported as having taken place or b) correspond to another ASCII value
* for example Control-A under Unix/X11 will not map to A with a control
* modifier
*****************************************************************************/
class KeyboardEvent {
public:
/**
* Constructor for a keyboard event from a pair of parameters.
*/
KeyboardEvent(const int key, // Default value
const KeyModifiers km = KeyModifiers::ANY_MODIFIERS);
KeyboardEvent(const KeyboardEvent &ke);
KeyboardEvent();
/**
* Comparison operators for equality on keyboard events
*/
bool operator==(const KeyboardEvent& rhs) const;
/**
* Comparison operators for inequality on keyboard events
*/
bool operator!=(const KeyboardEvent& rhs) const;
////// Accessors //////
/**
* Obtain the integer value cooresponding to the event
*/
const int getValue() const;
/**
* Obtain the set of modifers active at the time of the event
*/
const KeyModifiers getModifiers() const;
private:
// Ignore these
int value;
KeyModifiers modifiers;
};
// Declare the existance of operator<< on keyboard events
std::ostream& operator<<(std::ostream& s, const KeyboardEvent& event);
/******************************************************************************
* The NamedKey class acts as a namespace for constants that
* correspond to keys that do not have a simple ASCII representation.
*
* <p>So for example, if you wanted the value that corresponds to the
* letter A you would use 'A', since it can be represented using a displable
* ASCII character. If you wanted the value that corresponds to the left
* arrow key, you would use NamedKey::LEFTARROW.
*****************************************************************************/
class NamedKey {
public:
////// Non-displayable ASCII characters //////
static const int BACKSPACE;
static const int ENTER;
static const int ESCAPE;
static const int DELETE_KEY;
////// Function keys //////
static const int FUNCTION_1;
static const int FUNCTION_2;
static const int FUNCTION_3;
static const int FUNCTION_4;
static const int FUNCTION_5;
static const int FUNCTION_6;
static const int FUNCTION_7;
static const int FUNCTION_8;
static const int FUNCTION_9;
static const int FUNCTION_10;
static const int FUNCTION_11;
static const int FUNCTION_12;
////// Arrow keys //////
static const int LEFT_ARROW;
static const int UP_ARROW;
static const int RIGHT_ARROW;
static const int DOWN_ARROW;
////// Other keys //////
static const int PAGE_UP;
static const int PAGE_DOWN;
static const int HOME;
static const int END;
static const int INSERT;
private:
//// Ignore ////
static const int BASE;
static const int LAST;
// Should not be able to create an instance of NamedKey
NamedKey() { };
friend class KeyboardEvent;
};
/******************************************************************************
* The Color class is used by the system to represent color information
* (of all things). The default color object is simply black, but it is also
* possible to construct a color by specifying RGB (red, green, blue) and
* RGBA (red, green, blue, alpha) component values. The alpha channel
* information is use to carry information about the opacity of the color.
* It is possible that your renderer may not support this capability, in
* which case it is simply ignored.
*
* <P>Currently, the internal representation of colors is unsigned characters,
* and the external representation uses integers. This is not completely
* satisfactory, because the user can create colors using invalid components.
* Currently, component values are clamped between 0 and 255 and issues a
* warning message when an out of bounds color is supplied. In future releases
* it may be desirable to use an internal and external representation that
* will more closely match. The internal representation can be changed to
* use integers, but then the end user would have to use negative numbers to
* specify some values, which is not entirely intutitive. Floating point
* values have the same sort of problem.
*****************************************************************************/
class Color {
public:
/**
* Construct an empty color (which is by default, fully opaque black)
*/
Color();
/**
* Construct a completely opaque color from three component hues
*/
Color(int red, int green, int blue);
/**
* Construct a color from the three component hues and an alpha channel.
* This may be used to provide opacity information to the renderer.
*/
Color(int red, int green, int blue, int alpha);
/**
* Comparison operator for equality on color objects
*/
bool operator==(const Color& rhs) const;
/**
* Comparison operator for inequality on color objects
*/
bool operator!=(const Color& rhs) const;
////// Accessors //////
// Obtain the specified component value
int getRed() const { return static_cast<int>(red); }
int getGreen() const { return static_cast<int>(green); }
int getBlue() const { return static_cast<int>(blue); }
int getAlpha() const { return static_cast<int>(alpha); }
////// Mutators //////
// Modify the specified component value
void setRed (int value) { red = checkValue(value, __RED); }
void setGreen(int value) { green = checkValue(value, __GREEN); }
void setBlue (int value) { blue = checkValue(value, __BLUE); }
void setAlpha(int value) { alpha = checkValue(value, __ALPHA); }
////// Some predefined colors ////////
static const Color BLACK;
static const Color WHITE;
static const Color RED;
static const Color GREEN;
static const Color BLUE;
/* CPPDOC_BEGIN_EXCLUDE */
private:
// Ignore these
unsigned char red, green, blue, alpha;
typedef enum { __RED, __GREEN, __BLUE, __ALPHA } ComponentName;
std::string ComponentNameToString(ComponentName cn);
unsigned char checkValue(int value, ComponentName cn);
/* CPPDOC_END_EXCLUDE */
};
// Declare the existance of operator<< on Color objects
std::ostream& operator<<(std::ostream& s, const Color& color);
/******************************************************************************
* The Image class
*****************************************************************************/
class Image {
public:
/**
* Image types currently supported
*
* <table>
* <tr><td>JPEG</td> <td>JPEG Images</td></tr>
* <tr><td>PNG</td> <td>PNG Images</td></tr>
* <tr><td>SCREEN</td><td>An image created from a region in a window</td></tr>
* </table>
*/
typedef enum {
JPEG, // JPEG images
PNG, // PNG images
SCREEN, // An image created from region in a window
NO_TYPE,
} Type;
Image(const std::string &file, const Type type);
Image();
~Image();
/**
* Copy constructor
*/
Image(const Image& image);
/**
* Assignment operator
*/
Image& operator=(const Image &rhs);
/**
* Comparison operator for equality on images
*/
bool operator==(const Image& rhs) const;
/**
* Comparison operator for inequality on images
*/
bool operator!=(const Image& rhs) const;
/**
* Save this image to a file of the specified type.
*/
void save(const std::string &file, const Type type) const;
////// Accessors //////
/**
* Get the width of the image
*/
int getWidth() const;
/**
* Get the height of the image
*/
int getHeight() const;
/**
* Get the type of the image
*/
Type getType() const;
/**
* Class function for checking to see whether an Image exists
*/
static bool checkImage(const std::string &file, const Type type);
/**
* Copy out a sub-portion of the image and return it.
* This is very useful for creating an animation in a single image and then
* chopping it into an array of sprites in your program.
*/
Image subImage(int x,int y,int w,int h);
protected:
/* CPPDOC_BEGIN_EXCLUDE */
//// Ignore these ////
int width, height;
int imagehandle;
Type type;
Image(int handle, int width, int height, Type type);
friend class DaemonImp;
friend class RENDERER;
// this should be unnecessary
friend class EditableImage;
/* CPPDOC_END_EXCLUDE */
};
// Declare the existance of operator<< on keyboard events
std::ostream& operator<<(std::ostream& s, const Image& image);
/******************************************************************************
* Images that can be manipulated at the pixel level. EditableImages should
* be used when you want to either do lots and lots of pixel manipulation quickly
* or be able to modify other images. You can use EditableImages just as you would
* Images, just that you can manipulate pixels.
* @see .Window#drawImage
* @since 2.1.4a
*****************************************************************************/
class EditableImage : public Image {
public:
/**
* Copy constructor
*/
EditableImage(const EditableImage &image);
/**
* Cast Image object up to an EditableImage
*/
EditableImage(const Image &image);
/**
* Constructor to make an image that's width x height.
*/
EditableImage(int width, int height);
~EditableImage();
/**
* Assignment operator. As always, assignment is done via references,
* so this is a "shallow" copy of the image. Changes to either the left-hand-side or
* right-hand-side will affect the other.
* @see #clone
*/
EditableImage &operator=(const EditableImage &image);
/**
* gets the color of the pixel at (x,y)
*/
Color getPixel(int x, int y);
/**
* sets the color of the pixel at (x,y)
*/
void setPixel(int x, int y, const Color &c);
/**
* sets the color of the pixel at (x,y)
*/
void setPixel(int x, int y, unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255);
/**
* return a "deep" copy of this image
*/
EditableImage clone();
protected:
/* CPPDOC_BEGIN_EXCLUDE */
EditableImage clone(int imagehandle, int width, int height);
EditableImage(int imagehandle, int width, int height);
unsigned char *data;
bool editable;
int dataheight, datawidth;
void *imageinstance;
/* CPPDOC_END_EXCLUDE */
};
/******************************************************************************
* Class for representing fonts. A new font object can be created given
* the location of a TrueType font file, and a point size.
*
* <p>For example to create a font for 20 point Arial, the user would do the
* following:
*
* <pre>
* Font myArial("/where/I/keep/my/fonts/arial.ttf", 20);
* </pre>
*
* <P>The string for specifing the font location is dependent upon the platform
* used.
*
* <P>The user may also use the mutators to alter the font after creation.
* <P><B>Update:</B> You can now also create a font using one of the built-in fonts. See {@link #Font(int,int)}.
*****************************************************************************/
class Font {
public:
/**
* Constructor for creating fonts from a TrueType font file. <B>Warning:</B> Not supported on MacOS.
*/
Font(const std::string &face, const int pointsize);
/**
* Constructor for creating fonts from one of the builtin fonts.
* @see #ROMAN
* @see #MONO_ROMAN
* @see #HELVETICA
* @see #TIMES
* @since 2.10
*/
Font(int fontID, int pointsize);
~Font();
/**
* Copy constructor
*/
Font(const Font& font);
/**
* Assignment operator
*/
Font& operator=(const Font &rhs);
/**
* Comparison operator for equality on fonts
*/
bool operator==(const Font& rhs) const;
/**
* Comparison operator for inequality on fonts
*/
bool operator!=(const Font& rhs) const;
////// Accessors //////
std::string getFace() const;
int getPointSize() const;
////// Mutators //////
void setFace(const std::string &face);
void setPointSize(const int pointsize);
/**
* Class function for checking to see whether a font exists
*/
static bool checkFont(const std::string &face, const int pointsize);
/**
* Get the dimensions of the specified text. Put the results in width and height.
* @param text [in] Text to measure
* @param width [out] Width of the text.
* @param height [out] Height of the text.
* @since 2.1.2
*/
void getStringSize(const std::string &text, int &width, int &height);
/**
* stroked font, can be used at any resolution
*/
static const int ROMAN;
/**
* stroked font, can be used at any resolution
*/
static const int MONO_ROMAN;
/**
* bitmapped fonts, must be used at specific sizes;
* helvetica sizes: 10,12, 18.
*/
static const int HELVETICA;
/**
* bitmapped fonts, must be used at specific sizes;
* times sizes: 10, 24.
*/
static const int TIMES;
private:
////// Ignore //////
std::string name;
int size;
int fonthandle;
friend class DaemonImp;
};
// Declare the existance of operator<< on keyboard events
std::ostream& operator<<(std::ostream& s, const Font& font);
/******************************************************************************
* Style objects are used to encapsulate several pieces of style information
* to be passed to drawing calls. At the most basic level styles store color
* information, but they also contain information about line-widths,
* the type of raster operation to use when rendering, and what pattern to use
* when drawing lines and outline primatives.
*
* <P>So if you want to draw a green line you could create a style like so:
*
* <pre>
* Style mystyle = Style(Color::GREEN);
* </pre>
*
* <P>or
*
* <pre>
* Style mystyle = Style(Color(0,0,255));
* </pre>
*
* <P>However, when you draw your line it will only be one pixel thick. If you
* want a thicker green line (3 pixels wide) you can do the following:
*
* <pre>
* Style mystyle = Style(Color::GREEN, 3);
* </pre>
*
* <P>In another situation you might want to create an rubber-banding box by
* XORing and outline rectangle, so you would create the following style:
*
* <pre>
* Style mystyle = Style(Color::BLUE, 2, Style::XOR_OP);
* </pre>
*
* <P>Patterns for lines, arcs, and curves are represented using 16 bits.
*****************************************************************************/
class Style {
private:
// Ignore
static std::vector<bool> defaultpattern;
public:
/**
* Possible raster operations
* <table>
* <tr><td>COPY_OP</td> <td>Simply draw the color, default behavior</td></tr>
* <tr><td>INVERT_OP</td> <td>Invert the drawing surface's color</td></tr>
* <tr><td>XOR_OP</td> <td>XOR drawing surface with color</td></tr>
* <tr><td>AND_OP</td> <td>AND drawing surface with color</td></tr>
* <tr><td>OR_OP</td> <td>OR drawing surface with color</td></tr>
* </table>
*/
typedef enum {
COPY_OP, // Simply draw the color, default behavior
INVERT_OP, // Invert the drawing surface's color
XOR_OP, // XOR drawing surface with color
AND_OP, // AND drawing surface with color
OR_OP // OR drawing surface with color
} RasterOp;
/**
* Construct a style from a set of parameters
*/
Style(Color col, // Default values
int lwidth = 1,
RasterOp rop = COPY_OP,
const std::vector<bool> &newpattern = defaultpattern);
Style(const Style &s);
Style &operator=(const Style& rhs);
/**
* Comparison operator for equality on style objects
*/
bool operator==(const Style& rhs) const;
/**
* Comparison operator for inequality on style objects
*/
bool operator!=(const Style& rhs) const;
////// Accessors //////
Color getColor() const;
int getLineWidth() const;
RasterOp getRasterOp() const;
std::vector<bool> getPattern() const;
unsigned short getPatternAsUShort() const;
////// Mutators //////
void setRasterOp(RasterOp rop);
void setColor(Color col);
void setLineWidth(int value);
void flipPatternBit(int position);
void setPattern(const std::vector<bool> &newpattern);
////// Some predefined styles //////
static const Style BLACK;
static const Style WHITE;
static const Style RED;
static const Style GREEN;