source: abuse/branches/lol/src/imlib/input.h @ 729

Last change on this file since 729 was 729, checked in by Sam Hocevar, 8 years ago

build: sync with newer Lol Engine changes.

  • 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-2013 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
14#include "imlib/window.h"
15#include "imlib/filter.h"
16
17extern WindowManager *wm; /* FIXME: get rid of this if possible */
18
19class AButton : public AWidget
20{
21public:
22    AButton(ivec2 pos, int id, char const *Text);
23    AButton(ivec2 pos, int id, AImage *vis);
24    AButton(ivec2 pos, int id, AImage *Depressed, AImage *Pressed, AImage *active);
25    virtual ~AButton() { }
26
27    virtual ibox2 GetArea();
28    virtual void draw_first(AImage *screen);
29    virtual void Draw(int active, AImage *screen);
30    virtual void handle_event(Event &ev, AImage *screen, InputManager *im);
31    void change_visual(AImage *new_visual);
32    virtual void remap(Filter *f);
33    void push();
34    virtual char const *read() { return (char const *)&up; }
35    int status() { return up; }
36    void set_act_id(int id) { act_id=id; }
37
38private:
39    int up, act;
40    String m_text;
41    AImage *visual, *pressed, *act_pict;
42    int act_id;
43};
44
45class AButtonBox : public AWidget
46{
47public:
48    AButtonBox(ivec2 pos, int id, int MaxDown, array<AButton *> const &buttons = array<AButton *>());
49    virtual ~AButtonBox();
50
51    void add_button(AButton *b);
52    void press_button(int id);      // if button box doesn't contain id, nothing happens
53    virtual void remap(Filter *f);
54    virtual void Move(ivec2 pos);
55    virtual ibox2 GetArea();
56    virtual void draw_first(AImage *screen);
57    virtual void Draw(int active, AImage *screen);
58    virtual void handle_event(Event &ev, AImage *screen, InputManager *im);
59    virtual char const *read();   // return pointer to first button which is depressed
60    virtual AWidget *find(int search_id);  // should return pointer to item you control with this id
61    void arrange_left_right();
62    void arrange_up_down();
63
64private:
65    array<AButton *> m_buttons;
66    int maxdown;
67};
68
69class ATextField : public AWidget
70{
71public:
72    ATextField(ivec2 pos, int id, char const *Prompt, char const *Format, char const *Data);
73    ATextField(ivec2 pos, int id, char const *Prompt, char const *Format, double Data);
74    virtual ~ATextField() { free(prompt); free(format); free(data); }
75
76    virtual ibox2 GetArea();
77    virtual void draw_first(AImage *screen);
78    virtual void Draw(int active, AImage *screen);
79    virtual void handle_event(Event &ev, AImage *screen, InputManager *im);
80
81    virtual char const *read();
82    void change_data(char const *new_data, int new_cursor,       // cursor==-1, does not change it.
83                     int active, AImage *screen);
84
85private:
86    int cur;
87    char *prompt, *data, *format;
88    int xstart() { return m_pos.x + wm->font()->Size().x * (strlen(prompt)+1) + 3; }
89    int xend() { return m_pos.x + wm->font()->Size().x * (strlen(prompt) + 1 + strlen(format)) + 7; }
90    int yend() { return m_pos.y + wm->font()->Size().y + 5; }
91    void draw_cur(int color, AImage *screen);
92    int last_spot() { int x=strlen(data); while (x && data[x-1]==' ') x--; return x; }
93    void draw_text(AImage *screen)
94    {
95        screen->Bar(ivec2(xstart() + 1, m_pos.y + 1), ivec2(xend() - 1, yend() - 1),
96                    wm->dark_color());
97        wm->font()->PutString(screen, ivec2(xstart() + 1, m_pos.y + 3), data);
98    }
99};
100
101
102class AInfoField : public AWidget
103{
104public:
105    AInfoField(ivec2 pos, int id, char const *info);
106    virtual ~AInfoField() { }
107
108    virtual ibox2 GetArea();
109    virtual void draw_first(AImage *screen);
110    virtual void Draw(int active, AImage *screen) { UNUSED(active, screen); }
111    virtual void handle_event(Event &ev, AImage *screen, InputManager *im) { UNUSED(ev, screen, im); }
112    virtual char const *read() { return m_text.C(); }
113    virtual int selectable() { return 0; }
114
115private:
116    String m_text;
117    int w, h;
118    void put_para(AImage *screen, char const *st, int dx, int dy,
119                  int xspace, int yspace, JCFont *font, int color);
120};
121
122#endif
123
Note: See TracBrowser for help on using the repository browser.