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

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

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

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