3
// "Immediate mode"-lookalike buffered drawing. Very fast way to draw 2D.
5
#include "base/basictypes.h"
6
#include "base/colorutil.h"
7
#include "gfx/gl_lost_manager.h"
8
#include "gfx/texture_atlas.h"
9
#include "math/geom2d.h"
10
#include "math/lin/matrix4x4.h"
11
#include "thin3d/thin3d.h"
24
ALIGN_VBASELINE = 32, // text only, possibly not yet working
26
ALIGN_CENTER = ALIGN_HCENTER | ALIGN_VCENTER,
27
ALIGN_TOPLEFT = ALIGN_TOP | ALIGN_LEFT,
28
ALIGN_TOPRIGHT = ALIGN_TOP | ALIGN_RIGHT,
29
ALIGN_BOTTOMLEFT = ALIGN_BOTTOM | ALIGN_LEFT,
30
ALIGN_BOTTOMRIGHT = ALIGN_BOTTOM | ALIGN_RIGHT,
32
// Only for text drawing
33
ROTATE_90DEG_LEFT = 256,
34
ROTATE_90DEG_RIGHT = 512,
37
// For "uncachable" text like debug log.
38
// Avoids using system font drawing as it's too slow.
39
// Not actually used here but is reserved for whatever system wraps DrawBuffer.
40
FLAG_DYNAMIC_ASCII = 2048,
41
FLAG_NO_PREFIX = 4096, // means to not process ampersands
42
FLAG_WRAP_TEXT = 8192,
45
class Thin3DShaderSet;
47
enum DrawBufferPrimitiveMode {
64
void Begin(Thin3DShaderSet *shaders, DrawBufferPrimitiveMode mode = DBMODE_NORMAL);
67
// TODO: Enforce these. Now Init is autocalled and shutdown not called.
68
void Init(Thin3DContext *t3d);
71
int Count() const { return count_; }
73
void Flush(bool set_blend_state = true);
75
void Rect(float x, float y, float w, float h, uint32_t color, int align = ALIGN_TOPLEFT);
76
void hLine(float x1, float y, float x2, uint32_t color);
77
void vLine(float x, float y1, float y2, uint32_t color);
78
void vLineAlpha50(float x, float y1, float y2, uint32_t color);
80
void Line(int atlas_image, float x1, float y1, float x2, float y2, float thickness, uint32_t color);
82
void RectOutline(float x, float y, float w, float h, uint32_t color, int align = ALIGN_TOPLEFT);
84
void RectVGradient(float x, float y, float w, float h, uint32_t colorTop, uint32_t colorBottom);
85
void RectVDarkFaded(float x, float y, float w, float h, uint32_t colorTop) {
86
RectVGradient(x, y, w, h, colorTop, darkenColor(colorTop));
89
void MultiVGradient(float x, float y, float w, float h, GradientStop *stops, int numStops);
91
void RectCenter(float x, float y, float w, float h, uint32_t color) {
92
Rect(x - w/2, y - h/2, w, h, color);
94
void Rect(float x, float y, float w, float h, float u, float v, float uw, float uh, uint32_t color);
96
void V(float x, float y, float z, uint32_t color, float u, float v);
97
void V(float x, float y, uint32_t color, float u, float v) {
98
V(x, y, 0.0f, color, u, v);
101
void Circle(float x, float y, float radius, float thickness, int segments, float startAngle, uint32_t color, float u_mul);
105
// Must call this before you use any functions with atlas_image etc.
106
void SetAtlas(const Atlas *_atlas) {
109
const Atlas *GetAtlas() const { return atlas; }
110
void MeasureImage(ImageID atlas_image, float *w, float *h);
111
void DrawImage(ImageID atlas_image, float x, float y, float scale, Color color = COLOR(0xFFFFFF), int align = ALIGN_TOPLEFT);
112
void DrawImageStretch(ImageID atlas_image, float x1, float y1, float x2, float y2, Color color = COLOR(0xFFFFFF));
113
void DrawImageStretch(int atlas_image, const Bounds &bounds, Color color = COLOR(0xFFFFFF)) {
114
DrawImageStretch(atlas_image, bounds.x, bounds.y, bounds.x2(), bounds.y2(), color);
116
void DrawImageRotated(ImageID atlas_image, float x, float y, float scale, float angle, Color color = COLOR(0xFFFFFF), bool mirror_h = false); // Always centers
117
void DrawTexRect(float x1, float y1, float x2, float y2, float u1, float v1, float u2, float v2, Color color);
118
void DrawTexRect(const Bounds &bounds, float u1, float v1, float u2, float v2, Color color) {
119
DrawTexRect(bounds.x, bounds.y, bounds.x2(), bounds.y2(), u1, v1, u2, v2, color);
121
// Results in 18 triangles. Kind of expensive for a button.
122
void DrawImage4Grid(ImageID atlas_image, float x1, float y1, float x2, float y2, Color color = COLOR(0xFFFFFF), float corner_scale = 1.0);
123
// This is only 6 triangles, much cheaper.
124
void DrawImage2GridH(ImageID atlas_image, float x1, float y1, float x2, Color color = COLOR(0xFFFFFF), float scale = 1.0);
126
void MeasureText(int font, const char *text, float *w, float *h);
128
// NOTE: Count is in plain chars not utf-8 chars!
129
void MeasureTextCount(int font, const char *text, int count, float *w, float *h);
130
void MeasureTextRect(int font, const char *text, int count, const Bounds &bounds, float *w, float *h, int align = 0);
132
void DrawTextRect(int font, const char *text, float x, float y, float w, float h, Color color = 0xFFFFFFFF, int align = 0);
133
void DrawText(int font, const char *text, float x, float y, Color color = 0xFFFFFFFF, int align = 0);
134
void DrawTextShadow(int font, const char *text, float x, float y, Color color = 0xFFFFFFFF, int align = 0);
136
void RotateSprite(ImageID atlas_image, float x, float y, float angle, float scale, Color color);
138
void SetFontScale(float xs, float ys) {
143
static void DoAlign(int flags, float *x, float *y, float *w, float *h);
145
void SetDrawMatrix(const Matrix4x4 &m) {
156
Matrix4x4 drawMatrix_;
160
Thin3DVertexFormat *vformat_;
161
Thin3DShaderSet *shaderSet_;
165
DrawBufferPrimitiveMode mode_;