C_Layer: fixed some headers and code so that examples can build also with >= c99

git-svn-id: svn://kolibrios.org@8581 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Rustem Gimadutdinov (rgimad)
2021-02-05 23:27:15 +00:00
parent d5cfdf6d55
commit 10b3ae76ba
17 changed files with 348 additions and 339 deletions

View File

@@ -8,7 +8,7 @@ CLAYER = $(abspath ../../)
LDFLAGS = -static -S -nostdlib -T $(SDK_DIR)/sources/newlib/app.lds \
--image-base 0
CFLAGS = -g -U_Win32 -U_WIN32 -U__MINGW32__
CFLAGS = -g -U_Win32 -U_WIN32 -U__MINGW32__ -std=c99
INCLUDES = -I. -I$(SDK_DIR)/sources/newlib/libc/include
LIBPATH = -L $(SDK_DIR)/lib -L /home/autobuild/tools/win32/mingw32/lib
@@ -29,4 +29,4 @@ $(NAME): $(OBJECTS) Makefile
$(CC) -c $(INCLUDES) $(CFLAGS) -o $@ $<
clean:
-rm -f *.o *.map
-rm -f *.o *.map $(NAME)

View File

@@ -8,7 +8,7 @@ CLAYER:= $(abspath ../../)
LDFLAGS = -static -S -nostdlib -T $(SDK_DIR)/sources/newlib/app.lds \
--image-base 0
CFLAGS = -c -fno-ident -O2 -fomit-frame-pointer -fno-ident -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32
CFLAGS = -c -fno-ident -O2 -fomit-frame-pointer -fno-ident -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32 -std=c99
INCLUDES= -I. -I$(SDK_DIR)/sources/newlib/libc/include -I$(CLAYER)/INCLUDE
LIBPATH:= -L $(SDK_DIR)/lib -L /home/autobuild/tools/win32/mingw32/lib
@@ -17,9 +17,9 @@ OBJPATH = $(CLAYER)/OBJ
all:
$(CC) $(CFLAGS) $(INCLUDES) $(SOURCES) main.c
$(LD) $(LIBPATH) $(LDFLAGS) --subsystem native main.o $(OBJPATH)/loadlibimg.obj -o $(NAME) -lgcc -lc.dll
$(LD) $(LIBPATH) $(LDFLAGS) --subsystem native main.o $(OBJPATH)/loadlibimg.obj $(OBJPATH)/loadboxlib.obj -o $(NAME) -lgcc -lc.dll
strip -S $(NAME)
objcopy $(NAME) -O binary
clean:
-rm -f *.o
-rm -f *.o $(NAME)

View File

@@ -3,8 +3,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <kolibri_libimg.h>
#include <kos32sys.h>
#include <kolibri_gui.h>
#include <kolibri_libimg.h>
#define NEW_IMG_H 128
#define NEW_IMG_W 128

View File

@@ -8,7 +8,7 @@ CLAYER:= $(abspath ../../)
LDFLAGS = -static -S -nostdlib -T $(SDK_DIR)/sources/newlib/app.lds \
--image-base 0 -lgcc -ldll -lc.dll
CFLAGS = -g -U_Win32 -U_WIN32 -U__MINGW32__ -std=gnu90
CFLAGS = -g -U_Win32 -U_WIN32 -U__MINGW32__ -std=c99
INCLUDES= -I. -I$(SDK_DIR)/sources/newlib/libc/include -I$(CLAYER)/INCLUDE
LIBPATH:= -L $(SDK_DIR)/lib -L /home/autobuild/tools/win32/mingw32/lib
@@ -29,4 +29,4 @@ $(NAME): $(OBJECTS) Makefile
$(CC) -c $(INCLUDES) $(CFLAGS) -o $@ $<
clean:
-rm -f *.o *.map
-rm -f *.o *.map $(NAME)

View File

@@ -8,7 +8,7 @@ CLAYER:= $(abspath ../../)
LDFLAGS = -static -S -nostdlib -T $(SDK_DIR)/sources/newlib/app-dynamic.lds \
--image-base 0 -lgcc -ldll -lc.dll
CFLAGS = -g -U_Win32 -U_WIN32 -U__MINGW32__ -std=gnu90 -mno-ms-bitfields
CFLAGS = -g -U_Win32 -U_WIN32 -U__MINGW32__ -std=c99 -mno-ms-bitfields
INCLUDES= -I. -I$(SDK_DIR)/sources/newlib/libc/include -I$(CLAYER)/INCLUDE
LIBPATH:= -L $(SDK_DIR)/lib -L /home/autobuild/tools/win32/mingw32/lib
@@ -47,4 +47,4 @@ dbutton_files: dbutton_files.o
$(CC) -c $(INCLUDES) $(CFLAGS) -o $@ $<
clean:
-rm -f *.o
-rm -f *.o boardmsg boardmsg.map dbutton_files editor_tree_msgbox editor_tree_msgbox.map option_menu scroll_progress

View File

@@ -22,6 +22,14 @@
#include "kolibri_libimg.h"
#include "kolibri_msgbox.h"
/*extern inline scrollbar* kolibri_scrollbar(scrollbar* sb, uint32_t x_w, uint32_t y_h, uint32_t btn_height, uint32_t max_area,
uint32_t cur_area, uint32_t position, uint32_t back_color, uint32_t front_color, uint32_t line_color);
extern inline scrollbar* kolibri_new_scrollbar(uint32_t x_w, uint32_t y_h, uint32_t btn_height, uint32_t max_area,
uint32_t cur_area, uint32_t position, uint32_t back_color, uint32_t front_color, uint32_t line_color);
extern inline scrollbar* kolibri_new_scrollbar_def(uint32_t x_w, uint32_t y_h, uint32_t max_area, uint32_t cur_area, uint32_t position);
*/
char run_path[4096];
char fname[4096];
@@ -37,13 +45,13 @@ void set_os_keyb_mode(int mode)
};
int main(int argc, char **argv)
{
/* 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
*/
int main(int argc, char **argv)
{
/* 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();
set_os_keyb_mode(1); // scan code mode needed for editor
// kolibri_proclib_init(); // opensave && color dialogs
@@ -78,22 +86,22 @@ int main(int argc, char **argv)
//adding sample text @cursor
char *sampletext = "*123*=========ADDED SAMPLE TEXT=========*789*\n";
(*ted_text_add)(ed, sampletext, strlen(sampletext), 0);
// treelist as tree
treelist *tl = kolibri_new_treelist(X_Y(0, 200), X_Y(200, 200), 16, X_Y(16, 16), 100, 50, 0, 0, /*TL_KEY_NO_EDIT |*/ TL_DRAW_PAR_LINE, &ed_lock, 0x8080ff, 0x0000ff, 0xffffff);
(*tl_data_init)(tl);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
strcpy(fname, run_path);
strcat(fname, "tl_sys_16.png");
tl->data_img_sys = load_image_file(fname);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
strcpy(fname, run_path);
strcat(fname, "tl_nod_16.png");
tl->data_img = load_image_file(fname);
treelist_node_add(tl, "node1", 1, 0, 0); // <20><><EFBFBD> 1 <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
treelist_node_add(tl, "node1", 1, 0, 0); // <20><><EFBFBD> 1 <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
(*tl_cur_next)(tl);
treelist_node_add(tl, "node1.1", 1, 0, 1);
(*tl_cur_next)(tl);
@@ -110,7 +118,7 @@ int main(int argc, char **argv)
treelist_node_add(tl, "node3", 1, 0, 0);
(*tl_cur_next)(tl);
(*tl_cur_beg)(tl); //;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
(*tl_cur_beg)(tl); //;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
gui_add_treelist(main_window, tl);
// treelist as listbox, no caption, no icons
@@ -121,7 +129,7 @@ int main(int argc, char **argv)
tl2->data_img_sys = tl->data_img_sys;
//tl2->data_img = tl->data_img; - no icons will be drawed
treelist_node_add(tl2, "list1", 0, 0, 0); // <20><><EFBFBD> 1 <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
treelist_node_add(tl2, "list1", 0, 0, 0); // <20><><EFBFBD> 1 <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
(*tl_cur_next)(tl2);
treelist_node_add(tl2, "list2", 0, 0, 0);
@@ -130,13 +138,13 @@ int main(int argc, char **argv)
treelist_node_add(tl2, "list3", 0, 0, 0);
(*tl_cur_next)(tl2);
(*tl_cur_beg)(tl2); //;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
(*tl_cur_beg)(tl2); //;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
gui_add_treelist(main_window, tl2);
msgbox* box = kolibri_new_msgbox("Exit", "Are\rYOU\rSure?", 3, "YES", "Absolute", "Not Yet", NULL); // default NOT
oskey_t key;
do /* Start of main activity loop */
do /* Start of main activity loop */
{
switch(gui_event)
{
@@ -163,22 +171,22 @@ int main(int argc, char **argv)
kolibri_handle_event_key(main_window, key);
break;
case KOLIBRI_EVENT_BUTTON:
pressed_button = get_os_button();
switch (pressed_button)
{
pressed_button = get_os_button();
switch (pressed_button)
{
case BTN_QUIT:
if (box->retval == 3 || box->retval == 0) // not started or cancelled, analyze when redraw after closing msgbox
kolibri_start_msgbox(box, NULL);
break;
}
break;
break;
}
break;
case KOLIBRI_EVENT_MOUSE:
kolibri_handle_event_mouse(main_window);
break;
break;
}
gui_event = get_os_event();
} while(1) ; /* End of main activity loop */
} while(1) ; /* End of main activity loop */
clearing:
trap(0x55); // for stop in debug
@@ -190,10 +198,10 @@ trap(0x55); // for stop in debug
editor_delete(ed);
treelist_data_clear(tl);
return 0;
}
treelist_data_clear(tl);
return 0;
}
char* load_file_inmem(char* fname, int32_t* read_sz)
@@ -230,14 +238,14 @@ char* load_image_file(char* fname)
char *image_data = 0, *image_data_rgb = 0, *filedata = 0;
filedata = load_file_inmem(fname, &read_bytes);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> image_data
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> image_data
image_data = (*img_decode)(filedata, read_bytes, 0);
w = *(int*)(image_data +4);
h = *(int*)(image_data +8);
image_data_rgb = malloc(w * h * 3);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> rgb
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> rgb
(*img_to_rgb2)(image_data, image_data_rgb);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> image_data
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> image_data
(*img_destroy)(image_data);
free(filedata);

View File

@@ -20,8 +20,8 @@
#define SCAN_CODE_ALTM 50
#define SCAN_CODE_ALTE 18
inline
uint32_t get_os_keyb_modifiers()
static inline uint32_t get_os_keyb_modifiers()
{
register uint32_t val;
__asm__ __volatile__(
@@ -43,8 +43,7 @@ uint32_t get_os_keyb_modifiers()
#define KEY_LWIN 0x200
#define KEY_RWIN 0x400
inline
void set_os_keyb_mode(int mode)
static inline void set_os_keyb_mode(int mode)
// 0 - ASCII, 1 - SCAN
{
__asm__ __volatile__(
@@ -52,14 +51,14 @@ void set_os_keyb_mode(int mode)
::"a"(66), "b"(1), "c"(mode));
};
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 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;
@@ -68,18 +67,18 @@ int main()
// creating GUI using library functions
kolibri_window *main_window = kolibri_new_window(50, 40, 400, 160, "OptionBox and Menu demo");
kolibri_window *main_window = kolibri_new_window(50, 40, 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 opts1[3];
option_box *option1sel = opts1; // intially selected RED
option_box *op1_1 = gui_optionbox(opts1, X_Y(20, 50), "G1 Item RED", &option1sel);
option_box *op1_2 = gui_optionbox(opts1+1, X_Y(20, 70), "G1 Item GREEN", &option1sel);
option_box *op1_3 = gui_optionbox(opts1+2, X_Y(20, 90), "G1 Item BLUE", &option1sel);
option_box* option_group1[] = {op1_1, op1_2, op1_3, NULL};
option_box opts2[3];
option_box opts2[3];
option_box *option2sel = opts2 + 1; // intially selected #2
option_box *op2_1 = gui_optionbox(&opts2[0], X_Y(140, 50), "G2 Item 1st", &option2sel);
option_box *op2_2 = gui_optionbox(&opts2[1], X_Y(140, 70), "G2 Item 2nd", &option2sel);
@@ -89,17 +88,17 @@ int main()
frame *fr1 = kolibri_new_frame_def(X_Y(12, 110), X_Y(40, 70), "Option 1");
frame *fr2 = kolibri_new_frame_def(X_Y(132, 100), X_Y(40, 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);
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;
char *menu1stru[] = {"Menu1", "Set RED", "Set GREEN", "Set BLUE", NULL};
menubar* menu1 = kolibri_new_menubar_def(X_Y(10, 40), X_Y(5, 15), 80, 100, menu1stru);
gui_add_menubar(main_window, menu1);
gui_add_menubar(main_window, menu1);
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(5, 15), 80, 100, menu2stru);
@@ -107,7 +106,7 @@ int main()
char *menu3stru[] = {"Quit", NULL};
menubar* menu3 = kolibri_new_menubar_def(X_Y(90, 40), X_Y(5, 15), 0, 0, menu3stru);
menu3->type = 1; // no subitems
menu3->type = 1; // no subitems
gui_add_menubar(main_window, menu3);
@@ -115,7 +114,7 @@ int main()
set_os_keyb_mode(1); // needed for keyboard use in menu
do /* Start of main activity loop */
do /* Start of main activity loop */
{
if(option_index1 != option1sel - opts1)
debug_board_printf("Option1 change to %d\n", option1sel - opts1);
@@ -138,17 +137,17 @@ int main()
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 ( . but Alt+F1 worked in opendial.asm:463
break;
case KOLIBRI_EVENT_BUTTON:
pressed_button = get_os_button();
switch (pressed_button)
{
case BTN_QUIT:
return 0;
break;
}
break;
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();
@@ -167,13 +166,13 @@ int main()
{
return 0; // quit
}
break;
break;
}
gui_event = get_os_event();
} while(1) ; /* End of main activity loop */
return 0;
}
} while(1) ; /* End of main activity loop */
return 0;
}

View File

@@ -8,7 +8,7 @@ CLAYER:= $(abspath ../../)
LDFLAGS = -static -S -nostdlib -T $(SDK_DIR)/sources/newlib/app.lds \
--image-base 0 -lgcc -ldll -lc.dll
CFLAGS = -g -U_Win32 -U_WIN32 -U__MINGW32__
CFLAGS = -g -U_Win32 -U_WIN32 -U__MINGW32__ -std=c99
INCLUDES= -I. -I$(SDK_DIR)/sources/newlib/libc/include -I$(CLAYER)/INCLUDE
LIBPATH:= -L $(SDK_DIR)/lib -L /home/autobuild/tools/win32/mingw32/lib
@@ -29,4 +29,4 @@ $(NAME): $(OBJECTS) Makefile
$(CC) -c $(INCLUDES) $(CFLAGS) -o $@ $<
clean:
-rm -f *.o
-rm -f *.o $(NAME)