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.3 by elmex, Fri Apr 7 18:16:51 2006 UTC vs.
Revision 1.11 by elmex, Fri Apr 7 20:39:58 2006 UTC

1package Client::Widget; 1package Crossfire::Client::Widget;
2
2use strict; 3use strict;
4use SDL::OpenGL;
5use SDL::OpenGL::Constants;
3 6
4our $FOCUS; # the widget with current focus 7our $FOCUS; # the widget with current focus
5our %ACTIVE_WIDGETS; 8our %ACTIVE_WIDGETS;
6 9
7# class methods for events 10# class methods for events
10sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS } 13sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS }
11sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS } 14sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS }
12 15
13sub new { 16sub new {
14 my $class = shift; 17 my $class = shift;
15 my $self = { @_ }; 18
16 bless $self, $class; 19 bless { @_ }, $class
17 return $self;
18} 20}
19 21
20sub activate { 22sub activate {
21 $ACTIVE_WIDGETS{$_[0]} = $_[0]; 23 $ACTIVE_WIDGETS{$_[0]} = $_[0];
22} 24}
25
23sub deactivate { 26sub deactivate {
24 delete $ACTIVE_WIDGETS{$_[0]}; 27 delete $ACTIVE_WIDGETS{$_[0]};
25} 28}
26 29
27sub focus_in { 30sub focus_in {
28 my ($widget) = @_; 31 my ($widget) = @_;
29 $FOCUS = $widget; 32 $FOCUS = $widget;
30} 33}
34
31sub focus_out { 35sub focus_out {
32 my ($widget) = @_; 36 my ($widget) = @_;
33} 37}
38
34sub key_down { 39sub key_down {
35 my ($widget, $sdlev) = @_; 40 my ($widget, $sdlev) = @_;
36} 41}
42
37sub key_up { 43sub key_up {
38 my ($widget, $sdlev) = @_; 44 my ($widget, $sdlev) = @_;
39} 45}
46
40sub button_down { 47sub button_down {
41 my ($widget, $sdlev) = @_; 48 my ($widget, $sdlev) = @_;
42} 49}
50
43sub button_up { 51sub button_up {
44 my ($widget, $sdlev) = @_; 52 my ($widget, $sdlev) = @_;
45} 53}
54
55sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} }
56sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} }
57
46sub 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 {
47 my ($widget) = @_; 68 my ($widget) = @_;
48} 69}
70
49sub bbox { 71sub bbox {
50 my ($widget) = @_; 72 my ($widget) = @_;
51} 73}
52 74
53package Client::TextView; 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
107package Crossfire::Client::Widget::TextView;
108
54use strict; 109use strict;
110
55our @ISA = qw/Client::Widget/; 111our @ISA = qw/Crossfire::Client::Widget/;
56 112
57use SDL::OpenGL; 113use SDL::OpenGL;
58use SDL::OpenGL::Constants; 114use SDL::OpenGL::Constants;
59 115
60sub add_line { 116sub add_line {
61 my ($self, $line) = @_; 117 my ($self, $line) = @_;
62 push @{$self->{lines}}, $line; 118 push @{$self->{lines}}, $line;
63} 119}
64 120
65sub draw { 121sub _draw {
66 my ($self) = @_; 122 my ($self) = @_;
67 123
68} 124}
69 125
70package Client::MapWidget; 126package Crossfire::Client::Widget::MapWidget;
127
71use strict; 128use strict;
129
72our @ISA = qw/Client::Widget/; 130our @ISA = qw/Crossfire::Client::Widget/;
73 131
74use SDL::OpenGL; 132use SDL::OpenGL;
75use SDL::OpenGL::Constants; 133use SDL::OpenGL::Constants;
76 134
77sub key_down { 135sub key_down {
79} 137}
80 138
81sub key_up { 139sub key_up {
82} 140}
83 141
84sub draw { 142sub _draw {
85 glEnable GL_TEXTURE_2D; 143 glEnable GL_TEXTURE_2D;
86 glEnable GL_BLEND; 144 glEnable GL_BLEND;
87 145
88 my $map = $::CONN->{map}; 146 my $map = $::CONN->{map};
89 147
95 153
96 my $darkness = $cell->[3] * (1 / 255); 154 my $darkness = $cell->[3] * (1 / 255);
97 glColor $darkness, $darkness, $darkness; 155 glColor $darkness, $darkness, $darkness;
98 156
99 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { 157 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) {
100 my $tex = $::CONN->{face}[$num]{texture} || 0; 158 my $tex = $::CONN->{face}[$num]{texture} || next;
101 159
102 glBindTexture GL_TEXTURE_2D, $tex; 160 glBindTexture GL_TEXTURE_2D, $tex->{name};
103 161
104 glBegin GL_QUADS; 162 glBegin GL_QUADS;
105 glTexCoord 0, 0; glVertex $x, $y; 163 glTexCoord 0, 0; glVertex $x * 32 , $y * 32;
106 glTexCoord 0, 1; glVertex $x, $y + 1; 164 glTexCoord 0, 1; glVertex $x * 32 , $y * 32 + 32;
107 glTexCoord 1, 1; glVertex $x + 1, $y + 1; 165 glTexCoord 1, 1; glVertex $x * 32 + 32, $y * 32 + 32;
108 glTexCoord 1, 0; glVertex $x + 1, $y; 166 glTexCoord 1, 0; glVertex $x * 32 + 32, $y * 32;
109 glEnd; 167 glEnd;
110 } 168 }
111 } 169 }
112 } 170 }
113 171
114 glDisable GL_TEXTURE_2D; 172 glDisable GL_TEXTURE_2D;
115 glDisable GL_BLEND; 173 glDisable GL_BLEND;
116} 174}
117 175
1181; 1761;
177

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines