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.9 by elmex, Fri Apr 7 20:09:52 2006 UTC vs.
Revision 1.11 by elmex, Fri Apr 7 20:39:58 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
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 $ACTIVE_WIDGETS{$_[0]} = $_[0];
23} 24}
49 50
50sub button_up { 51sub button_up {
51 my ($widget, $sdlev) = @_; 52 my ($widget, $sdlev) = @_;
52} 53}
53 54
55sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} }
56sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} }
57
54sub draw { 58sub draw {
59 my ($self) = @_;
60
61 glPushMatrix;
62 glTranslate ($self->{x} || 0, $self->{y} || 0, 0);
63 $self->_draw;
64 glPopMatrix;
65}
66
67sub _draw {
55 my ($widget) = @_; 68 my ($widget) = @_;
56} 69}
57 70
58sub bbox { 71sub bbox {
59 my ($widget) = @_; 72 my ($widget) = @_;
60} 73}
61 74
75package Crossfire::Client::Widget::Label;
76
77use SDL::OpenGL;
78
79sub new {
80 my ($class, $ttf, $text) = @_;
81
82 my $self = $class->SUPER::new;
83
84 $self->{texture} = new_from_ttf Crossfire::Client::Texture $ttf, $text;
85
86 $self
87}
88
89sub _draw {
90 my ($self) = @_;
91
92 my $tex = $self->{texture};
93
94 glEnable GL_TEXTURE_2D;
95 glBindTexture GL_TEXTURE_2D, $tex->{name};
96
97 glBegin GL_QUADS;
98 glTexCoord 0, 0; glVertex 0 , 0;
99 glTexCoord 0, 1; glVertex 0 , $tex->{height};
100 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
101 glTexCoord 1, 0; glVertex $tex->{width}, 0;
102 glEnd;
103
104 glDisable GL_TEXTURE_2D;
105}
106
62package Crossfire::Client::Widget::TextView; 107package Crossfire::Client::Widget::TextView;
63 108
64use strict; 109use strict;
110
65our @ISA = qw/Crossfire::Client::Widget/; 111our @ISA = qw/Crossfire::Client::Widget/;
66 112
67use SDL::OpenGL; 113use SDL::OpenGL;
68use SDL::OpenGL::Constants; 114use SDL::OpenGL::Constants;
69 115
70sub add_line { 116sub add_line {
71 my ($self, $line) = @_; 117 my ($self, $line) = @_;
72 push @{$self->{lines}}, $line; 118 push @{$self->{lines}}, $line;
73} 119}
74 120
75sub draw { 121sub _draw {
76 my ($self) = @_; 122 my ($self) = @_;
77 123
78} 124}
79 125
80package Crossfire::Client::Widget::MapWidget; 126package Crossfire::Client::Widget::MapWidget;
91} 137}
92 138
93sub key_up { 139sub key_up {
94} 140}
95 141
96sub draw { 142sub _draw {
97 glEnable GL_TEXTURE_2D; 143 glEnable GL_TEXTURE_2D;
98 glEnable GL_BLEND; 144 glEnable GL_BLEND;
99 145
100 my $map = $::CONN->{map}; 146 my $map = $::CONN->{map};
101 147
112 my $tex = $::CONN->{face}[$num]{texture} || next; 158 my $tex = $::CONN->{face}[$num]{texture} || next;
113 159
114 glBindTexture GL_TEXTURE_2D, $tex->{name}; 160 glBindTexture GL_TEXTURE_2D, $tex->{name};
115 161
116 glBegin GL_QUADS; 162 glBegin GL_QUADS;
117 glTexCoord 0, 0; glVertex $x, $y; 163 glTexCoord 0, 0; glVertex $x * 32 , $y * 32;
118 glTexCoord 0, 1; glVertex $x, $y + 1; 164 glTexCoord 0, 1; glVertex $x * 32 , $y * 32 + 32;
119 glTexCoord 1, 1; glVertex $x + 1, $y + 1; 165 glTexCoord 1, 1; glVertex $x * 32 + 32, $y * 32 + 32;
120 glTexCoord 1, 0; glVertex $x + 1, $y; 166 glTexCoord 1, 0; glVertex $x * 32 + 32, $y * 32;
121 glEnd; 167 glEnd;
122 } 168 }
123 } 169 }
124 } 170 }
125 171

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines