2012-11-20 22:35:40 +00:00
|
|
|
#pragma once
|
|
|
|
|
2013-05-27 22:32:00 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2013-08-30 12:44:23 +00:00
|
|
|
#include "base/basictypes.h"
|
2013-05-27 22:32:00 +00:00
|
|
|
#include "math/geom2d.h"
|
|
|
|
#include "gfx/texture_atlas.h"
|
|
|
|
|
2012-11-20 22:35:40 +00:00
|
|
|
// Everything you need to draw a UI collected into a single unit that can be passed around.
|
|
|
|
// Everything forward declared so this header is safe everywhere.
|
|
|
|
|
|
|
|
struct GLSLProgram;
|
|
|
|
class Texture;
|
|
|
|
class DrawBuffer;
|
2013-08-30 12:44:23 +00:00
|
|
|
class TextDrawer;
|
2012-11-20 22:35:40 +00:00
|
|
|
|
2013-05-27 22:32:00 +00:00
|
|
|
namespace UI {
|
2013-06-08 20:41:17 +00:00
|
|
|
struct Drawable;
|
2013-05-27 22:32:00 +00:00
|
|
|
struct Theme;
|
2013-08-30 12:44:23 +00:00
|
|
|
struct FontStyle;
|
2013-05-27 22:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class DrawBuffer;
|
|
|
|
|
2012-11-20 22:35:40 +00:00
|
|
|
class UIContext {
|
|
|
|
public:
|
2013-08-30 12:44:23 +00:00
|
|
|
UIContext();
|
|
|
|
~UIContext();
|
2012-11-20 22:35:40 +00:00
|
|
|
|
2013-08-30 12:44:23 +00:00
|
|
|
void Init(const GLSLProgram *uishader, const GLSLProgram *uishadernotex, Texture *uitexture, DrawBuffer *uidrawbuffer, DrawBuffer *uidrawbufferTop);
|
2012-11-20 22:35:40 +00:00
|
|
|
|
|
|
|
void Begin();
|
2013-03-30 18:23:02 +00:00
|
|
|
void BeginNoTex();
|
2012-11-21 14:30:43 +00:00
|
|
|
void Flush();
|
2012-11-20 22:35:40 +00:00
|
|
|
void End();
|
2013-03-30 18:23:02 +00:00
|
|
|
|
2013-03-30 19:10:01 +00:00
|
|
|
void RebindTexture() const;
|
2012-11-20 22:35:40 +00:00
|
|
|
|
2013-05-27 22:32:00 +00:00
|
|
|
// TODO: Support transformed bounds using stencil
|
|
|
|
void PushScissor(const Bounds &bounds);
|
|
|
|
void PopScissor();
|
2013-06-10 20:05:58 +00:00
|
|
|
Bounds GetScissorBounds();
|
2013-05-27 22:32:00 +00:00
|
|
|
|
|
|
|
void ActivateTopScissor();
|
|
|
|
|
|
|
|
DrawBuffer *Draw() const { return uidrawbuffer_; }
|
2013-08-27 17:43:40 +00:00
|
|
|
DrawBuffer *DrawTop() const { return uidrawbufferTop_; }
|
2013-05-27 22:32:00 +00:00
|
|
|
const UI::Theme *theme;
|
|
|
|
|
2013-06-08 20:41:17 +00:00
|
|
|
// Utility methods
|
|
|
|
|
2013-08-30 12:44:23 +00:00
|
|
|
TextDrawer *Text() const { return textDrawer_; }
|
2013-06-08 20:41:17 +00:00
|
|
|
|
2013-08-30 12:44:23 +00:00
|
|
|
void SetFontStyle(const UI::FontStyle &style);
|
2013-11-26 13:36:22 +00:00
|
|
|
const UI::FontStyle &GetFontStyle() { return *fontStyle_; }
|
2013-08-30 12:44:23 +00:00
|
|
|
void SetFontScale(float scaleX, float scaleY);
|
|
|
|
void MeasureText(const UI::FontStyle &style, const char *str, float *x, float *y, int align = 0) const;
|
|
|
|
void DrawText(const char *str, float x, float y, uint32_t color, int align = 0);
|
|
|
|
void DrawTextRect(const char *str, const Bounds &bounds, uint32_t color, int align = 0);
|
|
|
|
void FillRect(const UI::Drawable &drawable, const Bounds &bounds);
|
2013-06-08 20:41:17 +00:00
|
|
|
|
2012-11-20 22:35:40 +00:00
|
|
|
private:
|
2013-08-30 12:44:23 +00:00
|
|
|
float fontScaleX_;
|
|
|
|
float fontScaleY_;
|
|
|
|
UI::FontStyle *fontStyle_;
|
|
|
|
TextDrawer *textDrawer_;
|
2012-11-20 22:35:40 +00:00
|
|
|
// TODO: Collect these into a UIContext
|
|
|
|
const GLSLProgram *uishader_;
|
2012-11-21 14:30:43 +00:00
|
|
|
const GLSLProgram *uishadernotex_;
|
2012-11-20 22:35:40 +00:00
|
|
|
Texture *uitexture_;
|
|
|
|
DrawBuffer *uidrawbuffer_;
|
|
|
|
DrawBuffer *uidrawbufferTop_;
|
2013-05-27 22:32:00 +00:00
|
|
|
|
|
|
|
std::vector<Bounds> scissorStack_;
|
2012-11-20 22:35:40 +00:00
|
|
|
};
|