00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef ARCHON_UTILITIES_WINDOW_H
00021 #define ARCHON_UTILITIES_WINDOW_H
00022
00023 #include <string>
00024
00025 #include <archon/util/exception.H>
00026 #include <archon/util/ref.H>
00027 #include <archon/util/window_keys.H>
00028
00029 namespace Archon
00030 {
00031 namespace Utilities
00032 {
00033 using namespace std;
00034
00035 class Window
00036 {
00037 public:
00038 struct KeyboardHandler
00039 {
00040 virtual void press(Key, unsigned long milliSecondTime) = 0;
00041 virtual void release(Key) = 0;
00042 virtual ~KeyboardHandler() {}
00043 };
00044
00045 struct MouseHandler
00046 {
00047 virtual void press(unsigned button, unsigned x, unsigned y, unsigned long milliSecondTime) = 0;
00048 virtual void release(unsigned button, unsigned x, unsigned y) = 0;
00049 virtual void motion(unsigned xAbs, unsigned yAbs, int xRel, int yRel) = 0;
00050 virtual ~MouseHandler() {}
00051 };
00052
00053 struct WindowHandler
00054 {
00055 virtual void quit() = 0;
00056 virtual ~WindowHandler() {}
00057 };
00058
00059 enum DrawMode { set, add, sub };
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 class MouseCursor: public virtual RefObjectBase
00112 {
00113 friend class Window;
00114 void *data;
00115 MouseCursor(const char *image[]);
00116 public:
00117 ~MouseCursor();
00118 };
00119
00120 private:
00121 void *dataHolder;
00122 DrawMode drawMode;
00123 unsigned long drawColor;
00124 Key *keyXlat;
00125 KeyboardHandler *keyboardHandler;
00126 MouseHandler *mouseHandler;
00127 WindowHandler *windowHandler;
00128 void *defaultMouseCursor;
00129 int mouseX;
00130 int mouseY;
00131
00132 unsigned long combineRGBA(unsigned r, unsigned g,
00133 unsigned b, unsigned a);
00134
00135 void initializeKeyXlat();
00136
00137 public:
00145 Window(unsigned width,
00146 unsigned height,
00147 unsigned bitsPerPixel = 24,
00148 bool fullScreen = false,
00149 bool openGlSupport = false,
00150 KeyboardHandler * = 0,
00151 MouseHandler * = 0,
00152 WindowHandler * = 0);
00153 ~Window();
00154
00155 Ref<MouseCursor> newMouseCursor(const char *image[]);
00156 void setMouseCursor(Ref<MouseCursor>);
00157 void setDefaultMouseCursor();
00158 void showMouseCursor();
00159 void hideMouseCursor();
00160
00161
00162
00163 int getMouseX() const { return mouseX; }
00164 int getMouseY() const { return mouseY; }
00165
00166 void swapBuffers();
00167
00168 void discardEventQueue();
00169 void executeEventQueue(unsigned long milliSecondTime);
00170
00171 unsigned getWidth() const;
00172 unsigned getHeight() const;
00173
00174 void setDrawMode(DrawMode mode) { drawMode = mode; }
00175 void setColor(unsigned red,
00176 unsigned green,
00177 unsigned blue,
00178 unsigned alpha = 255)
00179 {
00180 drawColor = combineRGBA(red, green, blue, alpha);
00181 }
00182
00183 struct Update
00184 {
00185 Update(Window *);
00186 ~Update();
00187
00188 void clear();
00189
00190
00191
00192 void drawPoint(unsigned x, unsigned y)
00193 {
00194 if(x >= width || y >= height)
00195 ARCHON_THROW1(ArgumentException,
00196 "coordinates out of range");
00197 drawPoint(x, y, drawMode, drawColor);
00198 }
00199
00200 void drawPoint(unsigned x, unsigned y, DrawMode mode)
00201 {
00202 if(x >= width || y >= height)
00203 ARCHON_THROW1(ArgumentException,
00204 "coordinates out of range");
00205 drawPoint(x, y, mode, drawColor);
00206 }
00207
00208 void drawPoint(unsigned x, unsigned y, DrawMode mode,
00209 unsigned red, unsigned green,
00210 unsigned blue, unsigned alpha = 255)
00211 {
00212 if(x >= width || y >= height)
00213 ARCHON_THROW1(ArgumentException,
00214 "coordinates out of range");
00215 drawPoint(x, y, mode, frame->combineRGBA(red, green, blue, alpha));
00216 }
00217
00218
00219
00220 void drawLine(unsigned x1, unsigned y1, unsigned x2, unsigned y2)
00221 {
00222 if(x1 >= width || y1 >= height || x2 >= width || y2 >= height)
00223 ARCHON_THROW1(ArgumentException,
00224 "coordinates out of range");
00225 drawLine(x1, y1, x2, y2, drawMode, drawColor);
00226 }
00227
00228 void drawLine(unsigned x1, unsigned y1, unsigned x2, unsigned y2,
00229 DrawMode mode)
00230 {
00231 if(x1 >= width || y1 >= height || x2 >= width || y2 >= height)
00232 ARCHON_THROW1(ArgumentException,
00233 "coordinates out of range");
00234 drawLine(x1, y1, x2, y2, mode, drawColor);
00235 }
00236
00237 void drawLine(unsigned x1, unsigned y1, unsigned x2, unsigned y2,
00238 unsigned red, unsigned green,
00239 unsigned blue, unsigned alpha = 255)
00240 {
00241 if(x1 >= width || y1 >= height || x2 >= width || y2 >= height)
00242 ARCHON_THROW1(ArgumentException,
00243 "coordinates out of range");
00244 drawLine(x1, y1, x2, y2, drawMode,
00245 frame->combineRGBA(red, green, blue, alpha));
00246 }
00247
00248 private:
00249 const unsigned bytesPerPixel;
00250 const unsigned bytesPerScanline;
00251 void *const pixels;
00252 const unsigned width;
00253 const unsigned height;
00254 const DrawMode drawMode;
00255 const unsigned long drawColor;
00256 Window *const frame;
00257
00258 void drawPoint(unsigned x, unsigned y,
00259 DrawMode mode, unsigned long color);
00260 void drawLine(unsigned x1, unsigned y1, unsigned x2, unsigned y2,
00261 DrawMode mode, unsigned long color);
00262 };
00263
00264 friend struct Update;
00265 };
00266 }
00267 }
00268
00269 #endif // ARCHON_UTILITIES_WINDOW_H