00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
#ifndef UGRAPHICS_HPP
00029
#define UGRAPHICS_HPP
00030
00031
#include "uobject.hpp"
00032
00033
#include "font/ufont.hpp"
00034
#include "util/urectangle.hpp"
00035
#include "util/ucolor.hpp"
00036
00037
#include "image/uimage.hpp"
00038
00039
namespace ufo {
00040
00041
class UContext;
00042
00043
class UImage;
00044
class UImageIO;
00045
class UVertexArray;
00046
00060 class UFO_EXPORT UGraphics :
public UObject {
00061 UFO_DECLARE_ABSTRACT_CLASS(UGraphics)
00062
public:
00063
enum VertexType {
00064 Points,
00065 Lines,
00066 LineStrip,
00067 Triangles,
00068 TriangleStrip,
00069 TriangleFan
00070 };
00071
enum GCState {
00072 Blending = 1,
00073 SmoothShading,
00074 LineAntialiasing,
00075 FillAntialiasing
00076 };
00077
public:
00079
virtual UContext * getContext()
const = 0;
00080
00085
virtual URectangle mapToDevice(
const URectangle & rect) = 0;
00086
00091
virtual URectangle mapFromDevice(
const URectangle & rect) = 0;
00092
00093
public:
00099
virtual void begin() = 0;
00104
virtual void end() = 0;
00106
virtual void clear() = 0;
00110
virtual UImageIO * dump() = 0;
00111
00116 virtual void resetDeviceAttributes() {}
00121 virtual void resetDeviceViewMatrix() {}
00123 void flush() {}
00124
00125
virtual void setEnabled(GCState state,
bool b) = 0;
00126
virtual bool isEnabled(GCState state)
const = 0;
00127
00128
00129
public:
00134
virtual void setColor(
const UColor & color) = 0;
00140
virtual UColor getColor() const = 0;
00141
00142 virtual
void setClearColor(const
UColor & clearColor) = 0;
00143 virtual
UColor getClearColor() const = 0;
00144
00146 virtual
void setFont(const
UFont & font) = 0;
00148 virtual
UFont getFont() const = 0;
00149
00150 public:
00154 virtual
void drawString(const std::string & string,
int x = 0,
int y = 0) = 0;
00155
00159 virtual
UDimension getStringSize(const std::string & string) = 0;
00160
00161 public:
00165 virtual
void setClipRect(const
URectangle & rect) = 0;
00167 virtual
URectangle getClipRect() const = 0;
00168
00169 virtual
void setLineWidth(
float width) = 0;
00170 virtual
float getLineWidth() const = 0;
00171 public:
00173 virtual
void translate(
float x,
float y) = 0;
00174 virtual
float getTranslationX() const = 0;
00175 virtual
float getTranslationY() const = 0;
00176
00177 public:
00181 virtual
void drawRect(const
URectangle & rect) = 0;
00183 virtual
void fillRect(const
URectangle & rect) = 0;
00184
00186 virtual
void drawLine(const
UPoint & p1, const
UPoint & p2) = 0;
00187
00192 virtual
void drawVertexArray(VertexType type,
UVertexArray * buffer) = 0;
00193
00203 virtual
void drawImage(
UImage * image, const
URectangle & rect) = 0;
00204
00214 virtual
void drawSubImage(
UImage * image,
00215 const
URectangle & srcRect, const
URectangle & destRect) = 0;
00216
00217 public:
00218
void drawRect(
int x,
int y,
int w,
int h) {
00219 drawRect(
URectangle(x, y, w, h));
00220 }
00221
void fillRect(
int x,
int y,
int w,
int h) {
00222 fillRect(URectangle(x, y, w, h));
00223 }
00224
00225
void drawLine(
int x1,
int y1,
int x2,
int y2) {
00226 drawLine(UPoint(x1, y1), UPoint(x2, y2));
00227 }
00230 void drawImage(
UImage * image,
int x,
int y) {
00231 drawImage(image,
UPoint(x, y));
00232 }
00233
void drawImage(
UImage * image,
const UPoint & p) {
00234 drawImage(image,
URectangle(p, image->
getImageSize()));
00235 }
00236
void drawImage(UImage * image,
int x,
int y,
int w,
int h) {
00237 drawImage(image, URectangle(x, y, w, h));
00238 }
00239
void drawSubImage(UImage * image,
00240
int srcX,
int srcY,
int srcWidth,
int srcHeight,
00241
int destX,
int destY) {
00242 drawSubImage(image, URectangle(srcX, srcY, srcWidth, srcHeight),
00243 UPoint(destX, destY));
00244 }
00246 void drawSubImage(
UImage * image,
const URectangle & srcRect,
00247
const UPoint & destLocation) {
00248 drawSubImage(image, srcRect,
URectangle(destLocation, image->
getImageSize()));
00249 }
00250
00251
void drawSubImage(
UImage * image,
00252
int srcX,
int srcY,
int srcWidth,
int srcHeight,
00253
int destX,
int destY,
int destWidth,
int destHeight) {
00254 drawSubImage(image,
URectangle(srcX, srcY, srcWidth, srcHeight),
00255
URectangle(destX, destY, destWidth, destHeight));
00256 }
00257 };
00258
00259 }
00260
00261
#endif // UGRAPHICS_HPP