Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4973 | right-hear | 1 | #ifndef __GUI_H |
2 | #define __GUI_H |
||
3 | |||
4 | #ifdef __cplusplus |
||
5 | extern "C" { |
||
6 | #endif |
||
7 | |||
8 | #include |
||
9 | |||
10 | #define GUI_DX 10 |
||
11 | #define GUI_DY 20 |
||
12 | |||
13 | typedef struct __button_t |
||
14 | { |
||
15 | int id; |
||
16 | char * txt; |
||
17 | int x,y; |
||
18 | int xsz,ysz; |
||
19 | void (* press_proc)(void); |
||
20 | } button_t; |
||
21 | |||
22 | typedef struct |
||
23 | { |
||
24 | int x,y; |
||
25 | int max_len; |
||
26 | __u32 back_color,text_color; |
||
27 | int current; |
||
28 | __u8 * buffer; |
||
29 | } input_line_t; |
||
30 | |||
31 | static inline void draw_button(button_t * b) |
||
32 | { |
||
33 | int l; |
||
34 | l=strlen(b->txt)<<3; |
||
35 | l=(b->xsz-l)>>1; |
||
36 | __menuet__make_button(b->x-2+10,b->y-2+20,b->xsz,b->ysz,b->id,0x808080); |
||
37 | __menuet__write_text(b->x+l+10,b->y+((b->ysz-8)>>1)+20,0,b->txt,strlen(b->txt)); |
||
38 | } |
||
39 | |||
40 | static inline void repaint_button_group(button_t * bt,int nr) |
||
41 | { |
||
42 | int i; |
||
43 | for(i=0;i |
||
44 | } |
||
45 | |||
46 | static inline void check_button_click(button_t * bt,int nr,int clicked) |
||
47 | { |
||
48 | int i; |
||
49 | for(i=0;i |
||
50 | if(bt[i].id==clicked) |
||
51 | { |
||
52 | if(bt[i].press_proc) bt[i].press_proc(); |
||
53 | return; |
||
54 | } |
||
55 | } |
||
56 | |||
57 | static inline void draw_input_line(input_line_t * k) |
||
58 | { |
||
59 | __menuet__bar(k->x+GUI_DX,k->y+GUI_DY,(k->max_len<<3)+10,8+5,k->back_color); |
||
60 | if(k->current) |
||
61 | __menuet__write_text(k->x+GUI_DX,k->y+GUI_DY,k->text_color,k->buffer,k->current); |
||
62 | } |
||
63 | |||
64 | static inline void handle_input_line(input_line_t * l) |
||
65 | { |
||
66 | for(;;) |
||
67 | { |
||
68 | int k=__menuet__wait_for_event(); |
||
69 | switch(k) |
||
70 | { |
||
71 | case 1: |
||
72 | WINDOW_PAINT_PROC(); |
||
73 | continue; |
||
74 | case 2: |
||
75 | k=__menuet__getkey(); |
||
76 | break; |
||
77 | case 3: |
||
78 | if(__menuet__get_button_id()==1) __menuet__sys_exit(); |
||
79 | continue; |
||
80 | } |
||
81 | if(!k) continue; |
||
82 | if(k==13) return; |
||
83 | if(k=='\b') |
||
84 | { |
||
85 | if(l->current) l->current--; |
||
86 | l->buffer[l->current]='\0'; |
||
87 | } else { |
||
88 | if(l->current>=l->max_len) continue; |
||
89 | l->buffer[l->current]=(__u8)k; |
||
90 | l->current++; |
||
91 | l->buffer[l->current]='\0'; |
||
92 | } |
||
93 | draw_input_line(l); |
||
94 | } |
||
95 | } |
||
96 | |||
97 | static inline void outtextxy(int x,int y,__u32 tcol,__u32 bcol,char * txt) |
||
98 | { |
||
99 | int l,m; |
||
100 | m=l=strlen(txt); |
||
101 | l<<=3; |
||
102 | l+=4; |
||
103 | __menuet__bar(GUI_DX+x,GUI_DY+y,l,10,bcol); |
||
104 | __menuet__write_text(GUI_DX+x,GUI_DY+y,tcol,txt,m); |
||
105 | } |
||
106 | |||
107 | #ifdef __cplusplus |
||
108 | } |
||
109 | #endif |
||
110 | |||
111 | #endif=3; |