mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-12-01 16:56:34 +01:00
* add yutil * add yutil to util.h * remove util file that same as yutil's * replace the old header file like '#include <LCUI/util/*>' with yutil's head file * Replace the old UTIL module associated data structures and function call code * change timer * Replace the old UTIL module associated data structures and function call code * fix * fix compilation problems(RGB to YUTIL_TEST_RGB) * turn some useless changes back to origin * change YUTIL_TEST_RGB back to RGB and add lcui-util/xmake.lua include * update github action * update github action * update github action * change new yutil func name * update xmake and change way to include yutil * update include to <yutil.h> * update list_for_each to for(list_each()) * fix * add graph.h to test_* * add #include <LCUI/graph.h> * update yutil * change timer func name and update submodule * update submodules * test strncpy * turn useless code back origin * fix lose RGB issue * fix yutil charset * update yutil * update yutil * add yutil_test instead of lcui-util test * change timer func name style Co-authored-by: 李梓豪 <yidianyiko@foxmail.com>
101 lines
2.5 KiB
C
101 lines
2.5 KiB
C
/** test_touch.c -- test touch support */
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <LCUI.h>
|
|
#include <LCUI/display.h>
|
|
#include <LCUI/gui/widget.h>
|
|
#include <LCUI/graph.h>
|
|
|
|
/** 触点绑定记录 */
|
|
typedef struct TouchPointBindingRec_ {
|
|
int point_id; /**< 触点 ID */
|
|
LCUI_Widget widget; /**< 部件 */
|
|
list_node_t node; /**< 在链表中的结点 */
|
|
LCUI_BOOL is_valid; /**< 是否有效 */
|
|
} TouchPointBindingRec, *TouchPointBinding;
|
|
|
|
/** 触点绑定记录列表 */
|
|
static list_t touch_bindings;
|
|
|
|
static void OnTouchWidget(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
|
|
{
|
|
LCUI_TouchPoint point;
|
|
TouchPointBinding binding;
|
|
|
|
if (e->touch.n_points == 0) {
|
|
return;
|
|
}
|
|
binding = e->data;
|
|
point = &e->touch.points[0];
|
|
switch (point->state) {
|
|
case LCUI_WEVENT_TOUCHMOVE:
|
|
Widget_Move(w, point->x - 32.0f, point->y - 32.0f);
|
|
break;
|
|
case LCUI_WEVENT_TOUCHUP:
|
|
if (!binding->is_valid) {
|
|
break;
|
|
}
|
|
/* 当触点释放后销毁部件及绑定记录 */
|
|
Widget_ReleaseTouchCapture(w, -1);
|
|
list_unlink(&touch_bindings, &binding->node);
|
|
binding->is_valid = FALSE;
|
|
Widget_Destroy(w);
|
|
free(binding);
|
|
break;
|
|
case LCUI_WEVENT_TOUCHDOWN:
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
static void OnTouch(LCUI_SysEvent e, void *arg)
|
|
{
|
|
int i;
|
|
LCUI_Widget w;
|
|
list_node_t *node;
|
|
LCUI_TouchPoint point;
|
|
LCUI_Color bgcolor = RGB(255, 0, 0);
|
|
|
|
for (i = 0; i < e->touch.n_points; ++i) {
|
|
TouchPointBinding binding;
|
|
LCUI_BOOL is_existed = FALSE;
|
|
point = &e->touch.points[i];
|
|
_DEBUG_MSG("point: %d\n", point->id);
|
|
/* 检查该触点是否已经被绑定 */
|
|
for (list_each(node, &touch_bindings)) {
|
|
binding = node->data;
|
|
if (binding->point_id == point->id) {
|
|
is_existed = TRUE;
|
|
}
|
|
}
|
|
if (is_existed) {
|
|
continue;
|
|
}
|
|
w = LCUIWidget_New(NULL);
|
|
/* 新建绑定记录 */
|
|
binding = NEW(TouchPointBindingRec, 1);
|
|
binding->point_id = point->id;
|
|
binding->node.data = binding;
|
|
binding->is_valid = TRUE;
|
|
binding->widget = w;
|
|
Widget_Resize(w, 64, 64);
|
|
Widget_Move(w, point->x - 32.0f, point->y - 32.0f);
|
|
/* 设置让该部件捕获当前触点 */
|
|
Widget_SetTouchCapture(w, binding->point_id);
|
|
Widget_BindEvent(w, "touch", OnTouchWidget, binding, NULL);
|
|
Widget_SetStyle(w, key_position, SV_ABSOLUTE, style);
|
|
Widget_SetStyle(w, key_background_color, bgcolor, color);
|
|
list_append_node(&touch_bindings, &binding->node);
|
|
Widget_Top(w);
|
|
}
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
LCUI_Init();
|
|
list_create(&touch_bindings);
|
|
LCUI_BindEvent(LCUI_TOUCH, OnTouch, NULL, NULL);
|
|
return LCUI_Main();
|
|
}
|