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.3 by elmex, Fri Apr 7 18:16:51 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::TextView;
54use strict;
55our @ISA = qw/Client::Widget/;
56
57use SDL::OpenGL;
58use SDL::OpenGL::Constants;
59
60sub add_line {
61 my ($self, $line) = @_;
62 push @{$self->{lines}}, $line;
63}
64
65sub draw {
66 my ($self) = @_;
67
68}
69
70package Client::MapWidget;
71use strict;
72our @ISA = qw/Client::Widget/;
73
74use SDL::OpenGL;
75use SDL::OpenGL::Constants;
76
77sub key_down {
78 print "MAPKEYDOWN\n";
79}
80
81sub key_up {
82}
83
84sub draw {
85 glEnable GL_TEXTURE_2D;
86 glEnable GL_BLEND;
87
88 my $map = $::CONN->{map};
89
90 for my $x (0 .. $::CONN->{mapw} - 1) {
91 for my $y (0 .. $::CONN->{maph} - 1) {
92
93 my $cell = $map->[$x][$y]
94 or next;
95
96 my $darkness = $cell->[3] * (1 / 255);
97 glColor $darkness, $darkness, $darkness;
98
99 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) {
100 my $tex = $::CONN->{face}[$num]{texture} || 0;
101
102 glBindTexture GL_TEXTURE_2D, $tex;
103
104 glBegin GL_QUADS;
105 glTexCoord 0, 0; glVertex $x, $y;
106 glTexCoord 0, 1; glVertex $x, $y + 1;
107 glTexCoord 1, 1; glVertex $x + 1, $y + 1;
108 glTexCoord 1, 0; glVertex $x + 1, $y;
109 glEnd;
110 }
111 }
112 }
113
114 glDisable GL_TEXTURE_2D;
115 glDisable GL_BLEND;
116}
117
451; 1181;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines