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.11 by elmex, Fri Apr 7 20:39:58 2006 UTC vs.
Revision 1.14 by root, Fri Apr 7 21:07:29 2006 UTC

3use strict; 3use strict;
4use SDL::OpenGL; 4use SDL::OpenGL;
5use SDL::OpenGL::Constants; 5use SDL::OpenGL::Constants;
6 6
7our $FOCUS; # the widget with current focus 7our $FOCUS; # the widget with current focus
8our %ACTIVE_WIDGETS; 8our @ACTIVE_WIDGETS;
9 9
10# class methods for events 10# class methods for events
11sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } 11sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS }
12sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } 12sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS }
13sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS } 13sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS }
18 18
19 bless { @_ }, $class 19 bless { @_ }, $class
20} 20}
21 21
22sub activate { 22sub activate {
23 $ACTIVE_WIDGETS{$_[0]} = $_[0]; 23 push @ACTIVE_WIDGETS, $_[0];
24} 24}
25 25
26sub deactivate { 26sub deactivate {
27 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";
28} 35}
29 36
30sub focus_in { 37sub focus_in {
31 my ($widget) = @_; 38 my ($widget) = @_;
32 $FOCUS = $widget; 39 $FOCUS = $widget;
52 my ($widget, $sdlev) = @_; 59 my ($widget, $sdlev) = @_;
53} 60}
54 61
55sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} } 62sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} }
56sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} } 63sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} }
64sub z { $_[0]->{z} = $_[1] if $_[1]; $_[0]->{z} }
57 65
58sub draw { 66sub draw {
59 my ($self) = @_; 67 my ($self) = @_;
60 68
61 glPushMatrix; 69 glPushMatrix;
62 glTranslate ($self->{x} || 0, $self->{y} || 0, 0); 70 glTranslate $self->{x}, $self->{y}, 0;
63 $self->_draw; 71 $self->_draw;
64 glPopMatrix; 72 glPopMatrix;
65} 73}
66 74
67sub _draw { 75sub _draw {
72 my ($widget) = @_; 80 my ($widget) = @_;
73} 81}
74 82
75package Crossfire::Client::Widget::Label; 83package Crossfire::Client::Widget::Label;
76 84
85our @ISA = Crossfire::Client::Widget::;
86
77use SDL::OpenGL; 87use SDL::OpenGL;
78 88
79sub new { 89sub new {
80 my ($class, $ttf, $text) = @_; 90 my ($class, $x, $y, $z, $ttf, $text) = @_;
81 91
82 my $self = $class->SUPER::new; 92 my $self = $class->SUPER::new (x => $x, y => $y, z => $z);
83 93
84 $self->{texture} = new_from_ttf Crossfire::Client::Texture $ttf, $text; 94 $self->{texture} = new_from_ttf Crossfire::Client::Texture $ttf, $text;
85 95
86 $self 96 $self
87} 97}
88 98
99sub size_request {
100 my ($self) = @_;
101
102 (
103 $self->{texture}{width},
104 $self->{texture}{height},
105 )
106}
107
89sub _draw { 108sub _draw {
90 my ($self) = @_; 109 my ($self) = @_;
91 110
92 my $tex = $self->{texture}; 111 my $tex = $self->{texture};
93 112
113 $self->{x}--;
114
115 glEnable GL_BLEND;
94 glEnable GL_TEXTURE_2D; 116 glEnable GL_TEXTURE_2D;
117 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
95 glBindTexture GL_TEXTURE_2D, $tex->{name}; 118 glBindTexture GL_TEXTURE_2D, $tex->{name};
119
120 glColor 1, 1, 1;
96 121
97 glBegin GL_QUADS; 122 glBegin GL_QUADS;
98 glTexCoord 0, 0; glVertex 0 , 0; 123 glTexCoord 0, 0; glVertex 0 , 0;
99 glTexCoord 0, 1; glVertex 0 , $tex->{height}; 124 glTexCoord 0, 1; glVertex 0 , $tex->{height};
100 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; 125 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
101 glTexCoord 1, 0; glVertex $tex->{width}, 0; 126 glTexCoord 1, 0; glVertex $tex->{width}, 0;
102 glEnd; 127 glEnd;
103 128
129 glDisable GL_BLEND;
104 glDisable GL_TEXTURE_2D; 130 glDisable GL_TEXTURE_2D;
105} 131}
106 132
107package Crossfire::Client::Widget::TextView; 133package Crossfire::Client::Widget::TextView;
108 134
140} 166}
141 167
142sub _draw { 168sub _draw {
143 glEnable GL_TEXTURE_2D; 169 glEnable GL_TEXTURE_2D;
144 glEnable GL_BLEND; 170 glEnable GL_BLEND;
171 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
145 172
146 my $map = $::CONN->{map}; 173 my $map = $::CONN->{map};
147 174
148 for my $x (0 .. $::CONN->{mapw} - 1) { 175 for my $x (0 .. $::CONN->{mapw} - 1) {
149 for my $y (0 .. $::CONN->{maph} - 1) { 176 for my $y (0 .. $::CONN->{maph} - 1) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines