cstool/pen.h Source File (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

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

- 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/graph2d.h"
    00037 #include "ivideo/graph3d.h"
    00038 #include "ivideo/texture.h"
    00039
    00040 struct iFont;
    00041
    00042 enum CS_PEN_TEXT_ALIGN
    00043 {
    00044   CS_PEN_TA_TOP,
    00045   CS_PEN_TA_BOT,
    00046   CS_PEN_TA_LEFT,
    00047   CS_PEN_TA_RIGHT,
    00048   CS_PEN_TA_CENTER
    00049 };
    00050
    00051 enum CS_PEN_FLAGS
    00052 {
    00053   CS_PEN_FILL = 1,
    00054   CS_PEN_SWAPCOLORS= 2,
    00055   CS_PEN_TEXTURE_ONLY=4,
    00056   CS_PEN_TEXTURE = 5 /* fill | 4 */
    00057 };
    00058
    00059
    00063 struct iPen
    00064 {
    00065 protected:
    00066   virtual ~iPen() {}
    00067 public:
    00072   virtual void SetFlag(uint flag) = 0;
    00073
    00078   virtual void ClearFlag(uint flag) = 0;
    00079
    00083   virtual void SetMixMode(uint mode) = 0;
    00084
    00092   virtual void SetColor (float r, float g, float b, float a) = 0;
    00093
    00097   virtual void SetColor(const csColor4 &color) = 0;
    00098
    00103   virtual void SetTexture(csRef<iTextureHandle> tex) = 0;
    00104
    00108   virtual void SwapColors() = 0;
    00109
    00113   virtual void SetPenWidth(float width)=0;
    00114
    00118   virtual void ClearTransform() = 0;
    00119
    00123   virtual void PushTransform() = 0;
    00124
    00129   virtual void PopTransform() = 0;
    00130
    00134   virtual void SetOrigin(const csVector3 &o) = 0;
    00135
    00139   virtual void Translate(const csVector3 &t) = 0;
    00140
    00144   virtual void Rotate(const float &a) = 0;
    00145
    00149   virtual void DrawLine (uint x1, uint y1, uint x2, uint y2) = 0;
    00150
    00154   virtual void DrawPoint (uint x1, uint y2) = 0;
    00155
    00159   virtual void DrawRect (uint x1, uint y1, uint x2, uint y2) = 0;
    00160
    00165   virtual void DrawMiteredRect (uint x1, uint y1, uint x2, uint y2,
    00166     uint miter) = 0;
    00167
    00172   virtual void DrawRoundedRect (uint x1, uint y1, uint x2, uint y2,
    00173     uint roundness) = 0;
    00174
    00182   virtual void DrawArc(uint x1, uint y1, uint x2, uint y2, float start_angle,
    00183         float end_angle) = 0;
    00184
    00188   virtual void DrawTriangle(uint x1, uint y1, uint x2, uint y2, uint x3, uint y3) = 0;
    00189
    00193   virtual void Write(iFont *font, uint x1, uint y1, const char *text) = 0;
    00194
    00198   virtual void WriteLines(iFont *font, uint x1, uint y1, const csStringArray& lines) = 0;
    00199
    00204   virtual void WriteBoxed(iFont *font, uint x1, uint y1, uint x2, uint y2,
    00205     uint h_align, uint v_align, const char *text) = 0;
    00206
    00212   virtual void WriteLinesBoxed(iFont *font, uint x1, uint y1, uint x2, uint y2,
    00213     uint h_align, uint v_align, const csStringArray& lines) = 0;
    00214 };
    00215
    00217 class CS_CRYSTALSPACE_EXPORT csPen : public iPen
    00218 {
    00220   csRef<iGraphics3D> g3d;
    00221
    00223   csRef<iGraphics2D> g2d;
    00224
    00226   csSimpleRenderMesh mesh;
    00227
    00229   csPolyIndexed poly_idx;
    00230
    00232   csPoly3D poly;
    00233
    00235   csVector4 color;
    00236
    00238   csVector4 alt_color;
    00239
    00241   csRef<iTextureHandle> tex;
    00242
    00244   csVector3 tt;
    00245
    00247   csDirtyAccessArray<csVector4> colors;
    00248
    00250   csDirtyAccessArray<csVector2> texcoords;
    00251
    00253   csArray<csReversibleTransform> transforms;
    00254
    00256   csArray<csVector3> translations;
    00257
    00259   float pen_width;
    00260
    00262   uint flags;
    00263
    00265   struct point
    00266   {
    00267     float x,y;
    00268   };
    00269
    00271   csArray<point> line_points;
    00272
    00274   point last[2];
    00275
    00278   float sh_w, sh_h;
    00279
    00282   bool gen_tex_coords;
    00283
    00284 protected:
    00288   void Start();
    00289
    00297   void AddVertex(float x, float y, bool force_add=false);
    00298
    00303   inline void AddTexCoord(float x, float y);
    00304
    00308   void SetupMesh();
    00309
    00313   void DrawMesh(csRenderMeshType mesh_type);
    00314
    00318   void SetAutoTexture(float w, float h);
    00319
    00325   void AddThickPoints(float x1, float y1, float x2, float y2);
    00326
    00327 public:
    00328   csPen(iGraphics2D *_g2d, iGraphics3D *_g3d);
    00329   virtual ~csPen();
    00330
    00331   virtual void SetFlag(uint flag);
    00332   virtual void ClearFlag(uint flag);
    00333
    00334   virtual void SetMixMode(uint mode);
    00335
    00336   virtual void SetColor (float r, float g, float b, float a);
    00337   virtual void SetColor(const csColor4 &color);
    00338
    00339   virtual void SetTexture(csRef<iTextureHandle> tex);
    00340
    00341   virtual void SwapColors();
    00342
    00343   virtual void SetPenWidth(float width);
    00344
    00345   virtual void ClearTransform();
    00346   virtual void PushTransform();
    00347   virtual void PopTransform();
    00348
    00349   virtual void SetOrigin(const csVector3 &o);
    00350   virtual void Translate(const csVector3 &t);
    00351   virtual void Rotate(const float &a);
    00352
    00353   virtual void DrawLine (uint x1, uint y1, uint x2, uint y2);
    00354   void DrawThickLine(uint x1, uint y1, uint x2, uint y2);
    00355   virtual void DrawPoint (uint x1, uint y2);
    00356   virtual void DrawRect (uint x1, uint y1, uint x2, uint y2);
    00357   virtual void DrawMiteredRect (uint x1, uint y1, uint x2, uint y2,
    00358     uint miter);
    00359   virtual void DrawRoundedRect (uint x1, uint y1, uint x2, uint y2,
    00360     uint roundness);
    00361   virtual void DrawArc(uint x1, uint y1, uint x2, uint y2,
    00362         float start_angle=0, float end_angle=6.2831853);
    00363   virtual void DrawTriangle(uint x1, uint y1, uint x2, uint y2, uint x3, uint y3);
    00364
    00365   virtual void Write(iFont *font, uint x1, uint y1, const char *text);
    00366   virtual void WriteLines(iFont *font, uint x1, uint y1, const csStringArray& lines);
    00367
    00368   virtual void WriteBoxed(iFont *font, uint x1, uint y1, uint x2, uint y2,
    00369     uint h_align, uint v_align, const char *text);
    00370   virtual void WriteLinesBoxed(iFont *font, uint x1, uint y1, uint x2, uint y2,
    00371     uint h_align, uint v_align, const csStringArray& lines);
    00372 };
    00373
    00374 #endif