Fix code format and add Style object (unused)
This commit is contained in:
parent
896f98476e
commit
d15b25dba6
25 changed files with 320 additions and 201 deletions
2
.ccls
2
.ccls
|
|
@ -1,4 +1,4 @@
|
||||||
clang++
|
clangd
|
||||||
-std=c++17
|
-std=c++17
|
||||||
-DDEBUG
|
-DDEBUG
|
||||||
-Wall
|
-Wall
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
BasedOnStyle: Microsoft
|
BasedOnStyle: Microsoft
|
||||||
AccessModifierOffset: -3
|
AccessModifierOffset: -4
|
||||||
AlignAfterOpenBracket: AlwaysBreak
|
AlignAfterOpenBracket: AlwaysBreak
|
||||||
AlignConsecutiveAssignments: None
|
AlignConsecutiveAssignments: None
|
||||||
AlignConsecutiveBitFields: None
|
AlignConsecutiveBitFields: None
|
||||||
|
|
@ -21,7 +21,7 @@ AllowShortLoopsOnASingleLine: true
|
||||||
AlwaysBreakAfterReturnType: None
|
AlwaysBreakAfterReturnType: None
|
||||||
AlwaysBreakBeforeMultilineStrings: false
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
AlwaysBreakTemplateDeclarations: No
|
AlwaysBreakTemplateDeclarations: No
|
||||||
AttributeMacros: ['__ununsed']
|
AttributeMacros: ['__unused']
|
||||||
BinPackArguments: true
|
BinPackArguments: true
|
||||||
BinPackParameters: true
|
BinPackParameters: true
|
||||||
BitFieldColonSpacing: Both
|
BitFieldColonSpacing: Both
|
||||||
|
|
@ -50,12 +50,13 @@ BreakBeforeTernaryOperators: true
|
||||||
BreakConstructorInitializers: AfterColon
|
BreakConstructorInitializers: AfterColon
|
||||||
BreakInheritanceList: AfterColon
|
BreakInheritanceList: AfterColon
|
||||||
BreakStringLiterals: true
|
BreakStringLiterals: true
|
||||||
ColumnLimit: 140
|
ColumnLimit: 120
|
||||||
CompactNamespaces: false
|
CompactNamespaces: false
|
||||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
Cpp11BracedListStyle: true
|
Cpp11BracedListStyle: true
|
||||||
DeriveLineEnding: true
|
DeriveLineEnding: true
|
||||||
DerivePointerAlignment: false
|
DerivePointerAlignment: false
|
||||||
|
EmptyLineAfterAccessModifier: Never
|
||||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||||
FixNamespaceComments: true
|
FixNamespaceComments: true
|
||||||
IncludeBlocks: Regroup
|
IncludeBlocks: Regroup
|
||||||
|
|
@ -78,13 +79,14 @@ IncludeCategories:
|
||||||
- Regex: '^"'
|
- Regex: '^"'
|
||||||
Priority: 4
|
Priority: 4
|
||||||
SortPriority: 4
|
SortPriority: 4
|
||||||
|
IndentAccessModifiers: false
|
||||||
IndentCaseBlocks: true
|
IndentCaseBlocks: true
|
||||||
IndentCaseLabels: true
|
IndentCaseLabels: true
|
||||||
IndentExternBlock: NoIndent
|
IndentExternBlock: NoIndent
|
||||||
IndentGotoLabels: false
|
IndentGotoLabels: false
|
||||||
IndentPPDirectives: BeforeHash
|
IndentPPDirectives: BeforeHash
|
||||||
IndentRequires: true
|
IndentRequires: true
|
||||||
IndentWidth: 3
|
IndentWidth: 4
|
||||||
IndentWrappedFunctionNames: false
|
IndentWrappedFunctionNames: false
|
||||||
InsertTrailingCommas: None
|
InsertTrailingCommas: None
|
||||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
|
@ -116,6 +118,6 @@ SpacesInContainerLiterals: false
|
||||||
SpacesInParentheses: false
|
SpacesInParentheses: false
|
||||||
SpacesInSquareBrackets: false
|
SpacesInSquareBrackets: false
|
||||||
Standard: c++17
|
Standard: c++17
|
||||||
TabWidth: 3
|
TabWidth: 4
|
||||||
UseCRLF: false
|
UseCRLF: false
|
||||||
UseTab: Always
|
UseTab: Always
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
|
* layout
|
||||||
|
|
||||||
* button
|
* button
|
||||||
|
|
||||||
* layout (constraint)
|
* lambda constructor
|
||||||
|
|
||||||
* scroll
|
* scroll
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ constexpr unsigned int FONT_TEXTURE_UNIT = GL_TEXTURE0;
|
||||||
namespace uui
|
namespace uui
|
||||||
{
|
{
|
||||||
typedef std::variant<int, float> position_t;
|
typedef std::variant<int, float> position_t;
|
||||||
|
typedef std::variant<int, float> size_t;
|
||||||
enum Direction
|
enum Direction
|
||||||
{
|
{
|
||||||
HORIZONTAL,
|
HORIZONTAL,
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ public:
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
std::shared_ptr<GlWindow> create_window(int width, int height, const std::string& title);
|
std::shared_ptr<GlWindow> create_window(int width, int height, const std::string& title);
|
||||||
std::shared_ptr<GlWindow> get_window(size_t index) const;
|
std::shared_ptr<GlWindow> get_window(std::size_t index) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static GlApplication* application_pointer;
|
static GlApplication* application_pointer;
|
||||||
|
|
@ -55,9 +55,11 @@ public:
|
||||||
GlWindow(GlWindow&&) = delete;
|
GlWindow(GlWindow&&) = delete;
|
||||||
~GlWindow();
|
~GlWindow();
|
||||||
|
|
||||||
std::shared_ptr<GlComponent> create_component(const position_t x, const position_t y, const position_t width, const position_t height);
|
std::shared_ptr<GlComponent> create_component(
|
||||||
|
const position_t x, const position_t y, const position_t width, const position_t height);
|
||||||
std::shared_ptr<GlLabel> create_label(
|
std::shared_ptr<GlLabel> create_label(
|
||||||
const position_t x, const position_t y, const std::string& text, const std::tuple<float, float, float, float>& text_color);
|
const position_t x, const position_t y, const std::string& text,
|
||||||
|
const std::tuple<float, float, float, float>& text_color);
|
||||||
std::shared_ptr<GlFlex> create_flex(const position_t x, const position_t y, const Direction direction);
|
std::shared_ptr<GlFlex> create_flex(const position_t x, const position_t y, const Direction direction);
|
||||||
std::shared_ptr<GlStack> create_stack(const position_t x, const position_t y, const Direction direction);
|
std::shared_ptr<GlStack> create_stack(const position_t x, const position_t y, const Direction direction);
|
||||||
|
|
||||||
|
|
|
||||||
29
include/uui/opengl/button.hpp
Normal file
29
include/uui/opengl/button.hpp
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
#include "uui/opengl/component.hpp"
|
||||||
|
|
||||||
|
namespace uui
|
||||||
|
{
|
||||||
|
class GlButton: public GlComponent
|
||||||
|
{
|
||||||
|
friend class GlWindow;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
GlButton(
|
||||||
|
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent,
|
||||||
|
std::size_t parent_index, const position_t x, const position_t y, const Direction direction);
|
||||||
|
GlButton(
|
||||||
|
std::shared_ptr<GlWindow> window, std::size_t window_index, const position_t x, const position_t y,
|
||||||
|
const Direction direction):
|
||||||
|
GlButton(window, window_index, window, window_index, x, y, direction)
|
||||||
|
{}
|
||||||
|
|
||||||
|
virtual std::tuple<int, int> get_child_position(const std::size_t child_index) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace uui
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include "graphic_context.hpp"
|
#include "graphic_context.hpp"
|
||||||
#include "uui/config.hpp"
|
#include "uui/config.hpp"
|
||||||
#include "uui/opengl/container.hpp"
|
#include "uui/opengl/container.hpp"
|
||||||
|
#include "uui/style.hpp"
|
||||||
#include "window.hpp"
|
#include "window.hpp"
|
||||||
|
|
||||||
namespace uui
|
namespace uui
|
||||||
|
|
@ -19,21 +20,22 @@ class GlComponent: public std::enable_shared_from_this<GlComponent>
|
||||||
friend class GlStack;
|
friend class GlStack;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~GlComponent();
|
virtual ~GlComponent();
|
||||||
|
|
||||||
void set_background_color(float r, float g, float b, float a = 1.0f);
|
void set_background_color(float r, float g, float b, float a = 1.0f);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<GlWindow> window;
|
std::shared_ptr<GlWindow> window;
|
||||||
size_t window_index;
|
std::size_t window_index;
|
||||||
std::shared_ptr<GlContainer> parent;
|
std::shared_ptr<GlContainer> parent;
|
||||||
size_t parent_index;
|
std::size_t parent_index;
|
||||||
|
|
||||||
position_t position_x;
|
position_t position_x;
|
||||||
position_t position_y;
|
position_t position_y;
|
||||||
position_t size_width;
|
size_t size_width;
|
||||||
position_t size_height;
|
size_t size_height;
|
||||||
bool coord_all_relative;
|
bool coord_all_relative;
|
||||||
|
Style style;
|
||||||
|
|
||||||
std::array<float, 4> background_color;
|
std::array<float, 4> background_color;
|
||||||
|
|
||||||
|
|
@ -44,11 +46,12 @@ protected:
|
||||||
GLuint gl_ebo;
|
GLuint gl_ebo;
|
||||||
|
|
||||||
GlComponent(
|
GlComponent(
|
||||||
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent, std::size_t parent_index,
|
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent,
|
||||||
const position_t x, const position_t y, const position_t width, const position_t height);
|
std::size_t parent_index, const position_t x, const position_t y, const position_t width,
|
||||||
|
const position_t height);
|
||||||
GlComponent(
|
GlComponent(
|
||||||
std::shared_ptr<GlWindow> window, std::size_t window_index, const position_t x, const position_t y, const position_t width,
|
std::shared_ptr<GlWindow> window, std::size_t window_index, const position_t x, const position_t y,
|
||||||
const position_t height):
|
const position_t width, const position_t height):
|
||||||
GlComponent(window, window_index, window, window_index, x, y, width, height)
|
GlComponent(window, window_index, window, window_index, x, y, width, height)
|
||||||
{}
|
{}
|
||||||
GlComponent(const GlComponent&) = delete;
|
GlComponent(const GlComponent&) = delete;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
@ -39,7 +40,11 @@ public:
|
||||||
std::vector<std::shared_ptr<GlComponent>> components;
|
std::vector<std::shared_ptr<GlComponent>> components;
|
||||||
Type type;
|
Type type;
|
||||||
|
|
||||||
~GlContainer() { components.clear(); }
|
virtual ~GlContainer()
|
||||||
|
{
|
||||||
|
std::cout << "Destroying Container" << std::endl;
|
||||||
|
components.clear();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace uui
|
} // namespace uui
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,11 @@ class GlFlex: public GlStack
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GlFlex(
|
GlFlex(
|
||||||
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent, std::size_t parent_index,
|
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent,
|
||||||
const position_t x, const position_t y, const Direction direction);
|
std::size_t parent_index, const position_t x, const position_t y, const Direction direction);
|
||||||
GlFlex(std::shared_ptr<GlWindow> window, std::size_t window_index, const position_t x, const position_t y, const Direction direction):
|
GlFlex(
|
||||||
|
std::shared_ptr<GlWindow> window, std::size_t window_index, const position_t x, const position_t y,
|
||||||
|
const Direction direction):
|
||||||
GlFlex(window, window_index, window, window_index, x, y, direction)
|
GlFlex(window, window_index, window, window_index, x, y, direction)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,6 @@ private:
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void deinit();
|
void deinit();
|
||||||
const Font& init_font(const std::string& font_path, size_t font_size);
|
const Font& init_font(const std::string& font_path, std::size_t font_size);
|
||||||
};
|
};
|
||||||
} // namespace uui
|
} // namespace uui
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class GlLabel: public GlComponent
|
||||||
friend class GlFlex;
|
friend class GlFlex;
|
||||||
friend class GlStack;
|
friend class GlStack;
|
||||||
|
|
||||||
size_t font_index;
|
std::size_t font_index;
|
||||||
|
|
||||||
float get_width() const;
|
float get_width() const;
|
||||||
float get_height() const;
|
float get_height() const;
|
||||||
|
|
@ -29,11 +29,12 @@ protected:
|
||||||
int text_height;
|
int text_height;
|
||||||
|
|
||||||
GlLabel(
|
GlLabel(
|
||||||
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent, std::size_t parent_index,
|
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent,
|
||||||
const position_t x, const position_t y, const std::string& text, const std::tuple<float, float, float, float>& text_color);
|
std::size_t parent_index, const position_t x, const position_t y, const std::string& text,
|
||||||
|
const std::tuple<float, float, float, float>& text_color);
|
||||||
GlLabel(
|
GlLabel(
|
||||||
std::shared_ptr<GlWindow> window, std::size_t window_index, const position_t x, const position_t y, const std::string& text,
|
std::shared_ptr<GlWindow> window, std::size_t window_index, const position_t x, const position_t y,
|
||||||
const std::tuple<float, float, float, float>& text_color):
|
const std::string& text, const std::tuple<float, float, float, float>& text_color):
|
||||||
GlLabel(window, window_index, window, window_index, x, y, text, text_color)
|
GlLabel(window, window_index, window, window_index, x, y, text, text_color)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,8 @@ class GlStack: public GlComponent, public GlContainer
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::shared_ptr<GlComponent> create_component(const position_t width, const position_t height);
|
std::shared_ptr<GlComponent> create_component(const position_t width, const position_t height);
|
||||||
std::shared_ptr<GlLabel> create_label(const std::string& text, const std::tuple<float, float, float, float>& text_color);
|
std::shared_ptr<GlLabel> create_label(
|
||||||
|
const std::string& text, const std::tuple<float, float, float, float>& text_color);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Direction direction;
|
Direction direction;
|
||||||
|
|
@ -24,9 +25,11 @@ protected:
|
||||||
int content_height;
|
int content_height;
|
||||||
|
|
||||||
GlStack(
|
GlStack(
|
||||||
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent, std::size_t parent_index,
|
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent,
|
||||||
const position_t x, const position_t y, const Direction direction);
|
std::size_t parent_index, const position_t x, const position_t y, const Direction direction);
|
||||||
GlStack(std::shared_ptr<GlWindow> window, std::size_t window_index, const position_t x, const position_t y, const Direction direction):
|
GlStack(
|
||||||
|
std::shared_ptr<GlWindow> window, std::size_t window_index, const position_t x, const position_t y,
|
||||||
|
const Direction direction):
|
||||||
GlStack(window, window_index, window, window_index, x, y, direction)
|
GlStack(window, window_index, window, window_index, x, y, direction)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
|
||||||
46
include/uui/style.hpp
Normal file
46
include/uui/style.hpp
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
#include "config.hpp"
|
||||||
|
|
||||||
|
namespace uui
|
||||||
|
{
|
||||||
|
struct Style
|
||||||
|
{
|
||||||
|
enum Position
|
||||||
|
{
|
||||||
|
RELATIVE,
|
||||||
|
ABSOLUTE
|
||||||
|
};
|
||||||
|
enum Alignment
|
||||||
|
{
|
||||||
|
START,
|
||||||
|
CENTER,
|
||||||
|
END
|
||||||
|
};
|
||||||
|
struct AbsolutePostion
|
||||||
|
{
|
||||||
|
std::optional<position_t> left;
|
||||||
|
std::optional<position_t> right;
|
||||||
|
std::optional<position_t> top;
|
||||||
|
std::optional<position_t> bottom;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Layout
|
||||||
|
Position position;
|
||||||
|
Alignment horizontal_alignment;
|
||||||
|
Alignment vertical_alignment;
|
||||||
|
std::optional<uui::size_t> width;
|
||||||
|
std::optional<uui::size_t> height;
|
||||||
|
std::optional<uui::size_t> margin;
|
||||||
|
std::optional<uui::size_t> padding;
|
||||||
|
// For absolute positioning
|
||||||
|
std::unique_ptr<AbsolutePostion> absolute_position;
|
||||||
|
|
||||||
|
// Color
|
||||||
|
std::optional<std::tuple<float, float, float, float>> background_color;
|
||||||
|
};
|
||||||
|
} // namespace uui
|
||||||
3
makefile
3
makefile
|
|
@ -11,3 +11,6 @@ debug:
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@PYTHONPATH=$(UMAKE_PATH) python $(MAKE_PATH)/make.py --clean
|
@PYTHONPATH=$(UMAKE_PATH) python $(MAKE_PATH)/make.py --clean
|
||||||
|
|
||||||
|
lint:
|
||||||
|
@clang-format --dry-run --Werror include/uui/*.hpp include/uui/**/*.hpp src/uui/*.cpp src/uui/**/*.cpp src/test/*.cpp
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,7 @@ int main()
|
||||||
uui::GlApplication app;
|
uui::GlApplication app;
|
||||||
// uui::GlApplication app2; // exception : application already created
|
// uui::GlApplication app2; // exception : application already created
|
||||||
auto window = app.create_window(800, 600, "OpenGl!");
|
auto window = app.create_window(800, 600, "OpenGl!");
|
||||||
for(int i = 0; i < 100; i += 1)
|
for(int i = 0; i < 100; i += 1) window->create_label(4 * i, 4 * i, "Hello World!", {1.0f, 1.0f, 1.0f, 0.5f});
|
||||||
window->create_label(4*i, 4*i, "Hello World!", {1.0f, 1.0f, 1.0f, 0.5f});
|
|
||||||
app.run();
|
app.run();
|
||||||
}
|
}
|
||||||
catch(const std::exception& error)
|
catch(const std::exception& error)
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ using namespace std;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// try
|
try
|
||||||
// {
|
{
|
||||||
cout << "Starting example 1" << endl;
|
cout << "Starting example 1" << endl;
|
||||||
{
|
{
|
||||||
uui::GlApplication app;
|
uui::GlApplication app;
|
||||||
|
|
@ -63,28 +63,28 @@ int main()
|
||||||
|
|
||||||
app.run();
|
app.run();
|
||||||
}
|
}
|
||||||
// cout << "\nStarting example 2" << endl;
|
cout << "\nStarting example 2" << endl;
|
||||||
// {
|
{
|
||||||
// uui::GlApplication app;
|
uui::GlApplication app;
|
||||||
// auto window_1 = app.create_window(800, 600, "OpenGl!");
|
auto window_1 = app.create_window(800, 600, "OpenGl!");
|
||||||
// auto comp = window_1->create_component(0.25f, 0.25f, 0.5f, 0.5f);
|
auto comp = window_1->create_component(0.25f, 0.25f, 0.5f, 0.5f);
|
||||||
// comp->set_background_color(0.8f, 0.1f, 0.5f);
|
comp->set_background_color(0.8f, 0.1f, 0.5f);
|
||||||
// comp = window_1->create_component(0.75f, 0.75f, 0.25f, 0.25f);
|
comp = window_1->create_component(0.75f, 0.75f, 0.25f, 0.25f);
|
||||||
// comp->set_background_color(0.2f, 0.1f, 0.5f);
|
comp->set_background_color(0.2f, 0.1f, 0.5f);
|
||||||
|
|
||||||
// auto window_2 = app.create_window(600, 600, "OpenGL 2!");
|
auto window_2 = app.create_window(600, 600, "OpenGL 2!");
|
||||||
// comp = window_2->create_component(0, 0.5f, 100, 0.5f);
|
comp = window_2->create_component(0, 0.5f, 100, 0.5f);
|
||||||
// comp->set_background_color(0.2f, 0.5f, 0.3f);
|
comp->set_background_color(0.2f, 0.5f, 0.3f);
|
||||||
// auto label = window_2->create_label(50, 50, "Hello World!", {0.5f, 1.0f, 0.5f, 1.0f});
|
auto label = window_2->create_label(50, 50, "Hello World!", {0.5f, 1.0f, 0.5f, 1.0f});
|
||||||
// label->set_background_color(0.1f, 0.2f, 0.5f);
|
label->set_background_color(0.1f, 0.2f, 0.5f);
|
||||||
// app.run();
|
app.run();
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// catch(const std::exception& error)
|
catch(const std::exception& error)
|
||||||
// {
|
{
|
||||||
// std::cerr << error.what() << std::endl;
|
std::cerr << error.what() << std::endl;
|
||||||
// return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
// }
|
}
|
||||||
|
|
||||||
cout << "Example done" << endl;
|
cout << "Example done" << endl;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ std::shared_ptr<uui::GlWindow> uui::GlApplication::create_window(int width, int
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<uui::GlWindow> uui::GlApplication::get_window(size_t index) const
|
std::shared_ptr<uui::GlWindow> uui::GlApplication::get_window(std::size_t index) const
|
||||||
{
|
{
|
||||||
if(index > windows.size())
|
if(index > windows.size())
|
||||||
throw std::runtime_error("Application doesn't have window at given index");
|
throw std::runtime_error("Application doesn't have window at given index");
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
#include "uui/opengl/gl_utils.hpp"
|
#include "uui/opengl/gl_utils.hpp"
|
||||||
|
|
||||||
uui::GlComponent::GlComponent(
|
uui::GlComponent::GlComponent(
|
||||||
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent, std::size_t parent_index,
|
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent,
|
||||||
const position_t x, const position_t y, const position_t width, const position_t height):
|
std::size_t parent_index, const position_t x, const position_t y, const position_t width, const position_t height):
|
||||||
window(window),
|
window(window),
|
||||||
window_index(window_index), parent(parent), parent_index(parent_index), position_x(x), position_y(y), size_width(width),
|
window_index(window_index), parent(parent), parent_index(parent_index), position_x(x), position_y(y),
|
||||||
size_height(height), initialized(false)
|
size_width(width), size_height(height), initialized(false)
|
||||||
{
|
{
|
||||||
if constexpr(uui::GlApplication::debug_mode)
|
if constexpr(uui::GlApplication::debug_mode)
|
||||||
std::cout << "Creating a GlBox" << std::endl;
|
std::cout << "Creating a GlBox" << std::endl;
|
||||||
|
|
@ -86,20 +86,25 @@ void uui::GlComponent::init()
|
||||||
|
|
||||||
void uui::GlComponent::set_vbo_data()
|
void uui::GlComponent::set_vbo_data()
|
||||||
{
|
{
|
||||||
float vert_x =
|
float vert_x = position_x.index() == 1
|
||||||
position_x.index() == 1 ? std::get<1>(position_x) : static_cast<float>(std::get<0>(position_x)) / static_cast<float>(window->width);
|
? std::get<1>(position_x)
|
||||||
float vert_y =
|
: static_cast<float>(std::get<0>(position_x)) / static_cast<float>(window->width);
|
||||||
position_y.index() == 1 ? std::get<1>(position_y) : static_cast<float>(std::get<0>(position_y)) / static_cast<float>(window->height);
|
float vert_y = position_y.index() == 1
|
||||||
float vert_w =
|
? std::get<1>(position_y)
|
||||||
size_width.index() == 1 ? std::get<1>(size_width) : static_cast<float>(std::get<0>(size_width)) / static_cast<float>(window->width);
|
: static_cast<float>(std::get<0>(position_y)) / static_cast<float>(window->height);
|
||||||
float vert_h = size_height.index() == 1 ? std::get<1>(size_height)
|
float vert_w = size_width.index() == 1
|
||||||
|
? std::get<1>(size_width)
|
||||||
|
: static_cast<float>(std::get<0>(size_width)) / static_cast<float>(window->width);
|
||||||
|
float vert_h = size_height.index() == 1
|
||||||
|
? std::get<1>(size_height)
|
||||||
: static_cast<float>(std::get<0>(size_height)) / static_cast<float>(window->height);
|
: static_cast<float>(std::get<0>(size_height)) / static_cast<float>(window->height);
|
||||||
float x_min = (2.0f * vert_x) - 1.0f;
|
float x_min = (2.0f * vert_x) - 1.0f;
|
||||||
float x_max = x_min + (2.0f * vert_w);
|
float x_max = x_min + (2.0f * vert_w);
|
||||||
float y_min = (-2.0f * vert_y) + 1.0f;
|
float y_min = (-2.0f * vert_y) + 1.0f;
|
||||||
float y_max = y_min - (2.0f * vert_h);
|
float y_max = y_min - (2.0f * vert_h);
|
||||||
// clang-format off
|
// clang-format off
|
||||||
float vertices[] = {
|
float vertices[] =
|
||||||
|
{
|
||||||
x_max, y_min, background_color[0], background_color[1], background_color[2], background_color[3], // top right
|
x_max, y_min, background_color[0], background_color[1], background_color[2], background_color[3], // top right
|
||||||
x_max, y_max, background_color[0], background_color[1], background_color[2], background_color[3], // bottom right
|
x_max, y_max, background_color[0], background_color[1], background_color[2], background_color[3], // bottom right
|
||||||
x_min, y_max, background_color[0], background_color[1], background_color[2], background_color[3], // bottom left
|
x_min, y_max, background_color[0], background_color[1], background_color[2], background_color[3], // bottom left
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
#include "uui/opengl/gl_utils.hpp"
|
#include "uui/opengl/gl_utils.hpp"
|
||||||
|
|
||||||
uui::GlFlex::GlFlex(
|
uui::GlFlex::GlFlex(
|
||||||
std::shared_ptr<uui::GlWindow> window, std::size_t window_index, std::shared_ptr<uui::GlContainer> parent, std::size_t parent_index,
|
std::shared_ptr<uui::GlWindow> window, std::size_t window_index, std::shared_ptr<uui::GlContainer> parent,
|
||||||
const position_t x, const position_t y, const Direction direction):
|
std::size_t parent_index, const position_t x, const position_t y, const Direction direction):
|
||||||
GlStack(window, window_index, parent, parent_index, x, y, direction)
|
GlStack(window, window_index, parent, parent_index, x, y, direction)
|
||||||
{
|
{
|
||||||
if constexpr(uui::GlApplication::debug_mode)
|
if constexpr(uui::GlApplication::debug_mode)
|
||||||
|
|
@ -18,10 +18,12 @@ uui::GlFlex::GlFlex(
|
||||||
|
|
||||||
std::tuple<int, int> uui::GlFlex::get_child_position(const std::size_t child_index) const
|
std::tuple<int, int> uui::GlFlex::get_child_position(const std::size_t child_index) const
|
||||||
{
|
{
|
||||||
const int initial_x =
|
const int initial_x = position_x.index() == 0
|
||||||
position_x.index() == 0 ? std::get<0>(position_x) : static_cast<int>(std::get<1>(position_x) * static_cast<float>(window->width));
|
? std::get<0>(position_x)
|
||||||
const int initial_y =
|
: static_cast<int>(std::get<1>(position_x) * static_cast<float>(window->width));
|
||||||
position_y.index() == 0 ? std::get<0>(position_y) : static_cast<int>(std::get<1>(position_y) * static_cast<float>(window->height));
|
const int initial_y = position_y.index() == 0
|
||||||
|
? std::get<0>(position_y)
|
||||||
|
: static_cast<int>(std::get<1>(position_y) * static_cast<float>(window->height));
|
||||||
|
|
||||||
if(child_index == 0)
|
if(child_index == 0)
|
||||||
return {initial_x, initial_y};
|
return {initial_x, initial_y};
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ void uui::GlFontManager::deinit()
|
||||||
initialized = false;
|
initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uui::GlFontManager::Font& uui::GlFontManager::init_font(const std::string& font_path, size_t font_size)
|
const uui::GlFontManager::Font& uui::GlFontManager::init_font(const std::string& font_path, std::size_t font_size)
|
||||||
{
|
{
|
||||||
fonts.emplace_back();
|
fonts.emplace_back();
|
||||||
auto& font = fonts.back();
|
auto& font = fonts.back();
|
||||||
|
|
@ -206,7 +206,8 @@ const uui::GlFontManager::Font& uui::GlFontManager::init_font(const std::string&
|
||||||
}
|
}
|
||||||
|
|
||||||
glTexSubImage2D(
|
glTexSubImage2D(
|
||||||
GL_TEXTURE_2D, 0, offset_x, offset_y, glyph->bitmap.width, glyph->bitmap.rows, GL_RED, GL_UNSIGNED_BYTE, glyph->bitmap.buffer);
|
GL_TEXTURE_2D, 0, offset_x, offset_y, glyph->bitmap.width, glyph->bitmap.rows, GL_RED, GL_UNSIGNED_BYTE,
|
||||||
|
glyph->bitmap.buffer);
|
||||||
font.char_infos[i].advance_x = glyph->advance.x >> 6;
|
font.char_infos[i].advance_x = glyph->advance.x >> 6;
|
||||||
font.char_infos[i].advance_y = glyph->advance.y >> 6;
|
font.char_infos[i].advance_y = glyph->advance.y >> 6;
|
||||||
|
|
||||||
|
|
@ -234,7 +235,7 @@ std::tuple<int, int> uui::GlFontManager::get_text_size(
|
||||||
float height = 0.0f;
|
float height = 0.0f;
|
||||||
for(auto current_char: text)
|
for(auto current_char: text)
|
||||||
{
|
{
|
||||||
const auto& char_info = font.char_infos[static_cast<size_t>(current_char)];
|
const auto& char_info = font.char_infos[static_cast<std::size_t>(current_char)];
|
||||||
width += char_info.advance_x * scale_x;
|
width += char_info.advance_x * scale_x;
|
||||||
// height = std::max(height, char_info.bitmap_top + char_info.bitmap_height * scale_y);
|
// height = std::max(height, char_info.bitmap_top + char_info.bitmap_height * scale_y);
|
||||||
height = std::max(height, roundf(char_info.bitmap_height * scale_y));
|
height = std::max(height, roundf(char_info.bitmap_height * scale_y));
|
||||||
|
|
@ -268,7 +269,7 @@ void uui::GlFontManager::render_text(
|
||||||
float out_base_y = y;
|
float out_base_y = y;
|
||||||
for(auto current_char: text)
|
for(auto current_char: text)
|
||||||
{
|
{
|
||||||
const auto& char_info = font.char_infos[static_cast<size_t>(current_char)];
|
const auto& char_info = font.char_infos[static_cast<std::size_t>(current_char)];
|
||||||
// Calculate the vertex and texture coordinates
|
// Calculate the vertex and texture coordinates
|
||||||
float char_x = out_base_x + char_info.bitmap_left * scale_x;
|
float char_x = out_base_x + char_info.bitmap_left * scale_x;
|
||||||
float char_y = out_base_y - char_info.bitmap_top * scale_y;
|
float char_y = out_base_y - char_info.bitmap_top * scale_y;
|
||||||
|
|
@ -284,7 +285,8 @@ void uui::GlFontManager::render_text(
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
float current_vertex[24] = {
|
float current_vertex[24] =
|
||||||
|
{
|
||||||
char_x, char_y, char_info.texture_x, char_info.texture_y, // top_left
|
char_x, char_y, char_info.texture_x, char_info.texture_y, // top_left
|
||||||
char_x + w, char_y, char_info.texture_x + char_info.bitmap_width / font.atlas_width, char_info.texture_y, // top-right
|
char_x + w, char_y, char_info.texture_x + char_info.bitmap_width / font.atlas_width, char_info.texture_y, // top-right
|
||||||
char_x, char_y + h, char_info.texture_x, char_info.texture_y + char_info.bitmap_height / font.atlas_height, // bottom-right
|
char_x, char_y + h, char_info.texture_x, char_info.texture_y + char_info.bitmap_height / font.atlas_height, // bottom-right
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,9 @@
|
||||||
#include "uui/opengl/gl_utils.hpp"
|
#include "uui/opengl/gl_utils.hpp"
|
||||||
|
|
||||||
uui::GlLabel::GlLabel(
|
uui::GlLabel::GlLabel(
|
||||||
std::shared_ptr<uui::GlWindow> window, std::size_t window_index, std::shared_ptr<uui::GlContainer> parent, std::size_t parent_index,
|
std::shared_ptr<uui::GlWindow> window, std::size_t window_index, std::shared_ptr<uui::GlContainer> parent,
|
||||||
const position_t x, const position_t y, const std::string& text, const std::tuple<float, float, float, float>& text_color):
|
std::size_t parent_index, const position_t x, const position_t y, const std::string& text,
|
||||||
|
const std::tuple<float, float, float, float>& text_color):
|
||||||
GlComponent(window, window_index, parent, parent_index, x, y, 0.0f, 0.0f),
|
GlComponent(window, window_index, parent, parent_index, x, y, 0.0f, 0.0f),
|
||||||
text(text), text_color(text_color)
|
text(text), text_color(text_color)
|
||||||
{
|
{
|
||||||
|
|
@ -14,7 +15,8 @@ uui::GlLabel::GlLabel(
|
||||||
std::cout << "Creating a GlLabel" << std::endl;
|
std::cout << "Creating a GlLabel" << std::endl;
|
||||||
|
|
||||||
font_index = 0;
|
font_index = 0;
|
||||||
std::tie(text_width, text_height) = window->font_manager.get_text_size(text, window->font_manager.fonts[font_index], 1.0f, 1.0f);
|
std::tie(text_width, text_height) =
|
||||||
|
window->font_manager.get_text_size(text, window->font_manager.fonts[font_index], 1.0f, 1.0f);
|
||||||
size_width = text_width;
|
size_width = text_width;
|
||||||
size_height = text_height;
|
size_height = text_height;
|
||||||
coord_all_relative = false;
|
coord_all_relative = false;
|
||||||
|
|
@ -22,14 +24,15 @@ uui::GlLabel::GlLabel(
|
||||||
|
|
||||||
void uui::GlLabel::render()
|
void uui::GlLabel::render()
|
||||||
{
|
{
|
||||||
float text_x =
|
float text_x = position_x.index() == 1 ? std::get<1>(position_x) * static_cast<float>(window->width)
|
||||||
position_x.index() == 1 ? std::get<1>(position_x) * static_cast<float>(window->width) : static_cast<float>(std::get<0>(position_x));
|
: static_cast<float>(std::get<0>(position_x));
|
||||||
float text_y =
|
float text_y = position_y.index() == 1 ? std::get<1>(position_y) * static_cast<float>(window->height)
|
||||||
position_y.index() == 1 ? std::get<1>(position_y) * static_cast<float>(window->height) : static_cast<float>(std::get<0>(position_y));
|
: static_cast<float>(std::get<0>(position_y));
|
||||||
text_y += static_cast<float>(text_height) - 1;
|
text_y += static_cast<float>(text_height) - 1;
|
||||||
|
|
||||||
glBindVertexArray(gl_vao);
|
glBindVertexArray(gl_vao);
|
||||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, (void*)0);
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, (void*)0);
|
||||||
window->font_manager.render_text(text.c_str(), window->font_manager.fonts.front(), text_x, text_y, 1.0f, 1.0f, text_color);
|
window->font_manager.render_text(
|
||||||
|
text.c_str(), window->font_manager.fonts.front(), text_x, text_y, 1.0f, 1.0f, text_color);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,14 @@
|
||||||
#include "uui/opengl/gl_utils.hpp"
|
#include "uui/opengl/gl_utils.hpp"
|
||||||
|
|
||||||
uui::GlStack::GlStack(
|
uui::GlStack::GlStack(
|
||||||
std::shared_ptr<uui::GlWindow> window, std::size_t window_index, std::shared_ptr<uui::GlContainer> parent, std::size_t parent_index,
|
std::shared_ptr<uui::GlWindow> window, std::size_t window_index, std::shared_ptr<uui::GlContainer> parent,
|
||||||
const position_t x, const position_t y, const Direction direction):
|
std::size_t parent_index, const position_t x, const position_t y, const Direction direction):
|
||||||
GlComponent(window, window_index, parent, parent_index, x, y, 0.0f, 0.0f),
|
GlComponent(window, window_index, parent, parent_index, x, y, 0.0f, 0.0f),
|
||||||
direction(direction)
|
direction(direction)
|
||||||
{
|
{
|
||||||
if constexpr(uui::GlApplication::debug_mode)
|
if constexpr(uui::GlApplication::debug_mode)
|
||||||
std::cout << "Creating a GlStack" << std::endl;
|
std::cout << "Creating a GlStack" << std::endl;
|
||||||
|
|
||||||
std::cout << "Stack:" << direction << std::endl;
|
|
||||||
|
|
||||||
type = Type::STACK;
|
type = Type::STACK;
|
||||||
coord_all_relative = false;
|
coord_all_relative = false;
|
||||||
}
|
}
|
||||||
|
|
@ -26,8 +24,8 @@ std::shared_ptr<uui::GlComponent> uui::GlStack::create_component(const position_
|
||||||
|
|
||||||
glfwMakeContextCurrent(window->glfw_window);
|
glfwMakeContextCurrent(window->glfw_window);
|
||||||
std::shared_ptr<uui::GlComponent> component(new uui::GlComponent(
|
std::shared_ptr<uui::GlComponent> component(new uui::GlComponent(
|
||||||
window, window->components.size(), std::dynamic_pointer_cast<uui::GlContainer>(shared_from_this()), components.size(), 0, 0, width,
|
window, window->components.size(), std::dynamic_pointer_cast<uui::GlContainer>(shared_from_this()),
|
||||||
height));
|
components.size(), 0, 0, width, height));
|
||||||
push_child(component);
|
push_child(component);
|
||||||
component->init();
|
component->init();
|
||||||
std::tie(component->position_x, component->position_y) = get_child_position(components.size() - 1);
|
std::tie(component->position_x, component->position_y) = get_child_position(components.size() - 1);
|
||||||
|
|
@ -36,15 +34,16 @@ std::shared_ptr<uui::GlComponent> uui::GlStack::create_component(const position_
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<uui::GlLabel> uui::GlStack::create_label(const std::string& text, const std::tuple<float, float, float, float>& text_color)
|
std::shared_ptr<uui::GlLabel> uui::GlStack::create_label(
|
||||||
|
const std::string& text, const std::tuple<float, float, float, float>& text_color)
|
||||||
{
|
{
|
||||||
if(!initialized)
|
if(!initialized)
|
||||||
throw std::runtime_error("GlWindow error : cannot create component while not initialized");
|
throw std::runtime_error("GlWindow error : cannot create component while not initialized");
|
||||||
|
|
||||||
glfwMakeContextCurrent(window->glfw_window);
|
glfwMakeContextCurrent(window->glfw_window);
|
||||||
std::shared_ptr<uui::GlLabel> label(new uui::GlLabel(
|
std::shared_ptr<uui::GlLabel> label(new uui::GlLabel(
|
||||||
window, window->components.size(), std::dynamic_pointer_cast<uui::GlContainer>(shared_from_this()), components.size(), 0, 0, text,
|
window, window->components.size(), std::dynamic_pointer_cast<uui::GlContainer>(shared_from_this()),
|
||||||
text_color));
|
components.size(), 0, 0, text, text_color));
|
||||||
push_child(label);
|
push_child(label);
|
||||||
label->init();
|
label->init();
|
||||||
std::tie(label->position_x, label->position_y) = get_child_position(components.size() - 1);
|
std::tie(label->position_x, label->position_y) = get_child_position(components.size() - 1);
|
||||||
|
|
@ -55,10 +54,10 @@ std::shared_ptr<uui::GlLabel> uui::GlStack::create_label(const std::string& text
|
||||||
|
|
||||||
std::tuple<int, int> uui::GlStack::get_child_position(const std::size_t child_index) const
|
std::tuple<int, int> uui::GlStack::get_child_position(const std::size_t child_index) const
|
||||||
{
|
{
|
||||||
int x =
|
int x = position_x.index() == 0 ? std::get<0>(position_x)
|
||||||
position_x.index() == 0 ? std::get<0>(position_x) : static_cast<int>(std::get<1>(position_x) * static_cast<float>(window->width));
|
: static_cast<int>(std::get<1>(position_x) * static_cast<float>(window->width));
|
||||||
int y =
|
int y = position_y.index() == 0 ? std::get<0>(position_y)
|
||||||
position_y.index() == 0 ? std::get<0>(position_y) : static_cast<int>(std::get<1>(position_y) * static_cast<float>(window->height));
|
: static_cast<int>(std::get<1>(position_y) * static_cast<float>(window->height));
|
||||||
|
|
||||||
if(child_index == 0)
|
if(child_index == 0)
|
||||||
return {x, y};
|
return {x, y};
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,9 @@
|
||||||
#include "uui/opengl/label.hpp"
|
#include "uui/opengl/label.hpp"
|
||||||
#include "uui/shader.hpp"
|
#include "uui/shader.hpp"
|
||||||
|
|
||||||
static void APIENTRY
|
static void APIENTRY glDebugOutput(
|
||||||
glDebugOutput(GLenum source, GLenum type, unsigned int id, GLenum severity, GLsizei length, const char* message, const void* userParam)
|
GLenum source, GLenum type, unsigned int id, GLenum severity, GLsizei length, const char* message,
|
||||||
|
const void* userParam)
|
||||||
{
|
{
|
||||||
// ignore non-significant error/warning codes
|
// ignore non-significant error/warning codes
|
||||||
if(id == 131169 || id == 131185 || id == 131218 || id == 131204)
|
if(id == 131169 || id == 131185 || id == 131218 || id == 131204)
|
||||||
|
|
@ -66,7 +67,9 @@ void uui::GlWindow::glfw_resize_callback(GLFWwindow* window, int width, int heig
|
||||||
glm::mat4 projection = glm::ortho(0.0f, static_cast<float>(width), static_cast<float>(height), 0.0f);
|
glm::mat4 projection = glm::ortho(0.0f, static_cast<float>(width), static_cast<float>(height), 0.0f);
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
glUseProgram(gl_window->font_manager.gl_program);
|
glUseProgram(gl_window->font_manager.gl_program);
|
||||||
glUniformMatrix4fv(glGetUniformLocation(gl_window->font_manager.gl_program, "projection"), 1, GL_FALSE, glm::value_ptr(projection));
|
glUniformMatrix4fv(
|
||||||
|
glGetUniformLocation(gl_window->font_manager.gl_program, "projection"), 1, GL_FALSE,
|
||||||
|
glm::value_ptr(projection));
|
||||||
}
|
}
|
||||||
|
|
||||||
void uui::GlWindow::glfw_iconify_callback(GLFWwindow* window, int iconified)
|
void uui::GlWindow::glfw_iconify_callback(GLFWwindow* window, int iconified)
|
||||||
|
|
@ -82,7 +85,8 @@ void uui::GlWindow::glfw_key_callback(GLFWwindow* window, int key, int scancode,
|
||||||
}
|
}
|
||||||
|
|
||||||
uui::GlWindow::GlWindow(uui::GlApplication* app, int width, int height, const std::string& title):
|
uui::GlWindow::GlWindow(uui::GlApplication* app, int width, int height, const std::string& title):
|
||||||
app(app), initialized(false), width(width), height(height), render_needed(true), resize_needed(false), iconified(false)
|
app(app), initialized(false), width(width), height(height), render_needed(true), resize_needed(false),
|
||||||
|
iconified(false)
|
||||||
{
|
{
|
||||||
if constexpr(uui::GlApplication::debug_mode)
|
if constexpr(uui::GlApplication::debug_mode)
|
||||||
std::cout << "Creating a GlWindow" << std::endl;
|
std::cout << "Creating a GlWindow" << std::endl;
|
||||||
|
|
@ -206,7 +210,8 @@ void uui::GlWindow::init()
|
||||||
font_manager.init();
|
font_manager.init();
|
||||||
glUseProgram(font_manager.gl_program);
|
glUseProgram(font_manager.gl_program);
|
||||||
glm::mat4 projection = glm::ortho(0.0f, static_cast<float>(width), static_cast<float>(height), 0.0f);
|
glm::mat4 projection = glm::ortho(0.0f, static_cast<float>(width), static_cast<float>(height), 0.0f);
|
||||||
glUniformMatrix4fv(glGetUniformLocation(font_manager.gl_program, "projection"), 1, GL_FALSE, glm::value_ptr(projection));
|
glUniformMatrix4fv(
|
||||||
|
glGetUniformLocation(font_manager.gl_program, "projection"), 1, GL_FALSE, glm::value_ptr(projection));
|
||||||
glUseProgram(gl_program);
|
glUseProgram(gl_program);
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
|
@ -255,26 +260,30 @@ std::shared_ptr<uui::GlComponent> uui::GlWindow::create_component(
|
||||||
throw std::runtime_error("GlWindow error : cannot create component while not initialized");
|
throw std::runtime_error("GlWindow error : cannot create component while not initialized");
|
||||||
|
|
||||||
glfwMakeContextCurrent(glfw_window);
|
glfwMakeContextCurrent(glfw_window);
|
||||||
std::shared_ptr<uui::GlComponent> component(new uui::GlComponent(shared_from_this(), components.size(), x, y, width, height));
|
std::shared_ptr<uui::GlComponent> component(
|
||||||
|
new uui::GlComponent(shared_from_this(), components.size(), x, y, width, height));
|
||||||
push_child(component);
|
push_child(component);
|
||||||
component->init();
|
component->init();
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<uui::GlLabel> uui::GlWindow::create_label(
|
std::shared_ptr<uui::GlLabel> uui::GlWindow::create_label(
|
||||||
const position_t x, const position_t y, const std::string& text, const std::tuple<float, float, float, float>& text_color)
|
const position_t x, const position_t y, const std::string& text,
|
||||||
|
const std::tuple<float, float, float, float>& text_color)
|
||||||
{
|
{
|
||||||
if(!initialized)
|
if(!initialized)
|
||||||
throw std::runtime_error("GlWindow error : cannot create label while not initialized");
|
throw std::runtime_error("GlWindow error : cannot create label while not initialized");
|
||||||
|
|
||||||
glfwMakeContextCurrent(glfw_window);
|
glfwMakeContextCurrent(glfw_window);
|
||||||
std::shared_ptr<uui::GlLabel> label(new uui::GlLabel(shared_from_this(), components.size(), x, y, text, text_color));
|
std::shared_ptr<uui::GlLabel> label(
|
||||||
|
new uui::GlLabel(shared_from_this(), components.size(), x, y, text, text_color));
|
||||||
push_child(label);
|
push_child(label);
|
||||||
label->init();
|
label->init();
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<uui::GlFlex> uui::GlWindow::create_flex(const position_t x, const position_t y, const Direction direction)
|
std::shared_ptr<uui::GlFlex> uui::GlWindow::create_flex(
|
||||||
|
const position_t x, const position_t y, const Direction direction)
|
||||||
{
|
{
|
||||||
if(!initialized)
|
if(!initialized)
|
||||||
throw std::runtime_error("GlWindow error : cannot create flex while not initialized");
|
throw std::runtime_error("GlWindow error : cannot create flex while not initialized");
|
||||||
|
|
@ -286,7 +295,8 @@ std::shared_ptr<uui::GlFlex> uui::GlWindow::create_flex(const position_t x, cons
|
||||||
return flex;
|
return flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<uui::GlStack> uui::GlWindow::create_stack(const position_t x, const position_t y, const Direction direction)
|
std::shared_ptr<uui::GlStack> uui::GlWindow::create_stack(
|
||||||
|
const position_t x, const position_t y, const Direction direction)
|
||||||
{
|
{
|
||||||
if(!initialized)
|
if(!initialized)
|
||||||
throw std::runtime_error("GlWindow error : cannot create stack while not initialized");
|
throw std::runtime_error("GlWindow error : cannot create stack while not initialized");
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#include "uui/shader.hpp"
|
#include "uui/shader.hpp"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <ios>
|
||||||
|
|
||||||
std::vector<char> uui::readFile(const std::string& filename)
|
std::vector<char> uui::readFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
|
|
@ -10,10 +10,10 @@ std::vector<char> uui::readFile(const std::string& filename)
|
||||||
if(!file.is_open())
|
if(!file.is_open())
|
||||||
throw std::runtime_error("failed to open file!");
|
throw std::runtime_error("failed to open file!");
|
||||||
|
|
||||||
size_t fileSize = (size_t)file.tellg();
|
std::size_t fileSize = static_cast<std::size_t>(file.tellg());
|
||||||
std::vector<char> buffer(fileSize);
|
std::vector<char> buffer(fileSize);
|
||||||
file.seekg(0);
|
file.seekg(0);
|
||||||
file.read(buffer.data(), fileSize);
|
file.read(buffer.data(), static_cast<std::streamsize>(fileSize));
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue