Skip to content

Commit

Permalink
kineticUI update, v0.75b
Browse files Browse the repository at this point in the history
  • Loading branch information
milgra committed Feb 27, 2023
1 parent 72b10a4 commit 0bcb87e
Show file tree
Hide file tree
Showing 62 changed files with 2,284 additions and 1,201 deletions.
50 changes: 24 additions & 26 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
project(
'wcp',
'c',
version: '0.74b',
version: '0.75b',
license: 'MIT',
default_options: ['c_std=gnu99']
default_options: ['c_std=gnu99',
'warning_level=3']
)

cc = meson.get_compiler('c')
Expand Down Expand Up @@ -72,6 +73,7 @@ wcp_version = '"@0@"'.format(meson.project_version())
pkg_datadir = join_paths(get_option('prefix'), get_option('datadir')) / 'wcp'
add_project_arguments('-DPKG_DATADIR="' + pkg_datadir + '"',
'-DWCP_VERSION=@0@'.format(wcp_version),
'-Wno-unused-parameter',
language: 'c')
add_project_arguments('-Wno-unused-but-set-variable', language: 'c')

Expand Down Expand Up @@ -115,26 +117,17 @@ com_sources = ['src/wcp/ui.c',
'src/wcp/ku_bitmap_ext.c',

'src/mt_core_ext/mt_string_ext.c',
# 'src/mt_core_ext/mt_map_ext.c',

# 'src/mt_core/mt_channel.c',
'src/mt_core/mt_string.c',
'src/mt_core/mt_path.c',
'src/mt_core/mt_log.c',
'src/mt_core/mt_map.c',
'src/mt_core/mt_memory.c',
# 'src/mt_core/mt_number.c',
'src/mt_core/mt_time.c',
'src/mt_core/mt_vector.c',
'src/mt_core/mt_wrapper.c',

# 'src/mt_math/mt_matrix_3d.c',
'src/mt_math/mt_matrix_4d.c',
# 'src/mt_math/mt_vector_2d.c',
# 'src/mt_math/mt_vector_3d.c',
# 'src/mt_math/mt_vector_4d.c',
# 'src/mt_math/mt_math_2d.c',
# 'src/mt_math/mt_math_3d.c',

'src/kinetic_ui/ku_event.c',
'src/kinetic_ui/ku_html.c',
Expand All @@ -143,26 +136,14 @@ com_sources = ['src/wcp/ui.c',
'src/kinetic_ui/ku_rect.c',
'src/kinetic_ui/ku_bitmap.c',
'src/kinetic_ui/texture/tg_css.c',
# 'src/kinetic_ui/texture/tg_knob.c',
'src/kinetic_ui/texture/tg_text.c',
# 'src/kinetic_ui/texture/tg_scaledimg.c',
'src/kinetic_ui/handler/vh_anim.c',
'src/kinetic_ui/handler/vh_button.c',
'src/kinetic_ui/handler/vh_drag.c',
'src/kinetic_ui/handler/vh_key.c',
# 'src/kinetic_ui/handler/vh_knob.c',
# 'src/kinetic_ui/handler/vh_roll.c',
'src/kinetic_ui/handler/vh_slider.c',
'src/kinetic_ui/handler/vh_textinput.c',
'src/kinetic_ui/handler/vh_touch.c',
# 'src/kinetic_ui/handler/vh_cv_body.c',
# 'src/kinetic_ui/handler/vh_cv_scrl.c',
# 'src/kinetic_ui/handler/vh_cv_evnt.c',
# 'src/kinetic_ui/handler/vh_tbl_body.c',
# 'src/kinetic_ui/handler/vh_tbl_evnt.c',
# 'src/kinetic_ui/handler/vh_tbl_scrl.c',
# 'src/kinetic_ui/handler/vh_tbl_head.c',
# 'src/kinetic_ui/handler/vh_table.c',
'src/kinetic_ui/ku_view.c',
'src/kinetic_ui/egl/ku_gl_atlas.c',
'src/kinetic_ui/egl/ku_gl_floatbuffer.c',
Expand Down Expand Up @@ -228,9 +209,26 @@ executable(
install: false,
)

e = executable('maintest', 'src/tests/test_kvlist.c')

test('MAIN TEST', e)
mt_core_test = executable(
'mt_core_test',
['src/mt_core/mt_log.c',
'src/mt_core/mt_memory.c',
'src/mt_core/mt_vector.c',
'src/mt_core/mt_map.c',
'src/mt_core/mt_string.c',
'src/mt_core/mt_channel.c',
'src/mt_core/mt_path.c',
'src/mt_core_test/mt_core_test.c',
'src/mt_core_test/mt_memory_test.c',
'src/mt_core_test/mt_vector_test.c',
'src/mt_core_test/mt_map_test.c',
'src/mt_core_test/mt_string_test.c',
'src/mt_core_test/mt_channel_test.c',
'src/mt_core_test/mt_path_test.c'
],
include_directories: ['src/mt_core'])

test('MT_CORE_TEST', mt_core_test)

scripttests = find_program('tst/runtests.sh')

Expand Down
9 changes: 8 additions & 1 deletion res/script/logout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,12 @@ if [ $# -eq 0 ]
then
echo ""
else
swaymsg exec loginctl terminate-user $USER
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
DISTRIB=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
if [[ ${DISTRIB} = *"Void"* ]]; then
sway exit
else
swaymsg exec loginctl terminate-user $USER
fi
fi
fi
24 changes: 13 additions & 11 deletions src/kinetic_ui/egl/ku_gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,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 Down Expand Up @@ -136,8 +136,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 @@ -169,9 +170,7 @@ void ku_gl_init(int max_dev_width, int max_dev_height)
{
GLenum err = glewInit();
if (GLEW_OK != err)
{
printf("ERROR 5 %s\n", glewGetErrorString(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 All @@ -195,7 +194,8 @@ void ku_gl_init(int max_dev_width, int max_dev_height)

/* don't let it be bigger than max size */

if (binsize > value) binsize = value;
if (binsize > value)
binsize = value;

mt_log_debug("texture size will be %i", binsize);

Expand Down Expand Up @@ -235,7 +235,8 @@ void ku_gl_add_textures(mt_vector_t* views, int force)
}

/* reset atlas */
if (kugl.atlas) REL(kugl.atlas);
if (kugl.atlas)
REL(kugl.atlas);
kugl.atlas = ku_gl_atlas_new(kugl.texturesize, kugl.texturesize);
}

Expand All @@ -245,7 +246,7 @@ void ku_gl_add_textures(mt_vector_t* views, int force)
int reset = 0;

/* add texture to atlas */
for (int index = 0; index < views->length; index++)
for (size_t index = 0; index < views->length; index++)
{
ku_view_t* view = views->data[index];

Expand Down Expand Up @@ -328,7 +329,8 @@ void ku_gl_add_textures(mt_vector_t* views, int force)
glBindTexture(GL_TEXTURE_2D, 0);

/* in case of reset do the whole thing once again with forced reset*/
if (reset == 1) ku_gl_add_textures(views, 1);
if (reset == 1)
ku_gl_add_textures(views, 1);
}

/* upload vertexes */
Expand All @@ -338,7 +340,7 @@ void ku_gl_add_vertexes(mt_vector_t* views)
ku_floatbuffer_reset(kugl.floatbuffer);

/* add vertexes to buffer */
for (int index = 0; index < views->length; index++)
for (size_t index = 0; index < views->length; index++)
{
ku_view_t* view = views->data[index];

Expand Down
6 changes: 3 additions & 3 deletions src/kinetic_ui/egl/ku_gl_floatbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ typedef struct ku_floatbuffer_t ku_floatbuffer_t;
struct ku_floatbuffer_t
{
GLfloat* data;
uint32_t pos;
uint32_t cap;
size_t pos;
size_t cap;
char changed;
};

Expand Down Expand Up @@ -56,7 +56,7 @@ void ku_floatbuffer_reset(ku_floatbuffer_t* fb)

void ku_floatbuffer_expand(ku_floatbuffer_t* fb)
{
assert(fb->cap < UINT32_MAX / 2);
assert(fb->cap < SIZE_MAX / 2);
fb->cap *= 2;
fb->data = mt_memory_realloc(fb->data, sizeof(void*) * fb->cap);
}
Expand Down
63 changes: 38 additions & 25 deletions src/kinetic_ui/handler/vh_anim.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ void vh_anim_add(ku_view_t* view, void (*on_event)(vh_anim_event_t), void* userd

#if __INCLUDE_LEVEL__ == 0

void vh_anim_evt(ku_view_t* view, ku_event_t ev)
#include "mt_log.c"

int vh_anim_evt(ku_view_t* view, ku_event_t ev)
{
vh_anim_t* vh = view->handler_data;
vh_anim_t* vh = view->evt_han_data;
if (ev.type == KU_EVENT_FRAME)
{
if (vh->anim_frame)
Expand Down Expand Up @@ -100,16 +102,17 @@ void vh_anim_evt(ku_view_t* view, ku_event_t ev)
else if (vh->type == AT_EASE)
{
// speed function based on cosine ( half circle )
float angle = 3.14 + (3.14 / vh->fsteps) * delta;
float delta = (cos(angle) + 1.0) / 2.0;
float angle = (3.14 / 2 / vh->fsteps) * delta;
float fdelta = sin(angle);

cf.x = sf.x + (ef.x - sf.x) * delta;
cf.y = sf.y + (ef.y - sf.y) * delta;
cf.w = sf.w + (ef.w - sf.w) * delta;
cf.h = sf.h + (ef.h - sf.h) * delta;
cf.x = sf.x + (ef.x - sf.x) * fdelta;
cf.y = sf.y + (ef.y - sf.y) * fdelta;
cf.w = sf.w + (ef.w - sf.w) * fdelta;
cf.h = sf.h + (ef.h - sf.h) * fdelta;
}

if (delta == vh->fsteps - 1) cf = ef;
if (delta == vh->fsteps - 1)
cf = ef;

ku_view_set_frame(view, cf);

Expand All @@ -119,7 +122,8 @@ void vh_anim_evt(ku_view_t* view, ku_event_t ev)
{
vh->anim_frame = 0;
vh_anim_event_t event = {.id = VH_ANIM_END, .view = view, .userdata = vh->userdata};
if (vh->on_event) (*vh->on_event)(event);
if (vh->on_event)
(*vh->on_event)(event);
}
}
}
Expand Down Expand Up @@ -159,17 +163,19 @@ void vh_anim_evt(ku_view_t* view, ku_event_t ev)
cr.h = sr.h + (er.h - sr.h) * delta;
}

if (delta == vh->rsteps - 1) cr = er;
if (delta == vh->rsteps - 1)
cr = er;

ku_view_set_region(view, cr);

vh->rstep += 1;

if (delta == vh->rsteps)
{
ku_view_set_region(view, (ku_rect_t){-1, -1, -1. - 1});
ku_view_set_region(view, (ku_rect_t){-1, -1, -1, -1});
vh_anim_event_t event = {.id = VH_ANIM_END, .view = view, .userdata = vh->userdata};
if (vh->on_event) (*vh->on_event)(event);
if (vh->on_event)
(*vh->on_event)(event);
}
}
}
Expand All @@ -195,7 +201,8 @@ void vh_anim_evt(ku_view_t* view, ku_event_t ev)
ca = sa + (ea - sa) * delta;
}

if (vh->astep == vh->asteps - 1) ca = ea;
if (vh->astep == vh->asteps - 1)
ca = ea;

ku_view_set_texture_alpha(view, ca, 1);

Expand All @@ -205,16 +212,19 @@ void vh_anim_evt(ku_view_t* view, ku_event_t ev)
{
vh->anim_alpha = 0;
vh_anim_event_t event = {.id = VH_ANIM_END, .view = view, .userdata = vh->userdata};
if (vh->on_event) (*vh->on_event)(event);
if (vh->on_event)
(*vh->on_event)(event);
}
}
}
}

