## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# cstool/pen.h

Go to the documentation of this file.

    00001 /*
    00002   Copyright (C) 2005 by Christopher Nelson
    00003
    00004   This library is free software; you can redistribute it and/or
    00005   modify it under the terms of the GNU Library General Public
    00006   License as published by the Free Software Foundation; either
    00007   version 2 of the License, or (at your option) any later version.
    00008
    00009   This library is distributed in the hope that it will be useful,
    00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012   Library General Public License for more details.
    00013
    00014   You should have received a copy of the GNU Library General Public
    00015   License along with this library; if not, write to the Free
    00016   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00017 */
    00018
    00019 #ifndef __CS_CSTOOL_PEN_H__
    00020 #define __CS_CSTOOL_PEN_H__
    00021
    00026 #include "csgeom/poly3d.h"
    00027 #include "csgeom/polyidx.h"
    00028 #include "csgeom/vector4.h"
    00029 #include "csgeom/vector2.h"
    00030 #include "csutil/cscolor.h"
    00031 #include "csutil/dirtyaccessarray.h"
    00032 #include "csutil/ref.h"
    00033 #include "csutil/refarr.h"
    00034 #include "csutil/memfile.h"
    00035
    00036 #include "ivideo/graph3d.h"
    00037 #include "ivideo/texture.h"
    00038
    00039 struct iFont;
    00040 struct iGraphics2D;
    00041 struct iGraphics3D;
    00042
    00043 enum CS_PEN_TEXT_ALIGN
    00044 {
    00045   CS_PEN_TA_TOP,
    00046   CS_PEN_TA_BOT,
    00047   CS_PEN_TA_LEFT,
    00048   CS_PEN_TA_RIGHT,
    00049   CS_PEN_TA_CENTER
    00050 };
    00051
    00052 enum CS_PEN_FLAGS
    00053 {
    00054         CS_PEN_FILL = 1,
    00055         CS_PEN_SWAPCOLORS= 2,
    00056         CS_PEN_TEXTURE_ONLY=4,
    00057         CS_PEN_TEXTURE = 5 /* fill | 4 */
    00058 };
    00059
    00060
    00064 struct iPen
    00065 {
    00066 protected:
    00067   virtual ~iPen() {}
    00068 public:
    00073   virtual void SetFlag(uint flag) = 0;
    00074
    00079   virtual void ClearFlag(uint flag) = 0;
    00080
    00084   virtual void SetMixMode(uint mode) = 0;
    00085
    00093   virtual void SetColor (float r, float g, float b, float a) = 0;
    00094
    00098   virtual void SetColor(const csColor4 &color) = 0;
    00099
    00104   virtual void SetTexture(csRef<iTextureHandle> tex) = 0;
    00105
    00109   virtual void SwapColors() = 0;
    00110
    00114   virtual void SetPenWidth(float width)=0;
    00115
    00119   virtual void ClearTransform() = 0;
    00120
    00124   virtual void PushTransform() = 0;
    00125
    00130   virtual void PopTransform() = 0;
    00131
    00135   virtual void SetOrigin(const csVector3 &o) = 0;
    00136
    00140   virtual void Translate(const csVector3 &t) = 0;
    00141
    00145   virtual void Rotate(const float &a) = 0;
    00146
    00150   virtual void DrawLine (uint x1, uint y1, uint x2, uint y2) = 0;
    00151
    00155   virtual void DrawPoint (uint x1, uint y2) = 0;
    00156
    00160   virtual void DrawRect (uint x1, uint y1, uint x2, uint y2) = 0;
    00161
    00166   virtual void DrawMiteredRect (uint x1, uint y1, uint x2, uint y2,
    00167     uint miter) = 0;
    00168
    00173   virtual void DrawRoundedRect (uint x1, uint y1, uint x2, uint y2,
    00174     uint roundness) = 0;
    00175
    00183   virtual void DrawArc(uint x1, uint y1, uint x2, uint y2, float start_angle,
    00184         float end_angle) = 0;
    00185
    00189   virtual void DrawTriangle(uint x1, uint y1, uint x2, uint y2, uint x3, uint y3) = 0;
    00190
    00194   virtual void Write(iFont *font, uint x1, uint y1, char *text) = 0;
    00195
    00200   virtual void WriteBoxed(iFont *font, uint x1, uint y1, uint x2, uint y2,
    00201     uint h_align, uint v_align, char *text) = 0;
    00202 };
    00203
    00205 class CS_CRYSTALSPACE_EXPORT csPen : public iPen
    00206 {
    00208   csRef<iGraphics3D> g3d;
    00209
    00211   csRef<iGraphics2D> g2d;
    00212
    00214   csSimpleRenderMesh mesh;
    00215
    00217   csPolyIndexed poly_idx;
    00218
    00220   csPoly3D poly;
    00221
    00223   csVector4 color;
    00224
    00226   csVector4 alt_color;
    00227
    00229   csRef<iTextureHandle> tex;
    00230
    00232   csVector3 tt;
    00233
    00235   csDirtyAccessArray<csVector4> colors;
    00236
    00238   csDirtyAccessArray<csVector2> texcoords;
    00239
    00241   csArray<csReversibleTransform> transforms;
    00242
    00244   csArray<csVector3> translations;
    00245
    00247   float pen_width;
    00248
    00250   uint flags;
    00251
    00253   struct point
    00254   {
    00255           float x,y;
    00256   };
    00257
    00259   csArray<point> line_points;
    00260
    00262   point last[2];
    00263
    00266   float sh_w, sh_h;
    00267
    00270   bool gen_tex_coords;
    00271
    00272 protected:
    00276   void Start();
    00277
    00285   void AddVertex(float x, float y, bool force_add=false);
    00286
    00291   inline void AddTexCoord(float x, float y);
    00292
    00296   void SetupMesh();
    00297
    00301   void DrawMesh(csRenderMeshType mesh_type);
    00302
    00306   void SetAutoTexture(float w, float h);
    00307
    00313   void AddThickPoints(float x1, float y1, float x2, float y2);
    00314
    00315 public:
    00316   csPen(iGraphics2D *_g2d, iGraphics3D *_g3d);
    00317   virtual ~csPen();
    00318
    00323   virtual void SetFlag(uint flag);
    00324
    00329   virtual void ClearFlag(uint flag);
    00330
    00331
    00335   virtual void SetMixMode(uint mode);
    00336
    00340   virtual void SetColor (float r, float g, float b, float a);
    00341
    00345   virtual void SetColor(const csColor4 &color);
    00346
    00351   virtual void SetTexture(csRef<iTextureHandle> tex);
    00352
    00356   virtual void SwapColors();
    00357
    00361   virtual void SetPenWidth(float width);
    00362
    00366   virtual void ClearTransform();
    00367
    00371   virtual void PushTransform();
    00372
    00377   virtual void PopTransform();
    00378
    00382   virtual void SetOrigin(const csVector3 &o);
    00383
    00387   virtual void Translate(const csVector3 &t);
    00388
    00392   virtual void Rotate(const float &a);
    00393
    00397   virtual void DrawLine (uint x1, uint y1, uint x2, uint y2);
    00398
    00402   void DrawThickLine(uint x1, uint y1, uint x2, uint y2);
    00403
    00407   virtual void DrawPoint (uint x1, uint y2);
    00408
    00412   virtual void DrawRect (uint x1, uint y1, uint x2, uint y2);
    00413
    00418   virtual void DrawMiteredRect (uint x1, uint y1, uint x2, uint y2,
    00419     uint miter);
    00420
    00425   virtual void DrawRoundedRect (uint x1, uint y1, uint x2, uint y2,
    00426     uint roundness);
    00427
    00435   virtual void DrawArc(uint x1, uint y1, uint x2, uint y2,
    00436         float start_angle=0, float end_angle=6.2831853);
    00437
    00441   virtual void DrawTriangle(uint x1, uint y1, uint x2, uint y2, uint x3, uint y3);
    00442
    00446   virtual void Write(iFont *font, uint x1, uint y1, char *text);
    00447
    00452   virtual void WriteBoxed(iFont *font, uint x1, uint y1, uint x2, uint y2,
    00453     uint h_align, uint v_align, char *text);
    00454 };
    00455
    00456
    00457
    00460 class CS_CRYSTALSPACE_EXPORT csMemoryPen : public iPen
    00461 {
    00463         csMemFile *buf;
    00464
    00466         csRefArray<iTextureHandle> textures;
    00467
    00468 public:
    00469          csMemoryPen():buf(0) { Clear(); }
    00470          virtual ~csMemoryPen() {}
    00471
    00472
    00474
    00476           virtual void Clear();
    00477
    00479           void Draw(iPen *_pen_);
    00480
    00485   virtual void SetFlag(uint flag);
    00486
    00491   virtual void ClearFlag(uint flag);
    00492
    00493
    00497   virtual void SetMixMode(uint mode);
    00498
    00502   virtual void SetColor (float r, float g, float b, float a);
    00503
    00507   virtual void SetColor(const csColor4 &color);
    00508
    00513   virtual void SetTexture(csRef<iTextureHandle> tex);
    00514
    00518   virtual void SwapColors();
    00519
    00524   virtual void SetPenWidth(float width);
    00525
    00529   virtual void ClearTransform();
    00530
    00534   virtual void PushTransform();
    00535
    00540   virtual void PopTransform();
    00541
    00545   virtual void SetOrigin(const csVector3 &o);
    00546
    00550   virtual void Translate(const csVector3 &t);
    00551
    00555   virtual void Rotate(const float &a);
    00556
    00560   virtual void DrawLine (uint x1, uint y1, uint x2, uint y2);
    00561
    00565   virtual void DrawPoint (uint x1, uint y2);
    00566
    00570   virtual void DrawRect (uint x1, uint y1, uint x2, uint y2);
    00571
    00576   virtual void DrawMiteredRect (uint x1, uint y1, uint x2, uint y2, uint miter);
    00577
    00582   virtual void DrawRoundedRect (uint x1, uint y1, uint x2, uint y2,
    00583     uint roundness);
    00584
    00592   virtual void DrawArc(uint x1, uint y1, uint x2, uint y2, float start_angle,
    00593         float end_angle);
    00594
    00598   virtual void DrawTriangle(uint x1, uint y1, uint x2, uint y2, uint x3, uint y3);
    00599
    00603   virtual void Write(iFont *font, uint x1, uint y1, char *text);
    00604
    00609   virtual void WriteBoxed(iFont *font, uint x1, uint y1, uint x2, uint y2,
    00610     uint h_align, uint v_align, char *text);
    00611
    00612 };
    00613
    00614
    00615
    00616 #endif