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