Skip to content

Commit

Permalink
v0.91b, KineticUI update
Browse files Browse the repository at this point in the history
  • Loading branch information
milgra committed Mar 15, 2023
1 parent 9ab14a3 commit 711a4a1
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 240 deletions.
36 changes: 8 additions & 28 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
project(
'vmp',
'c',
version: '0.9b',
version: '0.91b',
license: 'MIT',
default_options: ['warning_level=3',
'c_std=gnu99']
)

cc = meson.get_compiler('c')

png = cc.find_library('png')
egl = dependency('egl')
png = dependency('libpng')
wegl = dependency('wayland-egl')
math = cc.find_library('m')
sdl2 = cc.find_library('SDL2')
freetype = cc.find_library('freetype')
sdl2 = dependency('sdl2')
glesv2 = dependency('glesv2')
freetype = dependency('freetype2')
xkbcommon = dependency('xkbcommon')

gl = cc.find_library('GL')
egl = cc.find_library('EGL')
wegl = cc.find_library('wayland-egl')
glew = cc.find_library('GLEW')

avutil = cc.find_library('avutil')
avcodec = cc.find_library('avcodec')
avdevice = cc.find_library('avdevice')
Expand Down Expand Up @@ -71,9 +69,8 @@ vmp_dependencies = [
png,
freetype,
math,
gl,
glew,
sdl2,
glesv2,
avutil,
avcodec,
avdevice,
Expand Down Expand Up @@ -109,25 +106,8 @@ vmp_inc = include_directories(
'src/mt_core_ext')

if build_machine.system() == 'freebsd'
vmp_inc = [
vmp_inc,
include_directories(
'/usr/local/include',
'/usr/local/include/GLES2',
'/usr/local/include/EGL',
'/usr/local/include/SDL2',
'/usr/local/include/freetype2')]
epoll = cc.find_library('epoll-shim')
vmp_dependencies += epoll
else
vmp_inc = [
vmp_inc,
include_directories(
'/usr/include',
'/usr/include/GLES2',
'/usr/include/EGL',
'/usr/include/SDL2',
'/usr/include/freetype2')]
endif

com_sources = ['src/vmp/analyzer.c',
Expand Down
33 changes: 12 additions & 21 deletions src/kinetic_ui/egl/ku_gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "ku_bitmap.c"
#include "mt_vector.c"
/* #include <GL/glew.h> */
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include <stdio.h>
Expand Down Expand Up @@ -31,7 +30,6 @@ void ku_gl_save_framebuffer(ku_bitmap_t* bitmap);
typedef struct _glbuf_t
{
GLuint vbo;
GLuint vao;
} glbuf_t;

typedef struct _gltex_t
Expand Down Expand Up @@ -76,7 +74,7 @@ glsha_t ku_gl_create_texture_shader()
"{"
" highp float alpha = vUv.w;"
" highp vec4 col = texture2D(sampler[0], vUv.xy);"
" if (alpha < 1.0) col.w *= alpha;"
" if (alpha != 1.0) col.w = alpha;"
" gl_FragColor = col;"
"}";

Expand All @@ -102,13 +100,6 @@ glbuf_t ku_gl_create_vertex_buffer()

glGenBuffers(1, &vb.vbo); // DEL 0
glBindBuffer(GL_ARRAY_BUFFER, vb.vbo);
glGenVertexArrays(1, &vb.vao); // DEL 1
glBindVertexArray(vb.vao);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 24, 0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 24, (const GLvoid*) 8);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);

return vb;
Expand All @@ -119,7 +110,6 @@ glbuf_t ku_gl_create_vertex_buffer()
void ku_gl_delete_vertex_buffer(glbuf_t buf)
{
glDeleteBuffers(1, &buf.vbo);
glDeleteVertexArrays(1, &buf.vao);
}

/* create texture */
Expand All @@ -136,8 +126,9 @@ gltex_t ku_gl_create_texture(int index, uint32_t w, uint32_t h)

glActiveTexture(GL_TEXTURE0 + tex.index);
glBindTexture(GL_TEXTURE_2D, tex.tx);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
/* !!! GL_LINEAR breaks session record/replay determinism, interpolated values can somehow differ */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
Expand Down Expand Up @@ -167,10 +158,6 @@ void ku_gl_delete_texture(gltex_t tex)

void ku_gl_init(int max_dev_width, int max_dev_height)
{
GLenum err = glewInit();
if (GLEW_OK != err)
mt_log_debug("GLEW Init error %s\n", glewGetErrorString(err));

kugl.shader = ku_gl_create_texture_shader();
kugl.buffer = ku_gl_create_vertex_buffer();

Expand Down Expand Up @@ -430,7 +417,10 @@ void ku_gl_add_vertexes(mt_vector_t* views)
void ku_gl_render(ku_bitmap_t* bitmap)
{
/* glBindFramebuffer(GL_FRAMEBUFFER, tex_frame.fb); */
glBindVertexArray(kugl.buffer.vao);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 24, 0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 24, (const GLvoid*) 8);

glActiveTexture(GL_TEXTURE0 + kugl.texture.index);
glBindTexture(GL_TEXTURE_2D, kugl.texture.tx);
Expand All @@ -447,15 +437,17 @@ void ku_gl_render(ku_bitmap_t* bitmap)
glViewport(0, 0, bitmap->w, bitmap->h);

glDrawArrays(GL_TRIANGLES, 0, kugl.floatbuffer->pos);
glBindVertexArray(0);
}

/* render one quad */

void ku_gl_render_quad(ku_bitmap_t* bitmap, uint32_t index, bmr_t mask)
{
/* glBindFramebuffer(GL_FRAMEBUFFER, tex_frame.fb); */
glBindVertexArray(kugl.buffer.vao);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 24, 0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 24, (const GLvoid*) 8);

glActiveTexture(GL_TEXTURE0 + kugl.texture.index);
glBindTexture(GL_TEXTURE_2D, kugl.texture.tx);
Expand All @@ -475,7 +467,6 @@ void ku_gl_render_quad(ku_bitmap_t* bitmap, uint32_t index, bmr_t mask)

glDrawArrays(GL_TRIANGLES, index * 6, 6);

glBindVertexArray(0);
glBindTexture(GL_TEXTURE_2D, 0);
}

Expand Down
2 changes: 1 addition & 1 deletion src/kinetic_ui/egl/ku_gl_floatbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define ku_floatbuffer_h

#include "mt_memory.c"
#include <GL/glew.h>
#include <GLES2/gl2.h>
#include <string.h>

typedef struct ku_floatbuffer_t ku_floatbuffer_t;
Expand Down
2 changes: 1 addition & 1 deletion src/kinetic_ui/egl/ku_gl_shader.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef ku_gl_shader_h
#define ku_gl_shader_h

#include <GL/glew.h>
#include <GLES2/gl2.h>

typedef struct _glsha_t
{
Expand Down
16 changes: 16 additions & 0 deletions src/kinetic_ui/handler/vh_cv_evnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ enum vh_cv_evnt_event_id
{
VH_CV_EVENT_RESIZE,
VH_CV_EVENT_CLICK,
VH_CV_EVENT_KEY_DOWN,
VH_CV_EVENT_KEY_UP
};

typedef struct _vh_cv_evnt_event_t
{
enum vh_cv_evnt_event_id id;
ku_view_t* view;
ku_event_t ev;
} vh_cv_evnt_event_t;

typedef struct _vh_cv_evnt_t
Expand Down Expand Up @@ -207,6 +211,18 @@ int vh_cv_evnt_evt(ku_view_t* view, ku_event_t ev)
if (vh->tscrl_view)
vh_cv_scrl_hide(vh->tscrl_view);
}
else if (ev.type == KU_EVENT_KEY_DOWN)
{
vh_cv_evnt_event_t event = {.id = VH_CV_EVENT_KEY_DOWN, .view = view, .ev = ev};
if (vh->on_event)
(*vh->on_event)(event);
}
else if (ev.type == KU_EVENT_KEY_UP)
{
vh_cv_evnt_event_t event = {.id = VH_CV_EVENT_KEY_UP, .view = view, .ev = ev};
if (vh->on_event)
(*vh->on_event)(event);
}

return 0;
}
Expand Down
6 changes: 5 additions & 1 deletion src/kinetic_ui/handler/vh_tbl_evnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,11 @@ int vh_tbl_evnt_evt(ku_view_t* view, ku_event_t ev)
vh->inertia_y = 0;
}

return (vh->tscrl_view != NULL);
/* TODO refactor ku_window's key and text handling */
if (ev.type == KU_EVENT_KEY_DOWN || ev.type == KU_EVENT_KEY_UP)
return 0;
else
return (vh->tscrl_view != NULL);
}

void vh_tbl_evnt_del(void* p)
Expand Down
9 changes: 8 additions & 1 deletion src/kinetic_ui/handler/vh_tbl_scrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ void vh_tbl_scrl_enable(ku_view_t* view, int flag);

#if __INCLUDE_LEVEL__ == 0

#include "mt_log.c"

#define SCROLLBAR 20.0

void vh_tbl_scrl_set_item_count(ku_view_t* view, size_t count)
Expand Down Expand Up @@ -262,7 +264,12 @@ int vh_tbl_scrl_evt(ku_view_t* view, ku_event_t ev)
{
vh_tbl_scrl_t* vh = view->evt_han_data;

if (ev.type == KU_EVENT_MOUSE_MOVE)
if (ev.type == KU_EVENT_FRAME)
{
vh_tbl_scrl_update(view);
/* frame update stops if there is no change in the ui, scroller reaches final position or alpha */
}
else if (ev.type == KU_EVENT_MOUSE_MOVE)
{
// show scroll
if (vh->scroll_visible == 0)
Expand Down
4 changes: 1 addition & 3 deletions src/kinetic_ui/ku_connector_wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ wl_window_t* ku_wayland_create_generic_layer(struct monitor_info* monitor, int w
info->margin = margin;
info->monitor = monitor;
info->hidden = 1;
memcpy(info->anchor, anchor, 4);
memcpy(info->anchor, anchor, strlen(anchor) < 5 ? strlen(anchor) : 4);

info->type = WL_WINDOW_LAYER;

Expand Down Expand Up @@ -1210,8 +1210,6 @@ void ku_wayland_pointer_handle_button(void* data, struct wl_pointer* wl_pointer,

if (window->wl_pointer == wl_pointer)
{
window->pointer.drag = window->pointer.down;

ku_event_t event = init_event();
event.x = window->pointer.px;
event.y = window->pointer.py;
Expand Down
11 changes: 7 additions & 4 deletions src/kinetic_ui/ku_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void ku_draw_insert_bitmap(ku_bitmap_t* base, ku_bitmap_t* src, int sx, int sy);

#if __INCLUDE_LEVEL__ == 0

#include "mt_log.c"
#include <string.h>

void ku_draw_circle(ku_bitmap_t* bitmap, float cx, float cy, float r, float edge, uint32_t c)
Expand Down Expand Up @@ -934,20 +935,21 @@ void ku_draw_scale(ku_bitmap_t* srcbmp, ku_bitmap_t* dstbmp)
int newWidth = dst->w;
int newHeight = dst->h;
int x, y;
for (x = 0, y = 0; y < newHeight; x++)
for (x = 0, y = 0; y < newHeight - 1; x++)
{
if (x > newWidth)
if (x == newWidth)
{
x = 0;
y++;
}
// float gx = x / (float)(newWidth) * (src->w - 1);
// float gy = y / (float)(newHeight) * (src->h - 1);
// Image should be clamped at the edges and not scaled.
float gx = max(x / (float) (newWidth) * (src->w) - 0.5f, src->w - 1);
float gy = max(y / (float) (newHeight) * (src->h) - 0.5, src->h - 1);
float gx = max(x / (float) (newWidth) * (src->w) - 0.5f, src->w - 2);
float gy = max(y / (float) (newHeight) * (src->h) - 0.5, src->h - 2);
int gxi = (int) gx;
int gyi = (int) gy;

uint32_t result = 0;
uint32_t c00 = getpixel(src, gxi, gyi);
uint32_t c10 = getpixel(src, gxi + 1, gyi);
Expand All @@ -959,6 +961,7 @@ void ku_draw_scale(ku_bitmap_t* srcbmp, ku_bitmap_t* dstbmp)
//((uint8_t*)&result)[i] = blerp( ((uint8_t*)&c00)[i], ((uint8_t*)&c10)[i], ((uint8_t*)&c01)[i], ((uint8_t*)&c11)[i], gxi - gx, gyi - gy); // this is shady
result |= (uint8_t) blerp(getByte(c00, i), getByte(c10, i), getByte(c01, i), getByte(c11, i), gx - gxi, gy - gyi) << (8 * i);
}

putpixel(dst, x, y, result);
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/kinetic_ui/ku_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ void ku_view_del(void* pointer)
REL(view->script);

REL(view->id);

for (size_t index = 0; index < view->views->length; index++)
{
ku_view_t* sview = view->views->data[index];
sview->parent = NULL;
}

REL(view->views);
}

Expand Down Expand Up @@ -332,6 +339,8 @@ void ku_view_insert_subview(ku_view_t* view, ku_view_t* subview, uint32_t index)

void ku_view_remove_subview(ku_view_t* view, ku_view_t* subview)
{
ku_view_set_parent(subview, NULL);

char success = VREM(view->views, subview);

if (success == 1)
Expand All @@ -340,8 +349,6 @@ void ku_view_remove_subview(ku_view_t* view, ku_view_t* subview)
ku_view_t* tview = view;
while (tview->parent != NULL) tview = tview->parent;
tview->rearrange = 1;

ku_view_set_parent(subview, NULL);
}
}

Expand All @@ -352,7 +359,7 @@ void ku_view_remove_from_parent(ku_view_t* view)

void ku_view_set_parent(ku_view_t* view, ku_view_t* parent)
{
view->parent = parent;
if (view) view->parent = parent;
}

void ku_view_coll_touched(ku_view_t* view, ku_event_t ev, mt_vector_t* queue)
Expand Down
5 changes: 4 additions & 1 deletion src/kinetic_ui/ku_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ void ku_window_event(ku_window_t* win, ku_event_t ev)
if (ev.type == KU_EVENT_MOUSE_UP)
outev.type = KU_EVENT_MOUSE_UP_OUT;

if (ev.type == KU_EVENT_MOUSE_DOWN)
/* binding this to only mouse down disables drop on different table */
/* but enables out of mouse input field activation */
if (ev.type == KU_EVENT_MOUSE_DOWN ||
(ev.type == KU_EVENT_MOUSE_UP && ev.drag))
{
for (size_t i = win->ptrqueue->length; i-- > 0;)
{
Expand Down
Loading

0 comments on commit 711a4a1

Please sign in to comment.