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.12 by root, Fri Apr 7 20:55:32 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}, $self->{y}, 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
62package Client::TextView; 75package Crossfire::Client::Widget::Label;
76
77our @ISA = Crossfire::Client::Widget::;
78
79use SDL::OpenGL;
80
81sub new {
82 my ($class, $x, $y, $z, $ttf, $text) = @_;
83
84 my $self = $class->SUPER::new (x => $x, y => $y, z => $z);
85
86 $self->{texture} = new_from_ttf Crossfire::Client::Texture $ttf, $text;
87
88 $self
89}
90
91sub _draw {
92 my ($self) = @_;
93
94 my $tex = $self->{texture};
95
96 $self->{x}--;
97
98 glEnable GL_BLEND;
99 glEnable GL_TEXTURE_2D;
100 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
101 glBindTexture GL_TEXTURE_2D, $tex->{name};
102
103 glColor 1, 1, 1;
104
105 glBegin GL_QUADS;
106 glTexCoord 0, 0; glVertex 0 , 0;
107 glTexCoord 0, 1; glVertex 0 , $tex->{height};
108 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
109 glTexCoord 1, 0; glVertex $tex->{width}, 0;
110 glEnd;
111
112 glDisable GL_BLEND;
113 glDisable GL_TEXTURE_2D;
114}
115
116package Crossfire::Client::Widget::TextView;
63 117
64use strict; 118use strict;
65 119
66our @ISA = qw/Client::Widget/; 120our @ISA = qw/Crossfire::Client::Widget/;
67 121
68use SDL::OpenGL; 122use SDL::OpenGL;
69use SDL::OpenGL::Constants; 123use SDL::OpenGL::Constants;
70 124
71sub add_line { 125sub add_line {
72 my ($self, $line) = @_; 126 my ($self, $line) = @_;
73 push @{$self->{lines}}, $line; 127 push @{$self->{lines}}, $line;
74} 128}
75 129
76sub draw { 130sub _draw {
77 my ($self) = @_; 131 my ($self) = @_;
78 132
79} 133}
80 134
81package Client::MapWidget; 135package Crossfire::Client::Widget::MapWidget;
82 136
83use strict; 137use strict;
84 138
85our @ISA = qw/Client::Widget/; 139our @ISA = qw/Crossfire::Client::Widget/;
86 140
87use SDL::OpenGL; 141use SDL::OpenGL;
88use SDL::OpenGL::Constants; 142use SDL::OpenGL::Constants;
89 143
90sub key_down { 144sub key_down {
92} 146}
93 147
94sub key_up { 148sub key_up {
95} 149}
96 150
97sub draw { 151sub _draw {
98 glEnable GL_TEXTURE_2D; 152 glEnable GL_TEXTURE_2D;
99 glEnable GL_BLEND; 153 glEnable GL_BLEND;
154 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
100 155
101 my $map = $::CONN->{map}; 156 my $map = $::CONN->{map};
102 157
103 for my $x (0 .. $::CONN->{mapw} - 1) { 158 for my $x (0 .. $::CONN->{mapw} - 1) {
104 for my $y (0 .. $::CONN->{maph} - 1) { 159 for my $y (0 .. $::CONN->{maph} - 1) {
113 my $tex = $::CONN->{face}[$num]{texture} || next; 168 my $tex = $::CONN->{face}[$num]{texture} || next;
114 169
115 glBindTexture GL_TEXTURE_2D, $tex->{name}; 170 glBindTexture GL_TEXTURE_2D, $tex->{name};
116 171
117 glBegin GL_QUADS; 172 glBegin GL_QUADS;
118 glTexCoord 0, 0; glVertex $x, $y; 173 glTexCoord 0, 0; glVertex $x * 32 , $y * 32;
119 glTexCoord 0, 1; glVertex $x, $y + 1; 174 glTexCoord 0, 1; glVertex $x * 32 , $y * 32 + 32;
120 glTexCoord 1, 1; glVertex $x + 1, $y + 1; 175 glTexCoord 1, 1; glVertex $x * 32 + 32, $y * 32 + 32;
121 glTexCoord 1, 0; glVertex $x + 1, $y; 176 glTexCoord 1, 0; glVertex $x * 32 + 32, $y * 32;
122 glEnd; 177 glEnd;
123 } 178 }
124 } 179 }
125 } 180 }
126 181

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines