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.2 by elmex, Fri Apr 7 17:37:11 2006 UTC

1package Client::Widget; 1package Client::Widget;
2use strict; 2use strict;
3 3
4our $FOCUS; # the widget with current focus 4our $FOCUS; # the widget with current focus
5our @ACTIVE_WIDGETS; 5our %ACTIVE_WIDGETS;
6 6
7# class methods for events 7# class methods for events
8sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } 8sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS }
9sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } 9sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS }
10sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS } 10sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS }
13sub new { 13sub new {
14 my $class = shift; 14 my $class = shift;
15 my $self = { @_ }; 15 my $self = { @_ };
16 bless $self, $class; 16 bless $self, $class;
17 return $self; 17 return $self;
18}
19
20sub activate {
21 $ACTIVE_WIDGETS{$_[0]} = $_[0];
22}
23sub deactivate {
24 delete $ACTIVE_WIDGETS{$_[0]};
18} 25}
19 26
20sub focus_in { 27sub focus_in {
21 my ($widget) = @_; 28 my ($widget) = @_;
22 $FOCUS = $widget; 29 $FOCUS = $widget;
40 my ($widget) = @_; 47 my ($widget) = @_;
41} 48}
42sub bbox { 49sub bbox {
43 my ($widget) = @_; 50 my ($widget) = @_;
44} 51}
52
53package Client::MapWidget;
54use strict;
55our @ISA = qw/Client::Widget/;
56
57use SDL::OpenGL;
58use SDL::OpenGL::Constants;
59
60sub key_down {
61 print "MAPKEYDOWN\n";
62}
63
64sub key_up {
65}
66
67sub draw {
68 glEnable GL_TEXTURE_2D;
69 glEnable GL_BLEND;
70
71 my $map = $::CONN->{map};
72
73 for my $x (0 .. $::CONN->{mapw} - 1) {
74 for my $y (0 .. $::CONN->{maph} - 1) {
75
76 my $cell = $map->[$x][$y]
77 or next;
78
79 my $darkness = $cell->[3] * (1 / 255);
80 glColor $darkness, $darkness, $darkness;
81
82 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) {
83 my $tex = $::CONN->{face}[$num]{texture} || 0;
84
85 glBindTexture GL_TEXTURE_2D, $tex;
86
87 glBegin GL_QUADS;
88 glTexCoord 0, 0; glVertex $x, $y;
89 glTexCoord 0, 1; glVertex $x, $y + 1;
90 glTexCoord 1, 1; glVertex $x + 1, $y + 1;
91 glTexCoord 1, 0; glVertex $x + 1, $y;
92 glEnd;
93 }
94 }
95 }
96
97 glDisable GL_TEXTURE_2D;
98 glDisable GL_BLEND;
99}
100
451; 1011;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines