ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
Revision: 1.5
Committed: Fri Apr 7 19:33:42 2006 UTC (18 years, 2 months ago) by root
Branch: MAIN
Changes since 1.4: +7 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 package Client::Widget;
2 use strict;
3
4 our $FOCUS; # the widget with current focus
5 our %ACTIVE_WIDGETS;
6
7 # class methods for events
8 sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS }
9 sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS }
10 sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS }
11 sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS }
12
13 sub new {
14 my $class = shift;
15 my $self = { @_ };
16 bless $self, $class;
17 return $self;
18 }
19
20 sub activate {
21 $ACTIVE_WIDGETS{$_[0]} = $_[0];
22 }
23
24 sub deactivate {
25 delete $ACTIVE_WIDGETS{$_[0]};
26 }
27
28 sub focus_in {
29 my ($widget) = @_;
30 $FOCUS = $widget;
31 }
32
33 sub focus_out {
34 my ($widget) = @_;
35 }
36
37 sub key_down {
38 my ($widget, $sdlev) = @_;
39 }
40
41 sub key_up {
42 my ($widget, $sdlev) = @_;
43 }
44
45 sub button_down {
46 my ($widget, $sdlev) = @_;
47 }
48
49 sub button_up {
50 my ($widget, $sdlev) = @_;
51 }
52
53 sub draw {
54 my ($widget) = @_;
55 }
56
57 sub bbox {
58 my ($widget) = @_;
59 }
60
61 package Client::TextView;
62
63 use strict;
64 our @ISA = qw/Client::Widget/;
65
66 use SDL::OpenGL;
67 use SDL::OpenGL::Constants;
68
69 sub add_line {
70 my ($self, $line) = @_;
71 push @{$self->{lines}}, $line;
72 }
73
74 sub draw {
75 my ($self) = @_;
76
77 }
78
79 package Client::MapWidget;
80
81 use strict;
82 our @ISA = qw/Client::Widget/;
83
84 use SDL::OpenGL;
85 use SDL::OpenGL::Constants;
86
87 sub key_down {
88 print "MAPKEYDOWN\n";
89 }
90
91 sub key_up {
92 }
93
94 my $x;
95
96 sub draw {
97 glEnable GL_TEXTURE_2D;
98 glEnable GL_BLEND;
99
100 glPushMatrix;
101
102 my $map = $::CONN->{map};
103
104 for my $x (0 .. $::CONN->{mapw} - 1) {
105 for my $y (0 .. $::CONN->{maph} - 1) {
106
107 my $cell = $map->[$x][$y]
108 or next;
109
110 my $darkness = $cell->[3] * (1 / 255);
111 glColor $darkness, $darkness, $darkness;
112
113 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) {
114 my $tex = $::CONN->{face}[$num]{texture} || next;
115
116 glBindTexture GL_TEXTURE_2D, $tex->{name};
117
118 glBegin GL_QUADS;
119 glTexCoord 0, 0; glVertex $x, $y;
120 glTexCoord 0, 1; glVertex $x, $y + 1;
121 glTexCoord 1, 1; glVertex $x + 1, $y + 1;
122 glTexCoord 1, 0; glVertex $x + 1, $y;
123 glEnd;
124 }
125 }
126 }
127
128 glPopMatrix;
129
130 glDisable GL_TEXTURE_2D;
131 glDisable GL_BLEND;
132 }
133
134 1;
135