1 /*
2  *  Abuse - dark 2D side-scrolling platform game
3  *  Copyright (c) 1995 Crack dot Com
4  *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5  *
6  *  This software was released into the Public Domain. As with most public
7  *  domain software, no warranty is made or implied by Crack dot Com, by
8  *  Jonathan Clark, or by Sam Hocevar.
9  */
10 
11 #ifndef __INPUT_HPP_
12 #define __INPUT_HPP_
13 #include "jwindow.h"
14 #include "filter.h"
15 
16 extern WindowManager *wm; /* FIXME: get rid of this if possible */
17 
18 class button : public ifield
19 {
20   int up,act;
21   char *text;
22   image *visual,*pressed,*act_pict;
23   int act_id;
24 public :
25   button(int X, int Y, int ID, char const *Text, ifield *Next);
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 
29   virtual void area(int &x1, int &y1, int &x2, int &y2);
30   virtual void draw_first(image *screen);
31   virtual void draw(int active, image *screen);
32   virtual void handle_event(event &ev, image *screen, InputManager *im);
33   void change_visual(image *new_visual);
34   virtual void remap(Filter *f);
~button()35   virtual ~button() { if (text) free(text); }
36   void push();
read()37   virtual char *read() { return (char *)&up; }
status()38   int status() { return up; }
set_act_id(int id)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;
46 public :
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
50   virtual void remap(Filter *f);
51   virtual void move(int newx, int newy);
52   virtual void area(int &x1, int &y1, int &x2, int &y2);
53   virtual void draw_first(image *screen);
54   virtual void draw(int active, image *screen);
55   virtual void handle_event(event &ev, image *screen, InputManager *im);
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
59   void arrange_left_right();
60   void arrange_up_down();
61 } ;
62 
63 class text_field : public ifield
64 {
65   int cur;
66   char *prompt,*data,*format;
xstart()67   int xstart() { return x+wm->font()->width()*(strlen(prompt)+1)+3; }
xend()68   int xend() { return x+wm->font()->width()*(strlen(prompt)+1+strlen(format))+7; }
yend()69   int yend() { return y+wm->font()->height()+5; }
70   void draw_cur(int color, image *screen);
last_spot()71   int last_spot() { int x=strlen(data); while (x && data[x-1]==' ') x--; return x; }
draw_text(image * screen)72   void draw_text(image *screen)
73   {
74     screen->bar(xstart()+1,y+1,xend()-1,yend()-1,wm->dark_color());
75     wm->font()->put_string(screen,xstart()+1,y+3,data);
76   }
77 public :
78   text_field(int X, int Y, int ID, char const *Prompt, char const *Format,
79                                char const *Data, ifield *Next);
80   text_field(int X, int Y, int ID, char const *Prompt, char const *Format,
81                                double Data, ifield *Next);
82 
83   virtual void area(int &x1, int &y1, int &x2, int &y2);
84   virtual void draw_first(image *screen);
85   virtual void draw(int active, image *screen);
86   virtual void handle_event(event &ev, image *screen, InputManager *im);
87 
~text_field()88   virtual ~text_field() { free(prompt); free(format); free(data); }
89   virtual char *read();
90   void change_data(char const *new_data, int new_cursor,       // cursor==-1, does not change it.
91            int active, image *screen);
92 } ;
93 
94 
95 class info_field : public ifield
96 {
97   char *text;
98   int w,h;
99   void put_para(image *screen, char const *st, int dx, int dy, int xspace,
100         int yspace, JCFont *font, int color);
101 public :
102   info_field(int X, int Y, int ID, char const *info, ifield *Next);
103   virtual void area(int &x1, int &y1, int &x2, int &y2);
104   virtual void draw_first(image *screen);
draw(int active,image * screen)105   virtual void draw(int active, image *screen) { ; }
handle_event(event & ev,image * screen,InputManager * im)106   virtual void handle_event(event &ev, image *screen, InputManager *im) { ; }
read()107   virtual char *read() { return text; }
selectable()108   virtual int selectable() { return 0; }
~info_field()109   virtual ~info_field() { free(text); }
110 } ;
111 
112 #endif
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123