Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 8817 → Rev 8818

/programs/develop/ktcc/trunk/libc.obj/include/sys/ksys.h
200,6 → 200,21
KSYS_SHM_WRITE = 0x01,
};
 
enum KSYS_EVENT_MASK{
KSYS_EVM_REDRAW = 1,
KSYS_EVM_KEY = 2,
KSYS_EVM_BUTTON = 4,
KSYS_EVM_EXIT = 8,
KSYS_EVM_BACKGROUND = 16,
KSYS_EVM_MOUSE = 32,
KSYS_EVM_IPC = 64,
KSYS_EVM_STACK = 128,
KSYS_EVM_DEBUG = 256,
KSYS_EVM_STACK2 = 512,
KSYS_EVM_MOUSE_FILTER = 0x80000000,
KSYS_EVM_CURSOR_FILTER = 0x40000000,
};
 
static inline
int _ksys_strcmp(const char * s1, const char * s2 )
{
/programs/develop/ktcc/trunk/libc.obj/samples/Makefile
1,9 → 1,9
 
KTCC=../../../ktcc/trunk/bin/kos32-tcc
KTCC=kos32-tcc
FASM= fasm
KPACK = kpack
CFLAGS = -I../include
LDFLAGS = -nostdlib -L../lib ../lib/crt0.o
LDFLAGS = -nostdlib -L../../bin/lib ../../bin/lib/crt0.o
 
BIN= stdio_test.kex \
basic_gui.kex \
13,12 → 13,20
whois.kex \
file_io.kex \
tmpdisk_work.kex \
fasm/sprintf_test.kex
consoleio.kex \
fasm/sprintf_test.kex \
clayer/rasterworks.kex \
clayer/libimg.kex \
clayer/dialog.kex \
clayer/msgbox.kex \
clayer/boxlib.kex
 
LIBS= -ltcc -ldialog -lrasterworks -limg -lbox -lmsgbox -lnetwork -lc.obj
 
all: $(BIN)
%.kex : %.c
$(KTCC) $(CFLAGS) $(LDFLAGS) $< -o $@ -ltcc -lnetwork -lc.obj
$(KTCC) $(CFLAGS) $(LDFLAGS) $< -o $@ $(LIBS)
$(KPACK) --nologo $@
%.kex : %.asm
26,4 → 34,4
$(KPACK) --nologo $@
 
clean:
rm *.kex
rm *.kex clayer/*.kex
/programs/develop/ktcc/trunk/libc.obj/samples/clayer/boxlib.c
0,0 → 1,92
// BOXLIB EXAMPLE (scrollbar, progressbar, editbox and checkbox)
// Writed by maxcodehack and superturbocat2001
 
#include <sys/ksys.h>
#include <stdlib.h>
#include <string.h>
#include <clayer/boxlib.h>
#include <stdio.h>
 
#define WIN_W 640
#define WIN_H 563
 
#define ED_BUFF_LEN 50
#define TEXT_SIZE 0x10000000
#define SCROLL_BUTTON_SIZE 15
#define SCROLL_MAX_LEN 215
#define BLACK 0x000000
#define WHITE 0xFFFFFF
#define BLUE 0x0000FF
#define X_W(X, W) ((X<<16)+W)
#define Y_H X_W
 
uint32_t wheels;
char* title = "Boxlib example";
char ed_buff[ED_BUFF_LEN];
scrollbar scroll = {15, WIN_W - 26, WIN_H - 29, 0, 0, 2, 215, SCROLL_BUTTON_SIZE, 0,0x707070,0xD2CED0,0x555555};
progressbar pg = {0, 10, 10, 270, 35, 1, 0, 200, 0xB4B4B4, 0x2728FF, 0xA9A9A9};
edit_box ed={WIN_W-140,10,60,0xFFFFFF,0x6a9480,0,0x6a9480, BLACK | TEXT_SIZE, ED_BUFF_LEN, ed_buff,NULL,ed_focus};
check_box output_off={X_W(10, 15), Y_H(120,15), 10, WHITE, BLUE, BLACK | TEXT_SIZE, "Disable duplicate output",0};
 
void draw_window(){
_ksys_start_draw();
_ksys_create_window(215,100,WIN_W,WIN_H,title, 0x858585, 0x34);
edit_box_draw(&ed);
check_box_draw2(&output_off);
if(!output_off.flags){
_ksys_draw_text(ed_buff, 10, 90, strlen(ed_buff), BLACK | TEXT_SIZE);
}
scrollbar_v_draw(&scroll);
progressbar_draw(&pg);
_ksys_end_draw();
}
 
 
int main()
{
kolibri_boxlib_init();
init_checkbox2(&output_off);
_ksys_set_event_mask(KSYS_EVM_REDRAW + KSYS_EVM_KEY + KSYS_EVM_BUTTON + KSYS_EVM_MOUSE+ KSYS_EVM_MOUSE_FILTER);
while(1){
switch(_ksys_get_event()){
case KSYS_EVENT_BUTTON:
if (_ksys_get_button() == 1) return 0;
break;
case KSYS_EVENT_KEY:
edit_box_key(&ed, _ksys_get_key().val);
draw_window();
break;
case KSYS_EVENT_REDRAW:
draw_window();
break;
case KSYS_EVENT_MOUSE:
edit_box_mouse(&ed);
scrollbar_v_mouse(&scroll);
pg.value = scroll.position;
progressbar_draw(&pg);
check_box_mouse2(&output_off);
unsigned int scroll_strong = 10;
wheels = _ksys_get_mouse_wheels();
if(wheels & 0xFFFF){
if((short)wheels > 0){
scroll.position += scroll_strong;
if(scroll.position>scroll.max_area-scroll.cur_area){
scroll.position=scroll.max_area-scroll.cur_area;
}
}else if((short)wheels < 0 && scroll.position > 0){
scroll.position -= scroll_strong;
if((int)scroll.position<0){
scroll.position=0;
}
}
scrollbar_v_draw(&scroll);
}
break;
}
}
return 0;
}
/programs/develop/ktcc/trunk/libc.obj/samples/clayer/dialog.c
0,0 → 1,32
#include <sys/ksys.h>
#include <clayer/dialog.h>
#include <stdio.h>
 
int main()
{
kolibri_dialog_init(); // dialog init
open_dialog *dlg_open = kolibri_new_open_dialog(OPEN, 10, 10, 420, 320); // create opendialog struct
OpenDialog_init(dlg_open); // Initializing an open dialog box.
OpenDialog_start(dlg_open); // Show open dialog box
color_dialog *color_select = kolibri_new_color_dialog(SELECT, 10, 10,420,320); // create colordialog struct
ColorDialog_init(color_select); // Initializing an color dialog box.
ColorDialog_start(color_select); // Show color dialog
if(dlg_open->status == SUCCESS){
printf("File selected '%s'\n",dlg_open->openfile_path);
}else{
puts("No file selected!");
}
if(color_select->status == SUCCESS){
printf("Color selected: #%06X\n",color_select->color);
rgb_t color_rgb = (rgb_t)color_select->color;
printf("Red:%d Green:%d Blue:%d", color_rgb.red, color_rgb.green, color_rgb.blue);
}else{
puts("No color selected!");
}
free(dlg_open);
free(color_select);
return 0;
}
/programs/develop/ktcc/trunk/libc.obj/samples/clayer/libimg.c
0,0 → 1,101
/* Written by turbocat2001 (Logaev Maxim) */
 
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <clayer/libimg.h>
#include <sys/ksys.h>
 
#define NEW_IMG_H 128
#define NEW_IMG_W 128
 
#define IMG_H 256
#define IMG_W 256
 
Image *image_blend; // Create image struct
 
ksys_colors_table_t sys_color_table; // Create system colors table
 
void* load_img(char* fname, uint32_t* read_sz){ // Image file upload function
FILE *f = fopen(fname, "rb");
if (!f) {
printf("Can't open file: %s\n", fname);
return NULL;
}
if (fseek(f, 0, SEEK_END)) {
printf("Can't SEEK_END file: %s\n", fname);
return NULL;
}
int filesize = ftell(f);
rewind(f);
void* fdata = malloc(filesize);
if(!fdata) {
printf("No memory for file %s\n", fname);
return NULL;
}
*read_sz = fread(fdata, 1, filesize, f);
if (ferror(f)) {
printf("Error reading file %s\n", fname);
return NULL;
}
fclose(f);
return fdata;
}
 
void draw_gui(){
_ksys_start_draw();
_ksys_create_window(10, 40, (IMG_W+NEW_IMG_W)+50, IMG_H+50, "Libimg", sys_color_table.work_area, 0x34);
img_draw(image_blend, 10, 10, IMG_W*2, IMG_H , 0, 0); // Draw blended image to window
_ksys_end_draw();
}
 
int main(){
if (kolibri_libimg_init() == -1){
printf("Error loading lib_img.obj\n");
exit(0);
}
_ksys_get_system_colors(&sys_color_table); // Get system colors theme
_ksys_set_event_mask(0xC0000027);
uint32_t img_size;
void *file_data = load_img("logo.png", &img_size); // Get RAW data and size
if(!file_data){
return 1;
}
 
Image* image = img_decode(file_data, img_size, 0); // Decode RAW data to Image data
if (image->Type != IMAGE_BPP32) {
image = img_convert(image, NULL, IMAGE_BPP32, 0, 0); // Convert image to format BPP32
if (!image) {
printf("Сonvert error!: \n");
return 1;
}
}
image_blend = img_create(IMG_W+NEW_IMG_W, IMG_H, IMAGE_BPP32); // Create an empty layer
img_fill_color(image_blend, IMG_W+NEW_IMG_W, IMG_H, sys_color_table.work_area); // Fill the layer with one color
img_blend(image_blend, image, 0, 0, 0, 0, IMG_W, IMG_H); // Blending images to display the alpha channel.
/* Reduce image size from 256x256 to 128x128 */
image = img_scale(image, 0, 0, IMG_W, IMG_H, NULL, LIBIMG_SCALE_STRETCH , LIBIMG_INTER_BILINEAR, NEW_IMG_W, NEW_IMG_H);
img_blend(image_blend, image, 256, 0, 0, 0, NEW_IMG_W, NEW_IMG_H);
img_destroy(image); // Destroy image structure
free(file_data); // Free allocated file_data buffer
/* Main event loop */
while (1) {
switch(_ksys_get_event()){
case KSYS_EVENT_REDRAW:
draw_gui();
break;
case KSYS_EVENT_BUTTON:
if (_ksys_get_button()==1){
return 0;
}
break;
}
}
return 0;
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/programs/develop/ktcc/trunk/libc.obj/samples/clayer/logo.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes:
Added: svn:mime-type
+image/png
\ No newline at end of property
/programs/develop/ktcc/trunk/libc.obj/samples/clayer/msgbox.c
0,0 → 1,8
#include <clayer/msgbox.h>
 
int main()
{
msgbox *msg1 = NULL;
msg1 = kolibri_new_msgbox("Title", "Text in window", 0, "Ok");
kolibri_start_msgbox(msg1, NULL);
}
/programs/develop/ktcc/trunk/libc.obj/samples/clayer/rasterworks.c
0,0 → 1,51
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ksys.h>
#include <clayer/rasterworks.h>
 
// Sizes
int x_size = 768, y_size = 256;
 
// Out example string
char* string = "Пример/Example";
 
int main()
{
// Count length
int ln_str = countUTF8Z(string, -1);
// Create image buffer
void *buffi = malloc(x_size * y_size * 3 * sizeof(char) + 8);
// Set sizes
*((int*)buffi) = x_size;
*((int*)buffi+1) = y_size;
// Fill color
memset((char*)buffi + 8, 0xFF, x_size * y_size * 3);
// Draw text on buffer
drawText(buffi, 5, 0, string, ln_str, 0xFF000000, 0x30C18);
drawText(buffi, 5, 32, string, ln_str, 0xFF000000, 0x1030C18);
drawText(buffi, 5, 64, string, ln_str, 0xFF000000, 0x2030C18);
drawText(buffi, 5, 96, string, ln_str, 0xFF000000, 0x4030C18);
drawText(buffi, 5, 128, string, ln_str, 0xFF000000, 0x8030C18);
drawText(buffi, 5, 160, string, ln_str, 0xFF000000, 0x0F031428);
while (1) {
switch (_ksys_get_event()){
case KSYS_EVENT_REDRAW:
_ksys_start_draw();
_ksys_create_window(50, 50, 800, 300, "Rasterworks Example", 0x999999, 0x34);
_ksys_draw_bitmap(buffi + 8, 10, 10, 768, 256);
_ksys_end_draw();
break;
 
case KSYS_EVENT_BUTTON:
if(_ksys_get_button() == 1) exit(0);
break;
};
}
return 0;
}
/programs/develop/ktcc/trunk/libc.obj/samples/consoleio.c
0,0 → 1,20
// demonstration conio use, color text
// more info in conio.h
 
#include <conio.h>
 
int main()
{
if(con_init()) return 1; // init fail
(*con_set_title)("Console colors");
 
// con_write_asciiz("\033[0;31;42m test \n"); // red on green bk
 
for(int i = 30; i < 48; i++){
(*con_printf)("\033[%dmColor 0x%02X: ", i, i);
(*con_write_asciiz)("Text sample.");
(*con_printf)(" printf %s test %d\n", "small", i);
}
 
(*con_exit)(0);
}