mirror of
https://github.com/zetaPRIME/libstarlight.git
synced 2025-06-26 13:42:46 +00:00
DrawLayerProxy, rudimentary preview in OSK
This commit is contained in:
parent
588817acc6
commit
92467e21c6
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
#include "starlight/ThemeManager.h"
|
#include "starlight/ThemeManager.h"
|
||||||
#include "starlight/InputManager.h"
|
#include "starlight/InputManager.h"
|
||||||
|
#include "starlight/GFXManager.h"
|
||||||
|
|
||||||
|
#include "starlight/gfx/Font.h"
|
||||||
|
|
||||||
#include "starlight/ui/Image.h"
|
#include "starlight/ui/Image.h"
|
||||||
#include "starlight/ui/Button.h"
|
#include "starlight/ui/Button.h"
|
||||||
@ -12,12 +15,17 @@
|
|||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
using starlight::ThemeManager;
|
||||||
using starlight::InputManager;
|
using starlight::InputManager;
|
||||||
|
using starlight::GFXManager;
|
||||||
|
|
||||||
|
using starlight::gfx::Font;
|
||||||
|
|
||||||
using starlight::ui::Image;
|
using starlight::ui::Image;
|
||||||
using starlight::ui::Button;
|
using starlight::ui::Button;
|
||||||
using starlight::ui::Label;
|
using starlight::ui::Label;
|
||||||
using starlight::ui::ScrollField;
|
using starlight::ui::ScrollField;
|
||||||
|
using starlight::ui::DrawLayerProxy;
|
||||||
|
|
||||||
using starlight::ui::Form;
|
using starlight::ui::Form;
|
||||||
|
|
||||||
@ -38,6 +46,7 @@ OSK::OSK(osk::InputHandler* handler) : Form(true), handler(handler) {
|
|||||||
|
|
||||||
auto actSym = [this](Button& key){
|
auto actSym = [this](Button& key){
|
||||||
this->handler->InputSymbol(key.label);
|
this->handler->InputSymbol(key.label);
|
||||||
|
this->OnKey();
|
||||||
};
|
};
|
||||||
|
|
||||||
Vector2 bs(24, 32);
|
Vector2 bs(24, 32);
|
||||||
@ -79,16 +88,19 @@ OSK::OSK(osk::InputHandler* handler) : Form(true), handler(handler) {
|
|||||||
auto key = std::make_shared<Button>(VRect(bpen, bs));
|
auto key = std::make_shared<Button>(VRect(bpen, bs));
|
||||||
key->rect.size.x *= 1.25;
|
key->rect.size.x *= 1.25;
|
||||||
key->SetText("< <");
|
key->SetText("< <");
|
||||||
key->eOnTap = [this](auto& btn){ this->handler->Backspace(); };
|
key->eOnTap = [this](auto& btn){ this->handler->Backspace(); this->OnKey(); };
|
||||||
touchScreen->Add(key);
|
touchScreen->Add(key);
|
||||||
|
|
||||||
|
// enter
|
||||||
bpen = bpstart + bs * Vector2(linestart[4] + 8, 4);
|
bpen = bpstart + bs * Vector2(linestart[4] + 8, 4);
|
||||||
key = std::make_shared<Button>(VRect(bpen, bs));
|
key = std::make_shared<Button>(VRect(bpen, bs));
|
||||||
key->rect.size.x *= 2.5;
|
key->rect.size.x *= 2.5;
|
||||||
key->SetText("Enter");
|
key->SetText("Enter");
|
||||||
key->eOnTap = [this](auto& btn){ this->handler->Enter(); };
|
key->eOnTap = [this](auto& btn){ this->handler->Enter(); this->OnKey(); };
|
||||||
touchScreen->Add(key);
|
touchScreen->Add(key);
|
||||||
|
|
||||||
|
preview = std::make_shared<DrawLayerProxy>(VRect::touchScreen.TopEdge(68).Expand(-2), [this](auto& layer){ this->DrawPreview(layer); }, true);
|
||||||
|
touchScreen->Add(preview);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSK::Update(bool focused) {
|
void OSK::Update(bool focused) {
|
||||||
@ -107,11 +119,13 @@ void OSK::Update(bool focused) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSK::OnSymKey(const string& chr) {
|
void OSK::OnKey() {
|
||||||
//pText->append(chr);
|
preview->Refresh();
|
||||||
//pText->append("sackboy ");
|
}
|
||||||
//auto& tx = *pText;
|
|
||||||
//ConfigManager::Get("user").Json()["log"].push_back(*pText);
|
void OSK::DrawPreview(DrawLayerProxy& layer) {
|
||||||
//tx.assign("shickaxe");
|
if (true || handler->showPreview) {
|
||||||
//if (eOnModify) eOnModify();
|
static auto tc = ThemeManager::GetMetric<TextConfig>("/dialogs/OSK/preview");
|
||||||
|
tc.Print(layer.rect, handler->GetPreviewText(), Vector2::zero);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "starlight/ui/Form.h"
|
#include "starlight/ui/Form.h"
|
||||||
|
#include "starlight/ui/DrawLayerProxy.h"
|
||||||
|
|
||||||
#include "starlight/dialog/osk/InputHandler.h"
|
#include "starlight/dialog/osk/InputHandler.h"
|
||||||
|
|
||||||
@ -14,6 +15,7 @@ namespace starlight {
|
|||||||
class OSK : public ui::Form, public ui::FormCreator<OSK> {
|
class OSK : public ui::Form, public ui::FormCreator<OSK> {
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<ui::UIContainer> setContainer;
|
std::shared_ptr<ui::UIContainer> setContainer;
|
||||||
|
std::shared_ptr<ui::DrawLayerProxy> preview;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::unique_ptr<osk::InputHandler> handler;
|
std::unique_ptr<osk::InputHandler> handler;
|
||||||
@ -23,7 +25,9 @@ namespace starlight {
|
|||||||
|
|
||||||
void Update(bool focused) override;
|
void Update(bool focused) override;
|
||||||
|
|
||||||
void OnSymKey(const std::string& chr);
|
void OnKey();
|
||||||
|
|
||||||
|
void DrawPreview(ui::DrawLayerProxy& layer);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,11 @@ using starlight::dialog::osk::InputHandlerBuffered;
|
|||||||
|
|
||||||
// DirectEdit
|
// DirectEdit
|
||||||
|
|
||||||
|
std::string& InputHandlerDirectEdit::GetPreviewText() { return *pText; }
|
||||||
|
|
||||||
|
unsigned int InputHandlerDirectEdit::GetCursor() { return pText->length(); }
|
||||||
|
void InputHandlerDirectEdit::SetCursor(unsigned int index) { }
|
||||||
|
|
||||||
void InputHandlerDirectEdit::InputSymbol(const string& sym) {
|
void InputHandlerDirectEdit::InputSymbol(const string& sym) {
|
||||||
pText->append(sym);
|
pText->append(sym);
|
||||||
if (eOnModify) eOnModify();
|
if (eOnModify) eOnModify();
|
||||||
@ -34,6 +39,11 @@ void InputHandlerDirectEdit::Done() {
|
|||||||
|
|
||||||
// Buffered
|
// Buffered
|
||||||
|
|
||||||
|
std::string& InputHandlerBuffered::GetPreviewText() { return buffer; }
|
||||||
|
|
||||||
|
unsigned int InputHandlerBuffered::GetCursor() { return buffer.length(); }
|
||||||
|
void InputHandlerBuffered::SetCursor(unsigned int index) { }
|
||||||
|
|
||||||
void InputHandlerBuffered::InputSymbol(const string& sym) {
|
void InputHandlerBuffered::InputSymbol(const string& sym) {
|
||||||
buffer.append(sym);
|
buffer.append(sym);
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,11 @@ namespace starlight {
|
|||||||
InputHandler() = default;
|
InputHandler() = default;
|
||||||
virtual ~InputHandler() = default;
|
virtual ~InputHandler() = default;
|
||||||
|
|
||||||
|
virtual std::string& GetPreviewText() { static std::string p = ""; return p; }
|
||||||
|
|
||||||
|
virtual unsigned int GetCursor() { return 0; }
|
||||||
|
virtual void SetCursor(unsigned int index) { }
|
||||||
|
|
||||||
virtual void InputSymbol(const std::string& sym) { }
|
virtual void InputSymbol(const std::string& sym) { }
|
||||||
virtual void Backspace() { }
|
virtual void Backspace() { }
|
||||||
virtual void Enter() { }
|
virtual void Enter() { }
|
||||||
@ -42,6 +47,11 @@ namespace starlight {
|
|||||||
: multiLine(multiLine), pText(textptr), minIndex(minIndex), eOnModify(onModify), eOnFinalize(onFinalize) { }
|
: multiLine(multiLine), pText(textptr), minIndex(minIndex), eOnModify(onModify), eOnFinalize(onFinalize) { }
|
||||||
~InputHandlerDirectEdit() override { }
|
~InputHandlerDirectEdit() override { }
|
||||||
|
|
||||||
|
std::string& GetPreviewText() override;
|
||||||
|
|
||||||
|
unsigned int GetCursor() override;
|
||||||
|
void SetCursor(unsigned int index) override;
|
||||||
|
|
||||||
void InputSymbol(const std::string& sym) override;
|
void InputSymbol(const std::string& sym) override;
|
||||||
void Backspace() override;
|
void Backspace() override;
|
||||||
void Enter() override;
|
void Enter() override;
|
||||||
@ -57,9 +67,14 @@ namespace starlight {
|
|||||||
std::function<void(const std::string&)> eOnFinalize = { };
|
std::function<void(const std::string&)> eOnFinalize = { };
|
||||||
|
|
||||||
InputHandlerBuffered(const std::string& text = "", bool multiLine = false, std::function<void(const std::string&)> onFinalize = {})
|
InputHandlerBuffered(const std::string& text = "", bool multiLine = false, std::function<void(const std::string&)> onFinalize = {})
|
||||||
: showPreview(true), buffer(text), multiLine(multiLine), eOnFinalize(onFinalize) { }
|
: buffer(text), multiLine(multiLine), eOnFinalize(onFinalize) { this->showPreview = true; }
|
||||||
~InputHandlerBuffered() override { }
|
~InputHandlerBuffered() override { }
|
||||||
|
|
||||||
|
std::string& GetPreviewText() override;
|
||||||
|
|
||||||
|
unsigned int GetCursor() override;
|
||||||
|
void SetCursor(unsigned int index) override;
|
||||||
|
|
||||||
void InputSymbol(const std::string& sym) override;
|
void InputSymbol(const std::string& sym) override;
|
||||||
void Backspace() override;
|
void Backspace() override;
|
||||||
void Enter() override;
|
void Enter() override;
|
||||||
|
33
libstarlight/source/starlight/ui/DrawLayerProxy.cpp
Normal file
33
libstarlight/source/starlight/ui/DrawLayerProxy.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include "DrawLayerProxy.h"
|
||||||
|
|
||||||
|
#include "starlight/GFXManager.h"
|
||||||
|
|
||||||
|
using starlight::GFXManager;
|
||||||
|
using starlight::gfx::DrawContextCanvas;
|
||||||
|
|
||||||
|
using starlight::ui::DrawLayerProxy;
|
||||||
|
|
||||||
|
void DrawLayerProxy::Refresh() {
|
||||||
|
canvas.reset();
|
||||||
|
MarkForRedraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawLayerProxy::PreDraw() {
|
||||||
|
if (useCanvas) {
|
||||||
|
if (!canvas) {
|
||||||
|
canvas = std::make_unique<DrawContextCanvas>(rect.size);
|
||||||
|
canvas->Clear();
|
||||||
|
GFXManager::PushContext(canvas.get());
|
||||||
|
if (eDraw) eDraw(*this);
|
||||||
|
GFXManager::PopContext();
|
||||||
|
}
|
||||||
|
} else canvas.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawLayerProxy::Draw() {
|
||||||
|
if (canvas) {
|
||||||
|
canvas->Draw(VRect(rect.pos, canvas->rect.size));
|
||||||
|
} else {
|
||||||
|
if (eDraw) eDraw(*this);
|
||||||
|
}
|
||||||
|
}
|
40
libstarlight/source/starlight/ui/DrawLayerProxy.h
Normal file
40
libstarlight/source/starlight/ui/DrawLayerProxy.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "starlight/_global.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
#include "starlight/datatypes/Vector2.h"
|
||||||
|
#include "starlight/datatypes/VRect.h"
|
||||||
|
|
||||||
|
#include "starlight/gfx/DrawContextCanvas.h"
|
||||||
|
|
||||||
|
#include "starlight/ui/UIElement.h"
|
||||||
|
|
||||||
|
namespace starlight {
|
||||||
|
namespace ui {
|
||||||
|
class DrawLayerProxy : public UIElement {
|
||||||
|
private:
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool useCanvas = false;
|
||||||
|
|
||||||
|
std::unique_ptr<gfx::DrawContextCanvas> canvas;
|
||||||
|
|
||||||
|
std::function<void(DrawLayerProxy&)> eDraw;
|
||||||
|
|
||||||
|
DrawLayerProxy(VRect rect, std::function<void(DrawLayerProxy&)> drawFunc, bool useCanvas = false) : useCanvas(useCanvas), eDraw(drawFunc) { this->rect = rect; }
|
||||||
|
~DrawLayerProxy() override { }
|
||||||
|
|
||||||
|
void Refresh();
|
||||||
|
|
||||||
|
//void Update() override;
|
||||||
|
void PreDraw() override;
|
||||||
|
void Draw() override;
|
||||||
|
|
||||||
|
//
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ roadmap to first release, in no particular order {
|
|||||||
InputManager::OpenKeyboard
|
InputManager::OpenKeyboard
|
||||||
}
|
}
|
||||||
textbox widget
|
textbox widget
|
||||||
|
- "draw proxy" UIElement (takes a std::function for draw operation)
|
||||||
|
|
||||||
add license!! (MIT?)
|
add license!! (MIT?)
|
||||||
ADD README.MD PLS
|
ADD README.MD PLS
|
||||||
|
@ -32,6 +32,13 @@
|
|||||||
"dialogs" : {
|
"dialogs" : {
|
||||||
"messageBox" : {
|
"messageBox" : {
|
||||||
"size" : [240, 160]
|
"size" : [240, 160]
|
||||||
|
},
|
||||||
|
"OSK" : {
|
||||||
|
"preview" : {
|
||||||
|
"font" : "default.16",
|
||||||
|
"textColor" : "white",
|
||||||
|
"borderColor" : "black"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user