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.13 by elmex, Fri Apr 7 20:57: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;
28} 31}
29 32
30sub focus_in { 33sub focus_in {
31 my ($widget) = @_; 34 my ($widget) = @_;
32 $FOCUS = $widget; 35 $FOCUS = $widget;
52 my ($widget, $sdlev) = @_; 55 my ($widget, $sdlev) = @_;
53} 56}
54 57
55sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} } 58sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} }
56sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} } 59sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} }
60sub z { $_[0]->{z} = $_[1] if $_[1]; $_[0]->{z} }
57 61
58sub draw { 62sub draw {
59 my ($self) = @_; 63 my ($self) = @_;
60 64
61 glPushMatrix; 65 glPushMatrix;
62 glTranslate ($self->{x} || 0, $self->{y} || 0, 0); 66 glTranslate $self->{x}, $self->{y}, 0;
63 $self->_draw; 67 $self->_draw;
64 glPopMatrix; 68 glPopMatrix;
65} 69}
66 70
67sub _draw { 71sub _draw {
72 my ($widget) = @_; 76 my ($widget) = @_;
73} 77}
74 78
75package Crossfire::Client::Widget::Label; 79package Crossfire::Client::Widget::Label;
76 80
81our @ISA = Crossfire::Client::Widget::;
82
77use SDL::OpenGL; 83use SDL::OpenGL;
78 84
79sub new { 85sub new {
80 my ($class, $ttf, $text) = @_; 86 my ($class, $x, $y, $z, $ttf, $text) = @_;
81 87
82 my $self = $class->SUPER::new; 88 my $self = $class->SUPER::new (x => $x, y => $y, z => $z);
83 89
84 $self->{texture} = new_from_ttf Crossfire::Client::Texture $ttf, $text; 90 $self->{texture} = new_from_ttf Crossfire::Client::Texture $ttf, $text;
85 91
86 $self 92 $self
87} 93}
89sub _draw { 95sub _draw {
90 my ($self) = @_; 96 my ($self) = @_;
91 97
92 my $tex = $self->{texture}; 98 my $tex = $self->{texture};
93 99
100 $self->{x}--;
101
102 glEnable GL_BLEND;
94 glEnable GL_TEXTURE_2D; 103 glEnable GL_TEXTURE_2D;
104 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
95 glBindTexture GL_TEXTURE_2D, $tex->{name}; 105 glBindTexture GL_TEXTURE_2D, $tex->{name};
106
107 glColor 1, 1, 1;
96 108
97 glBegin GL_QUADS; 109 glBegin GL_QUADS;
98 glTexCoord 0, 0; glVertex 0 , 0; 110 glTexCoord 0, 0; glVertex 0 , 0;
99 glTexCoord 0, 1; glVertex 0 , $tex->{height}; 111 glTexCoord 0, 1; glVertex 0 , $tex->{height};
100 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; 112 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
101 glTexCoord 1, 0; glVertex $tex->{width}, 0; 113 glTexCoord 1, 0; glVertex $tex->{width}, 0;
102 glEnd; 114 glEnd;
103 115
116 glDisable GL_BLEND;
104 glDisable GL_TEXTURE_2D; 117 glDisable GL_TEXTURE_2D;
105} 118}
106 119
107package Crossfire::Client::Widget::TextView; 120package Crossfire::Client::Widget::TextView;
108 121
140} 153}
141 154
142sub _draw { 155sub _draw {
143 glEnable GL_TEXTURE_2D; 156 glEnable GL_TEXTURE_2D;
144 glEnable GL_BLEND; 157 glEnable GL_BLEND;
158 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
145 159
146 my $map = $::CONN->{map}; 160 my $map = $::CONN->{map};
147 161
148 for my $x (0 .. $::CONN->{mapw} - 1) { 162 for my $x (0 .. $::CONN->{mapw} - 1) {
149 for my $y (0 .. $::CONN->{maph} - 1) { 163 for my $y (0 .. $::CONN->{maph} - 1) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines