[49] | 1 | #ifndef __INPUT_HPP_ |
---|
| 2 | #define __INPUT_HPP_ |
---|
| 3 | #include "jwindow.hpp" |
---|
| 4 | #include "filter.hpp" |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | class button : public ifield |
---|
| 8 | { |
---|
| 9 | int up,act; |
---|
| 10 | char *text; |
---|
| 11 | image *visual,*pressed,*act_pict; |
---|
| 12 | int act_id; |
---|
| 13 | public : |
---|
| 14 | button(int X, int Y, int ID, char *Text, ifield *Next); |
---|
| 15 | button(int X, int Y, int ID, image *vis, ifield *Next); |
---|
| 16 | button(int X, int Y, int ID, image *Depressed, image *Pressed, image *active, ifield *Next); |
---|
| 17 | |
---|
| 18 | virtual void area(int &x1, int &y1, int &x2, int &y2, window_manager *wm); |
---|
| 19 | virtual void draw_first(image *screen, window_manager *wm); |
---|
| 20 | virtual void draw(int active, image *screen, window_manager *wm); |
---|
| 21 | virtual void handle_event(event &ev, image *screen, window_manager *wm, input_manager *im); |
---|
| 22 | void change_visual(image *new_visual); |
---|
| 23 | virtual void remap(filter *f); |
---|
| 24 | virtual ~button() { if (text) jfree(text); } |
---|
| 25 | void push(); |
---|
| 26 | virtual char *read() { return (char *)&up; } |
---|
| 27 | int status() { return up; } |
---|
| 28 | void set_act_id(int id) { act_id=id; } |
---|
| 29 | } ; |
---|
| 30 | |
---|
| 31 | class button_box : public ifield |
---|
| 32 | { |
---|
| 33 | button *buttons; |
---|
| 34 | int maxdown; |
---|
| 35 | public : |
---|
| 36 | button_box(int X, int Y, int ID, int MaxDown, button *Buttons, ifield *Next); |
---|
| 37 | void add_button(button *b); |
---|
| 38 | void press_button(int id); // if button box doesn't contain id, nothing happens |
---|
| 39 | virtual void remap(filter *f); |
---|
| 40 | virtual void area(int &x1, int &y1, int &x2, int &y2, window_manager *wm); |
---|
| 41 | virtual void draw_first(image *screen, window_manager *wm); |
---|
| 42 | virtual void draw(int active, image *screen, window_manager *wm); |
---|
| 43 | virtual void handle_event(event &ev, image *screen, window_manager *wm, input_manager *im); |
---|
| 44 | virtual ~button_box(); |
---|
| 45 | virtual char *read(); // return pointer to first button which is depressed |
---|
| 46 | virtual ifield *find(int search_id); // should return pointer to item you control with this id |
---|
| 47 | void arrange_left_right(window_manager *wm); |
---|
| 48 | void arrange_up_down(window_manager *wm); |
---|
| 49 | } ; |
---|
| 50 | |
---|
| 51 | class text_field : public ifield |
---|
| 52 | { |
---|
| 53 | int cur; |
---|
| 54 | char *prompt,*data,*format; |
---|
| 55 | int xstart(window_manager *wm) { return x+wm->font()->width()*(strlen(prompt)+1)+3; } |
---|
| 56 | int xend(window_manager *wm) { return x+wm->font()->width()*(strlen(prompt)+1+strlen(format))+7; } |
---|
| 57 | int yend(window_manager *wm) { return y+wm->font()->height()+5; } |
---|
| 58 | void draw_cur(int color, image *screen, window_manager *wm); |
---|
| 59 | int last_spot() { int x=strlen(data); while (x && data[x-1]==' ') x--; return x; } |
---|
| 60 | void draw_text(image *screen, window_manager *wm) |
---|
| 61 | { |
---|
| 62 | screen->bar(xstart(wm)+1,y+1,xend(wm)-1,yend(wm)-1,wm->dark_color()); |
---|
| 63 | wm->font()->put_string(screen,xstart(wm)+1,y+3,data); |
---|
| 64 | } |
---|
| 65 | public : |
---|
| 66 | text_field(int X, int Y, int ID, char *Prompt, char *Format, |
---|
| 67 | char *Data, ifield *Next); |
---|
| 68 | text_field(int X, int Y, int ID, char *Prompt, char *Format, |
---|
| 69 | double Data, ifield *Next); |
---|
| 70 | |
---|
| 71 | virtual void area(int &x1, int &y1, int &x2, int &y2, window_manager *wm); |
---|
| 72 | virtual void draw_first(image *screen, window_manager *wm); |
---|
| 73 | virtual void draw(int active, image *screen, window_manager *wm); |
---|
| 74 | virtual void handle_event(event &ev, image *screen, window_manager *wm, input_manager *im); |
---|
| 75 | |
---|
| 76 | virtual ~text_field() { jfree(prompt); jfree(format); jfree(data); } |
---|
| 77 | virtual char *read(); |
---|
| 78 | void change_data(char *new_data, int new_cursor, // cursor==-1, does not change it. |
---|
| 79 | int active, image *screen, window_manager *wm); |
---|
| 80 | } ; |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | class info_field : public ifield |
---|
| 84 | { |
---|
| 85 | char *text; |
---|
| 86 | int w,h; |
---|
| 87 | void put_para(image *screen, char *st, int dx, int dy, int xspace, |
---|
| 88 | int yspace, JCFont *font, int color); |
---|
| 89 | public : |
---|
| 90 | info_field(int X, int Y, int ID, char *info, ifield *Next); |
---|
| 91 | virtual void area(int &x1, int &y1, int &x2, int &y2, window_manager *wm); |
---|
| 92 | virtual void draw_first(image *screen, window_manager *wm); |
---|
| 93 | virtual void draw(int active, image *screen, window_manager *wm) { ; } |
---|
| 94 | virtual void handle_event(event &ev, image *screen, window_manager *wm, input_manager *im) { ; } |
---|
| 95 | virtual char *read() { return text; } |
---|
| 96 | virtual int selectable() { return 0; } |
---|
| 97 | virtual ~info_field() { jfree(text); } |
---|
| 98 | } ; |
---|
| 99 | |
---|
| 100 | #endif |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | |
---|