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

# 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.9 package Crossfire::Client::Widget::TextView;
63 root 1.4
64 elmex 1.3 use strict;
65 elmex 1.9 our @ISA = qw/Crossfire::Client::Widget/;
66 elmex 1.3
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 elmex 1.9 package Crossfire::Client::Widget::MapWidget;
81 root 1.4
82 elmex 1.2 use strict;
83 elmex 1.7
84 elmex 1.9 our @ISA = qw/Crossfire::Client::Widget/;
85 elmex 1.2
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 root 1.4 my $tex = $::CONN->{face}[$num]{texture} || next;
113 elmex 1.2
114 root 1.4 glBindTexture GL_TEXTURE_2D, $tex->{name};
115 elmex 1.2
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 elmex 1.1 1;
131 root 1.5