source: abuse/trunk/src/imlib/input.hpp @ 106

Last change on this file since 106 was 106, checked in by Sam Hocevar, 11 years ago
  • Rename the "eh" variable to "wm" because it's a window manager, not an event handler.
  • No longer pass the window manager to functions, there's only one.

Inspired by Win32 Abuse changelog for January 28, 2001:

  • Starting work on singleton code; will get rid of all

references to an arbitrary window_manager* because
there's only going to be one, and it's not ever
going to change.

File size: 3.9 KB
Line 
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
10#ifndef __INPUT_HPP_
11#define __INPUT_HPP_
12#include "jwindow.hpp"
13#include "filter.hpp"
14
15extern window_manager *wm; /* FIXME: get rid of this if possible */
16
17class button : public ifield
18{
19  int up,act;
20  char *text;
21  image *visual,*pressed,*act_pict;
22  int act_id;
23public :
24  button(int X, int Y, int ID, char const *Text, ifield *Next);
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
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);
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
41class 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);
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); 
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
57  void arrange_left_right();
58  void arrange_up_down();
59} ;
60
61class text_field : public ifield
62{
63  int cur;
64  char *prompt,*data,*format;
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);
69  int last_spot() { int x=strlen(data); while (x && data[x-1]==' ') x--; return x; }
70  void draw_text(image *screen)
71  {
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);
74  }
75public :
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,
79                               double Data, ifield *Next);
80
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);
85 
86  virtual ~text_field() { jfree(prompt); jfree(format); jfree(data); }
87  virtual char *read();
88  void change_data(char const *new_data, int new_cursor,       // cursor==-1, does not change it.
89                   int active, image *screen);
90} ;
91
92
93class info_field : public ifield
94{
95  char *text;
96  int w,h;
97  void put_para(image *screen, char const *st, int dx, int dy, int xspace,
98                int yspace, JCFont *font, int color);
99public :
100  info_field(int X, int Y, int ID, char const *info, ifield *Next);
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) { ; }
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
Note: See TracBrowser for help on using the repository browser.