ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
Revision: 1.5
Committed: Fri Apr 7 19:33:42 2006 UTC (18 years, 2 months ago) by root
Branch: MAIN
Changes since 1.4: +7 -0 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 root 1.5 my $x;
95    
96 elmex 1.2 sub draw {
97     glEnable GL_TEXTURE_2D;
98     glEnable GL_BLEND;
99    
100 root 1.5 glPushMatrix;
101    
102 elmex 1.2 my $map = $::CONN->{map};
103    
104     for my $x (0 .. $::CONN->{mapw} - 1) {
105     for my $y (0 .. $::CONN->{maph} - 1) {
106    
107     my $cell = $map->[$x][$y]
108     or next;
109    
110     my $darkness = $cell->[3] * (1 / 255);
111     glColor $darkness, $darkness, $darkness;
112    
113     for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) {
114 root 1.4 my $tex = $::CONN->{face}[$num]{texture} || next;
115 elmex 1.2
116 root 1.4 glBindTexture GL_TEXTURE_2D, $tex->{name};
117 elmex 1.2
118     glBegin GL_QUADS;
119     glTexCoord 0, 0; glVertex $x, $y;
120     glTexCoord 0, 1; glVertex $x, $y + 1;
121     glTexCoord 1, 1; glVertex $x + 1, $y + 1;
122     glTexCoord 1, 0; glVertex $x + 1, $y;
123     glEnd;
124     }
125     }
126     }
127    
128 root 1.5 glPopMatrix;
129    
130 elmex 1.2 glDisable GL_TEXTURE_2D;
131     glDisable GL_BLEND;
132     }
133    
134 elmex 1.1 1;
135 root 1.5