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.13 by elmex, Fri Apr 7 20:57: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;
25} 31}
26 32
27sub focus_in { 33sub focus_in {
28 my ($widget) = @_; 34 my ($widget) = @_;
29 $FOCUS = $widget; 35 $FOCUS = $widget;
30} 36}
37
31sub focus_out { 38sub focus_out {
32 my ($widget) = @_; 39 my ($widget) = @_;
33} 40}
41
34sub key_down { 42sub key_down {
35 my ($widget, $sdlev) = @_; 43 my ($widget, $sdlev) = @_;
36} 44}
45
37sub key_up { 46sub key_up {
38 my ($widget, $sdlev) = @_; 47 my ($widget, $sdlev) = @_;
39} 48}
49
40sub button_down { 50sub button_down {
41 my ($widget, $sdlev) = @_; 51 my ($widget, $sdlev) = @_;
42} 52}
53
43sub button_up { 54sub button_up {
44 my ($widget, $sdlev) = @_; 55 my ($widget, $sdlev) = @_;
45} 56}
57
58sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} }
59sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} }
60sub z { $_[0]->{z} = $_[1] if $_[1]; $_[0]->{z} }
61
46sub draw { 62sub draw {
63 my ($self) = @_;
64
65 glPushMatrix;
66 glTranslate $self->{x}, $self->{y}, 0;
67 $self->_draw;
68 glPopMatrix;
69}
70
71sub _draw {
47 my ($widget) = @_; 72 my ($widget) = @_;
48} 73}
74
49sub bbox { 75sub bbox {
50 my ($widget) = @_; 76 my ($widget) = @_;
51} 77}
52 78
53package Client::TextView; 79package Crossfire::Client::Widget::Label;
80
81our @ISA = Crossfire::Client::Widget::;
82
83use SDL::OpenGL;
84
85sub new {
86 my ($class, $x, $y, $z, $ttf, $text) = @_;
87
88 my $self = $class->SUPER::new (x => $x, y => $y, z => $z);
89
90 $self->{texture} = new_from_ttf Crossfire::Client::Texture $ttf, $text;
91
92 $self
93}
94
95sub _draw {
96 my ($self) = @_;
97
98 my $tex = $self->{texture};
99
100 $self->{x}--;
101
102 glEnable GL_BLEND;
103 glEnable GL_TEXTURE_2D;
104 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
105 glBindTexture GL_TEXTURE_2D, $tex->{name};
106
107 glColor 1, 1, 1;
108
109 glBegin GL_QUADS;
110 glTexCoord 0, 0; glVertex 0 , 0;
111 glTexCoord 0, 1; glVertex 0 , $tex->{height};
112 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
113 glTexCoord 1, 0; glVertex $tex->{width}, 0;
114 glEnd;
115
116 glDisable GL_BLEND;
117 glDisable GL_TEXTURE_2D;
118}
119
120package Crossfire::Client::Widget::TextView;
121
54use strict; 122use strict;
123
55our @ISA = qw/Client::Widget/; 124our @ISA = qw/Crossfire::Client::Widget/;
56 125
57use SDL::OpenGL; 126use SDL::OpenGL;
58use SDL::OpenGL::Constants; 127use SDL::OpenGL::Constants;
59 128
60sub add_line { 129sub add_line {
61 my ($self, $line) = @_; 130 my ($self, $line) = @_;
62 push @{$self->{lines}}, $line; 131 push @{$self->{lines}}, $line;
63} 132}
64 133
65sub draw { 134sub _draw {
66 my ($self) = @_; 135 my ($self) = @_;
67 136
68} 137}
69 138
70package Client::MapWidget; 139package Crossfire::Client::Widget::MapWidget;
140
71use strict; 141use strict;
142
72our @ISA = qw/Client::Widget/; 143our @ISA = qw/Crossfire::Client::Widget/;
73 144
74use SDL::OpenGL; 145use SDL::OpenGL;
75use SDL::OpenGL::Constants; 146use SDL::OpenGL::Constants;
76 147
77sub key_down { 148sub key_down {
79} 150}
80 151
81sub key_up { 152sub key_up {
82} 153}
83 154
84sub draw { 155sub _draw {
85 glEnable GL_TEXTURE_2D; 156 glEnable GL_TEXTURE_2D;
86 glEnable GL_BLEND; 157 glEnable GL_BLEND;
158 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
87 159
88 my $map = $::CONN->{map}; 160 my $map = $::CONN->{map};
89 161
90 for my $x (0 .. $::CONN->{mapw} - 1) { 162 for my $x (0 .. $::CONN->{mapw} - 1) {
91 for my $y (0 .. $::CONN->{maph} - 1) { 163 for my $y (0 .. $::CONN->{maph} - 1) {
95 167
96 my $darkness = $cell->[3] * (1 / 255); 168 my $darkness = $cell->[3] * (1 / 255);
97 glColor $darkness, $darkness, $darkness; 169 glColor $darkness, $darkness, $darkness;
98 170
99 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { 171 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) {
100 my $tex = $::CONN->{face}[$num]{texture} || 0; 172 my $tex = $::CONN->{face}[$num]{texture} || next;
101 173
102 glBindTexture GL_TEXTURE_2D, $tex; 174 glBindTexture GL_TEXTURE_2D, $tex->{name};
103 175
104 glBegin GL_QUADS; 176 glBegin GL_QUADS;
105 glTexCoord 0, 0; glVertex $x, $y; 177 glTexCoord 0, 0; glVertex $x * 32 , $y * 32;
106 glTexCoord 0, 1; glVertex $x, $y + 1; 178 glTexCoord 0, 1; glVertex $x * 32 , $y * 32 + 32;
107 glTexCoord 1, 1; glVertex $x + 1, $y + 1; 179 glTexCoord 1, 1; glVertex $x * 32 + 32, $y * 32 + 32;
108 glTexCoord 1, 0; glVertex $x + 1, $y; 180 glTexCoord 1, 0; glVertex $x * 32 + 32, $y * 32;
109 glEnd; 181 glEnd;
110 } 182 }
111 } 183 }
112 } 184 }
113 185
114 glDisable GL_TEXTURE_2D; 186 glDisable GL_TEXTURE_2D;
115 glDisable GL_BLEND; 187 glDisable GL_BLEND;
116} 188}
117 189
1181; 1901;
191

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines