00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00035
00036 #ifndef GROOVX_GFX_CANVAS_H_UTC20050626084023_DEFINED
00037 #define GROOVX_GFX_CANVAS_H_UTC20050626084023_DEFINED
00038
00039 #include "nub/object.h"
00040 #include "nub/ref.h"
00041
00042 namespace rutz
00043 {
00044 class file_pos;
00045 class fstring;
00046 template <class T> class dynamic_block;
00047 }
00048
00049 namespace geom
00050 {
00051 template <class V> class box;
00052 template <class V> class rect;
00053 template <class V> class vec2;
00054 template <class V> class vec3;
00055 class txform;
00056 }
00057
00058 namespace media
00059 {
00060 class bmap_data;
00061 }
00062
00063 class GxRasterFont;
00064 class GxVectorFont;
00065
00066 namespace Gfx
00067 {
00068 class Canvas;
00069 class RgbaColor;
00070
00072
00079
00080
00081 class Canvas : public virtual nub::object
00082 {
00083 public:
00085 virtual ~Canvas() throw();
00086
00088
00089
00090
00092
00093
00095 geom::vec2<double> screenFromWorld2(const geom::vec2<double>& world_pos) const;
00096
00098 virtual geom::vec3<double> screenFromWorld3(const geom::vec3<double>& world_pos) const = 0;
00099
00101 virtual geom::vec3<double> worldFromScreen3(const geom::vec3<double>& screen_pos) const = 0;
00102
00104 geom::rect<int> screenBoundsFromWorldRect(const geom::rect<double>& world_pos) const;
00105
00107 virtual geom::rect<int> getScreenViewport() const = 0;
00108
00109
00111 virtual bool isRgba() const = 0;
00112
00114 virtual bool isColorIndex() const = 0;
00115
00117 virtual bool isDoubleBuffered() const = 0;
00118
00120 virtual unsigned int bitsPerPixel() const = 0;
00121
00123 virtual void throwIfError(const char* where,
00124 const rutz::file_pos& pos) const = 0;
00125
00126
00127
00129 typedef void (Canvas::* Manip)(const char*);
00130
00132 typedef void (Canvas::* Unmanip)();
00133
00134 #ifndef MEMBER_TEMPLATES_BROKEN
00135
00137 template <Manip doit, Unmanip undoit>
00138 class Saver
00139 {
00140 public:
00143 Saver(Canvas& canvas, const char* comment="") :
00144 itsCanvas(canvas)
00145 { (itsCanvas.*doit)(comment); }
00146
00149 template <class Arg>
00150 Saver(Canvas& canvas, Arg a, const char* comment="") :
00151 itsCanvas(canvas)
00152 { (itsCanvas.*doit)(a, comment); }
00153
00155 ~Saver()
00156 { (itsCanvas.*undoit)(); }
00157
00158 private:
00159 Saver(const Saver&);
00160 Saver& operator=(const Saver&);
00161
00162 Canvas& itsCanvas;
00163 };
00164
00165 #else
00166
00167
00168
00169 #define SAVER_CLASS(name, doit, undoit) \
00170 class name \
00171 { \
00172 public: \
00173 name(Canvas& canvas, const char* comment="") : \
00174 itsCanvas(canvas) \
00175 { itsCanvas.doit(comment); } \
00176 \
00177 template <class Arg> \
00178 name(Canvas& canvas, Arg a, const char* comment="") : \
00179 itsCanvas(canvas) \
00180 { itsCanvas.doit(a, comment); } \
00181 \
00182 ~name() \
00183 { itsCanvas.undoit(); } \
00184 \
00185 private: \
00186 name(const name&); \
00187 name& operator=(const name&); \
00188 \
00189 Canvas& itsCanvas; \
00190 }
00191 #endif
00192
00194
00195
00196
00198
00200 virtual void pushAttribs(const char* comment="") = 0;
00201
00203 virtual void popAttribs() = 0;
00204
00206 virtual void drawOnFrontBuffer() = 0;
00207
00209 virtual void drawOnBackBuffer() = 0;
00210
00212 virtual void setColor(const Gfx::RgbaColor& rgba) = 0;
00214 virtual void setClearColor(const Gfx::RgbaColor& rgba) = 0;
00215
00217 virtual void setColorIndex(unsigned int index) = 0;
00219 virtual void setClearColorIndex(unsigned int index) = 0;
00220
00222 virtual void swapForeBack() = 0;
00223
00226 virtual void setPolygonFill(bool on) = 0;
00227
00229 virtual void setPointSize(double size) = 0;
00230
00232 virtual void setLineWidth(double width) = 0;
00233
00235 virtual void setLineStipple(unsigned short bit_pattern = 0xFFFF) = 0;
00236
00238 virtual void enableAntialiasing() = 0;
00239
00241
00242
00243
00245
00247 virtual void viewport(int x, int y, int w, int h) = 0;
00248
00250 virtual void orthographic(const geom::rect<double>& bounds,
00251 double zNear, double zFar) = 0;
00252
00254 virtual void perspective(double fovy, double aspect,
00255 double zNear, double zFar) = 0;
00256
00258
00259
00260
00262
00264 virtual void pushMatrix(const char* comment="") = 0;
00265
00267 virtual void popMatrix() = 0;
00268
00270 virtual void translate(const geom::vec3<double>& v) = 0;
00272 virtual void scale(const geom::vec3<double>& v) = 0;
00274 virtual void rotate(const geom::vec3<double>& v, double degrees) = 0;
00275
00277 virtual void transform(const geom::txform& tx) = 0;
00278
00280 virtual void loadMatrix(const geom::txform& tx) = 0;
00281
00283
00284
00285
00287
00289 virtual void drawPixels(const media::bmap_data& data,
00290 const geom::vec3<double>& world_pos,
00291 const geom::vec2<double>& zoom) = 0;
00292
00294 virtual void drawBitmap(const media::bmap_data& data,
00295 const geom::vec3<double>& world_pos) = 0;
00296
00298 virtual void grabPixels(const geom::rect<int>& bounds,
00299 media::bmap_data& data_out) = 0;
00300
00302 virtual void clearColorBuffer() = 0;
00303
00305 virtual void clearColorBuffer(const geom::rect<int>& screen_rect) = 0;
00306
00308 virtual void drawRect(const geom::rect<double>& rect) = 0;
00309
00311 void drawRect(const geom::rect<double>& rect, bool filled);
00312
00314 virtual void drawBox(const geom::box<double>& box);
00315
00317 virtual void drawCircle(double inner_radius, double outer_radius, bool fill,
00318 unsigned int slices, unsigned int loops) = 0;
00319
00321 virtual void drawCylinder(double base_radius, double top_radius,
00322 double height, int slices, int stacks,
00323 bool fill) = 0;
00324
00326 virtual void drawSphere(double radius, int slices, int stacks,
00327 bool fill) = 0;
00328
00330 virtual void drawBezier4(const geom::vec3<double>& p1,
00331 const geom::vec3<double>& p2,
00332 const geom::vec3<double>& p3,
00333 const geom::vec3<double>& p4,
00334 unsigned int subdivisions);
00335
00337 virtual void drawBezierFill4(const geom::vec3<double>& center,
00338 const geom::vec3<double>& p1,
00339 const geom::vec3<double>& p2,
00340 const geom::vec3<double>& p3,
00341 const geom::vec3<double>& p4,
00342 unsigned int subdivisions);
00343
00345
00348 virtual void drawNurbsCurve
00349 (const rutz::dynamic_block<float>& knots,
00350 const rutz::dynamic_block<geom::vec3<float> >& pts);
00351
00352 virtual void beginPoints(const char* comment="") = 0;
00353 virtual void beginLines(const char* comment="") = 0;
00354 virtual void beginLineStrip(const char* comment="") = 0;
00355 virtual void beginLineLoop(const char* comment="") = 0;
00356 virtual void beginTriangles(const char* comment="") = 0;
00357 virtual void beginTriangleStrip(const char* comment="") = 0;
00358 virtual void beginTriangleFan(const char* comment="") = 0;
00359 virtual void beginQuads(const char* comment="") = 0;
00360 virtual void beginQuadStrip(const char* comment="") = 0;
00361 virtual void beginPolygon(const char* comment="") = 0;
00362
00364 enum VertexStyle
00365 {
00366
00367
00368 POINTS = 1,
00369 LINES = 2,
00370 LINE_STRIP = 3,
00371 LINE_LOOP = 4,
00372 TRIANGLES = 5,
00373 TRIANGLE_STRIP = 6,
00374 TRIANGLE_FAN = 7,
00375 QUADS = 8,
00376 QUAD_STRIP = 9,
00377 POLYGON = 10
00378 };
00379
00381 void begin(VertexStyle s, const char* comment="");
00382
00384 virtual void vertex2(const geom::vec2<double>& v) = 0;
00386 virtual void vertex3(const geom::vec3<double>& v) = 0;
00387
00389 virtual void end() = 0;
00390
00392 virtual void drawRasterText(const rutz::fstring& text,
00393 const GxRasterFont& font) = 0;
00394
00396 virtual void drawVectorText(const rutz::fstring& text,
00397 const GxVectorFont& font) = 0;
00398
00400 virtual void flushOutput() = 0;
00401
00403
00404 virtual void finishDrawing();
00405 };
00406
00407 #ifndef MEMBER_TEMPLATES_BROKEN
00408 #define BLOCK_TYPEDEF(name) \
00409 typedef Canvas::Saver<&Canvas::begin##name, &Canvas::end> name##Block
00410 #else
00411 #define BLOCK_TYPEDEF(name) \
00412 SAVER_CLASS(name##Block, begin##name, end)
00413 #endif
00414
00415 BLOCK_TYPEDEF(Points);
00416 BLOCK_TYPEDEF(Lines);
00417 BLOCK_TYPEDEF(LineStrip);
00418 BLOCK_TYPEDEF(LineLoop);
00419 BLOCK_TYPEDEF(Triangles);
00420 BLOCK_TYPEDEF(TriangleStrip);
00421 BLOCK_TYPEDEF(TriangleFan);
00422 BLOCK_TYPEDEF(Quads);
00423 BLOCK_TYPEDEF(QuadStrip);
00424 BLOCK_TYPEDEF(Polygon);
00425
00426 #undef BLOCK_TYPEDEF
00427
00428 #ifndef MEMBER_TEMPLATES_BROKEN
00429
00432 typedef Canvas::Saver<&Canvas::pushMatrix, &Canvas::popMatrix>
00433 MatrixSaver;
00434
00437 typedef Canvas::Saver<&Canvas::pushAttribs, &Canvas::popAttribs>
00438 AttribSaver;
00439
00440 #else
00441 SAVER_CLASS(MatrixSaver, pushMatrix, popMatrix);
00442 SAVER_CLASS(AttribSaver, pushAttribs, popAttribs);
00443 #endif
00444
00445 }
00446
00447 static const char __attribute__((used)) vcid_groovx_gfx_canvas_h_utc20050626084023[] = "$Id: canvas.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00448 #endif // !GROOVX_GFX_CANVAS_H_UTC20050626084023_DEFINED