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.3 by elmex, Fri Apr 7 18:16:51 2006 UTC vs.
Revision 1.14 by root, Fri Apr 7 21:07:29 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines