dbutton, opensave demo

git-svn-id: svn://kolibrios.org@6524 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
siemargl 2016-09-19 11:17:21 +00:00
parent 63939f9591
commit 799306dee1
9 changed files with 326 additions and 31 deletions

View File

@ -144,3 +144,9 @@ public option_box_mouse as '_option_box_mouse'
public menu_bar_draw as '_menu_bar_draw' public menu_bar_draw as '_menu_bar_draw'
public menu_bar_mouse as '_menu_bar_mouse' public menu_bar_mouse as '_menu_bar_mouse'
public menu_bar_activate as '_menu_bar_activate' public menu_bar_activate as '_menu_bar_activate'
public dynamic_button_draw as '_dynamic_button_draw'
public dynamic_button_mouse as '_dynamic_button_mouse'
public path_show_prepare as '_path_show_prepare'
public path_show_draw as '_path_show_draw'

View File

@ -0,0 +1,152 @@
/*
KolibriGUI demobox
-Picture Button
-StaticText
-File Open/Save Dialog
-Filebrowser (planned)
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"
#include "kolibri_opendialog.h"
#include "kolibri_libimg.h"
char temp_path[4096];
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();
kolibri_proclib_init(); // opensave && color dialogs
kolibri_libimg_init(); // png handling
int gui_event = KOLIBRI_EVENT_REDRAW;
uint32_t pressed_button = 0;
// uint32_t mouse_button;
// pos_t mouse_pos;
oskey_t keypress;
// load image for buttons
const int icon_rgb_size = 16*16*3; // every icons 16x16 24bpp
char *image_data_rgb = malloc(icon_rgb_size * 3),
*image_data;
// make full path + argv
FILE *ficon = fopen("reload_16x16_8b.png", "rb");
if (!ficon)
{
debug_board_write_str("no icons file reload_16x16_8b.png ");
return 1;
}
int ficon_size = fread(image_data_rgb, 1, icon_rgb_size * 3, ficon);
if (ferror(ficon))
{
debug_board_write_str("error reading file reload_16x16_8b.png ");
return 1;
}
fclose(ficon);
// îïðåäåëÿåì âèä èçîáðàæåíèÿ è ïåðåâîäèì åãî âî âðåìåííûé áóôåð image_data
image_data = (*img_decode)(image_data_rgb, ficon_size, 0);
// ïðåîáðàçóåì èçîáðàæåíèå ê ôîðìàòó rgb
(*img_to_rgb2)(image_data, image_data_rgb);
// óäàëÿåì âðåìåííûé áóôåð image_data
(*img_destroy)(image_data);
// creating GUI using library functions
kolibri_window *main_window = kolibri_new_window(50, 40, 400, 160, "PictureButton and File dialog demo");
pict_button tbar[3];
gui_add_pict_button(main_window, kolibri_pict_button(&tbar[0], X_Y(10, 16), X_Y(10, 16), image_data_rgb, image_data_rgb + icon_rgb_size, image_data_rgb + icon_rgb_size * 2, 24, NULL, 0));
gui_add_pict_button(main_window, kolibri_pict_button(&tbar[1], X_Y(20, 16), X_Y(10, 16), image_data_rgb, image_data_rgb + icon_rgb_size, image_data_rgb + icon_rgb_size * 2, 24, NULL, 0));
gui_add_pict_button(main_window, kolibri_pict_button(&tbar[2], X_Y(30, 16), X_Y(10, 16), image_data_rgb, image_data_rgb + icon_rgb_size, image_data_rgb + icon_rgb_size * 2, 24, NULL, 0));
statictext labels[3]; // tips
gui_add_statictext(main_window, kolibri_statictext_def(&labels[0], X_Y(5, 28), "Open"));
gui_add_statictext(main_window, kolibri_statictext_def(&labels[1], X_Y(20, 28), "Save"));
gui_add_statictext(main_window, kolibri_statictext_def(&labels[2], X_Y(30, 28), "Select Dir"));
open_dialog *dlg_opensave = kolibri_new_open_dialog(OPEN, 10, 10, 420, 320);
(*OpenDialog_init)(dlg_opensave);
pathview pview;
gui_add_pathview(main_window, kolibri_pathview(&pview, X_Y(10, 40), 330, 0, 0, dlg_opensave->openfile_path, temp_path, 0, 0)); // black font, no background
do /* Start of main activity loop */
{
switch(gui_event)
{
case KOLIBRI_EVENT_REDRAW:
kolibri_handle_event_redraw(main_window);
break;
case KOLIBRI_EVENT_NONE:
break;
case KOLIBRI_EVENT_KEY:
keypress = get_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);
if(tbar[0].click) // open
{
tbar[0].click = 0;
dlg_opensave->mode = OPEN;
(*OpenDialog_start)(dlg_opensave);
if (dlg_opensave->status != 2 && dlg_opensave->status != 1) // fail or cancel
(*path_show_prepare)(&pview);
kolibri_handle_event_redraw(main_window);
}
if(tbar[1].click) // save
{
tbar[1].click = 0;
dlg_opensave->mode = SAVE;
(*OpenDialog_start)(dlg_opensave);
if (dlg_opensave->status != 2 && dlg_opensave->status != 1) // fail or cancel
(*path_show_prepare)(&pview);
kolibri_handle_event_redraw(main_window);
}
if(tbar[2].click) // select
{
tbar[2].click = 0;
dlg_opensave->mode = SELECT;
(*OpenDialog_start)(dlg_opensave);
if (dlg_opensave->status != 2 && dlg_opensave->status != 1) // fail or cancel
(*path_show_prepare)(&pview);
kolibri_handle_event_redraw(main_window);
}
break;
}
gui_event = get_os_event();
} while(1) ; /* End of main activity loop */
return 0;
}

View File

@ -107,7 +107,7 @@ int main()
switch(gui_event) switch(gui_event)
{ {
case KOLIBRI_EVENT_REDRAW: case KOLIBRI_EVENT_REDRAW:
sbh->all_redraw = sbv->all_redraw = 1; // resetted sbh->all_redraw = sbv->all_redraw = 1; // resetted by sbar
kolibri_handle_event_redraw(main_window); kolibri_handle_event_redraw(main_window);
valuechange = 0; valuechange = 0;
break; break;
@ -162,7 +162,8 @@ int main()
// 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();
// add logic to find widget under mouse // add logic to find widget under mouse
kolibri_handle_event_mouse(main_window); kolibri_handle_event_mouse(main_window);
// we can optimize a lot, if sb->delta2 == 1 then call sb->mouse() and redraw only if sb->redraw with flag all_redraw = 0 (only runner). Then reset redraw. OMG (
if (sbh->position != value) // scrollbars was changed if (sbh->position != value) // scrollbars was changed
{ {
value = sbh->position; value = sbh->position;

View File

@ -26,7 +26,7 @@ struct open_dialog* kolibri_new_color_dialog(unsigned int type, unsigned short t
{ {
color_dialog *new_colordialog = (color_dialog *)malloc(sizeof(color_dialog)); color_dialog *new_colordialog = (color_dialog *)malloc(sizeof(color_dialog));
char *proc_info = (char *)calloc(1024, sizeof(char)); char *proc_info = (char *)calloc(1024, sizeof(char));
new_colordialog -> type = type; new_colordialog -> type = type;
new_colordialog -> procinfo = proc_info; new_colordialog -> procinfo = proc_info;
new_colordialog -> com_area_name = &cd_com_area_name; new_colordialog -> com_area_name = &cd_com_area_name;
@ -43,6 +43,7 @@ struct open_dialog* kolibri_new_color_dialog(unsigned int type, unsigned short t
return new_colordialog; return new_colordialog;
} }
extern void kolibri_proclib_init() __attribute__((__stdcall__));
extern void (*ColorDialog_init)(color_dialog *) __attribute__((__stdcall__)); extern void (*ColorDialog_init)(color_dialog *) __attribute__((__stdcall__));
extern void (*ColorDialog_start)(color_dialog *) __attribute__((__stdcall__)); extern void (*ColorDialog_start)(color_dialog *) __attribute__((__stdcall__));
#endif /* KOLIBRI_COLORDIALOG_H */ #endif /* KOLIBRI_COLORDIALOG_H */

View File

@ -0,0 +1,52 @@
#ifndef KOLIBRI_DBUTTON_H
#define KOLIBRI_DBUTTON_H
typedef struct {
uint32_t type;
uint32_t x_w;
uint32_t y_h;
uint32_t mouse_pos;
uint32_t mouse_keys;
uint32_t mouse_keys_old;
void* active_raw; //active bitmap
void* passive_raw; //passive bitmap
void* click_raw; //pressed bitmap
uint32_t resolution_raw; // bpp, as esi fn65
void* palette_raw; // palette, as edi fn65
uint32_t offset_raw; // width as ebp fn65
uint32_t select; // internal state: 0 - passive, 2 - pressed, 1 - clicked
uint32_t click; // clicked - 1, zero it after tested
} pict_button;
inline pict_button* kolibri_pict_button(pict_button* b, uint32_t x_w, uint32_t y_h, void* active_pict, void* passive_pict, void* pressed_pict, uint32_t bpp, void* palette, int32_t offset_line)
{
b->type = b->mouse_pos = b->mouse_keys = b->mouse_keys_old = b->select = b->click = 0;
b->x_w = x_w;
b->y_h = y_h;
b->active_raw = active_pict;
b->passive_raw = passive_pict;
b->click_raw = pressed_pict;
b->resolution_raw = bpp;
b->palette_raw = palette;
b->offset_raw = offset_line;
return b;
}
inline pict_button* kolibri_new_pict_button(uint32_t x_w, uint32_t y_h, void* active_pict, void* passive_pict, void* pressed_pict, uint32_t bpp, void* palette, int32_t offset_line)
{
pict_button *new_d_but = (pict_button *)malloc(sizeof(pict_button));
return kolibri_pict_button(new_d_but, x_w, y_h, active_pict, passive_pict, pressed_pict, bpp, palette, offset_line);
}
inline void gui_add_pict_button(kolibri_window *wnd, pict_button* db)
{
kolibri_window_add_element(wnd, KOLIBRI_D_BUTTON, db);
}
extern void (*dynamic_button_draw)(pict_button *) __attribute__((__stdcall__));
extern void (*dynamic_button_mouse)(pict_button *) __attribute__((__stdcall__));
#endif /* KOLIBRI_DBUTTON_H */

View File

@ -21,8 +21,9 @@ enum KOLIBRI_GUI_ELEMENT_TYPE {
KOLIBRI_PROGRESS_BAR, KOLIBRI_PROGRESS_BAR,
KOLIBRI_STATICTEXT, KOLIBRI_STATICTEXT,
KOLIBRI_STATICNUM, KOLIBRI_STATICNUM,
KOLIBRI_BUTTON, KOLIBRI_BUTTON,
KOLIBRI_D_BUTTON,
KOLIBRI_PATHSHOW,
/* Add elements above this element in order to let KOLIBRI_NUM_GUI_ELEMENTS */ /* Add elements above this element in order to let KOLIBRI_NUM_GUI_ELEMENTS */
/* stay at correct value */ /* stay at correct value */
@ -65,15 +66,18 @@ typedef struct{
void kolibri_window_add_element(kolibri_window *some_window, enum KOLIBRI_GUI_ELEMENT_TYPE element_type, void *some_gui_element); // forward declaration 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 */ /* GUI Elements being used */
#include "kolibri_editbox.h"
#include "kolibri_checkbox.h"
#include "kolibri_button.h" #include "kolibri_button.h"
#include "kolibri_progressbar.h" #include "kolibri_checkbox.h"
#include "kolibri_d_button.h"
#include "kolibri_editbox.h"
#include "kolibri_frame.h" #include "kolibri_frame.h"
#include "kolibri_menubar.h"
#include "kolibri_optionbox.h"
#include "kolibri_pathshow.h"
#include "kolibri_progressbar.h"
#include "kolibri_scrollbar.h" #include "kolibri_scrollbar.h"
#include "kolibri_statictext.h" #include "kolibri_statictext.h"
#include "kolibri_optionbox.h"
#include "kolibri_menubar.h"
@ -135,7 +139,15 @@ kolibri_gui_op_table[KOLIBRI_MENU_BAR].redraw_fn = (cb_elem_boxlib)menu_bar_draw
kolibri_gui_op_table[KOLIBRI_MENU_BAR].mouse_fn = (cb_elem_boxlib)menu_bar_mouse; kolibri_gui_op_table[KOLIBRI_MENU_BAR].mouse_fn = (cb_elem_boxlib)menu_bar_mouse;
kolibri_gui_op_table[KOLIBRI_MENU_BAR].key_fn = NULL; kolibri_gui_op_table[KOLIBRI_MENU_BAR].key_fn = NULL;
debug_board_printf("KOLIBRI_MENU_BAR (%x,%x,%x)\n", menu_bar_draw,menu_bar_mouse,menu_bar_activate); kolibri_gui_op_table[KOLIBRI_D_BUTTON].redraw_fn = (cb_elem_boxlib)dynamic_button_draw;
kolibri_gui_op_table[KOLIBRI_D_BUTTON].mouse_fn = (cb_elem_boxlib)dynamic_button_mouse;
kolibri_gui_op_table[KOLIBRI_D_BUTTON].key_fn = NULL;
debug_board_printf("KOLIBRI_D_BUTTON (%x,%x,%x)\n", dynamic_button_draw, dynamic_button_mouse, 0);
kolibri_gui_op_table[KOLIBRI_PATHSHOW].redraw_fn = (cb_elem_boxlib)path_show_draw;
kolibri_gui_op_table[KOLIBRI_PATHSHOW].mouse_fn = NULL;
kolibri_gui_op_table[KOLIBRI_PATHSHOW].key_fn = NULL;
debug_board_printf("KOLIBRI_PATHSHOW (%x,%x,%x)\n", path_show_draw, 0, 0);
} }
/* Create a new main GUI window for KolibriOS */ /* Create a new main GUI window for KolibriOS */

View File

@ -3,35 +3,41 @@
char sz_com_area_name[] = "FFFFFFFF_open_dialog"; char sz_com_area_name[] = "FFFFFFFF_open_dialog";
char sz_dir_default_path[] = "/rd/1"; char sz_dir_default_path[] = "/rd/1";
char sz_start_path[] = "/rd/1/File managers/opendial"; char sz_start_path[] = "/rd/1/File managers/opendial";
enum open_dialog_mode {
OPEN,
SAVE,
SELECT
};
typedef struct {
unsigned int size;
unsigned char end;
}od_filter;
typedef struct { typedef struct {
unsigned int mode; unsigned int mode;
unsigned int procinfo; char* procinfo;
unsigned int com_area_name; char* com_area_name;
unsigned int com_area; unsigned int com_area;
unsigned int opendir_path; char* opendir_path;
unsigned int dir_default_path; char* dir_default_path;
unsigned int start_path; char* start_path;
unsigned int draw_window; void (*draw_window)();
unsigned int status; unsigned int status;
unsigned int openfile_path; char* openfile_path;
unsigned int filename_area; char* filename_area;
unsigned int filter_area; od_filter* filter_area;
unsigned short x_size; unsigned short x_size;
unsigned short x_start; unsigned short x_start;
unsigned short y_size; unsigned short y_size;
unsigned short y_start; unsigned short y_start;
}open_dialog; }open_dialog;
typedef struct {
unsigned int size;
unsigned char end;
}od_filter;
void fake_on_redraw(void) {} void fake_on_redraw(void) {}
struct open_dialog* kolibri_new_open_dialog(unsigned int mode, unsigned short tlx, unsigned short tly, unsigned short x_size, unsigned short y_size) open_dialog* kolibri_new_open_dialog(unsigned int mode, unsigned short tlx, unsigned short tly, unsigned short x_size, unsigned short y_size)
{ {
open_dialog *new_opendialog = (open_dialog *)malloc(sizeof(open_dialog)); open_dialog *new_opendialog = (open_dialog *)malloc(sizeof(open_dialog));
od_filter *new_od_filter = (od_filter *)malloc(sizeof(od_filter)); od_filter *new_od_filter = (od_filter *)malloc(sizeof(od_filter));
@ -39,17 +45,17 @@ struct open_dialog* kolibri_new_open_dialog(unsigned int mode, unsigned short tl
char *openfile_path = (char *)calloc(4096, sizeof(char)); char *openfile_path = (char *)calloc(4096, sizeof(char));
char *proc_info = (char *)calloc(1024, sizeof(char)); char *proc_info = (char *)calloc(1024, sizeof(char));
char *filename_area = (char *)calloc(256, sizeof(char)); char *filename_area = (char *)calloc(256, sizeof(char));
new_od_filter -> size = 0; new_od_filter -> size = 0;
new_od_filter -> end = 0; new_od_filter -> end = 0;
new_opendialog -> mode = mode; new_opendialog -> mode = mode;
new_opendialog -> procinfo = proc_info; new_opendialog -> procinfo = proc_info;
new_opendialog -> com_area_name = &sz_com_area_name; new_opendialog -> com_area_name = sz_com_area_name;
new_opendialog -> com_area = 0; new_opendialog -> com_area = 0;
new_opendialog -> opendir_path = plugin_path; new_opendialog -> opendir_path = plugin_path;
new_opendialog -> dir_default_path = &sz_dir_default_path; new_opendialog -> dir_default_path = sz_dir_default_path;
new_opendialog -> start_path = &sz_start_path; new_opendialog -> start_path = sz_start_path;
new_opendialog -> draw_window = &fake_on_redraw; new_opendialog -> draw_window = &fake_on_redraw;
new_opendialog -> status = 0; new_opendialog -> status = 0;
new_opendialog -> openfile_path = openfile_path; new_opendialog -> openfile_path = openfile_path;
@ -62,6 +68,7 @@ struct open_dialog* kolibri_new_open_dialog(unsigned int mode, unsigned short tl
return new_opendialog; return new_opendialog;
} }
extern void kolibri_proclib_init();
extern void (*OpenDialog_init)(open_dialog *) __attribute__((__stdcall__)); extern void (*OpenDialog_init)(open_dialog *) __attribute__((__stdcall__));
extern void (*OpenDialog_start)(open_dialog *) __attribute__((__stdcall__)); extern void (*OpenDialog_start)(open_dialog *) __attribute__((__stdcall__));
#endif /* KOLIBRI_OPENDIALOG_H */ #endif /* KOLIBRI_OPENDIALOG_H */

View File

@ -0,0 +1,51 @@
#ifndef KOLIBRI_PATHSHOW_H
#define KOLIBRI_PATHSHOW_H
typedef struct {
uint32_t type;
uint32_t x_y;
uint16_t font_size_x; // 6 - for font 0, 8 - for font 1
uint16_t area_size_x;
uint32_t font_number; // 0 - monospace, 1 - variable, as fn4 (2bit only 0-3)
uint32_t background_flag; // as fn4, if 0, bk_color unneeded
color_t font_color; // as fn4
color_t background_color; // as fn4
char* text_pointer; // 4096 ?
char* work_area_pointer; // 4096 ?
uint32_t temp_text_length;
} pathview;
inline pathview* kolibri_pathview(pathview* p, uint32_t x_y, uint32_t width, uint32_t font_number, uint32_t is_bkgr, char* text, char* temp_buf, color_t font, color_t bkgr)
{
p->type = p->temp_text_length = 0;
p->x_y = x_y;
p->font_size_x = font_number == 0 ? 6 : 8; // need correction for bigger fonts
p->area_size_x = width;
p->font_number = font_number;
p->background_flag = is_bkgr;
p->text_pointer = text;
p->work_area_pointer = temp_buf;
p->font_color = font;
p->background_color = bkgr;
return p;
}
inline pathview* kolibri_new_pathview(pathview* p, uint32_t x_y, uint32_t width, uint32_t font_number, uint32_t is_bkgr, char* text, char* temp_buf, color_t font, color_t bkgr)
{
pathview *new_pv = (pathview *)malloc(sizeof(pathview));
return kolibri_pathview(new_pv, x_y, width, font_number, is_bkgr, text, temp_buf, font, bkgr);
}
inline void gui_add_pathview(kolibri_window *wnd, pathview* pv)
{
kolibri_window_add_element(wnd, KOLIBRI_PATHSHOW, pv);
}
extern void (*path_show_prepare)(pathview *) __attribute__((__stdcall__));
extern void (*path_show_draw)(pathview *) __attribute__((__stdcall__));
#endif /* KOLIBRI_PATHSHOW_H */

View File

@ -66,6 +66,13 @@ void statictext_draw(statictext *st)
:); :);
} }
inline void gui_add_statictext(kolibri_window *wnd, statictext* st)
{
kolibri_window_add_element(wnd, KOLIBRI_STATICTEXT, st);
}
staticnum* kolibri_staticnum(staticnum* st, uint32_t xy, int32_t width, int16_t number, encoding_t enc, int size, color_t font, color_t bg) staticnum* kolibri_staticnum(staticnum* st, uint32_t xy, int32_t width, int16_t number, encoding_t enc, int size, color_t font, color_t bg)
{ {
st->start_xy = xy; st->start_xy = xy;
@ -97,6 +104,12 @@ staticnum* kolibri_new_staticnum_def(uint32_t xy, int32_t width, int32_t number)
return kolibri_new_staticnum(xy, width, number, cp866, 0, kolibri_color_table.color_work_text, 0); return kolibri_new_staticnum(xy, width, number, cp866, 0, kolibri_color_table.color_work_text, 0);
} }
inline void gui_add_staticnum(kolibri_window *wnd, staticnum* sn)
{
kolibri_window_add_element(wnd, KOLIBRI_STATICNUM, sn);
}
__attribute__((__stdcall__)) __attribute__((__stdcall__))
void staticnum_draw(staticnum *st) void staticnum_draw(staticnum *st)
{ {