ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
Revision: 1.9
Committed: Fri Apr 7 20:09:52 2006 UTC (18 years, 2 months ago) by elmex
Branch: MAIN
Changes since 1.8: +4 -5 lines
Log Message:
fixed ISA

File Contents

# Content
1 package Crossfire::Client::Widget;
2
3 use strict;
4
5 our $FOCUS; # the widget with current focus
6 our %ACTIVE_WIDGETS;
7
8 # class methods for events
9 sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS }
10 sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS }
11 sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS }
12 sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS }
13
14 sub new {
15 my $class = shift;
16 my $self = { @_ };
17 bless $self, $class;
18 return $self;
19 }
20
21 sub activate {
22 $ACTIVE_WIDGETS{$_[0]} = $_[0];
23 }
24
25 sub deactivate {
26 delete $ACTIVE_WIDGETS{$_[0]};
27 }
28
29 sub focus_in {
30 my ($widget) = @_;
31 $FOCUS = $widget;
32 }
33
34 sub focus_out {
35 my ($widget) = @_;
36 }
37
38 sub key_down {
39 my ($widget, $sdlev) = @_;
40 }
41
42 sub key_up {
43 my ($widget, $sdlev) = @_;
44 }
45
46 sub button_down {
47 my ($widget, $sdlev) = @_;
48 }
49
50 sub button_up {
51 my ($widget, $sdlev) = @_;
52 }
53
54 sub draw {
55 my ($widget) = @_;
56 }
57
58 sub bbox {
59 my ($widget) = @_;
60 }
61
62 package Crossfire::Client::Widget::TextView;
63
64 use strict;
65 our @ISA = qw/Crossfire::Client::Widget/;
66
67 use SDL::OpenGL;
68 use SDL::OpenGL::Constants;
69
70 sub add_line {
71 my ($self, $line) = @_;
72 push @{$self->{lines}}, $line;
73 }
74
75 sub draw {
76 my ($self) = @_;
77
78 }
79
80 package Crossfire::Client::Widget::MapWidget;
81
82 use strict;
83
84 our @ISA = qw/Crossfire::Client::Widget/;
85
86 use SDL::OpenGL;
87 use SDL::OpenGL::Constants;
88
89 sub key_down {
90 print "MAPKEYDOWN\n";
91 }
92
93 sub key_up {
94 }
95
96 sub draw {
97 glEnable GL_TEXTURE_2D;
98 glEnable GL_BLEND;
99
100 my $map = $::CONN->{map};
101
102 for my $x (0 .. $::CONN->{mapw} - 1) {
103 for my $y (0 .. $::CONN->{maph} - 1) {
104
105 my $cell = $map->[$x][$y]
106 or next;
107
108 my $darkness = $cell->[3] * (1 / 255);
109 glColor $darkness, $darkness, $darkness;
110
111 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) {
112 my $tex = $::CONN->{face}[$num]{texture} || next;
113
114 glBindTexture GL_TEXTURE_2D, $tex->{name};
115
116 glBegin GL_QUADS;
117 glTexCoord 0, 0; glVertex $x, $y;
118 glTexCoord 0, 1; glVertex $x, $y + 1;
119 glTexCoord 1, 1; glVertex $x + 1, $y + 1;
120 glTexCoord 1, 0; glVertex $x + 1, $y;
121 glEnd;
122 }
123 }
124 }
125
126 glDisable GL_TEXTURE_2D;
127 glDisable GL_BLEND;
128 }
129
130 1;
131