forked from KolibriOS/kolibrios
Menubar demo fix
git-svn-id: svn://kolibrios.org@6489 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
f281a3cb3f
commit
3130a376e1
@ -1,3 +1,6 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <kos32sys.h>
|
||||||
#include <kolibri_gui.h>
|
#include <kolibri_gui.h>
|
||||||
#include <kolibri_kmenu.h>
|
#include <kolibri_kmenu.h>
|
||||||
|
|
||||||
@ -15,33 +18,34 @@ int main()
|
|||||||
oskey_t key;
|
oskey_t key;
|
||||||
|
|
||||||
kolibri_window *main_window = kolibri_new_window(50, 50, 400, 200, "kmenu example");
|
kolibri_window *main_window = kolibri_new_window(50, 50, 400, 200, "kmenu example");
|
||||||
|
|
||||||
kmenu_init(NULL);
|
kmenu_init(NULL);
|
||||||
|
|
||||||
void *sub_menu1 = ksubmenu_new();
|
void *sub_menu1 = ksubmenu_new();
|
||||||
ksubmenu_add(sub_menu1, kmenuitem_new(0, "Open", 101));
|
ksubmenu_add(sub_menu1, kmenuitem_new(0, "Open", 101));
|
||||||
ksubmenu_add(sub_menu1, kmenuitem_new(0, "Save", 102));
|
ksubmenu_add(sub_menu1, kmenuitem_new(0, "Save", 102));
|
||||||
ksubmenu_add(sub_menu1, kmenuitem_new(2, "", 0));
|
ksubmenu_add(sub_menu1, kmenuitem_new(2, "", 0));
|
||||||
ksubmenu_add(sub_menu1, kmenuitem_new(0, "Exit", 103));
|
ksubmenu_add(sub_menu1, kmenuitem_new(0, "Exit", 103));
|
||||||
|
|
||||||
void *sub_menu2 = ksubmenu_new();
|
void *sub_menu2 = ksubmenu_new();
|
||||||
ksubmenu_add(sub_menu2, kmenuitem_new(0, "Find", 201));
|
ksubmenu_add(sub_menu2, kmenuitem_new(0, "Find", 201));
|
||||||
ksubmenu_add(sub_menu2, kmenuitem_new(0, "Replace", 202));
|
ksubmenu_add(sub_menu2, kmenuitem_new(0, "Replace", 202));
|
||||||
|
|
||||||
void *sub_menu22 = ksubmenu_new();
|
void *sub_menu22 = ksubmenu_new();
|
||||||
ksubmenu_add(sub_menu22, kmenuitem_new(0, "cp1251", 211));
|
ksubmenu_add(sub_menu22, kmenuitem_new(0, "cp1251", 211));
|
||||||
ksubmenu_add(sub_menu22, kmenuitem_new(0, "UTF-8", 212));
|
ksubmenu_add(sub_menu22, kmenuitem_new(0, "UTF-8", 212));
|
||||||
ksubmenu_add(sub_menu2, kmenuitem__submenu_new(1, "Encoding", sub_menu22));
|
ksubmenu_add(sub_menu2, kmenuitem__submenu_new(1, "Encoding", sub_menu22));
|
||||||
|
|
||||||
void *main_menu = ksubmenu_new();
|
void *main_menu = ksubmenu_new();
|
||||||
ksubmenu_add(main_menu, kmenuitem__submenu_new(1, "File", sub_menu1));
|
ksubmenu_add(main_menu, kmenuitem__submenu_new(1, "File", sub_menu1));
|
||||||
ksubmenu_add(main_menu, kmenuitem__submenu_new(1, "Edit", sub_menu2));
|
ksubmenu_add(main_menu, kmenuitem__submenu_new(1, "Edit", sub_menu2));
|
||||||
|
|
||||||
extern volatile unsigned press_key;
|
extern volatile unsigned press_key;
|
||||||
|
|
||||||
do /* Start of main activity loop */
|
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);
|
kolibri_handle_event_redraw(main_window);
|
||||||
kmainmenu_draw(main_menu);
|
kmainmenu_draw(main_menu);
|
||||||
|
@ -36,7 +36,7 @@ int main()
|
|||||||
|
|
||||||
edit_box *editbox_interlock = NULL;
|
edit_box *editbox_interlock = NULL;
|
||||||
edit_box *textbox = kolibri_new_edit_box(20, 60, 40, &editbox_interlock);
|
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);
|
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);
|
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 @@ int main()
|
|||||||
kolibri_window_add_element(main_window, KOLIBRI_CHECK_BOX, checkbox);
|
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_BUTTON, button);
|
||||||
kolibri_window_add_element(main_window, KOLIBRI_FRAME, fr);
|
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;
|
extern volatile unsigned press_key;
|
||||||
|
|
||||||
|
@ -18,6 +18,39 @@
|
|||||||
#include "kos32sys.h"
|
#include "kos32sys.h"
|
||||||
#include "kolibri_gui.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()
|
int main()
|
||||||
{
|
{
|
||||||
@ -64,24 +97,23 @@ int main()
|
|||||||
int option_index1 = 0; // index of selected option
|
int option_index1 = 0; // index of selected option
|
||||||
int option_index2 = 0;
|
int option_index2 = 0;
|
||||||
|
|
||||||
static char *menu1t = "Menu1";
|
char *menu1stru[] = {"Menu1", "Set RED", "Set GREEN", "Set BLUE", NULL};
|
||||||
static char *menu11t = "Set RED";
|
menubar* menu1 = kolibri_new_menubar_def(X_Y(10, 40), X_Y(25, 15), 80, 100, menu1stru);
|
||||||
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);
|
|
||||||
gui_add_menubar(main_window, menu1);
|
gui_add_menubar(main_window, menu1);
|
||||||
|
|
||||||
static char *menu2t = "Menu2";
|
char *menu2stru[] = {"mEnu2", "Set Option 1", "Set Option 2", "Set Option 3", NULL};
|
||||||
static char *menu21t = "Set Option 1";
|
menubar* menu2 = kolibri_new_menubar_def(X_Y(50, 40), X_Y(25, 15), 80, 100, menu2stru);
|
||||||
static char *menu22t = "Set Option 2";
|
gui_add_menubar(main_window, menu2);
|
||||||
static char *menu23t = "Set Option 3";
|
|
||||||
static char *menu24t = "";
|
char *menu3stru[] = {"Quit", NULL};
|
||||||
menubar* menu2 = kolibri_new_menubar_def(X_Y(60, 40), X_Y(25, 15), 80, 100, menu2t, menu21t);
|
menubar* menu3 = kolibri_new_menubar_def(X_Y(90, 40), X_Y(25, 15), 0, 0, menu3stru);
|
||||||
gui_add_menubar(main_window, menu2);
|
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 */
|
do /* Start of main activity loop */
|
||||||
{
|
{
|
||||||
@ -100,7 +132,13 @@ int main()
|
|||||||
case KOLIBRI_EVENT_NONE:
|
case KOLIBRI_EVENT_NONE:
|
||||||
break;
|
break;
|
||||||
case KOLIBRI_EVENT_KEY:
|
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;
|
break;
|
||||||
case KOLIBRI_EVENT_BUTTON:
|
case KOLIBRI_EVENT_BUTTON:
|
||||||
pressed_button = get_os_button();
|
pressed_button = get_os_button();
|
||||||
@ -114,7 +152,22 @@ int main()
|
|||||||
case KOLIBRI_EVENT_MOUSE:
|
case KOLIBRI_EVENT_MOUSE:
|
||||||
// mouse_pos = get_mouse_pos(POS_WINDOW); // window relative
|
// mouse_pos = get_mouse_pos(POS_WINDOW); // window relative
|
||||||
// mouse_button = get_mouse_eventstate();
|
// 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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ check_box* kolibri_new_check_box(unsigned int tlx, unsigned int tly, unsigned in
|
|||||||
new_checkbox -> left_s = (tlx << 16) + sizex;
|
new_checkbox -> left_s = (tlx << 16) + sizex;
|
||||||
new_checkbox -> top_s = (tly << 16) + sizey;
|
new_checkbox -> top_s = (tly << 16) + sizey;
|
||||||
new_checkbox -> ch_text_margin = 10;
|
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 -> border_color = kolibri_color_table.color_work_graph;
|
||||||
new_checkbox -> text_color = kolibri_color_table.color_work_text;
|
new_checkbox -> text_color = kolibri_color_table.color_work_text;
|
||||||
new_checkbox -> text = label_text;
|
new_checkbox -> text = label_text;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t type; // 1 åñëè íåò ïîäìåíþ ??
|
uint32_t type; // 1 åñëè íåò ïîäìåíþ, ïðîñòî ïóíêò
|
||||||
|
|
||||||
uint32_t x_w; // âĺđőíčé ďóíęň
|
uint32_t x_w; // âĺđőíčé ďóíęň
|
||||||
uint32_t y_h;
|
uint32_t y_h;
|
||||||
@ -40,7 +40,7 @@ typedef struct
|
|||||||
} menubar;
|
} 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)
|
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];
|
static char procinfo[1024];
|
||||||
@ -48,15 +48,22 @@ inline menubar* kolibri_menubar(menubar* bar, uint32_t x_w, uint32_t y_h, uint16
|
|||||||
bar->type = 0;
|
bar->type = 0;
|
||||||
bar->x_w = x_w;
|
bar->x_w = x_w;
|
||||||
bar->y_h = y_h;
|
bar->y_h = y_h;
|
||||||
bar->text_pointer = menutext;
|
|
||||||
bar->pos_pointer = subitems;
|
|
||||||
|
|
||||||
// search last item - double zero
|
// count summary length
|
||||||
char *pc = subitems;
|
char *pc, **mitem;
|
||||||
while (*pc) pc = strchr(pc, 0) + 1;
|
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->text_end = pc;
|
||||||
|
bar->pos_pointer = strchr(bar->text_pointer, 0) + 1;
|
||||||
|
|
||||||
bar->x_w1 = X_Y(x_w >> 16, sub_w);
|
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->interval = 16;
|
||||||
bar->font_height = 8;
|
bar->font_height = 8;
|
||||||
@ -72,25 +79,25 @@ inline menubar* kolibri_menubar(menubar* bar, uint32_t x_w, uint32_t y_h, uint16
|
|||||||
return bar;
|
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)
|
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));
|
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_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_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)
|
inline void gui_add_menubar(kolibri_window *wnd, menubar* bar)
|
||||||
|
Loading…
Reference in New Issue
Block a user