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.10 by root, Fri Apr 7 20:34:44 2006 UTC

1package Client::Widget; 1package Crossfire::Client::Widget;
2
2use strict; 3use strict;
3 4
4our $FOCUS; # the widget with current focus 5our $FOCUS; # the widget with current focus
5our @ACTIVE_WIDGETS; 6our %ACTIVE_WIDGETS;
6 7
7# class methods for events 8# class methods for events
8sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } 9sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS }
9sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } 10sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS }
10sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS } 11sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS }
11sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS } 12sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS }
12 13
13sub new { 14sub new {
14 my $class = shift; 15 my $class = shift;
15 my $self = { @_ }; 16
16 bless $self, $class; 17 bless { @_ }, $class
17 return $self; 18}
19
20sub activate {
21 $ACTIVE_WIDGETS{$_[0]} = $_[0];
22}
23
24sub deactivate {
25 delete $ACTIVE_WIDGETS{$_[0]};
18} 26}
19 27
20sub focus_in { 28sub focus_in {
21 my ($widget) = @_; 29 my ($widget) = @_;
22 $FOCUS = $widget; 30 $FOCUS = $widget;
23} 31}
32
24sub focus_out { 33sub focus_out {
25 my ($widget) = @_; 34 my ($widget) = @_;
26} 35}
36
27sub key_down { 37sub key_down {
28 my ($widget, $sdlev) = @_; 38 my ($widget, $sdlev) = @_;
29} 39}
40
30sub key_up { 41sub key_up {
31 my ($widget, $sdlev) = @_; 42 my ($widget, $sdlev) = @_;
32} 43}
44
33sub button_down { 45sub button_down {
34 my ($widget, $sdlev) = @_; 46 my ($widget, $sdlev) = @_;
35} 47}
48
36sub button_up { 49sub button_up {
37 my ($widget, $sdlev) = @_; 50 my ($widget, $sdlev) = @_;
38} 51}
52
39sub draw { 53sub draw {
40 my ($widget) = @_; 54 my ($widget) = @_;
41} 55}
56
42sub bbox { 57sub bbox {
43 my ($widget) = @_; 58 my ($widget) = @_;
44} 59}
60
61package Crossfire::Client::Widget::Label;
62
63use SDL::OpenGL;
64
65sub 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
75sub 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
93package Crossfire::Client::Widget::TextView;
94
95use strict;
96
97our @ISA = qw/Crossfire::Client::Widget/;
98
99use SDL::OpenGL;
100use SDL::OpenGL::Constants;
101
102sub add_line {
103 my ($self, $line) = @_;
104 push @{$self->{lines}}, $line;
105}
106
107sub draw {
108 my ($self) = @_;
109
110}
111
112package Crossfire::Client::Widget::MapWidget;
113
114use strict;
115
116our @ISA = qw/Crossfire::Client::Widget/;
117
118use SDL::OpenGL;
119use SDL::OpenGL::Constants;
120
121sub key_down {
122 print "MAPKEYDOWN\n";
123}
124
125sub key_up {
126}
127
128sub 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
451; 1621;
163

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines