/contrib/C_Layer/EXAMPLE/kmenu/kmenu_example.c |
---|
1,3 → 1,6 |
#include <stdlib.h> |
#include <string.h> |
#include <kos32sys.h> |
#include <kolibri_gui.h> |
#include <kolibri_kmenu.h> |
15,33 → 18,34 |
oskey_t key; |
kolibri_window *main_window = kolibri_new_window(50, 50, 400, 200, "kmenu example"); |
kmenu_init(NULL); |
void *sub_menu1 = ksubmenu_new(); |
ksubmenu_add(sub_menu1, kmenuitem_new(0, "Open", 101)); |
ksubmenu_add(sub_menu1, kmenuitem_new(0, "Save", 102)); |
ksubmenu_add(sub_menu1, kmenuitem_new(2, "", 0)); |
ksubmenu_add(sub_menu1, kmenuitem_new(0, "Exit", 103)); |
void *sub_menu2 = ksubmenu_new(); |
ksubmenu_add(sub_menu2, kmenuitem_new(0, "Find", 201)); |
ksubmenu_add(sub_menu2, kmenuitem_new(0, "Replace", 202)); |
void *sub_menu22 = ksubmenu_new(); |
ksubmenu_add(sub_menu22, kmenuitem_new(0, "cp1251", 211)); |
ksubmenu_add(sub_menu22, kmenuitem_new(0, "UTF-8", 212)); |
ksubmenu_add(sub_menu2, kmenuitem__submenu_new(1, "Encoding", sub_menu22)); |
void *main_menu = ksubmenu_new(); |
ksubmenu_add(main_menu, kmenuitem__submenu_new(1, "File", sub_menu1)); |
ksubmenu_add(main_menu, kmenuitem__submenu_new(1, "Edit", sub_menu2)); |
extern volatile unsigned press_key; |
do /* Start of main activity loop */ |
{ |
if(gui_event == KOLIBRI_EVENT_REDRAW) |
if(gui_event == KOLIBRI_EVENT_REDRAW)#include <string.h> |
{ |
kolibri_handle_event_redraw(main_window); |
kmainmenu_draw(main_menu); |
/contrib/C_Layer/EXAMPLE/libguic_kolibri/boardmsg.c |
---|
36,7 → 36,7 |
edit_box *editbox_interlock = NULL; |
edit_box *textbox = kolibri_new_edit_box(20, 60, 40, &editbox_interlock); |
edit_box *textbox2 = kolibri_new_edit_box(20, 80, 40, &editbox_interlock); |
edit_box *textbox2 = kolibri_new_edit_box(20, 80, 30, &editbox_interlock); |
kolibri_button *button = kolibri_new_button(310, 60, 24, 14, 0x21, kolibri_color_table.color_work_button); |
frame *fr = kolibri_new_frame(X_Y(12, 350), X_Y(35, 70), 0x00FCFCFC, 0x00DCDCDC, "Frame Title", 0, kolibri_color_table.color_work_text, kolibri_color_table.color_work_area); |
45,6 → 45,8 |
kolibri_window_add_element(main_window, KOLIBRI_CHECK_BOX, checkbox); |
kolibri_window_add_element(main_window, KOLIBRI_BUTTON, button); |
kolibri_window_add_element(main_window, KOLIBRI_FRAME, fr); |
(*edit_box_set_text)(textbox2, "Sample text very long to get shorted"); |
extern volatile unsigned press_key; |
/contrib/C_Layer/EXAMPLE/libguic_kolibri/option_menu.c |
---|
18,7 → 18,40 |
#include "kos32sys.h" |
#include "kolibri_gui.h" |
#define SCAN_CODE_ALTM 50 |
#define SCAN_CODE_ALTE 18 |
inline |
uint32_t get_os_keyb_modifiers() |
{ |
register uint32_t val; |
__asm__ __volatile__( |
"int $0x40" |
:"=a"(val) |
:"a"(66), "b"(3)); |
return val; |
}; |
#define KEY_LSHIFT 0x1 |
#define KEY_RSHIFT 0x2 |
#define KEY_LCTRL 0x4 |
#define KEY_RCTRL 0x8 |
#define KEY_LALT 0x10 |
#define KEY_RALT 0x20 |
#define KEY_CAPSLOCK 0x40 |
#define KEY_NUMLOCK 0x80 |
#define KEY_SCROLLLOCK 0x100 |
#define KEY_LWIN 0x200 |
#define KEY_RWIN 0x400 |
inline |
void set_os_keyb_mode(int mode) |
// 0 - ASCII, 1 - SCAN |
{ |
__asm__ __volatile__( |
"int $0x40" |
::"a"(66), "b"(1), "c"(mode)); |
}; |
int main() |
{ |
/* Load all libraries, initialize global tables like system color table and |
64,25 → 97,24 |
int option_index1 = 0; // index of selected option |
int option_index2 = 0; |
static char *menu1t = "Menu1"; |
static char *menu11t = "Set RED"; |
static char *menu12t = "Set GREEN"; |
static char *menu13t = "Set BLUE"; |
static char *menu14t = ""; |
menubar* menu1 = kolibri_new_menubar_def(X_Y(20, 40), X_Y(25, 15), 80, 100, menu1t, menu11t); |
char *menu1stru[] = {"Menu1", "Set RED", "Set GREEN", "Set BLUE", NULL}; |
menubar* menu1 = kolibri_new_menubar_def(X_Y(10, 40), X_Y(25, 15), 80, 100, menu1stru); |
gui_add_menubar(main_window, menu1); |
static char *menu2t = "Menu2"; |
static char *menu21t = "Set Option 1"; |
static char *menu22t = "Set Option 2"; |
static char *menu23t = "Set Option 3"; |
static char *menu24t = ""; |
menubar* menu2 = kolibri_new_menubar_def(X_Y(60, 40), X_Y(25, 15), 80, 100, menu2t, menu21t); |
gui_add_menubar(main_window, menu2); |
char *menu2stru[] = {"mEnu2", "Set Option 1", "Set Option 2", "Set Option 3", NULL}; |
menubar* menu2 = kolibri_new_menubar_def(X_Y(50, 40), X_Y(25, 15), 80, 100, menu2stru); |
gui_add_menubar(main_window, menu2); |
char *menu3stru[] = {"Quit", NULL}; |
menubar* menu3 = kolibri_new_menubar_def(X_Y(90, 40), X_Y(25, 15), 0, 0, menu3stru); |
menu3->type = 1; // no subitems |
gui_add_menubar(main_window, menu3); |
set_os_keyb_mode(1); // needed for keyboard use in menu |
do /* Start of main activity loop */ |
{ |
if(option_index1 != option1sel - opts1) |
100,7 → 132,13 |
case KOLIBRI_EVENT_NONE: |
break; |
case KOLIBRI_EVENT_KEY: |
kolibri_handle_event_key(main_window); // ??????? |
keypress = get_key(); |
debug_board_printf("Key pressed state(%d) code(%d) ctrl_key(%d) modifiers(%#x)\n", keypress.state, keypress.code, keypress.ctrl_key, get_os_keyb_modifiers()); |
kolibri_handle_event_key(main_window); // ??????? |
if(keypress.code == SCAN_CODE_ALTM && get_os_keyb_modifiers() & (KEY_LALT | KEY_RALT)) |
(*menu_bar_activate)(menu1); // wont work, immediately redraw command closes menu ( |
break; |
case KOLIBRI_EVENT_BUTTON: |
pressed_button = get_os_button(); |
114,7 → 152,22 |
case KOLIBRI_EVENT_MOUSE: |
// mouse_pos = get_mouse_pos(POS_WINDOW); // window relative |
// mouse_button = get_mouse_eventstate(); |
kolibri_handle_event_mouse(main_window); |
kolibri_handle_event_mouse(main_window); |
if(menu1->click && menu1->cursor_out) |
{ |
option1sel = opts1 + menu1->cursor_out - 1; // check bounds ? |
(*option_box_draw)(option_group1); |
} |
if(menu2->click && menu2->cursor_out) |
{ |
option2sel = opts2 + menu2->cursor_out - 1; // check bounds ? |
(*option_box_draw)(option_group2); |
} |
if(menu3->click && menu3->cursor_out) |
{ |
return 0; // quit |
} |
break; |
} |
/contrib/C_Layer/INCLUDE/kolibri_checkbox.h |
---|
39,7 → 39,7 |
new_checkbox -> left_s = (tlx << 16) + sizex; |
new_checkbox -> top_s = (tly << 16) + sizey; |
new_checkbox -> ch_text_margin = 10; |
new_checkbox -> color = kolibri_color_table.color_work_area; // 0xFFFFFFFF; // 0x80AABBCC, 31-bit mus be set asciiz |
new_checkbox -> color = kolibri_color_table.color_work_area | 0x80000000; // 0xFFFFFFFF; // 0x80AABBCC, 31-bit mus be set asciiz |
new_checkbox -> border_color = kolibri_color_table.color_work_graph; |
new_checkbox -> text_color = kolibri_color_table.color_work_text; |
new_checkbox -> text = label_text; |
/contrib/C_Layer/INCLUDE/kolibri_menubar.h |
---|
3,7 → 3,7 |
typedef struct |
{ |
uint32_t type; // 1 åñëè íåò ïîäìåíþ ?? |
uint32_t type; // 1 åñëè íåò ïîäìåíþ, ïðîñòî ïóíêò |
uint32_t x_w; // âåðõíèé ïóíêò |
uint32_t y_h; |
40,7 → 40,7 |
} menubar; |
inline menubar* kolibri_menubar(menubar* bar, uint32_t x_w, uint32_t y_h, uint16_t sub_w, uint16_t sub_h, char *menutext, char *subitems, |
inline menubar* kolibri_menubar(menubar* bar, uint32_t x_w, uint32_t y_h, uint16_t sub_w, uint16_t sub_h, char **menutext, |
color_t sel_font, color_t unsel_font, color_t top_bg, color_t top_select, color_t sub_bg, color_t sub_select) |
{ |
static char procinfo[1024]; |
48,15 → 48,22 |
bar->type = 0; |
bar->x_w = x_w; |
bar->y_h = y_h; |
bar->text_pointer = menutext; |
bar->pos_pointer = subitems; |
// search last item - double zero |
char *pc = subitems; |
while (*pc) pc = strchr(pc, 0) + 1; |
// count summary length |
char *pc, **mitem; |
int len = 0; |
for(mitem = menutext; *mitem; mitem++) len += strlen(*mitem) + 1; |
// copy menu items in needed format |
bar->text_pointer = malloc(len + 1); // need to be freed manual at closing secondary windows with menu |
for (pc = bar->text_pointer, mitem = menutext; *mitem; pc += strlen(*mitem++) + 1) |
strcpy(pc, *mitem); |
*pc = 0; |
bar->text_end = pc; |
bar->pos_pointer = strchr(bar->text_pointer, 0) + 1; |
bar->x_w1 = X_Y(x_w >> 16, sub_w); |
bar->y_h1 = X_Y((y_h >> 16) + (y_h & 0xFFFF), sub_h); |
bar->y_h1 = X_Y((y_h >> 16) + (y_h & 0xFFFF), sub_h); |
bar->interval = 16; |
bar->font_height = 8; |
72,25 → 79,25 |
return bar; |
} |
inline menubar* kolibri_new_menubar(uint32_t x_w, uint32_t y_h, uint16_t sub_w, uint16_t sub_h, char *menutext, char *subitems, |
inline menubar* kolibri_new_menubar(uint32_t x_w, uint32_t y_h, uint16_t sub_w, uint16_t sub_h, char **menutext, |
color_t sel_font, color_t unsel_font, color_t top_bg, color_t top_select, color_t sub_bg, color_t sub_select) |
{ |
menubar *new_bar = (menubar*)malloc(sizeof(menubar)); |
return kolibri_menubar(new_bar, x_w, y_h, sub_w, sub_h, menutext, subitems, sel_font, unsel_font, top_bg, top_select, sub_bg, sub_select); |
return kolibri_menubar(new_bar, x_w, y_h, sub_w, sub_h, menutext, sel_font, unsel_font, top_bg, top_select, sub_bg, sub_select); |
} |
inline menubar* kolibri_menubar_def(menubar* bar, uint32_t x_w, uint32_t y_h, uint16_t sub_w, uint16_t sub_h, char *menutext, char *subitems) |
inline menubar* kolibri_menubar_def(menubar* bar, uint32_t x_w, uint32_t y_h, uint16_t sub_w, uint16_t sub_h, char **menutext) |
{ |
return kolibri_menubar(bar, x_w, y_h, sub_w, sub_h, menutext, subitems, |
return kolibri_menubar(bar, x_w, y_h, sub_w, sub_h, menutext, |
kolibri_color_table.color_work_button_text, kolibri_color_table.color_work_text, kolibri_color_table.color_work_area, |
kolibri_color_table.color_work_button, kolibri_color_table.color_work_area, kolibri_color_table.color_work_button); |
kolibri_color_table.color_work_button, kolibri_color_table.color_grab_bar_button, kolibri_color_table.color_work_button); |
} |
inline menubar* kolibri_new_menubar_def(uint32_t x_w, uint32_t y_h, uint16_t sub_w, uint16_t sub_h, char *menutext, char *subitems) |
inline menubar* kolibri_new_menubar_def(uint32_t x_w, uint32_t y_h, uint16_t sub_w, uint16_t sub_h, char **menutext) |
{ |
return kolibri_new_menubar(x_w, y_h, sub_w, sub_h, menutext, subitems, |
return kolibri_new_menubar(x_w, y_h, sub_w, sub_h, menutext, |
kolibri_color_table.color_work_button_text, kolibri_color_table.color_work_text, kolibri_color_table.color_work_area, |
kolibri_color_table.color_work_button, kolibri_color_table.color_work_area, kolibri_color_table.color_work_button); |
kolibri_color_table.color_work_button, kolibri_color_table.color_grab_bar_button, kolibri_color_table.color_work_button); |
} |
inline void gui_add_menubar(kolibri_window *wnd, menubar* bar) |