ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
Revision: 1.10
Committed: Fri Apr 7 20:34:44 2006 UTC (18 years, 1 month ago) by root
Branch: MAIN
Changes since 1.9: +39 -7 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 package Crossfire::Client::Widget;
2
3 use strict;
4
5 our $FOCUS; # the widget with current focus
6 our %ACTIVE_WIDGETS;
7
8 # class methods for events
9 sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS }
10 sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS }
11 sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS }
12 sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS }
13
14 sub new {
15 my $class = shift;
16
17 bless { @_ }, $class
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 Crossfire::Client::Widget::Label;
62
63 use SDL::OpenGL;
64
65 sub new {
66 my ($class, $ttf, $text) = @_;
67
68 my $self = $class->SUPER::new;
69
70 $self->{texture} = new_from_ttf Crossfire::Client::Texture $ttf, $text;
71
72 $self
73 }
74
75 sub draw {
76 my ($self) = @_;
77
78 my $tex = $self->{texture};
79
80 glEnable GL_TEXTURE_2D;
81 glBindTexture GL_TEXTURE_2D, $tex->{name};
82
83 glBegin GL_QUADS;
84 glTexCoord 0, 0; glVertex 0 , 0;
85 glTexCoord 0, 1; glVertex 0 , $tex->{height};
86 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
87 glTexCoord 1, 0; glVertex $tex->{width}, 0;
88 glEnd;
89
90 glDisable GL_TEXTURE_2D;
91 }
92
93 package Crossfire::Client::Widget::TextView;
94
95 use strict;
96
97 our @ISA = qw/Crossfire::Client::Widget/;
98
99 use SDL::OpenGL;
100 use SDL::OpenGL::Constants;
101
102 sub add_line {
103 my ($self, $line) = @_;
104 push @{$self->{lines}}, $line;
105 }
106
107 sub draw {
108 my ($self) = @_;
109
110 }
111
112 package Crossfire::Client::Widget::MapWidget;
113
114 use strict;
115
116 our @ISA = qw/Crossfire::Client::Widget/;
117
118 use SDL::OpenGL;
119 use SDL::OpenGL::Constants;
120
121 sub key_down {
122 print "MAPKEYDOWN\n";
123 }
124
125 sub key_up {
126 }
127
128 sub draw {
129 glEnable GL_TEXTURE_2D;
130 glEnable GL_BLEND;
131
132 my $map = $::CONN->{map};
133
134 for my $x (0 .. $::CONN->{mapw} - 1) {
135 for my $y (0 .. $::CONN->{maph} - 1) {
136
137 my $cell = $map->[$x][$y]
138 or next;
139
140 my $darkness = $cell->[3] * (1 / 255);
141 glColor $darkness, $darkness, $darkness;
142
143 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) {
144 my $tex = $::CONN->{face}[$num]{texture} || next;
145
146 glBindTexture GL_TEXTURE_2D, $tex->{name};
147
148 glBegin GL_QUADS;
149 glTexCoord 0, 0; glVertex $x * 32 , $y * 32;
150 glTexCoord 0, 1; glVertex $x * 32 , $y * 32 + 32;
151 glTexCoord 1, 1; glVertex $x * 32 + 32, $y * 32 + 32;
152 glTexCoord 1, 0; glVertex $x * 32 + 32, $y * 32;
153 glEnd;
154 }
155 }
156 }
157
158 glDisable GL_TEXTURE_2D;
159 glDisable GL_BLEND;
160 }
161
162 1;
163