- Fixed boxlib loader

- Updated example boxlib.c

git-svn-id: svn://kolibrios.org@8465 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
superturbocat2001 2020-12-21 18:12:23 +00:00
parent 1dab73b754
commit 4d192ca472
4 changed files with 100 additions and 66 deletions

View File

@ -15,7 +15,6 @@ include '../../../../../dll.inc'
public init_boxlib as 'kolibri_boxlib_init'
proc init_boxlib
local retval dd ?
mov [retval], eax
@ -38,22 +37,21 @@ endp
;; Wrapper to handle edit_box_key function for editboxes.
;; Call this baby from C (refer kolibri_editbox.h for details)
;public editbox_key_thunk as '_editbox_key@4' ; renamed due to ambiguity
;public press_key as '_press_key'
public editbox_key_thunk as 'edit_box_key' ; renamed due to ambiguity
;; replaced by siemargl as inline ASM in C wrapper
;editbox_key_thunk:
; mov [oldebp], ebp ;Save ebp because GCC is crazy for it otherwise.
; pop ebp ;Save return address in ebp. Stack top is param now.
; mov eax, dword [press_key]
; call [edit_box_key] ; The pointer we passed should be on the stack already.
; push ebp ;push the return address back to stack
; mov ebp, [oldebp]
; ret
;oldebp dd ?
;press_key dd ?
editbox_key_thunk:
mov eax, [esp+8]
mov [oldebp], ebp ;Save ebp because GCC is crazy for it otherwise.
pop ebp ;Save return address in ebp. Stack top is param now.
;mov eax, dword [press_key]
call [edit_box_key] ; The pointer we passed should be on the stack already.
push ebp ;push the return address back to stack
mov ebp, [oldebp]
ret
oldebp dd ?
section '.data' writeable
@IMPORT:
library lib_boxlib, 'box_lib.obj'
@ -140,7 +138,8 @@ import lib_boxlib, \
public edit_box_draw as 'edit_box_draw'
public edit_box_key as 'edit_box_key'
;public edit_box_key as 'edit_box_key'
public edit_box_mouse as 'edit_box_mouse'
public edit_box_set_text as 'edit_box_set_text'

View File

@ -1,10 +1,38 @@
// writed by maxcodehack
// writed by maxcodehack and superturbocat2001
// adaptation of clayer for ktcc
#ifndef KOLIBRI_BOXLIB_H
#define KOLIBRI_BOXLIB_H
extern int kolibri_boxlib_init(void);
/* flags meaning */
#define ed_figure_only 0b1000000000000000 // одни символы
#define ed_always_focus 0b100000000000000 // всегда с курсором (фокусом)
#define ed_focus 0b10 // фокус ввода приложения, мышится самостоятельно
#define ed_pass 0b1 // поле с паролем
#define ed_shift_on 0b1000 // если не установлен -значит впервые нажат shift,если был установлен, значит мы уже что - то делали удерживая //shift
#define ed_shift_on_off 0b1111111111110111
#define ed_shift 0b100 //включается при нажатии на shift т.е. если нажимаю
#define ed_shift_off 0b1111111111111011
#define ed_shift_bac 0b10000 //бит для очистки выделеного shift т.е. при установке говорит что есть выделение
#define ed_shift_bac_cl 0b1111111111101111 //очистка при удалении выделения
#define ed_shift_cl 0b1111111111100011
#define ed_shift_mcl 0b1111111111111011
#define ed_left_fl 0b100000
#define ed_right_fl 0b1111111111011111
#define ed_offset_fl 0b1000000
#define ed_offset_cl 0b1111111110111111
#define ed_insert 0b10000000
#define ed_insert_cl 0b1111111101111111
#define ed_mouse_on 0b100000000
#define ed_mous_adn_b 0b100011000
#define ed_mouse_off ~ed_mouse_on
#define ed_ctrl_on 0b1000000000
#define ed_ctrl_off ~ed_ctrl_on
#define ed_alt_on 0b10000000000
#define ed_alt_off ~ed_alt_on
#define ed_disabled 0b100000000000
// SCROLLBAR
typedef struct {
uint16_t xsize;
@ -83,8 +111,9 @@ extern void (*dynamic_button_mouse __attribute__((__stdcall__)))(pict_button *);
// EDITBOX
#pragma pack(push,1)
typedef struct edit_box_t {
unsigned int width;
unsigned int width;
unsigned int left;
unsigned int top;
unsigned int color;
@ -108,12 +137,12 @@ typedef struct edit_box_t {
unsigned int height;
unsigned int char_width;
}edit_box;
#pragma pack(pop)
extern void (*edit_box_draw __attribute__((__stdcall__)))(edit_box *);
extern void (*edit_box_key __attribute__((__stdcall__)))(edit_box *);
extern void edit_box_key (edit_box *, unsigned int key_val)__attribute__((__stdcall__));
extern void (*edit_box_mouse __attribute__((__stdcall__)))(edit_box *);
extern void (*edit_box_set_text __attribute__((__stdcall__)))(edit_box *, char *);
extern volatile unsigned press_key;
// FRAME
typedef struct {

View File

@ -1,37 +1,43 @@
// BOXLIB EXAMPLE (scrollbar, progressbar)
// Writed by maxcodehack
// GCC version is in /contrib/C_Layer/EXAMPLE/boxlib
// BOXLIB EXAMPLE (scrollbar, progressbar, editbox and checkbox)
// Writed by maxcodehack and superturbocat2001
#include <kos32sys1.h>
#include <stdlib.h>
#include <string.h>
#include <clayer/boxlib.h>
#define evReDraw 1
#define evKey 2
#define evButton 3
#define evExit 4
#define evDesktop 5
#define evMouse 6
#define evIPC 7
#define evNetwork 8
#define evDebug 9
#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
uint32_t wheels;
char* title = "Boxlib example";
scrollbar scroll = {15, WIN_W - 26, WIN_H - 29, 0, 0, 2, 215, 15, 0,0x707070,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
progressbar pg = {0, 10, 10, 270, 35, 1, 0, 200, 0xB4B4B4, 0x2728FF, 0xA9A9A9};
char ed_buff[ED_BUFF_LEN];
/*
// System colors
struct kolibri_system_colors sys_color;
*/
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(){
BeginDraw();
DrawWindow(215,100,WIN_W,WIN_H,title, /* sys_color.work_area */ 0x858585, 0x34);
scrollbar_v_draw(&scroll);
DrawWindow(215,100,WIN_W,WIN_H,title, 0x858585, 0x34);
edit_box_draw(&ed);
check_box_draw2(&output_off);
if(!output_off.flags)
{
draw_text_sys(ed_buff, 10, 90, strlen(ed_buff), BLACK | TEXT_SIZE);
}
scrollbar_v_draw(&scroll);
progressbar_draw(&pg);
EndDraw();
}
@ -55,45 +61,45 @@ void draw_window(){
int main()
{
kolibri_boxlib_init();
/*
get_system_colors(&sys_color);
*/
set_event_mask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
init_checkbox2(&output_off);
set_event_mask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE+EVM_MOUSE_FILTER);
while(1)
{
switch(GetOsEvent())
{
case evButton:
case KOLIBRI_EVENT_BUTTON:
if (get_os_button() == 1) exit(0);
break;
case evKey:
get_key();
case KOLIBRI_EVENT_KEY:
edit_box_key(&ed, get_key().val);
break;
case evReDraw:
case KOLIBRI_EVENT_REDRAW:
draw_window();
break;
case evMouse:
case KOLIBRI_EVENT_MOUSE:
edit_box_mouse(&ed);
scrollbar_v_mouse(&scroll);
// Wheel scrolling
// Quite unstable
/*
int scroll_strong = 40;
wheels = GetMouseWheels();
if(wheels & 0xFFFF)
{
if((short)wheels > 0 && scroll.position < scroll.max_area - scroll_strong)
scroll.position += scroll_strong;
else if((short)wheels < 0 && scroll.position > 0)
scroll.position -= scroll_strong;
scrollbar_v_draw(&scroll);
}
*/
pg.value = scroll.position;
progressbar_draw(&pg);
check_box_mouse2(&output_off);
unsigned int scroll_strong = 10;
wheels = GetMouseWheels();
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;
}
scrollbar_v_draw(&scroll);
}
break;
}
}