Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rfc: LDN #26

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
/node_modules
.eslintrc.js
quasar.config.js
postcss.config.js
postcss.config.js
/ldn
18 changes: 18 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
[submodule "meter-data"]
path = meter-data
url = https://github.com/lost-ark-dev/meter-data
[submodule "ldn/third-party/glfw"]
path = ldn/third-party/glfw
url = https://github.com/glfw/glfw
[submodule "ldn/third-party/png"]
path = ldn/third-party/png
url = https://github.com/lvandeve/lodepng
[submodule "ldn/third-party/freetype2"]
path = ldn/third-party/freetype2
url = https://gitlab.freedesktop.org/freetype/freetype.git
[submodule "ldn/third-party/zlib"]
path = ldn/third-party/zlib
url = https://github.com/madler/zlib.git
[submodule "ldn/third-party/json"]
path = ldn/third-party/json
url = https://github.com/nlohmann/json
[submodule "ldn/third-party/libwebp"]
path = ldn/third-party/libwebp
url = https://chromium.googlesource.com/webm/libwebp.git
2 changes: 2 additions & 0 deletions ldn/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build_release
build_debug
68 changes: 68 additions & 0 deletions ldn/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
cmake_minimum_required(VERSION 3.16)
project("ldn")
set(CMAKE_CXX_STANDARD 17)
set(DISABLE_PACKAGE_CONFIG_AND_INSTALL ON)
set(SKIP_INSTALL_ALL ON)
set(WEBP_BUILD_ANIM_UTILS OFF)
set(WEBP_BUILD_CWEBP OFF)
set(WEBP_BUILD_DWEBP OFF)
set(WEBP_BUILD_GIF2WEBP OFF)
set(WEBP_BUILD_IMG2WEBP OFF)
set(WEBP_BUILD_VWEBP OFF)
set(WEBP_BUILD_WEBPINFO OFF)
set(WEBP_BUILD_LIBWEBPMUX OFF)
set(WEBP_BUILD_WEBPMUX OFF)
set(WEBP_BUILD_EXTRAS OFF)
set(WEBP_BUILD_WEBP_JS OFF)
set(WEBP_USE_THREAD OFF)
set(WEBP_NEAR_LOSSLESS "Enable near-lossless encoding" ON)
set(WEBP_ENABLE_SWAP_16BIT_CSP "Enable byte swap for 16 bit colorspaces."
OFF)

set(LDN_SOURCES
third-party/png/lodepng.cpp
src/main.cc
src/rendering/font_atlas.cc
src/rendering/glad.c
src/rendering/la.cc
src/rendering/opengl_state.cc
src/rendering/shader.cc
src/ldn.cc
src/components/text.cc
src/components/box.cc
src/components/row.cc
src/components/meter_header_row.cc
src/components/meter_row.cc
src/components/row_list.cc
src/components/button.cc
src/components/image.cc
src/components/header.cc
src/components/lower_row.cc
src/conn/connection.cc
src/conn/data_manager.cc
src/conn/static_data.cc
src/utils/image_cache.cc
)


add_executable(ldn ${LDN_SOURCES})


target_include_directories(ldn PRIVATE third-party/json/single_include)
target_include_directories(ldn PRIVATE third-party/zlib ${CMAKE_CURRENT_BINARY_DIR}/third-party/zlib)

add_subdirectory(third-party/zlib)
set(ZLIB_LIBRARY zlibstatic)
set(ZLIB_LIBRARIES zlibstatic)
set(ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/third-party/zlib ${CMAKE_CURRENT_BINARY_DIR}/third-party/zlib)
set(ZLIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third-party/zlib ${CMAKE_CURRENT_BINARY_DIR}/third-party/zlib)

add_subdirectory(third-party/glfw)
add_subdirectory(third-party/freetype2)
add_subdirectory(third-party/libwebp)

if(WIN32)
add_definitions(-DGLFW_EXPOSE_NATIVE_WIN32)
target_link_libraries(ldn PUBLIC glfw freetype wsock32 ws2_32 webp)
endif()
file(COPY assets DESTINATION .)
6 changes: 6 additions & 0 deletions ldn/assets/box.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#version 330 core
in vec4 outColor;
out vec4 color;
void main() {
color = outColor;
}
18 changes: 18 additions & 0 deletions ldn/assets/box.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#version 330 core
uniform vec2 resolution;
layout(location = 0) in vec2 position;
layout(location = 1) in vec2 size;
layout(location = 2) in vec4 color;

vec2 camera_project(vec2 point) {
return 2* (point) * (1 / resolution);
}

out vec4 outColor;

void main() {
vec2 uv = vec2(float(gl_VertexID & 1),
float((gl_VertexID >> 1) & 1));
outColor = color;
gl_Position = vec4(camera_project(uv * size + position), 0.0f, 1.0f);
}
Binary file added ldn/assets/fonts/MaterialIcons-Regular.ttf
Binary file not shown.
Binary file added ldn/assets/fonts/Roboto-Bold.ttf
Binary file not shown.
Binary file added ldn/assets/fonts/Roboto-Regular.ttf
Binary file not shown.
Binary file added ldn/assets/fonts/fa-regular-400.ttf
Binary file not shown.
Binary file added ldn/assets/fonts/fa-solid-900.ttf
Binary file not shown.
9 changes: 9 additions & 0 deletions ldn/assets/simple_image.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#version 330 core
uniform sampler2D img;

in vec2 uv;

