ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
Revision: 1.11
Committed: Fri Apr 7 20:39:58 2006 UTC (18 years, 2 months ago) by elmex
Branch: MAIN
Changes since 1.10: +17 -3 lines
Log Message:
added translation of widgets

File Contents

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