ini
This commit is contained in:
parent
f7f0d6e5be
commit
83d51d3e83
30 changed files with 1186 additions and 208 deletions
|
|
@ -24,25 +24,21 @@ Graphics::Canvas::Canvas() { mContext = new Context(); }
|
|||
|
||||
Graphics::Canvas::~Canvas() { delete mContext; }
|
||||
|
||||
void Graphics::Canvas::init() {
|
||||
mContext->vg = nvgCreateGL3(NVG_ANTIALIAS | NVG_STENCIL_STROKES);
|
||||
|
||||
void Graphics::Canvas::init() {
|
||||
mContext->vg = nvgCreateGL3(NVG_ANTIALIAS | NVG_STENCIL_STROKES);
|
||||
|
||||
if (nvgCreateFont(mContext->vg, "default", "Font.ttf") == -1) {
|
||||
// TODO
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
void Graphics::Canvas::deinit() {
|
||||
nvgDeleteGL3(mContext->vg);
|
||||
}
|
||||
void Graphics::Canvas::deinit() { nvgDeleteGL3(mContext->vg); }
|
||||
|
||||
RectF Graphics::Canvas::getAvaliableArea() {
|
||||
return { (halnf) 0, (halnf) 0, mWidth, mHeight };
|
||||
}
|
||||
RectF Graphics::Canvas::getAvaliableArea() { return { (halnf) 0, (halnf) 0, mWidth, mHeight }; }
|
||||
|
||||
void Graphics::Canvas::rect(const RectF& rec, const RGBA& col, halnf round) {
|
||||
nvgBeginPath(mContext->vg);
|
||||
|
||||
|
||||
if (round == 0) {
|
||||
nvgRect(mContext->vg, rec.x, rec.y, rec.z, rec.w);
|
||||
} else {
|
||||
|
|
@ -53,49 +49,69 @@ void Graphics::Canvas::rect(const RectF& rec, const RGBA& col, halnf round) {
|
|||
nvgFill(mContext->vg);
|
||||
}
|
||||
|
||||
void Graphics::Canvas::text(const String& string, const RectF& aRec, halnf size, Align align, halnf marging, const RGBA& col) {
|
||||
void Graphics::Canvas::pushClamp(const RectF& rec) {
|
||||
RectF intersection = rec;
|
||||
if (mScissors.size()) {
|
||||
mScissors.last().calcIntersection(rec, intersection);
|
||||
}
|
||||
nvgScissor(mContext->vg, intersection.x, intersection.y, intersection.z, intersection.w);
|
||||
mScissors.append(rec);
|
||||
}
|
||||
|
||||
void Graphics::Canvas::popClamp() {
|
||||
DEBUG_ASSERT(mScissors.size());
|
||||
mIsClamping = false;
|
||||
mScissors.pop();
|
||||
if (mScissors.size()) {
|
||||
const auto& rec = mScissors.last();
|
||||
nvgScissor(mContext->vg, rec.x, rec.y, rec.z, rec.w);
|
||||
} else {
|
||||
nvgResetScissor(mContext->vg);
|
||||
}
|
||||
}
|
||||
|
||||
void Graphics::Canvas::text(
|
||||
const String& string, const RectF& aRec, halnf size, Align align, halnf marging, const RGBA& col
|
||||
) {
|
||||
RectF rec = { aRec.x + marging, aRec.y + marging, aRec.z - marging * 2, aRec.w - marging * 2 };
|
||||
|
||||
nvgScissor(mContext->vg, rec.x, rec.y, rec.z, rec.w);
|
||||
pushClamp(rec);
|
||||
|
||||
nvgFontSize(mContext->vg, size);
|
||||
nvgFontFace(mContext->vg, "default");
|
||||
nvgFillColor(mContext->vg, { col.r, col.g, col.b, col.a } );
|
||||
nvgFillColor(mContext->vg, { col.r, col.g, col.b, col.a });
|
||||
|
||||
float centerX = rec.x;
|
||||
float centerY = rec.y;
|
||||
int alignNVG = 0;
|
||||
|
||||
if (((int1*)&align)[1] == 0x00) { // center x
|
||||
if (((int1*) &align)[1] == 0x00) { // center x
|
||||
alignNVG |= NVG_ALIGN_CENTER;
|
||||
centerX += rec.z * 0.5f;
|
||||
} else if (((int1*)&align)[1] == 0x01) { // left x
|
||||
} else if (((int1*) &align)[1] == 0x01) { // left x
|
||||
alignNVG |= NVG_ALIGN_LEFT;
|
||||
} else if (((int1*)&align)[1] == 0x02) { // right x
|
||||
} else if (((int1*) &align)[1] == 0x02) { // right x
|
||||
alignNVG |= NVG_ALIGN_RIGHT;
|
||||
centerX += rec.z;
|
||||
}
|
||||
|
||||
if (((int1*)&align)[0] == 0x00) { // center y
|
||||
if (((int1*) &align)[0] == 0x00) { // center y
|
||||
alignNVG |= NVG_ALIGN_MIDDLE;
|
||||
centerY += rec.w * 0.5f;
|
||||
} else if (((int1*)&align)[0] == 0x01) { // top y
|
||||
} else if (((int1*) &align)[0] == 0x01) { // top y
|
||||
alignNVG |= NVG_ALIGN_TOP;
|
||||
centerY += rec.w;
|
||||
} else if (((int1*)&align)[0] == 0x02) { // bottom y
|
||||
} else if (((int1*) &align)[0] == 0x02) { // bottom y
|
||||
alignNVG |= NVG_ALIGN_BOTTOM;
|
||||
}
|
||||
|
||||
nvgTextAlign(mContext->vg, alignNVG);
|
||||
|
||||
nvgText(mContext->vg, centerX, centerY, string.read(), nullptr);
|
||||
nvgResetScissor(mContext->vg);
|
||||
|
||||
popClamp();
|
||||
}
|
||||
|
||||
void Graphics::Canvas::proc() {
|
||||
nvgBeginFrame(mContext->vg, mWidth, mHeight, 1.0);
|
||||
}
|
||||
void Graphics::Canvas::proc() { nvgBeginFrame(mContext->vg, mWidth, mHeight, 1.0); }
|
||||
|
||||
void Graphics::Canvas::draw() {
|
||||
nvgEndFrame(mContext->vg);
|
||||
}
|
||||
void Graphics::Canvas::draw() { nvgEndFrame(mContext->vg); }
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
// -------- Debug UI -------- //
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <imgui_impl_glfw.h>
|
||||
#include <imgui_impl_opengl3.h>
|
||||
#include <imgui_internal.h>
|
||||
|
||||
namespace tp {
|
||||
class Graphics::GUI::Context {
|
||||
|
|
@ -33,6 +33,9 @@ void Graphics::GUI::init(Window* window) {
|
|||
// ImGui_ImplGlfw_GetBackendData();
|
||||
|
||||
ImGui_ImplOpenGL3_Init("#version 330");
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.Fonts->AddFontFromFileTTF("Font.ttf", 20.f);
|
||||
}
|
||||
|
||||
void Graphics::GUI::deinit() {
|
||||
|
|
|
|||
|
|
@ -47,8 +47,7 @@ void Graphics::GL::deinit() {
|
|||
glDeleteVertexArrays(1, &mContext->vao);
|
||||
}
|
||||
|
||||
void Graphics::GL::proc() {
|
||||
}
|
||||
void Graphics::GL::proc() {}
|
||||
|
||||
void Graphics::GL::draw() {
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
|
|
@ -102,7 +101,7 @@ Window::Window(int width, int height, const char* title) {
|
|||
}
|
||||
|
||||
mContext->inputManager.init(mContext->window);
|
||||
|
||||
|
||||
mGraphics.init(this);
|
||||
|
||||
mEvents.mContext = mContext;
|
||||
|
|
@ -149,7 +148,7 @@ bool Window::shouldClose() const { return glfwWindowShouldClose(mContext->window
|
|||
void Window::processEvents() {
|
||||
mContext->inputManager.isEvent = false;
|
||||
glfwPollEvents();
|
||||
|
||||
|
||||
int w, h;
|
||||
glfwGetWindowSize(mContext->window, &w, &h);
|
||||
|
||||
|
|
@ -176,22 +175,14 @@ auto Window::getContext() -> Context* { return mContext; }
|
|||
Graphics::Canvas& Window::getCanvas() { return mGraphics.mCanvas; }
|
||||
const Window::Events& Window::getEvents() { return mEvents; }
|
||||
|
||||
const Vec2F& Window::Events::getPos() const {
|
||||
return mContext->inputManager.getPos();
|
||||
}
|
||||
const Vec2F& Window::Events::getPos() const { return mContext->inputManager.getPos(); }
|
||||
|
||||
bool Window::Events::isPressed() const {
|
||||
return mContext->inputManager.isPressed();
|
||||
}
|
||||
bool Window::Events::isPressed() const { return mContext->inputManager.isPressed(); }
|
||||
|
||||
bool Window::Events::isDown() const {
|
||||
return mContext->inputManager.isDown();
|
||||
}
|
||||
bool Window::Events::isReleased() const { return mContext->inputManager.isReleased(); }
|
||||
|
||||
halnf Window::Events::getScrollY() const {
|
||||
return mContext->inputManager.getScrollY();
|
||||
}
|
||||
bool Window::Events::isDown() const { return mContext->inputManager.isDown(); }
|
||||
|
||||
bool Window::Events::isEvent() const {
|
||||
return mContext->inputManager.isEvents();
|
||||
}
|
||||
halnf Window::Events::getScrollY() const { return mContext->inputManager.getScrollY(); }
|
||||
|
||||
bool Window::Events::isEvent() const { return mContext->inputManager.isEvents(); }
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ namespace tp {
|
|||
class InputManager {
|
||||
public:
|
||||
InputManager() = default;
|
||||
|
||||
void init(GLFWwindow* aWindow) {
|
||||
|
||||
void init(GLFWwindow* aWindow) {
|
||||
window = aWindow;
|
||||
// Set up key and mouse button callbacks
|
||||
|
||||
|
|
@ -24,25 +24,17 @@ namespace tp {
|
|||
|
||||
const Vec2F& getPos() const { return mousePos; }
|
||||
|
||||
bool isKeyPressed(int key) const {
|
||||
return keyStates[key] == GLFW_PRESS;
|
||||
}
|
||||
bool isKeyPressed(int key) const { return keyStates[key] == GLFW_PRESS; }
|
||||
|
||||
bool isKeyDown(int key) const {
|
||||
return keyStates[key] == GLFW_REPEAT || keyStates[key] == GLFW_PRESS;
|
||||
}
|
||||
bool isKeyDown(int key) const { return keyStates[key] == GLFW_REPEAT || keyStates[key] == GLFW_PRESS; }
|
||||
|
||||
bool isPressed() const {
|
||||
return mouseButtonStates[GLFW_MOUSE_BUTTON_LEFT] == GLFW_PRESS;
|
||||
}
|
||||
bool isPressed() const { return mouseButtonStates[GLFW_MOUSE_BUTTON_LEFT] == GLFW_PRESS; }
|
||||
|
||||
bool isDown() const {
|
||||
return mouseButtonStates[GLFW_MOUSE_BUTTON_LEFT] == GLFW_REPEAT || mouseButtonStates[GLFW_MOUSE_BUTTON_LEFT] == GLFW_PRESS;
|
||||
}
|
||||
bool isReleased() const { return mouseButtonStates[GLFW_MOUSE_BUTTON_LEFT] == GLFW_RELEASE; }
|
||||
|
||||
bool isEvents() const {
|
||||
return isEvent;
|
||||
}
|
||||
bool isDown() const { return mouseButtonStates[GLFW_MOUSE_BUTTON_LEFT] == GLFW_REPEAT || mouseButtonStates[GLFW_MOUSE_BUTTON_LEFT] == GLFW_PRESS; }
|
||||
|
||||
bool isEvents() const { return isEvent; }
|
||||
|
||||
double getScrollY() const { return scrollY; }
|
||||
|
||||
|
|
@ -105,7 +97,7 @@ namespace tp {
|
|||
|
||||
bool isEvent = false;
|
||||
double scrollX = 0.0;
|
||||
double scrollY = 0.0;
|
||||
double scrollY = 0.0;
|
||||
GLFWwindow* window;
|
||||
Vec2F mousePos;
|
||||
Vec2F mousePosPrev;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue