source: abuse/trunk/src/imlib/input.h @ 655

Last change on this file since 655 was 655, checked in by Sam Hocevar, 12 years ago

imlib: refactor a few image methods so that they use vec2i.

  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
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
16extern WindowManager *wm; /* FIXME: get rid of this if possible */
17
18class button : public ifield
19{
20  int up,act;
21  char *text;
22  image *visual,*pressed,*act_pict;
23  int act_id;
24public :
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);
35  virtual ~button() { if (text) free(text); }
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
42class button_box : public ifield
43{
44  button *buttons;
45  int maxdown;
46public :
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
63class text_field : public ifield
64{
65  int cur;
66  char *prompt,*data,*format;
67  int xstart() { return x+wm->font()->width()*(strlen(prompt)+1)+3; }
68  int xend() { return x+wm->font()->width()*(strlen(prompt)+1+strlen(format))+7; }
69  int yend() { return y+wm->font()->height()+5; }
70  void draw_cur(int color, image *screen);
71  int last_spot() { int x=strlen(data); while (x && data[x-1]==' ') x--; return x; }
72  void draw_text(image *screen)
73  {
74    screen->Bar(vec2i(xstart() + 1, y + 1), vec2i(xend() - 1, yend() - 1),
75                wm->dark_color());
76    wm->font()->put_string(screen,xstart()+1,y+3,data);
77  }
78public :
79  text_field(int X, int Y, int ID, char const *Prompt, char const *Format,
80                               char const *Data, ifield *Next);
81  text_field(int X, int Y, int ID, char const *Prompt, char const *Format,
82                               double Data, ifield *Next);
83
84  virtual void area(int &x1, int &y1, int &x2, int &y2);
85  virtual void draw_first(image *screen);
86  virtual void draw(int active, image *screen);
87  virtual void handle_event(Event &ev, image *screen, InputManager *im);
88
89  virtual ~text_field() { free(prompt); free(format); free(data); }
90  virtual char *read();
91  void change_data(char const *new_data, int new_cursor,       // cursor==-1, does not change it.
92           int active, image *screen);
93} ;
94
95
96class info_field : public ifield
97{
98  char *text;
99  int w,h;
100  void put_para(image *screen, char const *st, int dx, int dy, int xspace,
101        int yspace, JCFont *font, int color);
102public :
103  info_field(int X, int Y, int ID, char const *info, ifield *Next);
104  virtual void area(int &x1, int &y1, int &x2, int &y2);
105  virtual void draw_first(image *screen);
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  }
111  virtual char *read() { return text; }
112  virtual int selectable() { return 0; }
113  virtual ~info_field() { free(text); }
114} ;
115
116#endif
117
118
119
120
121
122
123
124
125
126
Note: See TracBrowser for help on using the repository browser.