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

Last change on this file since 481 was 481, checked in by Sam Hocevar, 11 years ago

Fuck the history, I'm renaming all .hpp files to .h for my own sanity.

  • Property svn:keywords set to Id
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.h"
13#include "filter.h"
14
15extern WindowManager *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, InputManager *im);
32  void change_visual(image *new_visual);
33  virtual void remap(filter *f);
34  virtual ~button() { if (text) free(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;
45public :
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 move(int newx, int newy);
51  virtual void area(int &x1, int &y1, int &x2, int &y2);
52  virtual void draw_first(image *screen);
53  virtual void draw(int active, image *screen);
54  virtual void handle_event(event &ev, image *screen, InputManager *im);
55  virtual ~button_box();
56  virtual char *read();   // return pointer to first button which is depressed
57  virtual ifield *find(int search_id);  // should return pointer to item you control with this id
58  void arrange_left_right();
59  void arrange_up_down();
60} ;
61
62class text_field : public ifield
63{
64  int cur;
65  char *prompt,*data,*format;
66  int xstart() { return x+wm->font()->width()*(strlen(prompt)+1)+3; }
67  int xend() { return x+wm->font()->width()*(strlen(prompt)+1+strlen(format))+7; }
68  int yend() { return y+wm->font()->height()+5; }
69  void draw_cur(int color, image *screen);
70  int last_spot() { int x=strlen(data); while (x && data[x-1]==' ') x--; return x; }
71  void draw_text(image *screen)
72  {
73    screen->bar(xstart()+1,y+1,xend()-1,yend()-1,wm->dark_color());
74    wm->font()->put_string(screen,xstart()+1,y+3,data);
75  }
76public :
77  text_field(int X, int Y, int ID, char const *Prompt, char const *Format,
78                               char const *Data, ifield *Next);
79  text_field(int X, int Y, int ID, char const *Prompt, char const *Format,
80                               double Data, ifield *Next);
81
82  virtual void area(int &x1, int &y1, int &x2, int &y2);
83  virtual void draw_first(image *screen);
84  virtual void draw(int active, image *screen);
85  virtual void handle_event(event &ev, image *screen, InputManager *im);
86
87  virtual ~text_field() { free(prompt); free(format); free(data); }
88  virtual char *read();
89  void change_data(char const *new_data, int new_cursor,       // cursor==-1, does not change it.
90           int active, image *screen);
91} ;
92
93
94class info_field : public ifield
95{
96  char *text;
97  int w,h;
98  void put_para(image *screen, char const *st, int dx, int dy, int xspace,
99        int yspace, JCFont *font, int color);
100public :
101  info_field(int X, int Y, int ID, char const *info, ifield *Next);
102  virtual void area(int &x1, int &y1, int &x2, int &y2);
103  virtual void draw_first(image *screen);
104  virtual void draw(int active, image *screen) { ; }
105  virtual void handle_event(event &ev, image *screen, InputManager *im) { ; }
106  virtual char *read() { return text; }
107  virtual int selectable() { return 0; }
108  virtual ~info_field() { free(text); }
109} ;
110
111#endif
112
113
114
115
116
117
118
119
120
121
Note: See TracBrowser for help on using the repository browser.