return 1;
}

void vh_anim_frame(ku_view_t* view, ku_rect_t sf, ku_rect_t ef, int start, int steps, animtype_t type)
{
vh_anim_t* vh = view->handler_data;
vh_anim_t* vh = view->evt_han_data;
if (vh->fstep == vh->fsteps)
{
vh->sf = sf;
Expand All @@ -229,7 +239,7 @@ void vh_anim_frame(ku_view_t* view, ku_rect_t sf, ku_rect_t ef, int start, int s

void vh_anim_region(ku_view_t* view, ku_rect_t sr, ku_rect_t er, int start, int steps, animtype_t type)
{
vh_anim_t* vh = view->handler_data;
vh_anim_t* vh = view->evt_han_data;
if (vh->rstep == vh->rsteps)
{
vh->sr = sr;
Expand All @@ -246,7 +256,7 @@ void vh_anim_region(ku_view_t* view, ku_rect_t sr, ku_rect_t er, int start, int

void vh_anim_alpha(ku_view_t* view, float sa, float ea, int steps, animtype_t type)
{
vh_anim_t* vh = view->handler_data;
vh_anim_t* vh = view->evt_han_data;

if (vh->astep == vh->asteps)
{
Expand All @@ -264,14 +274,17 @@ void vh_anim_alpha(ku_view_t* view, float sa, float ea, int steps, animtype_t ty

void vh_anim_finish(ku_view_t* view)
{
vh_anim_t* vh = view->handler_data;
vh_anim_t* vh = view->evt_han_data;
vh->astep = vh->asteps;
vh->fstep = vh->fsteps;
vh->rstep = vh->rsteps;

if (vh->anim_frame) ku_view_set_frame(view, vh->ef);
if (vh->anim_region) ku_view_set_region(view, vh->er);
if (vh->anim_alpha) ku_view_set_texture_alpha(view, vh->ea, 1);
if (vh->anim_frame)
ku_view_set_frame(view, vh->ef);
if (vh->anim_region)
ku_view_set_region(view, vh->er);
if (vh->anim_alpha)
ku_view_set_texture_alpha(view, vh->ea, 1);

vh->anim_frame = 0;
vh->anim_region = 0;
Expand All @@ -285,14 +298,14 @@ void vh_anim_desc(void* p, int level)

void vh_anim_add(ku_view_t* view, void (*on_event)(vh_anim_event_t), void* userdata)
{
assert(view->handler == NULL && view->handler_data == NULL);
assert(view->evt_han == NULL && view->evt_han_data == NULL);

vh_anim_t* vh = CAL(sizeof(vh_anim_t), NULL, vh_anim_desc);
vh->on_event = on_event;
vh->userdata = userdata;

view->handler = vh_anim_evt;
view->handler_data = vh;
view->evt_han = vh_anim_evt;
view->evt_han_data = vh;
}

#endif
Loading

0 comments on commit 0bcb87e

Please sign in to comment.