2012-11-20 22:35:40 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-08-18 08:07:51 +00:00
|
|
|
#include <memory>
|
2013-05-27 22:32:00 +00:00
|
|
|
#include <vector>
|
2020-09-29 10:44:47 +00:00
|
|
|
#include <cstdint>
|
2022-03-31 15:03:34 +00:00
|
|
|
#include <string>
|
2013-05-27 22:32:00 +00:00
|
|
|
|
2020-10-03 22:25:21 +00:00
|
|
|
#include "Common/Math/geom2d.h"
|
|
|
|
#include "Common/Math/lin/vec3.h"
|
2020-10-04 21:24:14 +00:00
|
|
|
#include "Common/Render/TextureAtlas.h"
|
2013-05-27 22:32:00 +00:00
|
|
|
|
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.
|
|
|
|
|
2016-12-25 17:18:19 +00:00
|
|
|
namespace Draw {
|
2016-12-25 20:01:57 +00:00
|
|
|
class DrawContext;
|
2016-12-26 10:06:17 +00:00
|
|
|
class Pipeline;
|
2016-12-25 19:54:37 +00:00
|
|
|
class DepthStencilState;
|
|
|
|
class Texture;
|
2016-12-25 17:52:05 +00:00
|
|
|
class BlendState;
|
2016-12-25 19:54:37 +00:00
|
|
|
class SamplerState;
|
|
|
|
class RasterState;
|
2016-12-25 17:18:19 +00:00
|
|
|
}
|
|
|
|
|
2012-11-20 22:35:40 +00:00
|
|
|
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;
|
2020-08-18 08:07:51 +00:00
|
|
|
struct EventParams;
|
2013-05-27 22:32:00 +00:00
|
|
|
struct Theme;
|
2013-08-30 12:44:23 +00:00
|
|
|
struct FontStyle;
|
2020-08-18 08:07:51 +00:00
|
|
|
class Event;
|
|
|
|
class View;
|
2013-05-27 22:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class DrawBuffer;
|
|
|
|
|
2017-03-19 21:28:24 +00:00
|
|
|
struct UITransform {
|
|
|
|
// TODO: Or just use a matrix?
|
2019-10-22 20:58:10 +00:00
|
|
|
Lin::Vec3 translate;
|
|
|
|
Lin::Vec3 scale;
|
2017-03-19 21:28:24 +00:00
|
|
|
float alpha;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2023-12-08 11:29:24 +00:00
|
|
|
void Init(Draw::DrawContext *thin3d, Draw::Pipeline *uipipe, Draw::Pipeline *uipipenotex, DrawBuffer *uidrawbuffer);
|
2016-12-27 21:26:49 +00:00
|
|
|
|
2018-02-25 09:13:01 +00:00
|
|
|
void BeginFrame();
|
2012-11-20 22:35:40 +00:00
|
|
|
|
|
|
|
void Begin();
|
2013-03-30 18:23:02 +00:00
|
|
|
void BeginNoTex();
|
2018-12-16 20:48:35 +00:00
|
|
|
void BeginPipeline(Draw::Pipeline *pipeline, Draw::SamplerState *samplerState);
|
2012-11-21 14:30:43 +00:00
|
|
|
void Flush();
|
2013-03-30 18:23:02 +00:00
|
|
|
|
2013-03-30 19:10:01 +00:00
|
|
|
void RebindTexture() const;
|
2021-10-16 23:47:24 +00:00
|
|
|
void BindFontTexture() 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-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
|
|
|
|
2022-12-27 23:18:35 +00:00
|
|
|
void SetTintSaturation(float tint, float sat);
|
|
|
|
|
2023-07-03 20:54:25 +00:00
|
|
|
// High level drawing functions. They generally assume the default texture to be bounds.
|
|
|
|
|
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);
|
2016-08-07 23:49:50 +00:00
|
|
|
void MeasureTextCount(const UI::FontStyle &style, float scaleX, float scaleY, const char *str, int count, float *x, float *y, int align = 0) const;
|
|
|
|
void MeasureText(const UI::FontStyle &style, float scaleX, float scaleY, const char *str, float *x, float *y, int align = 0) const;
|
|
|
|
void MeasureTextRect(const UI::FontStyle &style, float scaleX, float scaleY, const char *str, int count, const Bounds &bounds, float *x, float *y, int align = 0) const;
|
2013-08-30 12:44:23 +00:00
|
|
|
void DrawText(const char *str, float x, float y, uint32_t color, int align = 0);
|
2015-05-07 02:45:24 +00:00
|
|
|
void DrawTextShadow(const char *str, float x, float y, uint32_t color, int align = 0);
|
2013-08-30 12:44:23 +00:00
|
|
|
void DrawTextRect(const char *str, const Bounds &bounds, uint32_t color, int align = 0);
|
2021-09-24 09:13:01 +00:00
|
|
|
void DrawTextShadowRect(const char *str, const Bounds &bounds, uint32_t color, int align = 0);
|
2023-07-17 09:44:36 +00:00
|
|
|
// Will squeeze the text into the bounds if needed.
|
|
|
|
void DrawTextRectSqueeze(const char *str, const Bounds &bounds, uint32_t color, int align = 0);
|
|
|
|
|
|
|
|
float CalculateTextScale(const char *text, float availWidth, float availHeight) const;
|
|
|
|
|
2013-08-30 12:44:23 +00:00
|
|
|
void FillRect(const UI::Drawable &drawable, const Bounds &bounds);
|
2023-07-03 20:54:25 +00:00
|
|
|
void DrawRectDropShadow(const Bounds &bounds, float radius, float alpha, uint32_t color = 0);
|
2021-01-17 12:44:57 +00:00
|
|
|
void DrawImageVGradient(ImageID image, uint32_t color1, uint32_t color2, const Bounds &bounds);
|
2013-06-08 20:41:17 +00:00
|
|
|
|
2014-02-10 11:35:36 +00:00
|
|
|
// in dps, like dp_xres and dp_yres
|
|
|
|
void SetBounds(const Bounds &b) { bounds_ = b; }
|
|
|
|
const Bounds &GetBounds() const { return bounds_; }
|
2020-03-30 22:47:01 +00:00
|
|
|
Bounds GetLayoutBounds() const;
|
2017-01-30 13:33:38 +00:00
|
|
|
Draw::DrawContext *GetDrawContext() { return draw_; }
|
2022-11-22 11:00:40 +00:00
|
|
|
const UI::Theme &GetTheme() const {
|
|
|
|
return *theme;
|
|
|
|
}
|
2018-12-16 20:48:35 +00:00
|
|
|
void SetCurZ(float curZ);
|
2014-02-10 11:35:36 +00:00
|
|
|
|
2017-03-19 21:28:24 +00:00
|
|
|
void PushTransform(const UITransform &transform);
|
|
|
|
void PopTransform();
|
|
|
|
Bounds TransformBounds(const Bounds &bounds);
|
|
|
|
|
2022-03-31 15:03:34 +00:00
|
|
|
void setUIAtlas(const std::string &name);
|
|
|
|
|
2022-11-22 11:00:40 +00:00
|
|
|
// TODO: Move to private.
|
|
|
|
const UI::Theme *theme;
|
|
|
|
|
2012-11-20 22:35:40 +00:00
|
|
|
private:
|
2021-02-09 23:20:52 +00:00
|
|
|
Draw::DrawContext *draw_ = nullptr;
|
2014-02-10 11:35:36 +00:00
|
|
|
Bounds bounds_;
|
|
|
|
|
2017-06-04 08:57:46 +00:00
|
|
|
float fontScaleX_ = 1.0f;
|
|
|
|
float fontScaleY_ = 1.0f;
|
|
|
|
UI::FontStyle *fontStyle_ = nullptr;
|
|
|
|
TextDrawer *textDrawer_ = nullptr;
|
2014-08-17 10:17:59 +00:00
|
|
|
|
2021-02-09 23:20:52 +00:00
|
|
|
Draw::SamplerState *sampler_ = nullptr;
|
2017-06-04 08:57:46 +00:00
|
|
|
Draw::Pipeline *ui_pipeline_ = nullptr;
|
|
|
|
Draw::Pipeline *ui_pipeline_notex_ = nullptr;
|
2023-12-12 22:10:46 +00:00
|
|
|
Draw::Texture *uitexture_ = nullptr;
|
|
|
|
Draw::Texture *fontTexture_ = nullptr;
|
2014-08-17 10:17:59 +00:00
|
|
|
|
2017-06-04 08:57:46 +00:00
|
|
|
DrawBuffer *uidrawbuffer_ = nullptr;
|
2013-05-27 22:32:00 +00:00
|
|
|
|
|
|
|
std::vector<Bounds> scissorStack_;
|
2017-03-19 21:28:24 +00:00
|
|
|
std::vector<UITransform> transformStack_;
|
2022-03-31 15:03:34 +00:00
|
|
|
|
|
|
|
std::string lastUIAtlas_;
|
|
|
|
std::string UIAtlas_ = "ui_atlas.zim";
|
2012-11-20 22:35:40 +00:00
|
|
|
};
|