ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
Revision: 1.7
Committed: Fri Apr 7 20:04:59 2006 UTC (18 years, 2 months ago) by elmex
Branch: MAIN
Changes since 1.6: +1 -0 lines
Log Message:
*** empty log message ***

File Contents

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