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

File Contents

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