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.8 by root, Fri Apr 7 20:08:57 2006 UTC vs.
Revision 1.14 by root, Fri Apr 7 21:07:29 2006 UTC

1package Crossfire::Client::Widget; 1package Crossfire::Client::Widget;
2 2
3use strict; 3use strict;
4use SDL::OpenGL;
5use SDL::OpenGL::Constants;
4 6
5our $FOCUS; # the widget with current focus 7our $FOCUS; # the widget with current focus
6our %ACTIVE_WIDGETS; 8our @ACTIVE_WIDGETS;
7 9
8# class methods for events 10# class methods for events
9sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } 11sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS }
10sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } 12sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS }
11sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS } 13sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS }
12sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS } 14sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS }
13 15
14sub new { 16sub new {
15 my $class = shift; 17 my $class = shift;
16 my $self = { @_ }; 18
17 bless $self, $class; 19 bless { @_ }, $class
18 return $self;
19} 20}
20 21
21sub activate { 22sub activate {
22 $ACTIVE_WIDGETS{$_[0]} = $_[0]; 23 push @ACTIVE_WIDGETS, $_[0];
23} 24}
24 25
25sub deactivate { 26sub deactivate {
26 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";
27} 35}
28 36
29sub focus_in { 37sub focus_in {
30 my ($widget) = @_; 38 my ($widget) = @_;
31 $FOCUS = $widget; 39 $FOCUS = $widget;
49 57
50sub button_up { 58sub button_up {
51 my ($widget, $sdlev) = @_; 59 my ($widget, $sdlev) = @_;
52} 60}
53 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
54sub draw { 66sub draw {
67 my ($self) = @_;
68
69 glPushMatrix;
70 glTranslate $self->{x}, $self->{y}, 0;
71 $self->_draw;
72 glPopMatrix;
73}
74
75sub _draw {
55 my ($widget) = @_; 76 my ($widget) = @_;
56} 77}
57 78
58sub bbox { 79sub bbox {
59 my ($widget) = @_; 80 my ($widget) = @_;
60} 81}
61 82
62package 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;
63 134
64use strict; 135use strict;
65 136
66our @ISA = qw/Client::Widget/; 137our @ISA = qw/Crossfire::Client::Widget/;
67 138
68use SDL::OpenGL; 139use SDL::OpenGL;
69use SDL::OpenGL::Constants; 140use SDL::OpenGL::Constants;
70 141
71sub add_line { 142sub add_line {
72 my ($self, $line) = @_; 143 my ($self, $line) = @_;
73 push @{$self->{lines}}, $line; 144 push @{$self->{lines}}, $line;
74} 145}
75 146
76sub draw { 147sub _draw {
77 my ($self) = @_; 148 my ($self) = @_;
78 149
79} 150}
80 151
81package Client::MapWidget; 152package Crossfire::Client::Widget::MapWidget;
82 153
83use strict; 154use strict;
84 155
85our @ISA = qw/Client::Widget/; 156our @ISA = qw/Crossfire::Client::Widget/;
86 157
87use SDL::OpenGL; 158use SDL::OpenGL;
88use SDL::OpenGL::Constants; 159use SDL::OpenGL::Constants;
89 160
90sub key_down { 161sub key_down {
92} 163}
93 164
94sub key_up { 165sub key_up {
95} 166}
96 167
97sub draw { 168sub _draw {
98 glEnable GL_TEXTURE_2D; 169 glEnable GL_TEXTURE_2D;
99 glEnable GL_BLEND; 170 glEnable GL_BLEND;
171 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
100 172
101 my $map = $::CONN->{map}; 173 my $map = $::CONN->{map};
102 174
103 for my $x (0 .. $::CONN->{mapw} - 1) { 175 for my $x (0 .. $::CONN->{mapw} - 1) {
104 for my $y (0 .. $::CONN->{maph} - 1) { 176 for my $y (0 .. $::CONN->{maph} - 1) {
113 my $tex = $::CONN->{face}[$num]{texture} || next; 185 my $tex = $::CONN->{face}[$num]{texture} || next;
114 186
115 glBindTexture GL_TEXTURE_2D, $tex->{name}; 187 glBindTexture GL_TEXTURE_2D, $tex->{name};
116 188
117 glBegin GL_QUADS; 189 glBegin GL_QUADS;
118 glTexCoord 0, 0; glVertex $x, $y; 190 glTexCoord 0, 0; glVertex $x * 32 , $y * 32;
119 glTexCoord 0, 1; glVertex $x, $y + 1; 191 glTexCoord 0, 1; glVertex $x * 32 , $y * 32 + 32;
120 glTexCoord 1, 1; glVertex $x + 1, $y + 1; 192 glTexCoord 1, 1; glVertex $x * 32 + 32, $y * 32 + 32;
121 glTexCoord 1, 0; glVertex $x + 1, $y; 193 glTexCoord 1, 0; glVertex $x * 32 + 32, $y * 32;
122 glEnd; 194 glEnd;
123 } 195 }
124 } 196 }
125 } 197 }
126 198

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines