Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 6470 → Rev 6479

/contrib/C_Layer/ASM/loadboxlib.asm
147,3 → 147,6
public scrollbar_v_mouse as '_scrollbar_v_mouse'
public scrollbar_h_draw as '_scrollbar_h_draw'
public scrollbar_h_mouse as '_scrollbar_h_mouse'
 
public option_box_draw as '_option_box_draw'
public option_box_mouse as '_option_box_mouse'
/contrib/C_Layer/EXAMPLE/libguic_kolibri/boardmsg.c
1,3 → 1,22
/*
KolibriGUI demobox
-Button
-CheckBox
-EditBox
-Frame
 
Free for all
 
Initially written by ashmew2, 2015
 
Updated by Siemargl, 2016
 
ToDo
*/
 
#include <stdlib.h>
#include <string.h>
#include <kos32sys.h>
#include <kolibri_gui.h>
 
int main()
12,13 → 31,17
unsigned int gui_event = KOLIBRI_EVENT_REDRAW;
oskey_t key;
 
kolibri_window *main_window = kolibri_new_window(50, 50, 400, 100, "BoardMsg: OpenDialog 0.12");
kolibri_window *main_window = kolibri_new_window(50, 50, 400, 120, "BoardMsg: OpenDialog 0.12");
check_box *checkbox = kolibri_new_check_box(20, 45, 12, 12, "Append BOARDMSG to entered message.");
edit_box *textbox = kolibri_new_edit_box(20, 60, 40);
 
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);
kolibri_button *button = kolibri_new_button(310, 60, 24, 14, 0x21, kolibri_color_table.color_work_button);
frame *fr = kolibri_new_frame(12, 35, 350, 50, 0x00FCFCFC, 0x00DCDCDC, 1, "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);
 
kolibri_window_add_element(main_window, KOLIBRI_EDIT_BOX, textbox);
kolibri_window_add_element(main_window, KOLIBRI_EDIT_BOX, textbox2);
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);
/contrib/C_Layer/EXAMPLE/libguic_kolibri/option_menu.c
0,0 → 1,107
/*
KolibriGUI demobox
-OptionBox
-MenuBar
-Frame
 
Free for all
 
Initially written by Siemargl, 2016
 
 
ToDo
*/
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "kos32sys.h"
#include "kolibri_gui.h"
 
 
int main()
{
/* Load all libraries, initialize global tables like system color table and
operations table. kolibri_gui_init() will EXIT with mcall -1 if it fails
to do it's job. This is all you need to call and all libraries and GUI
elements can be used after a successful call to this function
*/
kolibri_gui_init();
int gui_event = KOLIBRI_EVENT_REDRAW;
uint32_t pressed_button = 0;
// uint32_t mouse_button;
// pos_t mouse_pos;
oskey_t keypress;
 
 
// creating GUI using library functions
kolibri_window *main_window = kolibri_new_window(50, 50, 400, 160, "OptionBox and Menu demo");
//check_box *checkbox = kolibri_new_check_box(20, 45, 12, 12, "Append BOARDMSG to entered message.");
 
option_box opts1[3];
option_box *option1sel = opts1; // intially selected RED
 
option_box *op1_1 = gui_optionbox(opts1, X_Y(20, 60), "G1 Item RED", &option1sel);
option_box *op1_2 = gui_optionbox(opts1+1, X_Y(20, 80), "G1 Item GREEN", &option1sel);
option_box *op1_3 = gui_optionbox(opts1+2, X_Y(20, 100), "G1 Item BLUE", &option1sel);
option_box* option_group1[] = {op1_1, op1_2, op1_3, NULL};
 
option_box opts2[3];
option_box *option2sel = opts2 + 1; // intially selected #2
option_box *op2_1 = gui_optionbox(&opts2[0], X_Y(140, 60), "G2 Item 1st", &option2sel);
option_box *op2_2 = gui_optionbox(&opts2[1], X_Y(140, 80), "G2 Item 2nd", &option2sel);
option_box *op2_3 = gui_optionbox(&opts2[2], X_Y(140, 100), "G2 Item 3rd", &option2sel);
option_box* option_group2[] = {op2_1, op2_2, op2_3, NULL};
 
frame *fr1 = kolibri_new_frame_def(X_Y(12, 110), X_Y(50, 70), "Option 1");
frame *fr2 = kolibri_new_frame_def(X_Y(132, 100), X_Y(50, 70), "Option 2");
 
gui_add_optiongroup(main_window, option_group1); // new syntax
gui_add_optiongroup(main_window, option_group2);
gui_add_frame(main_window, fr1);
gui_add_frame(main_window, fr2);
 
int option_index1 = 0; // index of selected option
int option_index2 = 0;
 
do /* Start of main activity loop */
{
if(option_index1 != option1sel - opts1)
debug_board_printf("Option1 change to %d\n", option1sel - opts1);
if(option_index2 != option2sel - opts2)
debug_board_printf("Option2 change to %d\n", option2sel - opts2);
option_index1 = option1sel - opts1;
option_index2 = option2sel - opts2;
 
switch(gui_event)
{
case KOLIBRI_EVENT_REDRAW:
kolibri_handle_event_redraw(main_window);
break;
case KOLIBRI_EVENT_NONE:
break;
case KOLIBRI_EVENT_KEY:
kolibri_handle_event_key(main_window); // ???????
break;
case KOLIBRI_EVENT_BUTTON:
pressed_button = get_os_button();
switch (pressed_button)
{
case BTN_QUIT:
return 0;
break;
}
break;
case KOLIBRI_EVENT_MOUSE:
// mouse_pos = get_mouse_pos(POS_WINDOW); // window relative
// mouse_button = get_mouse_eventstate();
kolibri_handle_event_mouse(main_window);
break;
}
 
gui_event = get_os_event();
} while(1) ; /* End of main activity loop */
 
return 0;
}
 
/contrib/C_Layer/EXAMPLE/libguic_kolibri/scroll_progress.c
1,5 → 1,9
/*
Scrollbar and Progressbar usage example KolibriOS GUI lib
KolibriGUI demobox
-Scrollbar
-Progressbar
-StaticText
-StaticNum
 
Free for all
 
12,8 → 16,8
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "kos32sys.h"
#include "kolibri_gui.h"
#include "kos32sys.h"
 
// codes copied from \programs\cmm\lib\keyboard.h, but they're decimal
//ASCII KEYS
/contrib/C_Layer/INCLUDE/kolibri_colors.h
1,16 → 1,31
#ifndef KOLIBRI_COLORS_H
#define KOLIBRI_COLORS_H
/*
* +0: dword: frames - öâåò ðàìêè
* +4: dword: grab - öâåò çàãîëîâêà
* +8: dword: grab_button - öâåò êíîïêè íà ïîëîñå çàãîëîâêà
* +12 = +0xC: dword: grab_button_text - öâåò òåêñòà íà êíîïêå
íà ïîëîñå çàãîëîâêà
* +16 = +0x10: dword: grab_text - öâåò òåêñòà íà çàãîëîâêå
* +20 = +0x14: dword: work - öâåò ðàáî÷åé îáëàñòè
* +24 = +0x18: dword: work_button - öâåò êíîïêè â ðàáî÷åé îáëàñòè
* +28 = +0x1C: dword: work_button_text - öâåò òåêñòà íà êíîïêå
â ðàáî÷åé îáëàñòè
* +32 = +0x20: dword: work_text - öâåò òåêñòà â ðàáî÷åé îáëàñòè
* +36 = +0x24: dword: work_graph - öâåò ãðàôèêè â ðàáî÷åé îáëàñòè
*/
 
typedef struct {
unsigned int color_frame_area;
unsigned int color_grab_bar;
unsigned int color_grab_bar_button;
unsigned int color_grab_button_text;
unsigned int color_grab_text;
unsigned int color_work_area;
unsigned int color_work_button;
unsigned int color_work_button_text;
unsigned int color_work_text;
unsigned int color_work_graph;
unsigned int color_frame_area; // 0 öâåò ðàìêè
unsigned int color_grab_bar; // 4
unsigned int color_grab_bar_button; // 8
unsigned int color_grab_button_text; // 12
unsigned int color_grab_text; // 16
unsigned int color_work_area; // 20
unsigned int color_work_button; // 24
unsigned int color_work_button_text; // 28
unsigned int color_work_text; // 32
unsigned int color_work_graph; // 36
}kolibri_system_colors;
 
kolibri_system_colors kolibri_color_table;
/contrib/C_Layer/INCLUDE/kolibri_editbox.h
6,7 → 6,7
/* flags meaning
ed_figure_only= 1000000000000000b ;îäíè ñèìâîëû
ed_always_focus= 100000000000000b
ed_focus= 10b ;ôîêóñ ïðèëîæåíèÿ
ed_focus= 10b ;ôîêóñ ââîäà ïðèëîæåíèÿ
ed_pass= 1b ;ïîëå ñ ïàðîëåì
ed_shift_on= 1000b ;åñëè íå óñòàíîâëåí -çíà÷èò âïåðâûå íàæàò shift,åñëè áûë óñòàíîâëåí, çíà÷èò ìû óæå ÷òî - òî äåëàëè óäåðæèâàÿ shift
ed_shift_on_off=1111111111110111b
25,9 → 25,15
ed_mouse_on = 100000000b
ed_mous_adn_b= 100011000b
ed_mouse_on_off=1111111011111111b
ed_mouse_on_off= not (ed_mouse_on)
ed_ctrl_on = 1000000000b
ed_ctrl_off = not (ed_ctrl_on)
ed_alt_on = 10000000000b
ed_alt_off = not (ed_alt_on)
ed_disabled= 100000000000b
*/
 
typedef struct {
typedef struct edit_box_t {
unsigned int width;
unsigned int left;
unsigned int top;
38,7 → 44,7
unsigned int text_color;
unsigned int max;
char *text;
unsigned int mouse_variable; // mus be int* pointer to saved mouse pos ??
struct edit_box_t** mouse_variable; // must be pointer edit_box** to save focused editbox
unsigned int flags;
 
unsigned int size; // used symbols in buffer without trailing zero
66,11 → 72,11
max_chars = Limit of number of characters user can enter into edit box.
*/
 
edit_box* kolibri_new_edit_box(unsigned int tlx, unsigned int tly, unsigned int max_chars)
edit_box* kolibri_new_edit_box(unsigned int tlx, unsigned int tly, unsigned int max_chars, edit_box **editbox_interlock)
{
unsigned int PIXELS_PER_CHAR = 7;
edit_box *new_textbox = (edit_box *)malloc(sizeof(edit_box));
char *text_buffer = (char *)calloc(max_chars + 1, sizeof(char));
edit_box *new_textbox = (edit_box *)calloc(1, sizeof(edit_box));
char *text_buffer = (char *)calloc(max_chars + 2, sizeof(char)); // +2 as asked in box_lib src
 
/* Update blur_border_color and shift_color from box_lib.mac macro */
/* edit_boxes_set_sys_color */
85,19 → 91,9
new_textbox -> text_color = kolibri_color_table.color_work_text; /* Always black text when typing */
new_textbox -> max = max_chars;
new_textbox -> text = text_buffer;
new_textbox -> mouse_variable = 1; /* let the mouse take control? */
new_textbox -> mouse_variable = editbox_interlock;
new_textbox -> flags = 0x00000000;
/* If these lines are uncommented, the executable will crash for no reason at start */
/* Even though these lines are not ever read it ALWAYS causes a crash, even crashes MTDBG. What gives? */
 
new_textbox -> size = 0;
new_textbox -> pos = 0;
new_textbox -> offset = 0;
new_textbox -> cl_curs_x = 0;
new_textbox -> cl_curs_y = 0;
new_textbox -> shift = 0;
new_textbox -> shift_old = 0;
 
return new_textbox;
}
 
/contrib/C_Layer/INCLUDE/kolibri_frame.h
7,42 → 7,60
};
 
typedef struct {
unsigned int type;
uint16_t size_x;
uint16_t start_x;
uint16_t size_y;
uint16_t start_y;
unsigned int ext_col;
unsigned int int_col;
unsigned int draw_text_flag;
uint32_t type;
uint32_t x_w;
uint32_t y_h;
color_t ext_col;
color_t int_col;
uint32_t draw_text_flag;
char *text_pointer;
unsigned int text_position;
unsigned int font_number;
unsigned int font_size_y;
unsigned int font_color;
unsigned int font_backgr_color;
uint32_t text_position;
uint32_t font_number;
uint32_t font_size_y;
color_t font_color;
color_t font_bg_color;
}frame;
 
frame* kolibri_new_frame(uint16_t tlx, uint16_t tly, uint16_t sizex, uint16_t sizey, unsigned int ext_col, unsigned int int_col, unsigned int draw_text_flag, char *text_pointer, unsigned int text_position, unsigned int font_color, unsigned int font_bgcolor)
inline frame* kolibri_frame(frame* f, uint32_t x_w, uint32_t y_h, color_t ext_col, color_t int_col, char *text, uint32_t text_position, color_t font_color, color_t font_bgcolor)
{
f->type = 0;
f->x_w = x_w;
f->y_h = y_h;
f->ext_col = ext_col;
f->int_col = int_col;
f->draw_text_flag = text != NULL;
f->text_pointer = text;
f->text_position = text_position;
f->font_number = 0; // 0 == font 6x9, 1==8x16
f->font_size_y = 9;
f->font_color = font_color | 0x80000000;
f->font_bg_color = font_bgcolor;
 
return f;
}
 
inline frame* kolibri_new_frame(uint32_t x_w, uint32_t y_h, color_t ext_col, color_t int_col, char *text, uint32_t text_position, color_t font_color, color_t font_bgcolor)
{
frame *new_frame = (frame *)malloc(sizeof(frame));
new_frame -> type = 0;
new_frame -> size_x = sizex;
new_frame -> start_x = tlx;
new_frame -> size_y = sizey;
new_frame -> start_y = tly;
new_frame -> ext_col = ext_col;
new_frame -> int_col = int_col;
new_frame -> draw_text_flag = draw_text_flag;
new_frame -> text_pointer = text_pointer;
new_frame -> text_position = text_position;
new_frame -> font_number = 0; // 0 == font 6x9, 1==8x16
new_frame -> font_size_y = 9;
new_frame -> font_color = font_color;
new_frame -> font_backgr_color = font_bgcolor;
return new_frame;
return kolibri_frame(new_frame, x_w, y_h, ext_col, int_col, text, text_position, font_color, font_bgcolor);
}
 
inline frame* kolibri_frame_def(frame* f, uint32_t x_w, uint32_t y_h, char *text)
{
return kolibri_frame(f, x_w, y_h, 0x00FCFCFC, 0x00DCDCDC, text, TOP, kolibri_color_table.color_work_text, kolibri_color_table.color_work_area);
}
 
inline frame* kolibri_new_frame_def(uint32_t x_w, uint32_t y_h, char *text)
{
return kolibri_new_frame(x_w, y_h, 0x00FCFCFC, 0x00DCDCDC, text, TOP, kolibri_color_table.color_work_text, kolibri_color_table.color_work_area);
}
 
inline void gui_add_frame(kolibri_window *wnd, frame* f)
{
kolibri_window_add_element(wnd, KOLIBRI_FRAME, f);
}
 
 
extern void (*frame_draw)(frame *) __attribute__((__stdcall__));
 
#endif /* KOLIBRI_FRAME_H */
/contrib/C_Layer/INCLUDE/kolibri_gui.h
1,9 → 1,6
#ifndef KOLIBRI_GUI_H
#define KOLIBRI_GUI_H
 
#include <stdlib.h> /* for malloc() */
#include <kos32sys.h>
 
#include "kolibri_debug.h" /* work with debug board */
 
/* boxlib loader */
/contrib/C_Layer/INCLUDE/kolibri_gui_elements.h
1,23 → 1,14
#ifndef KOLIBRI_GUI_ELEMENTS_H
#define KOLIBRI_GUI_ELEMENTS_H
 
/* GUI Elements being used */
#include "kolibri_editbox.h"
#include "kolibri_checkbox.h"
#include "kolibri_button.h"
#include "kolibri_progressbar.h"
#include "kolibri_frame.h"
#include "kolibri_scrollbar.h"
#include "kolibri_statictext.h"
#include "kolibri_colors.h"
 
#define X_Y(x,y) (((x)<<16)|(y))
 
/* enum KOLIBRI_GUI_ELEMENT_TYPE contains all available GUI items from box_lib */
/* More elements can be added from other libraries as required */
enum KOLIBRI_GUI_ELEMENT_TYPE {
KOLIBRI_EDIT_BOX,
KOLIBRI_CHECK_BOX,
KOLIBRI_RADIO_BUTTON,
KOLIBRI_OPTIONGROUP,
KOLIBRI_SCROLL_BAR_H,
KOLIBRI_SCROLL_BAR_V,
KOLIBRI_DYNAMIC_BUTTON,
68,6 → 59,23
}kolibri_window;
 
/*---------------------End of Structure and enum definitions---------------*/
 
void kolibri_window_add_element(kolibri_window *some_window, enum KOLIBRI_GUI_ELEMENT_TYPE element_type, void *some_gui_element); // forward declaration
 
/* GUI Elements being used */
#include "kolibri_editbox.h"
#include "kolibri_checkbox.h"
#include "kolibri_button.h"
#include "kolibri_progressbar.h"
#include "kolibri_frame.h"
#include "kolibri_scrollbar.h"
#include "kolibri_statictext.h"
#include "kolibri_optionbox.h"
 
#define X_Y(x,y) (((x)<<16)|(y))
 
 
 
/*---------------------Define various functions for initializing GUI-------*/
 
/* Master table containing operations for various GUI elements in one place */
94,7 → 102,6
kolibri_gui_op_table[KOLIBRI_PROGRESS_BAR].redraw_fn = (cb_elem_boxlib)progressbar_draw;
kolibri_gui_op_table[KOLIBRI_PROGRESS_BAR].mouse_fn = NULL;
kolibri_gui_op_table[KOLIBRI_PROGRESS_BAR].key_fn = NULL;
debug_board_printf("PROGRESS (%x,%x,%x)\n", progressbar_draw,0,0);
 
/* Setting up functions for frame GUI elements*/
kolibri_gui_op_table[KOLIBRI_FRAME].redraw_fn = (cb_elem_boxlib)frame_draw;
101,19 → 108,14
kolibri_gui_op_table[KOLIBRI_FRAME].mouse_fn = NULL;
kolibri_gui_op_table[KOLIBRI_FRAME].key_fn = NULL;
 
debug_board_printf("FRAME (%x,%x,%x)\n", frame_draw,0,0);
 
 
/* scrollbars */
kolibri_gui_op_table[KOLIBRI_SCROLL_BAR_H].redraw_fn = (cb_elem_boxlib)scrollbar_h_draw;
kolibri_gui_op_table[KOLIBRI_SCROLL_BAR_H].mouse_fn = (cb_elem_boxlib)scrollbar_h_mouse;
kolibri_gui_op_table[KOLIBRI_SCROLL_BAR_H].key_fn = NULL;
debug_board_printf("SCROLL_H (%x,%x,%x)\n", scrollbar_h_draw,scrollbar_h_mouse,0);
 
kolibri_gui_op_table[KOLIBRI_SCROLL_BAR_V].redraw_fn = (cb_elem_boxlib)scrollbar_v_draw;
kolibri_gui_op_table[KOLIBRI_SCROLL_BAR_V].mouse_fn = (cb_elem_boxlib)scrollbar_v_mouse;
kolibri_gui_op_table[KOLIBRI_SCROLL_BAR_V].key_fn = NULL;
debug_board_printf("SCROLL_V (%x,%x,%x)\n", scrollbar_v_draw,scrollbar_v_mouse,0);
 
kolibri_gui_op_table[KOLIBRI_STATICTEXT].redraw_fn = (cb_elem_boxlib)statictext_draw;
kolibri_gui_op_table[KOLIBRI_STATICTEXT].mouse_fn = NULL;
122,7 → 124,12
kolibri_gui_op_table[KOLIBRI_STATICNUM].redraw_fn = (cb_elem_boxlib)staticnum_draw;
kolibri_gui_op_table[KOLIBRI_STATICNUM].mouse_fn = NULL;
kolibri_gui_op_table[KOLIBRI_STATICNUM].key_fn = NULL;
debug_board_printf("STATICNUM (%x,%x,%x)\n", staticnum_draw,0,0);
 
kolibri_gui_op_table[KOLIBRI_OPTIONGROUP].redraw_fn = (cb_elem_boxlib)option_box_draw;
kolibri_gui_op_table[KOLIBRI_OPTIONGROUP].mouse_fn = (cb_elem_boxlib)option_box_mouse;
kolibri_gui_op_table[KOLIBRI_OPTIONGROUP].key_fn = NULL;
 
debug_board_printf("KOLIBRI_OPTIONGROUP (%x,%x,%x)\n", option_box_draw,option_box_mouse,0);
}
 
/* Create a new main GUI window for KolibriOS */
/contrib/C_Layer/INCLUDE/kolibri_optionbox.h
0,0 → 1,55
#ifndef KOLIBRI_OPTIONBOX_H
#define KOLIBRI_OPTIONBOX_H
 
typedef struct option_box_t{
struct option_box_t **selected;
uint16_t posx;
uint16_t posy;
uint32_t text_margin; // = 4 ðàññòîÿíèå îò ïðÿìîóãîëüíèêà ÷åê áîêñà äî íàäïèñè
uint32_t size; // 12 ðàçìåð êâàäðàòà ÷åê áîêñà
color_t color;
color_t border_color; // individual border
color_t text_color;
char *text;
uint32_t text_len;
uint32_t flags;
}option_box;
 
extern void (*option_box_draw)(option_box **) __attribute__((__stdcall__));
extern void (*option_box_mouse)(option_box **)__attribute__((__stdcall__));
 
inline option_box* gui_optionbox(option_box* ob, uint32_t x_y, char* text, option_box**select)
{
ob->selected = select;
ob->posx = x_y >> 16;
ob->posy = x_y & 0xFFFF;
ob->text_margin = 4;
ob->size = 12;
ob->color = kolibri_color_table.color_work_button_text;
ob->border_color = kolibri_color_table.color_work_button;
ob->text_color = kolibri_color_table.color_work_text | 0x80000000;
ob->text = text;
ob->text_len = strlen(text);
ob->flags = 0; // not used
 
return ob;
}
 
inline option_box* gui_new_optionbox(uint32_t x_y, char* text, option_box**select)
{
option_box* ob = malloc(sizeof(option_box));
 
return gui_optionbox(ob, x_y, text, select);
}
 
#define gui_optionbox_def(a,b,c,d) gui_optionbox(a,b,c,d)
 
#define gui_new_optionbox_def(a,b,c) gui_new_optionbox(a,b,c)
 
inline void gui_add_optiongroup(kolibri_window *wnd, option_box** option_group)
{
kolibri_window_add_element(wnd, KOLIBRI_OPTIONGROUP, option_group);
}
 
 
#endif /* KOLIBRI_OPTIONBOX_H */