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.5 by root, Fri Apr 7 19:33:42 2006 UTC vs.
Revision 1.10 by root, Fri Apr 7 20:34:44 2006 UTC

1package 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;
115
82our @ISA = qw/Client::Widget/; 116our @ISA = qw/Crossfire::Client::Widget/;
83 117
84use SDL::OpenGL; 118use SDL::OpenGL;
85use SDL::OpenGL::Constants; 119use SDL::OpenGL::Constants;
86 120
87sub key_down { 121sub key_down {
89} 123}
90 124
91sub key_up { 125sub key_up {
92} 126}
93 127
94my $x;
95
96sub draw { 128sub draw {
97 glEnable GL_TEXTURE_2D; 129 glEnable GL_TEXTURE_2D;
98 glEnable GL_BLEND; 130 glEnable GL_BLEND;
99
100 glPushMatrix;
101 131
102 my $map = $::CONN->{map}; 132 my $map = $::CONN->{map};
103 133
104 for my $x (0 .. $::CONN->{mapw} - 1) { 134 for my $x (0 .. $::CONN->{mapw} - 1) {
105 for my $y (0 .. $::CONN->{maph} - 1) { 135 for my $y (0 .. $::CONN->{maph} - 1) {
114 my $tex = $::CONN->{face}[$num]{texture} || next; 144 my $tex = $::CONN->{face}[$num]{texture} || next;
115 145
116 glBindTexture GL_TEXTURE_2D, $tex->{name}; 146 glBindTexture GL_TEXTURE_2D, $tex->{name};
117 147
118 glBegin GL_QUADS; 148 glBegin GL_QUADS;
119 glTexCoord 0, 0; glVertex $x, $y; 149 glTexCoord 0, 0; glVertex $x * 32 , $y * 32;
120 glTexCoord 0, 1; glVertex $x, $y + 1; 150 glTexCoord 0, 1; glVertex $x * 32 , $y * 32 + 32;
121 glTexCoord 1, 1; glVertex $x + 1, $y + 1; 151 glTexCoord 1, 1; glVertex $x * 32 + 32, $y * 32 + 32;
122 glTexCoord 1, 0; glVertex $x + 1, $y; 152 glTexCoord 1, 0; glVertex $x * 32 + 32, $y * 32;
123 glEnd; 153 glEnd;
124 } 154 }
125 } 155 }
126 } 156 }
127
128 glPopMatrix;
129 157
130 glDisable GL_TEXTURE_2D; 158 glDisable GL_TEXTURE_2D;
131 glDisable GL_BLEND; 159 glDisable GL_BLEND;
132} 160}
133 161

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines