[56] | 1 | /* |
---|
| 2 | * Abuse - dark 2D side-scrolling platform game |
---|
| 3 | * Copyright (c) 1995 Crack dot Com |
---|
[494] | 4 | * Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net> |
---|
[56] | 5 | * |
---|
| 6 | * This software was released into the Public Domain. As with most public |
---|
[555] | 7 | * domain software, no warranty is made or implied by Crack dot Com, by |
---|
| 8 | * Jonathan Clark, or by Sam Hocevar. |
---|
[56] | 9 | */ |
---|
| 10 | |
---|
[2] | 11 | #ifndef __INPUT_HPP_ |
---|
| 12 | #define __INPUT_HPP_ |
---|
[481] | 13 | #include "jwindow.h" |
---|
| 14 | #include "filter.h" |
---|
[2] | 15 | |
---|
[120] | 16 | extern WindowManager *wm; /* FIXME: get rid of this if possible */ |
---|
[2] | 17 | |
---|
| 18 | class button : public ifield |
---|
| 19 | { |
---|
| 20 | int up,act; |
---|
| 21 | char *text; |
---|
| 22 | image *visual,*pressed,*act_pict; |
---|
| 23 | int act_id; |
---|
[124] | 24 | public : |
---|
[39] | 25 | button(int X, int Y, int ID, char const *Text, ifield *Next); |
---|
[2] | 26 | button(int X, int Y, int ID, image *vis, ifield *Next); |
---|
| 27 | button(int X, int Y, int ID, image *Depressed, image *Pressed, image *active, ifield *Next); |
---|
| 28 | |
---|
[106] | 29 | virtual void area(int &x1, int &y1, int &x2, int &y2); |
---|
| 30 | virtual void draw_first(image *screen); |
---|
[124] | 31 | virtual void draw(int active, image *screen); |
---|
[643] | 32 | virtual void handle_event(Event &ev, image *screen, InputManager *im); |
---|
[2] | 33 | void change_visual(image *new_visual); |
---|
[579] | 34 | virtual void remap(Filter *f); |
---|
[129] | 35 | virtual ~button() { if (text) free(text); } |
---|
[2] | 36 | void push(); |
---|
| 37 | virtual char *read() { return (char *)&up; } |
---|
| 38 | int status() { return up; } |
---|
| 39 | void set_act_id(int id) { act_id=id; } |
---|
| 40 | } ; |
---|
| 41 | |
---|
| 42 | class button_box : public ifield |
---|
| 43 | { |
---|
| 44 | button *buttons; |
---|
| 45 | int maxdown; |
---|
[109] | 46 | public : |
---|
[2] | 47 | button_box(int X, int Y, int ID, int MaxDown, button *Buttons, ifield *Next); |
---|
| 48 | void add_button(button *b); |
---|
| 49 | void press_button(int id); // if button box doesn't contain id, nothing happens |
---|
[579] | 50 | virtual void remap(Filter *f); |
---|
[682] | 51 | virtual void Move(ivec2 pos); |
---|
[106] | 52 | virtual void area(int &x1, int &y1, int &x2, int &y2); |
---|
| 53 | virtual void draw_first(image *screen); |
---|
[124] | 54 | virtual void draw(int active, image *screen); |
---|
[643] | 55 | virtual void handle_event(Event &ev, image *screen, InputManager *im); |
---|
[2] | 56 | virtual ~button_box(); |
---|
| 57 | virtual char *read(); // return pointer to first button which is depressed |
---|
| 58 | virtual ifield *find(int search_id); // should return pointer to item you control with this id |
---|
[106] | 59 | void arrange_left_right(); |
---|
| 60 | void arrange_up_down(); |
---|
[2] | 61 | } ; |
---|
| 62 | |
---|
| 63 | class text_field : public ifield |
---|
| 64 | { |
---|
| 65 | int cur; |
---|
| 66 | char *prompt,*data,*format; |
---|
[668] | 67 | int xstart() { return m_pos.x + wm->font()->Size().x * (strlen(prompt)+1) + 3; } |
---|
| 68 | int xend() { return m_pos.x + wm->font()->Size().x * (strlen(prompt) + 1 + strlen(format)) + 7; } |
---|
| 69 | int yend() { return m_pos.y + wm->font()->Size().y + 5; } |
---|
[106] | 70 | void draw_cur(int color, image *screen); |
---|
[2] | 71 | int last_spot() { int x=strlen(data); while (x && data[x-1]==' ') x--; return x; } |
---|
[106] | 72 | void draw_text(image *screen) |
---|
[2] | 73 | { |
---|
[682] | 74 | screen->Bar(ivec2(xstart() + 1, m_pos.y + 1), ivec2(xend() - 1, yend() - 1), |
---|
[655] | 75 | wm->dark_color()); |
---|
[682] | 76 | wm->font()->PutString(screen, ivec2(xstart() + 1, m_pos.y + 3), data); |
---|
[2] | 77 | } |
---|
[124] | 78 | public : |
---|
| 79 | text_field(int X, int Y, int ID, char const *Prompt, char const *Format, |
---|
[39] | 80 | char const *Data, ifield *Next); |
---|
[124] | 81 | text_field(int X, int Y, int ID, char const *Prompt, char const *Format, |
---|
[2] | 82 | double Data, ifield *Next); |
---|
| 83 | |
---|
[106] | 84 | virtual void area(int &x1, int &y1, int &x2, int &y2); |
---|
| 85 | virtual void draw_first(image *screen); |
---|
[124] | 86 | virtual void draw(int active, image *screen); |
---|
[643] | 87 | virtual void handle_event(Event &ev, image *screen, InputManager *im); |
---|
[124] | 88 | |
---|
[129] | 89 | virtual ~text_field() { free(prompt); free(format); free(data); } |
---|
[2] | 90 | virtual char *read(); |
---|
[39] | 91 | void change_data(char const *new_data, int new_cursor, // cursor==-1, does not change it. |
---|
[124] | 92 | int active, image *screen); |
---|
[2] | 93 | } ; |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | class info_field : public ifield |
---|
| 97 | { |
---|
| 98 | char *text; |
---|
| 99 | int w,h; |
---|
[124] | 100 | void put_para(image *screen, char const *st, int dx, int dy, int xspace, |
---|
| 101 | int yspace, JCFont *font, int color); |
---|
| 102 | public : |
---|
[39] | 103 | info_field(int X, int Y, int ID, char const *info, ifield *Next); |
---|
[106] | 104 | virtual void area(int &x1, int &y1, int &x2, int &y2); |
---|
| 105 | virtual void draw_first(image *screen); |
---|
[653] | 106 | virtual void draw(int active, image *screen) { (void)active; (void)screen; } |
---|
| 107 | virtual void handle_event(Event &ev, image *screen, InputManager *im) |
---|
| 108 | { |
---|
| 109 | (void)ev; (void)screen; (void)im; |
---|
| 110 | } |
---|
[2] | 111 | virtual char *read() { return text; } |
---|
[124] | 112 | virtual int selectable() { return 0; } |
---|
[129] | 113 | virtual ~info_field() { free(text); } |
---|
[2] | 114 | } ; |
---|
| 115 | |
---|
| 116 | #endif |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | |
---|