ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.1 by elmex, Fri Apr 7 17:18:22 2006 UTC vs.
Revision 1.12 by root, Fri Apr 7 20:55:32 2006 UTC

1package Client::Widget; 1package Crossfire::Client::Widget;
2
2use strict; 3use strict;
4use SDL::OpenGL;
5use SDL::OpenGL::Constants;
3 6
4our $FOCUS; # the widget with current focus 7our $FOCUS; # the widget with current focus
5our @ACTIVE_WIDGETS; 8our %ACTIVE_WIDGETS;
6 9
7# class methods for events 10# class methods for events
8sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } 11sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS }
9sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } 12sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS }
10sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS } 13sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS }
11sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS } 14sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS }
12 15
13sub new { 16sub new {
14 my $class = shift; 17 my $class = shift;
15 my $self = { @_ }; 18
16 bless $self, $class; 19 bless { @_ }, $class
17 return $self; 20}
21
22sub activate {
23 $ACTIVE_WIDGETS{$_[0]} = $_[0];
24}
25
26sub deactivate {
27 delete $ACTIVE_WIDGETS{$_[0]};
18} 28}
19 29
20sub focus_in { 30sub focus_in {
21 my ($widget) = @_; 31 my ($widget) = @_;
22 $FOCUS = $widget; 32 $FOCUS = $widget;
23} 33}
34
24sub focus_out { 35sub focus_out {
25 my ($widget) = @_; 36 my ($widget) = @_;
26} 37}
38
27sub key_down { 39sub key_down {
28 my ($widget, $sdlev) = @_; 40 my ($widget, $sdlev) = @_;
29} 41}
42
30sub key_up { 43sub key_up {
31 my ($widget, $sdlev) = @_; 44 my ($widget, $sdlev) = @_;
32} 45}
46
33sub button_down { 47sub button_down {
34 my ($widget, $sdlev) = @_; 48 my ($widget, $sdlev) = @_;
35} 49}
50
36sub button_up { 51sub button_up {
37 my ($widget, $sdlev) = @_; 52 my ($widget, $sdlev) = @_;
38} 53}
54
55sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} }
56sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} }
57
39sub draw { 58sub draw {
59 my ($self) = @_;
60
61 glPushMatrix;
62 glTranslate $self->{x}, $self->{y}, 0;
63 $self->_draw;
64 glPopMatrix;
65}
66
67sub _draw {
40 my ($widget) = @_; 68 my ($widget) = @_;
41} 69}
70
42sub bbox { 71sub bbox {
43 my ($widget) = @_; 72 my ($widget) = @_;
44} 73}
74
75package Crossfire::Client::Widget::Label;
76
77our @ISA = Crossfire::Client::Widget::;
78
79use SDL::OpenGL;
80
81sub new {
82 my ($class, $x, $y, $z, $ttf, $text) = @_;
83
84 my $self = $class->SUPER::new (x => $x, y => $y, z => $z);
85
86 $self->{texture} = new_from_ttf Crossfire::Client::Texture $ttf, $text;
87
88 $self
89}
90
91sub _draw {
92 my ($self) = @_;
93
94 my $tex = $self->{texture};
95
96 $self->{x}--;
97
98 glEnable GL_BLEND;
99 glEnable GL_TEXTURE_2D;
100 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
101 glBindTexture GL_TEXTURE_2D, $tex->{name};
102
103 glColor 1, 1, 1;
104
105 glBegin GL_QUADS;
106 glTexCoord 0, 0; glVertex 0 , 0;
107 glTexCoord 0, 1; glVertex 0 , $tex->{height};
108 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
109 glTexCoord 1, 0; glVertex $tex->{width}, 0;
110 glEnd;
111
112 glDisable GL_BLEND;
113 glDisable GL_TEXTURE_2D;
114}
115
116package Crossfire::Client::Widget::TextView;
117
118use strict;
119
120our @ISA = qw/Crossfire::Client::Widget/;
121
122use SDL::OpenGL;
123use SDL::OpenGL::Constants;
124
125sub add_line {
126 my ($self, $line) = @_;
127 push @{$self->{lines}}, $line;
128}
129
130sub _draw {
131 my ($self) = @_;
132
133}
134
135package Crossfire::Client::Widget::MapWidget;
136
137use strict;
138
139our @ISA = qw/Crossfire::Client::Widget/;
140
141use SDL::OpenGL;
142use SDL::OpenGL::Constants;
143
144sub key_down {
145 print "MAPKEYDOWN\n";
146}
147
148sub key_up {
149}
150
151sub _draw {
152 glEnable GL_TEXTURE_2D;
153 glEnable GL_BLEND;
154 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
155
156 my $map = $::CONN->{map};
157
158 for my $x (0 .. $::CONN->{mapw} - 1) {
159 for my $y (0 .. $::CONN->{maph} - 1) {
160
161 my $cell = $map->[$x][$y]
162 or next;
163
164 my $darkness = $cell->[3] * (1 / 255);
165 glColor $darkness, $darkness, $darkness;
166
167 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) {
168 my $tex = $::CONN->{face}[$num]{texture} || next;
169
170 glBindTexture GL_TEXTURE_2D, $tex->{name};
171
172 glBegin GL_QUADS;
173 glTexCoord 0, 0; glVertex $x * 32 , $y * 32;
174 glTexCoord 0, 1; glVertex $x * 32 , $y * 32 + 32;
175 glTexCoord 1, 1; glVertex $x * 32 + 32, $y * 32 + 32;
176 glTexCoord 1, 0; glVertex $x * 32 + 32, $y * 32;
177 glEnd;
178 }
179 }
180 }
181
182 glDisable GL_TEXTURE_2D;
183 glDisable GL_BLEND;
184}
185
451; 1861;
187

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines