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.7 by elmex, Fri Apr 7 20:04:59 2006 UTC vs.
Revision 1.10 by root, Fri Apr 7 20:34:44 2006 UTC

1package Crossfire::Client::Widget; 1package Crossfire::Client::Widget;
2
2use strict; 3use strict;
3 4
4our $FOCUS; # the widget with current focus 5our $FOCUS; # the widget with current focus
5our %ACTIVE_WIDGETS; 6our %ACTIVE_WIDGETS;
6 7
10sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS } 11sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS }
11sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS } 12sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS }
12 13
13sub new { 14sub new {
14 my $class = shift; 15 my $class = shift;
15 my $self = { @_ }; 16
16 bless $self, $class; 17 bless { @_ }, $class
17 return $self;
18} 18}
19 19
20sub activate { 20sub activate {
21 $ACTIVE_WIDGETS{$_[0]} = $_[0]; 21 $ACTIVE_WIDGETS{$_[0]} = $_[0];
22} 22}
56 56
57sub bbox { 57sub bbox {
58 my ($widget) = @_; 58 my ($widget) = @_;
59} 59}
60 60
61package Client::TextView; 61package Crossfire::Client::Widget::Label;
62
63use SDL::OpenGL;
64
65sub new {
66 my ($class, $ttf, $text) = @_;
67
68 my $self = $class->SUPER::new;
69
70 $self->{texture} = new_from_ttf Crossfire::Client::Texture $ttf, $text;
71
72 $self
73}
74
75sub draw {
76 my ($self) = @_;
77
78 my $tex = $self->{texture};
79
80 glEnable GL_TEXTURE_2D;
81 glBindTexture GL_TEXTURE_2D, $tex->{name};
82
83 glBegin GL_QUADS;
84 glTexCoord 0, 0; glVertex 0 , 0;
85 glTexCoord 0, 1; glVertex 0 , $tex->{height};
86 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
87 glTexCoord 1, 0; glVertex $tex->{width}, 0;
88 glEnd;
89
90 glDisable GL_TEXTURE_2D;
91}
92
93package Crossfire::Client::Widget::TextView;
62 94
63use strict; 95use strict;
96
64our @ISA = qw/Client::Widget/; 97our @ISA = qw/Crossfire::Client::Widget/;
65 98
66use SDL::OpenGL; 99use SDL::OpenGL;
67use SDL::OpenGL::Constants; 100use SDL::OpenGL::Constants;
68 101
69sub add_line { 102sub add_line {
74sub draw { 107sub draw {
75 my ($self) = @_; 108 my ($self) = @_;
76 109
77} 110}
78 111
79package Client::MapWidget; 112package Crossfire::Client::Widget::MapWidget;
80 113
81use strict; 114use strict;
82 115
83our @ISA = qw/Client::Widget/; 116our @ISA = qw/Crossfire::Client::Widget/;
84 117
85use SDL::OpenGL; 118use SDL::OpenGL;
86use SDL::OpenGL::Constants; 119use SDL::OpenGL::Constants;
87 120
88sub key_down { 121sub key_down {
90} 123}
91 124
92sub key_up { 125sub key_up {
93} 126}
94 127
95my $x;
96
97sub draw { 128sub draw {
98 glEnable GL_TEXTURE_2D; 129 glEnable GL_TEXTURE_2D;
99 glEnable GL_BLEND; 130 glEnable GL_BLEND;
100
101 glPushMatrix;
102 131
103 my $map = $::CONN->{map}; 132 my $map = $::CONN->{map};
104 133
105 for my $x (0 .. $::CONN->{mapw} - 1) { 134 for my $x (0 .. $::CONN->{mapw} - 1) {
106 for my $y (0 .. $::CONN->{maph} - 1) { 135 for my $y (0 .. $::CONN->{maph} - 1) {
115 my $tex = $::CONN->{face}[$num]{texture} || next; 144 my $tex = $::CONN->{face}[$num]{texture} || next;
116 145
117 glBindTexture GL_TEXTURE_2D, $tex->{name}; 146 glBindTexture GL_TEXTURE_2D, $tex->{name};
118 147
119 glBegin GL_QUADS; 148 glBegin GL_QUADS;
120 glTexCoord 0, 0; glVertex $x, $y; 149 glTexCoord 0, 0; glVertex $x * 32 , $y * 32;
121 glTexCoord 0, 1; glVertex $x, $y + 1; 150 glTexCoord 0, 1; glVertex $x * 32 , $y * 32 + 32;
122 glTexCoord 1, 1; glVertex $x + 1, $y + 1; 151 glTexCoord 1, 1; glVertex $x * 32 + 32, $y * 32 + 32;
123 glTexCoord 1, 0; glVertex $x + 1, $y; 152 glTexCoord 1, 0; glVertex $x * 32 + 32, $y * 32;
124 glEnd; 153 glEnd;
125 } 154 }
126 } 155 }
127 } 156 }
128
129 glPopMatrix;
130 157
131 glDisable GL_TEXTURE_2D; 158 glDisable GL_TEXTURE_2D;
132 glDisable GL_BLEND; 159 glDisable GL_BLEND;
133} 160}
134 161

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines