OSDN Git Service

cache
[psychlops/cpp.git] / psychlops / core / devices / psychlops_io_display.h
1 /*
2  *  psychlops_io_display.h
3  *  Psychlops Standard Library (Universal)
4  *
5  *  Last Modified 2009/06/19 by Kenchi HOSOKAWA
6  *  (C) 2009 Kenchi HOSOKAWA, Kazushi MARUYA, Takao SATO
7  */
8
9 #ifndef HEADER_PSYCHLOPS_DEVICES_DISPLAY
10 #define HEADER_PSYCHLOPS_DEVICES_DISPLAY
11
12
13 #include <sstream>
14 #include <vector>
15 #include <string>
16 #include <memory>
17 #include "../graphic/psychlops_g_shape.h"
18 #include "../graphic/psychlops_g_font.h"
19
20 namespace Psychlops {
21
22
23         class APIDisplayProperties;
24         class APICanvasPropertiesFullscreen;
25         class APICanvasPropertiesWindow;
26         class Canvas;
27         class Display {
28                 friend class Canvas;
29                 friend class APICanvasProperties;
30                 friend class APICanvasPropertiesFullscreen;
31                 friend class APICanvasPropertiesWindow;
32                 friend class APIDisplayProperties;
33
34         ////////////////        Body of expression of Display devices   ////////////////
35         private:
36                 mutable std::auto_ptr<APIDisplayProperties> api_;
37                 Display(APIDisplayProperties *);
38
39         public:
40                 int width, height;
41                 int color_depth;
42                 double refresh_rate;
43                 std::string name;
44                 Rectangle area;
45
46                 Display();
47                 Display(const Display&);
48                 ~Display();
49                 Display& operator =(const Display&);\r
50                 void refreshInfo();
51
52                 static const std::vector<Display> list();
53                 //static const Display main();
54                 struct PROPERTY_DISPLAY\r
55                 {\r
56                         private:\r
57                         int N;\r
58                         public:\r
59                         PROPERTY_DISPLAY();\r
60                         PROPERTY_DISPLAY(int n);\r
61                         operator Display() const;
62                         int getWidth() const;
63                         int getHeight() const;
64                         int getColorDepth() const;
65                         double getRefreshRate() const;
66                         Rectangle getArea() const;\r
67                 };
68                 static const PROPERTY_DISPLAY primary;
69                 static const PROPERTY_DISPLAY secondary;
70
71
72         ////////////////        Maybe replaced by Drawable::prime       ////////////////
73         public:
74                 static Canvas *the_canvas;
75
76
77         ////////////////        Wrapper of Canvas       ////////////////
78         public:
79                 static void flip(int and_wait_N_vsyncs = 1);
80                 static void flipAndWait(int and_wait_N_vsyncs);
81                 static void flipAfter(int frame);
82                         //      obsolete
83                         static void displayFrame(void);
84                         static void displayFrameWithWait(int num_frames_to_wait);
85 //              static void clear(Canvas::TargetSurface target=Canvas::BACK);
86 //              static void clear(Color col, Canvas::TargetSurface target=Canvas::BACK);
87                 enum TargetSurface { ALL=1, BACK=2, FRONT=4 };
88                 static void clear(TargetSurface target=BACK);
89                 static void clear(Color col, TargetSurface target=BACK);
90                 static void setClearColor(Color col);
91
92                 ////////        Drawing Graphical Elements   ////////
93                 static void copy(Rectangle &source, const Rectangle &target, bool doesdeletesource=false, const Color &delcol=Color::black);
94                 static void pix(const double x, const double y, const Color &col);
95                 static void pix(const Point &po, const Color &col);
96                 static void pix(int dotsCnt, double x[], double y[], const Color col[]);
97                 static void pix(int dotsCnt, double x[], double y[], const Color &col);
98                 static void pix(int dotsCnt, const Point po[], const Color col[]);
99                 static void line(double x1, double y1, double x2, double y2, const Color &col);
100                 static void line(const Point &po1, const Point &po2, const Color &col);
101                 static void line(double x1, double y1, double x2, double y2, const Stroke &strk);
102                 static void line(const Point &po1, const Point &po2, const Stroke &strk);
103                 static void rect(const Rectangle &rect, const Color &col);
104                 static void rect(const int nRects, const Rectangle *rec, const Color &col);
105                 static void rect(const int nRects, const Rectangle *rec, const Color *col);
106                 static void rect(const unsigned int nRectsBegin, const unsigned int nRectsEnd, const Rectangle *rec, const Color *col);
107                 static void rect(const Rectangle &rect, const Stroke &strk);
108                 static void rect(const int nRects, const Rectangle *rec, const Stroke &strk);
109                 static void rect(const int nRects, const Rectangle *rec, const Stroke *strk);
110                 static void rect(const unsigned int nRectsBegin, const unsigned int nRectsEnd, const Rectangle *rec, const Stroke *strk);
111                 static void oval(Rectangle &rect, const Color &col);
112                 static void oval(Rectangle &rect, const Stroke &strk);
113                 static void ellipse(Rectangle &rect, const Color &col);\r
114                 static void ellipse(Rectangle &rect, const Stroke &strk);\r
115                 static void ellipse(Ellipse &ell, const Color &col);\r
116                 static void ellipse(Ellipse &ell, const Stroke &strk);\r
117                 static void polygon(Point *vertices, unsigned int nVertices, const Color &col);
118                 static void polygon(Point *vertices, unsigned int nVertices, const Stroke &strk);
119                 static void drawPixel(double x, double y, const Color &col);
120                 static void drawPixel(const Point &po, const Color &col);
121                 static void drawPixel(int dotsCnt, double x[], double y[], const Color col[]);
122                 static void drawPixel(int dotsCnt, double x[], double y[], const Color &col);
123                 static void drawPixel(int dotsCnt, const Point po[], const Color col[]);
124                 static void drawLine(double x1, double y1, double x2, double y2, const Color &col);
125                 static void drawLine(const Point &po1, const Point &po2, const Color &col);
126                 static void fillRect(const Rectangle &rect, const Color &col);
127                 static void fillRect(const int nRects, const Rectangle *rec, const Color &col);
128                 static void fillRect(const int nRects, const Rectangle *rec, const Color *col);
129                 static void fillRect(const unsigned int nRectsBegin, const unsigned int nRectsEnd, const Rectangle *rec, const Color *col);
130                 static void fillOval(Rectangle &rect, const Color &col);
131                 static void drawPolygon(Point *vertices, unsigned int nVertices, const Color &col);
132
133                 static void copy(const Rectangle &source, const Rectangle &target, bool doesdeletesource=false, const Color &delcol=Color::black);
134                 static void to(Image &img, const Rectangle &srcrect);
135 //              static void to(Image &img, const Rectangle &srcrect, const Rectangle &tgtrect);
136                 static void drawImage(const Image &img);
137                 static void drawImage(const Image &img, const double left, const double top);
138
139                 ////////        Utilities   ////////
140
141                 //      FPS Checker
142                 static void displayFPS();
143                 static void initFPS();
144                 static void watchFPS();
145                 static void ignoreFPS();
146                 static void showFPS();
147                 static void hideFPS();
148                 static int lastFailedFrames();
149                         //      obsolete
150                         static void enableFPSChecker(); //      obsolete
151                         static void disableFPSChecker();        //      obsolete
152                         static void enableDisplayingFPS();      //      obsolete
153                         static void disableDisplayingFPS();     //      obsolete
154
155                 static void progressbar(Rectangle &inrect, Color fillcol=Color::blue, Color empcol=Color(0.25,0.25,0.25));
156                 static void progressbar(double l, double t, double r, double b, Color fillcol=Color::blue, Color empcol=Color(0.25,0.25,0.25));
157                 static void progressbar(double percentage);
158 //#ifdef __GNUC__
159                 template <typename X> static void progressbar(X now, X max) { progressbar((double)now/(double)max); }
160                 private:
161                 static void var_(const std::string number, const double x, const double y, const Color &col=Color::white, const bool fillForward = false);
162                 public:
163                 template <typename X> static void var(X val, double x, double y, const Color &col=Color::white, bool fillForward = false) {
164                         std::stringstream var_buffer_("");
165                         var_buffer_ << val;
166                         std::string str = var_buffer_.str();
167                         var_(str, x, y, col, fillForward);
168                 }
169                 //template <typename X> static void var(const X val, const double x, const double y, const Color col=Color::white, const bool fillForward=false) { var(val, x, y, col, fillForward); };
170                 template <typename X> static void checkVar(const X val, const double x, const double y, const Color col=Color::white, const bool fillForward=false) { var(val, x, y, col, fillForward); }
171                 template <typename X> static void varcheck(const X val, const double x, const double y, const Color col=Color::white, const bool fillForward=false) { var(val, x, y, col, fillForward); }
172 /*
173                 template <typename X> static void progressbar(X now, X max) { the_canvas->progressbar((double)now/(double)max); }
174                 template <typename X> static void var(const X val, const double x, const double y, const Color col=Color::white, const bool fillForward=false) { the_canvas->var(val, x, y, col, fillForward); };
175                 template <typename X> static void checkVar(const X val, const double x, const double y, const Color col=Color::white, const bool fillForward=false) { the_canvas->var(val, x, y, col, fillForward); }
176                         //      obsolete
177                         template <typename X> static void varcheck(const X val, const double x, const double y, const Color col=Color::white, const bool fillForward=false) { the_canvas->var(val, x, y, col, fillForward); }
178 */
179
180
181                 enum { TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT };
182                 static int msg(const char* string, const double x, const double y, const Color col=Color::white, const int align=TEXT_ALIGN_LEFT, const double max_width=-1.0);
183                 static int msg(const std::string &string, const double x, const double y, const Color col=Color::white, const int align=TEXT_ALIGN_LEFT, const double max_width=-1.0);
184                 static int msg(Letters &letters, const double x, const double y, const Color &col=Color::white, const int horiz_align=TEXT_ALIGN_LEFT, const double max_width=-1.0);
185                 static int msg(const std::wstring &string, const double x, const double y, const Color &col=Color::white, const int horiz_align=Letters::TEXT_ALIGN_LEFT, const double max_width=-1.0);
186                         //      obsolete alias
187                         static int showMessage(const char* string, const double x, const double y, const Color col=Color::white, const int align=TEXT_ALIGN_LEFT, const double max_width=-1.0);
188                         static int showMessage(const std::string &string, const double x, const double y, const Color col=Color::white, const int align=TEXT_ALIGN_LEFT, const double max_width=-1.0);
189                         static void message(const char* string, const double x, const double y, const Color col=Color::white);  //      obsolete
190
191
192                 static void setGammaValue(const double gamma_r, const double gamma_g, const double gamma_b);
193                 static void setGammaTable(const std::vector<double> &table_r, const std::vector<double> &table_g, const std::vector<double> &table_b);
194
195
196                 ////////        Properties      ////////
197                 static int getWidth();
198                 static int getHeight();
199                 static int getColorDepth();
200                 static double getRefreshRate();
201                 static double getHcenter();
202                 static double getVcenter();
203                 static Point getCenter();
204 /*              class READ_ONLY_X_ : public Canvas::READ_ONLY_<double> { public: operator double(); };
205                 class READ_ONLY_Y_ : public Canvas::READ_ONLY_<double> { public: operator double(); };
206                 class READ_ONLY_CENTER_ : public Canvas::READ_ONLY_POINT_ { public: READ_ONLY_X_ x; READ_ONLY_Y_ y; operator Point(); };
207                 static READ_ONLY_CENTER_ center;
208                 class READ_ONLY_REFRESH_ : public Canvas::READ_ONLY_<double> { public: operator double(); };
209                 static READ_ONLY_REFRESH_ RefreshRate;
210 */
211         };
212
213
214 }       /*      <- namespace Psycholops         */
215
216
217 #endif