2022-04-15 11:11:49 +02:00
|
|
|
#include <stdarg.h>
|
2021-04-27 18:33:31 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ksys.h>
|
|
|
|
|
|
|
|
ksys_colors_table_t sys_color_table;
|
|
|
|
|
|
|
|
char statusbar[255];
|
2021-07-27 02:20:54 +02:00
|
|
|
ksys_thread_t proc_info;
|
2021-04-27 18:33:31 +02:00
|
|
|
char text_line[255];
|
|
|
|
|
2022-04-15 11:11:49 +02:00
|
|
|
enum BUTTONS {
|
2021-04-27 18:33:31 +02:00
|
|
|
BTN_QUIT = 1,
|
|
|
|
BTN_POP = 10,
|
|
|
|
BTN_UNLOCK = 11
|
|
|
|
};
|
|
|
|
|
|
|
|
#define FONT_W 8
|
|
|
|
#define FONT_H 14
|
|
|
|
#define LINES 10
|
|
|
|
|
|
|
|
void draw_window()
|
|
|
|
{
|
2022-04-15 11:11:49 +02:00
|
|
|
int win_hight, win_width, i, pos_y = _ksys_get_skin_height() + 36; // 60 == 24+36
|
2021-04-27 18:33:31 +02:00
|
|
|
|
|
|
|
// start redraw
|
|
|
|
_ksys_start_draw();
|
2022-04-15 11:11:49 +02:00
|
|
|
// define&draw window
|
2021-04-27 18:33:31 +02:00
|
|
|
_ksys_create_window(10, 40, 600, 400, "My window", sys_color_table.work_area, 0x13);
|
2021-07-27 02:20:54 +02:00
|
|
|
_ksys_thread_info(&proc_info, -1);
|
2021-04-27 18:33:31 +02:00
|
|
|
|
2022-04-15 11:11:49 +02:00
|
|
|
win_width
|
|
|
|
= proc_info.winx_size;
|
2021-04-27 18:33:31 +02:00
|
|
|
win_hight = proc_info.winy_size;
|
2022-04-15 11:11:49 +02:00
|
|
|
|
2021-04-27 18:33:31 +02:00
|
|
|
_ksys_define_button(10, 30, 70, 20, BTN_POP, sys_color_table.work_button);
|
2022-04-15 11:11:49 +02:00
|
|
|
_ksys_draw_text("BUTTON1", 15, 34, 0, 0x90000000 | sys_color_table.work_button_text); // 0x80000000 asciiz
|
2021-04-27 18:33:31 +02:00
|
|
|
_ksys_define_button(100, 30, 80, 20, BTN_UNLOCK, sys_color_table.work_button);
|
|
|
|
_ksys_draw_text("BUTTTON2", 110, 34, 0, 0x90000000 | sys_color_table.work_button_text);
|
|
|
|
|
|
|
|
// display statusbar
|
2022-04-15 11:11:49 +02:00
|
|
|
_ksys_draw_bar(6, win_hight - 17, win_width - 11, 12, 0x80000000 | sys_color_table.work_area); // 0x80000000 gradient
|
2021-04-27 18:33:31 +02:00
|
|
|
_ksys_draw_text(statusbar, 10, win_hight - 15, 0, 0x80000000 | sys_color_table.work_text);
|
|
|
|
|
|
|
|
// display strings
|
2022-04-15 11:11:49 +02:00
|
|
|
for (i = LINES; i > 0; i--) {
|
|
|
|
snprintf(text_line, sizeof text_line, "Line[%d]<<Just a text>>", i);
|
2021-04-27 18:33:31 +02:00
|
|
|
|
|
|
|
text_line[(win_width - 10 - 5) / FONT_W + 1] = '\0'; // clip text size, seems to big lines crashing OS, and form len by window size
|
|
|
|
_ksys_draw_text(text_line, 5, pos_y, 0, 0x90000000 | sys_color_table.work_text);
|
|
|
|
pos_y += FONT_H;
|
|
|
|
|
2022-04-15 11:11:49 +02:00
|
|
|
if (pos_y + 29 > win_hight)
|
|
|
|
break; // 12 font + 12 statusbar + 5 border
|
2021-04-27 18:33:31 +02:00
|
|
|
}
|
|
|
|
// end redraw
|
|
|
|
_ksys_end_draw();
|
|
|
|
}
|
2022-04-15 11:11:49 +02:00
|
|
|
|
2021-04-27 18:33:31 +02:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int gui_event;
|
|
|
|
uint32_t pressed_button = 0, mouse_button;
|
|
|
|
ksys_pos_t mouse_pos;
|
|
|
|
strcpy(statusbar, "Program running...Double click on TEXT for details");
|
|
|
|
|
2021-05-10 00:12:43 +02:00
|
|
|
_ksys_get_system_colors(&sys_color_table);
|
2021-04-27 18:33:31 +02:00
|
|
|
_ksys_set_event_mask(0xC0000027); // mouse events only when focused window and mouse inside
|
|
|
|
|
2022-04-15 11:11:49 +02:00
|
|
|
do {
|
|
|
|
gui_event = _ksys_get_event();
|
|
|
|
switch (gui_event) {
|
2021-04-27 18:33:31 +02:00
|
|
|
case KSYS_EVENT_NONE:
|
2022-04-15 11:11:49 +02:00
|
|
|
break;
|
2021-04-27 18:33:31 +02:00
|
|
|
case KSYS_EVENT_REDRAW:
|
|
|
|
draw_window();
|
2022-04-15 11:11:49 +02:00
|
|
|
break;
|
2021-04-27 18:33:31 +02:00
|
|
|
case KSYS_EVENT_KEY:
|
2022-04-15 11:11:49 +02:00
|
|
|
break;
|
2021-04-27 18:33:31 +02:00
|
|
|
case KSYS_EVENT_BUTTON:
|
|
|
|
pressed_button = _ksys_get_button();
|
2022-04-15 11:11:49 +02:00
|
|
|
switch (pressed_button) {
|
|
|
|
case BTN_POP:
|
2021-04-27 18:33:31 +02:00
|
|
|
strcpy(statusbar, "POP pressed....");
|
|
|
|
draw_window();
|
|
|
|
break;
|
2022-04-15 11:11:49 +02:00
|
|
|
case BTN_UNLOCK:
|
2021-04-27 18:33:31 +02:00
|
|
|
strcpy(statusbar, "UNLOCK pressed....");
|
|
|
|
draw_window();
|
|
|
|
break;
|
2022-04-15 11:11:49 +02:00
|
|
|
case BTN_QUIT:
|
2021-04-27 18:33:31 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KSYS_EVENT_MOUSE:
|
|
|
|
mouse_pos = _ksys_get_mouse_pos(KSYS_MOUSE_WINDOW_POS); // window relative
|
|
|
|
mouse_button = _ksys_get_mouse_eventstate();
|
|
|
|
debug_printf("mouse ev (%d,%d)%x\n", mouse_pos.x, mouse_pos.y, mouse_button);
|
2022-04-15 11:11:49 +02:00
|
|
|
if (mouse_button & (1 << 24)) // double click
|
2021-04-27 18:33:31 +02:00
|
|
|
{
|
|
|
|
int n = (mouse_pos.y - 60) / FONT_H;
|
2022-04-15 11:11:49 +02:00
|
|
|
if (n < 0 || n >= LINES)
|
|
|
|
break;
|
2021-04-27 18:33:31 +02:00
|
|
|
debug_printf("click on str(%d), clip slot(%d)\n", n, LINES - n - 1);
|
|
|
|
sprintf(statusbar, "click on str(%d), clip slot(%d)\n", n, LINES - n - 1);
|
|
|
|
draw_window();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-04-15 11:11:49 +02:00
|
|
|
} while (1); /* End of main activity loop */
|
2021-04-27 18:33:31 +02:00
|
|
|
|
2022-04-15 11:11:49 +02:00
|
|
|
return 0;
|
2021-04-27 18:33:31 +02:00
|
|
|
}
|