out vec4 color;
void main() {
color = texture(img, uv);
}
17 changes: 17 additions & 0 deletions ldn/assets/simple_image.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#version 330 core
uniform vec2 resolution;
layout(location = 0) in vec2 position;
layout(location = 1) in vec2 size;
vec2 camera_project(vec2 point) {
return 2 * (point) * (1 / resolution);
}
out vec2 uv;

void main() {
vec2 uvIn = vec2(float(gl_VertexID & 1),
float((gl_VertexID >> 1) & 1));
uv = uvIn;
vec2 r = camera_project(uvIn * size + position);
r.y *= -1;
gl_Position = vec4(r, 0.0f, 1.0f);
}
23 changes: 23 additions & 0 deletions ldn/assets/text.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#version 330 core

uniform sampler2D font;

in vec2 uv;
in vec2 glyph_uv_pos;
in vec2 glyph_uv_size;
in vec4 glyph_fg_color;
in vec4 glyph_bg_color;
in float hasColor;


out vec4 color;
void main() {
vec2 t = glyph_uv_pos + glyph_uv_size * uv;
if(hasColor > 0.5) {
color = texture(font, t);
} else {
vec4 sampled = vec4(1.0, 1.0, 1.0, texture(font, t).x);
color = glyph_fg_color * sampled;
}

}
31 changes: 31 additions & 0 deletions ldn/assets/text.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#version 330 core


layout(location = 0) in vec2 pos;
layout(location = 1) in vec2 size;
layout(location = 2) in vec2 uv_pos;
layout(location = 3) in vec2 uv_size;
layout(location = 4) in vec4 fg_color;
layout(location = 5) in vec4 bg_color;
layout(location = 6) in float hColor;

out vec2 uv;
out vec2 glyph_uv_pos;
out vec2 glyph_uv_size;
out vec4 glyph_fg_color;
out vec4 glyph_bg_color;
out float hasColor;
uniform vec2 resolution;
vec2 camera_project(vec2 point) {
return 2* (point) * (1 / resolution);
}

void main() {
uv = vec2(float(gl_VertexID & 1), float((gl_VertexID >> 1) & 1));
gl_Position = vec4(camera_project(uv * (size) + (pos)), 0.0, 1.0);
glyph_uv_pos = uv_pos;
glyph_uv_size = uv_size;
glyph_fg_color = fg_color;
hasColor = hColor;
glyph_bg_color = vec4(0.0);
}
22 changes: 22 additions & 0 deletions ldn/src/components/box.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "box.h"

bool Box::canFocus() {
return false;
}
void Box::onPress(RenderContext* ctx) {

}
void Box::onFocus(bool focus) {

}
void Box::render(RenderContext* ctx) {
ShaderInstance* m_shader = ctx->gl_state->box_shader;
m_shader->shader.use();
m_shader->bindVertexArray();
m_shader->bindBuffer();
auto p = ctx->normalize(position);
ColorEntry entry = {vec2f(p.x, -p.y - size.y), size, color};
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(ColorEntry), &entry);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 6, (GLsizei)1);
}
18 changes: 18 additions & 0 deletions ldn/src/components/box.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef LDN_BOX_C_H
#define LDN_BOX_C_H
#include "../rendering/component.h"


class Box : public Component {
public:

void setData(std::string newData);
bool canFocus() override;
void onPress(RenderContext* ctx) override;
void onFocus(bool focus) override;
void render(RenderContext* ctx) override;
Vec4f color = vec4fs(1);
private:

};
#endif
53 changes: 53 additions & 0 deletions ldn/src/components/button.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "button.h"
#include "box.h"
#include "text.h"
#include "../ldn.h"

bool Button::canFocus() {
return true;
}
void Button::onPress(RenderContext* ctx) {
if(has_callback)
listener();
}
void Button::onFocus(bool focus) {

}
void Button::render(RenderContext* ctx) {
Vec2f render_size = size;
if(active)
render_size.y -= 4;
if(image){
image->position = position;
image->size = render_size;
image->render(ctx);
}
if(text.length()) {
Text text_r(text);
text_r.center = true;
text_r.color = text_color;
text_r.position = position;
text_r.size =render_size;
text_r.scale = scale;
text_r.render(ctx);
}
if(active) {
Box box;
box.position = position;
box.position.y = (position.y + size.y -2);
box.size = size;
box.size.y = 2;
box.color = active_color;
box.render(ctx);
}
}
void Button::setOnClick(const ClickListener& onclick) {
listener = onclick;
has_callback = true;
}
Button::Button() {
Ldn::g_ldn->button_list.push_back(this);
}
Button::~Button() {
Ldn::g_ldn->button_list.erase(std::remove(Ldn::g_ldn->button_list.begin(), Ldn::g_ldn->button_list.end(), this), Ldn::g_ldn->button_list.end());
}
28 changes: 28 additions & 0 deletions ldn/src/components/button.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef LDN_BUTTON_H
#define LDN_BUTTON_H
#include "../rendering/component.h"
#include "image.h"
#include <functional>

using ClickListener = std::function<void()>;
class Button : public Component {
public:
Button();
~Button();
bool canFocus() override;
void onPress(RenderContext* ctx) override;
void onFocus(bool focus) override;
void render(RenderContext* ctx) override;
bool active = false;
Image* image = nullptr;
std::string text;
Vec4f text_color = vec4fs(1);
Vec4f active_color = vec4fs(1);
void setOnClick(const ClickListener& onclick);
float scale = 1;
private:
bool has_callback = false;
ClickListener listener;

};
#endif
Loading