ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
Revision: 1.4
Committed: Fri Apr 7 18:49:53 2006 UTC (18 years, 2 months ago) by root
Branch: MAIN
Changes since 1.3: +12 -2 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 elmex 1.1 package Client::Widget;
2     use strict;
3    
4     our $FOCUS; # the widget with current focus
5 elmex 1.2 our %ACTIVE_WIDGETS;
6 elmex 1.1
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 elmex 1.2 sub activate {
21     $ACTIVE_WIDGETS{$_[0]} = $_[0];
22     }
23 root 1.4
24 elmex 1.2 sub deactivate {
25     delete $ACTIVE_WIDGETS{$_[0]};
26     }
27    
28 elmex 1.1 sub focus_in {
29     my ($widget) = @_;
30     $FOCUS = $widget;
31     }
32 root 1.4
33 elmex 1.1 sub focus_out {
34     my ($widget) = @_;
35     }
36 root 1.4
37 elmex 1.1 sub key_down {
38     my ($widget, $sdlev) = @_;
39     }
40 root 1.4
41 elmex 1.1 sub key_up {
42     my ($widget, $sdlev) = @_;
43     }
44 root 1.4
45 elmex 1.1 sub button_down {
46     my ($widget, $sdlev) = @_;
47     }
48 root 1.4
49 elmex 1.1 sub button_up {
50     my ($widget, $sdlev) = @_;
51     }
52 root 1.4
53 elmex 1.1 sub draw {
54     my ($widget) = @_;
55     }
56 root 1.4
57 elmex 1.1 sub bbox {
58     my ($widget) = @_;
59     }
60 elmex 1.2
61 elmex 1.3 package Client::TextView;
62 root 1.4
63 elmex 1.3 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 elmex 1.2 package Client::MapWidget;
80 root 1.4
81 elmex 1.2 use strict;
82     our @ISA = qw/Client::Widget/;
83    
84     use SDL::OpenGL;
85     use SDL::OpenGL::Constants;
86    
87     sub key_down {
88     print "MAPKEYDOWN\n";
89     }
90    
91     sub key_up {
92     }
93    
94     sub draw {
95     glEnable GL_TEXTURE_2D;
96     glEnable GL_BLEND;
97    
98     my $map = $::CONN->{map};
99    
100     for my $x (0 .. $::CONN->{mapw} - 1) {
101     for my $y (0 .. $::CONN->{maph} - 1) {
102    
103     my $cell = $map->[$x][$y]
104     or next;
105    
106     my $darkness = $cell->[3] * (1 / 255);
107     glColor $darkness, $darkness, $darkness;
108    
109     for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) {
110 root 1.4 my $tex = $::CONN->{face}[$num]{texture} || next;
111 elmex 1.2
112 root 1.4 glBindTexture GL_TEXTURE_2D, $tex->{name};
113 elmex 1.2
114     glBegin GL_QUADS;
115     glTexCoord 0, 0; glVertex $x, $y;
116     glTexCoord 0, 1; glVertex $x, $y + 1;
117     glTexCoord 1, 1; glVertex $x + 1, $y + 1;
118     glTexCoord 1, 0; glVertex $x + 1, $y;
119     glEnd;
120     }
121     }
122     }
123    
124     glDisable GL_TEXTURE_2D;
125     glDisable GL_BLEND;
126     }
127    
128 elmex 1.1 1;