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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines