Subversion Repositories Kolibri OS

Rev

Rev 9558 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8818 turbocat 1
// BOXLIB EXAMPLE (scrollbar, progressbar, editbox and checkbox)
2
// Writed by maxcodehack and superturbocat2001
3
 
4
#include 
5
#include 
6
#include 
7
#include 
8
#include 
9
 
10
#define WIN_W 640
11
#define WIN_H 563
12
 
13
#define ED_BUFF_LEN 50
14
#define TEXT_SIZE 0x10000000
15
#define SCROLL_BUTTON_SIZE 15
16
#define SCROLL_MAX_LEN 215
17
#define BLACK 0x000000
18
#define WHITE 0xFFFFFF
19
#define BLUE  0x0000FF
20
#define X_W(X, W) ((X<<16)+W)
21
#define Y_H X_W
22
 
23
uint32_t wheels;
24
char* title = "Boxlib example";
25
char ed_buff[ED_BUFF_LEN];
26
 
27
scrollbar scroll = {15, WIN_W - 26, WIN_H - 29, 0, 0, 2, 215, SCROLL_BUTTON_SIZE, 0,0x707070,0xD2CED0,0x555555};
28
progressbar pg = {0, 10, 10, 270, 35, 1, 0, 200, 0xB4B4B4, 0x2728FF, 0xA9A9A9};
29
edit_box ed={WIN_W-140,10,60,0xFFFFFF,0x6a9480,0,0x6a9480, BLACK | TEXT_SIZE, ED_BUFF_LEN, ed_buff,NULL,ed_focus};
30
check_box output_off={X_W(10, 15), Y_H(120,15), 10, WHITE, BLUE, BLACK | TEXT_SIZE, "Disable duplicate output",0};
31
 
32
void draw_window(){
33
    _ksys_start_draw();
34
    _ksys_create_window(215,100,WIN_W,WIN_H,title, 0x858585, 0x34);
35
	edit_box_draw(&ed);
36
	check_box_draw2(&output_off);
37
	if(!output_off.flags){
38
		_ksys_draw_text(ed_buff, 10, 90, strlen(ed_buff), BLACK | TEXT_SIZE);
39
	}
40
	scrollbar_v_draw(&scroll);
41
    progressbar_draw(&pg);
42
	_ksys_end_draw();
43
}
44
 
45
int main()
46
{
47
	init_checkbox2(&output_off);
48
	_ksys_set_event_mask(KSYS_EVM_REDRAW + KSYS_EVM_KEY + KSYS_EVM_BUTTON + KSYS_EVM_MOUSE+ KSYS_EVM_MOUSE_FILTER);
49
	while(1){
50
		switch(_ksys_get_event()){
51
		case KSYS_EVENT_BUTTON:
52
			if (_ksys_get_button() == 1) return 0;
53
		break;
54
 
55
		case KSYS_EVENT_KEY:
9620 turbocat 56
			edit_box_key_safe(&ed, _ksys_get_key());
8818 turbocat 57
            draw_window();
58
		break;
59
 
60
		case KSYS_EVENT_REDRAW:
61
			draw_window();
62
		break;
63
 
64
		case KSYS_EVENT_MOUSE:
65
			edit_box_mouse(&ed);
66
			scrollbar_v_mouse(&scroll);
67
			pg.value = scroll.position;
68
			progressbar_draw(&pg);
69
			check_box_mouse2(&output_off);
70
			unsigned int scroll_strong = 10;
71
            wheels = _ksys_get_mouse_wheels();
72
			if(wheels & 0xFFFF){
73
				if((short)wheels > 0){
74
					scroll.position += scroll_strong;
75
					if(scroll.position>scroll.max_area-scroll.cur_area){
76
						scroll.position=scroll.max_area-scroll.cur_area;
77
					}
78
				}else if((short)wheels < 0 && scroll.position > 0){
79
            		scroll.position -= scroll_strong;
80
					if((int)scroll.position<0){
81
						scroll.position=0;
82
					}
83
				}
84
            	scrollbar_v_draw(&scroll);
85
            }
86
			break;
87
		}
88
	}
89
	return 0;
9620 turbocat 90
}