ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.260 by elmex, Tue May 30 14:35:09 2006 UTC vs.
Revision 1.266 by root, Thu Jun 1 03:42:58 2006 UTC

40 40
41 $LAYOUT = $layout; 41 $LAYOUT = $layout;
42} 42}
43 43
44sub check_tooltip { 44sub check_tooltip {
45 return if $ENV{CFPLUS_DEBUG} & 8;
46
45 if (!$GRAB) { 47 if (!$GRAB) {
46 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 48 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
47 if (length $widget->{tooltip}) { 49 if (length $widget->{tooltip}) {
48
49 if ($TOOLTIP->{owner} != $widget) { 50 if ($TOOLTIP->{owner} != $widget) {
50 $TOOLTIP->hide; 51 $TOOLTIP->hide;
51 52
52 $TOOLTIP->{owner} = $widget; 53 $TOOLTIP->{owner} = $widget;
53 54
1522} 1523}
1523 1524
1524sub size_allocate { 1525sub size_allocate {
1525 my ($self, $w, $h) = @_; 1526 my ($self, $w, $h) = @_;
1526 1527
1527 delete $self->{texture}; 1528 delete $self->{texture}
1529 unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w};
1528} 1530}
1529 1531
1530sub set_fontsize { 1532sub set_fontsize {
1531 my ($self, $fontsize) = @_; 1533 my ($self, $fontsize) = @_;
1532 1534
2776 2778
2777 $self->{timer}->cancel 2779 $self->{timer}->cancel
2778 if $self->{timer}; 2780 if $self->{timer};
2779 2781
2780 $self->SUPER::DESTROY; 2782 $self->SUPER::DESTROY;
2781}
2782
2783#############################################################################
2784
2785package CFClient::UI::Inventory;
2786
2787our @ISA = CFClient::UI::ScrolledWindow::;
2788
2789sub new {
2790 my $class = shift;
2791
2792 my $self = $class->SUPER::new (
2793 scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]),
2794 @_,
2795 );
2796
2797 $self
2798}
2799
2800sub set_items {
2801 my ($self, $items) = @_;
2802
2803 $self->{scrolled}->clear;
2804 return unless $items;
2805
2806 my @items = sort {
2807 ($a->{type} <=> $b->{type})
2808 or ($a->{name} cmp $b->{name})
2809 } @$items;
2810
2811 $self->{real_items} = \@items;
2812
2813 my $row = 0;
2814 for my $item (@items) {
2815 CFClient::Item::update_widgets $item;
2816
2817 $self->{scrolled}->add (0, $row, $item->{face_widget});
2818 $self->{scrolled}->add (1, $row, $item->{desc_widget});
2819 $self->{scrolled}->add (2, $row, $item->{weight_widget});
2820
2821 $row++;
2822 }
2823} 2783}
2824 2784
2825############################################################################# 2785#############################################################################
2826 2786
2827package CFClient::UI::Menu; 2787package CFClient::UI::Menu;
3004 $self->SUPER::reconfigure; 2964 $self->SUPER::reconfigure;
3005} 2965}
3006 2966
3007############################################################################# 2967#############################################################################
3008 2968
3009package CFClient::UI::Root; 2969package CFClient::UI::Inventory;
3010 2970
3011our @ISA = CFClient::UI::Container::; 2971our @ISA = CFClient::UI::ScrolledWindow::;
3012
3013use CFClient::OpenGL;
3014 2972
3015sub new { 2973sub new {
3016 my $class = shift; 2974 my $class = shift;
3017 2975
3018 my $self = $class->SUPER::new ( 2976 my $self = $class->SUPER::new (
3019 visible => 1, 2977 scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]),
3020 @_, 2978 @_,
3021 ); 2979 );
3022 2980
3023 Scalar::Util::weaken ($self->{root} = $self);
3024
3025 $self 2981 $self
3026} 2982}
3027 2983
3028sub size_request { 2984sub set_items {
3029 my ($self) = @_; 2985 my ($self, $items) = @_;
3030 2986
3031 ($self->{w}, $self->{h}) 2987 $self->{scrolled}->clear;
3032} 2988 return unless $items;
3033 2989
3034sub _to_pixel { 2990 my @items = sort {
3035 my ($coord, $size, $max) = @_; 2991 ($a->{type} <=> $b->{type})
2992 or ($a->{name} cmp $b->{name})
2993 } @$items;
3036 2994
3037 $coord = 2995 $self->{real_items} = \@items;
3038 $coord eq "center" ? ($max - $size) * 0.5
3039 : $coord eq "max" ? $max
3040 : $coord;
3041 2996
3042 $coord = 0 if $coord < 0; 2997 my $row = 0;
3043 $coord = $max - $size if $coord > $max - $size; 2998 for my $item (@items) {
2999 CFClient::Item::update_widgets $item;
3044 3000
3045 int $coord + 0.5 3001 $self->{scrolled}->add (0, $row, $item->{face_widget});
3046} 3002 $self->{scrolled}->add (1, $row, $item->{desc_widget});
3003 $self->{scrolled}->add (2, $row, $item->{weight_widget});
3047 3004
3048sub size_allocate { 3005 $row++;
3049 my ($self, $w, $h) = @_;
3050
3051 for my $child ($self->children) {
3052 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
3053
3054 $X = $child->{force_x} if exists $child->{force_x};
3055 $Y = $child->{force_y} if exists $child->{force_y};
3056
3057 $X = _to_pixel $X, $W, $self->{w};
3058 $Y = _to_pixel $Y, $H, $self->{h};
3059
3060 $child->configure ($X, $Y, $W, $H);
3061 } 3006 }
3062}
3063
3064sub coord2local {
3065 my ($self, $x, $y) = @_;
3066
3067 ($x, $y)
3068}
3069
3070sub coord2global {
3071 my ($self, $x, $y) = @_;
3072
3073 ($x, $y)
3074}
3075
3076sub update {
3077 my ($self) = @_;
3078
3079 $::WANT_REFRESH++;
3080}
3081
3082sub add {
3083 my ($self, @children) = @_;
3084
3085 $_->{is_toplevel} = 1
3086 for @children;
3087
3088 $self->SUPER::add (@children);
3089}
3090
3091sub remove {
3092 my ($self, @children) = @_;
3093
3094 $self->SUPER::remove (@children);
3095
3096 delete $self->{is_toplevel}
3097 for @children;
3098
3099 while (@children) {
3100 my $w = pop @children;
3101 push @children, $w->children;
3102 $w->set_invisible;
3103 }
3104}
3105
3106sub on_refresh {
3107 my ($self, $id, $cb) = @_;
3108
3109 $self->{refresh_hook}{$id} = $cb;
3110}
3111
3112sub on_post_alloc {
3113 my ($self, $id, $cb) = @_;
3114
3115 $self->{post_alloc_hook}{$id} = $cb;
3116}
3117
3118sub draw {
3119 my ($self) = @_;
3120
3121 while ($self->{refresh_hook}) {
3122 $_->()
3123 for values %{delete $self->{refresh_hook}};
3124 }
3125
3126 if ($self->{realloc}) {
3127 my @queue;
3128
3129 while () {
3130 if ($self->{realloc}) {
3131 #TODO use array-of-depth approach
3132
3133 use sort 'stable';
3134
3135 @queue = sort { $a->{visible} <=> $b->{visible} }
3136 @queue, values %{delete $self->{realloc}};
3137 }
3138
3139 my $widget = pop @queue || last;
3140
3141 $widget->{visible} or last; # do not resize invisible widgets
3142
3143 my ($w, $h) = $widget->size_request;
3144
3145 $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2;
3146 $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2;
3147
3148 $w = $widget->{force_w} if exists $widget->{force_w};
3149 $h = $widget->{force_h} if exists $widget->{force_h};
3150
3151 if ($widget->{req_w} != $w || $widget->{req_h} != $h
3152 || delete $widget->{force_realloc}) {
3153 $widget->{req_w} = $w;
3154 $widget->{req_h} = $h;
3155
3156 $self->{size_alloc}{$widget+0} = $widget;
3157
3158 if (my $parent = $widget->{parent}) {
3159 $self->{realloc}{$parent+0} = $parent;
3160 #unshift @queue, $parent;
3161 $parent->{force_size_alloc} = 1;
3162 $self->{size_alloc}{$parent+0} = $parent;
3163 }
3164 }
3165
3166 delete $self->{realloc}{$widget+0};
3167 }
3168 }
3169
3170 while (my $size_alloc = delete $self->{size_alloc}) {
3171 my @queue = sort { $b->{visible} <=> $a->{visible} }
3172 values %$size_alloc;
3173
3174 while () {
3175 my $widget = pop @queue || last;
3176
3177 my ($w, $h) = @$widget{qw(alloc_w alloc_h)};
3178
3179 $w = 0 if $w < 0;
3180 $h = 0 if $h < 0;
3181
3182 $w = int $w + 0.5;
3183 $h = int $h + 0.5;
3184
3185 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) {
3186 $widget->{w} = $w;
3187 $widget->{h} = $h;
3188
3189 $widget->emit (size_allocate => $w, $h);
3190 }
3191 }
3192 }
3193
3194 while ($self->{post_alloc_hook}) {
3195 $_->()
3196 for values %{delete $self->{post_alloc_hook}};
3197 }
3198
3199
3200 glViewport 0, 0, $::WIDTH, $::HEIGHT;
3201 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
3202 glClear GL_COLOR_BUFFER_BIT;
3203
3204 glMatrixMode GL_PROJECTION;
3205 glLoadIdentity;
3206 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3207 glMatrixMode GL_MODELVIEW;
3208 glLoadIdentity;
3209
3210 $self->_draw;
3211} 3007}
3212 3008
3213############################################################################# 3009#############################################################################
3214 3010
3215package CFClient::UI::BindEditor; 3011package CFClient::UI::BindEditor;
3221 3017
3222 my $self = $class->SUPER::new (binding => [], commands => [], @_); 3018 my $self = $class->SUPER::new (binding => [], commands => [], @_);
3223 3019
3224 $self->add (my $vb = new CFClient::UI::VBox); 3020 $self->add (my $vb = new CFClient::UI::VBox);
3225 3021
3226 $vb->add (my $hb = new CFClient::UI::HBox);
3227 $hb->add (new CFClient::UI::Label text => "Key: ");
3228 $hb->add ($self->{keylbl} = new CFClient::UI::Label);
3229 $hb->add (new CFClient::UI::Button
3230 text => "bind",
3231 tooltip => "This opens a query where you have to press the key combination to bind the recorded actions",
3232 on_activate => sub {
3233 $self->ask_for_bind;
3234 });
3235 3022
3236 $vb->add (new CFClient::UI::Label text => "Actions:");
3237 $vb->add ($self->{rec_btn} = new CFClient::UI::Button 3023 $vb->add ($self->{rec_btn} = new CFClient::UI::Button
3238 text => "start recording", 3024 text => "start recording",
3239 tooltip => "Start/Stops recording of actions." 3025 tooltip => "Start/Stops recording of actions."
3240 ."All subsequent actions after the recording started will be captured." 3026 ."All subsequent actions after the recording started will be captured."
3241 ."The actions are displayed after the record was stopped." 3027 ."The actions are displayed after the record was stopped."
3246 } else { 3032 } else {
3247 $self->stop; 3033 $self->stop;
3248 } 3034 }
3249 }); 3035 });
3250 3036
3037 $vb->add (new CFClient::UI::Label text => "Actions:");
3251 $vb->add ($self->{cmdbox} = new CFClient::UI::VBox); 3038 $vb->add ($self->{cmdbox} = new CFClient::UI::VBox);
3039
3040 $vb->add (new CFClient::UI::Label text => "Bound to: ");
3041 $vb->add (my $hb = new CFClient::UI::HBox);
3042 $hb->add ($self->{keylbl} = new CFClient::UI::Label expand => 1);
3043 $hb->add (new CFClient::UI::Button
3044 text => "bind",
3045 tooltip => "This opens a query where you have to press the key combination to bind the recorded actions",
3046 on_activate => sub {
3047 $self->ask_for_bind;
3048 });
3252 3049
3253 $vb->add (my $hb = new CFClient::UI::HBox); 3050 $vb->add (my $hb = new CFClient::UI::HBox);
3254 $hb->add (new CFClient::UI::Button 3051 $hb->add (new CFClient::UI::Button
3255 text => "ok", 3052 text => "ok",
3053 expand => 1,
3256 tooltip => "This closes the binding editor and saves the binding", 3054 tooltip => "This closes the binding editor and saves the binding",
3257 on_activate => sub { 3055 on_activate => sub {
3258 $self->hide; 3056 $self->hide;
3259 $self->commit; 3057 $self->commit;
3260 }); 3058 });
3261 3059
3262 $hb->add (new CFClient::UI::Button 3060 $hb->add (new CFClient::UI::Button
3263 text => "cancel", 3061 text => "cancel",
3062 expand => 1,
3264 tooltip => "This closes the binding editor without saving", 3063 tooltip => "This closes the binding editor without saving",
3265 on_activate => sub { 3064 on_activate => sub {
3266 $self->hide; 3065 $self->hide;
3267 $self->{binding_cancel}->() 3066 $self->{binding_cancel}->()
3268 if $self->{binding_cancel}; 3067 if $self->{binding_cancel};
3280 $::STATUSBOX->add ("Bound actions to '".CFClient::Binder::keycombo_to_name ($mod, $sym) 3079 $::STATUSBOX->add ("Bound actions to '".CFClient::Binder::keycombo_to_name ($mod, $sym)
3281 ."'. Don't forget 'Save Config'!"); 3080 ."'. Don't forget 'Save Config'!");
3282 $self->{binding_change}->($mod, $sym, $cmds) 3081 $self->{binding_change}->($mod, $sym, $cmds)
3283 if $self->{binding_change}; 3082 if $self->{binding_change};
3284 } else { 3083 } else {
3285 $::STATUSBOX->add ("No action bound, no keys specified!"); 3084 $::STATUSBOX->add ("No action bound, no key or action specified!");
3286 $self->{binding_cancel}->() 3085 $self->{binding_cancel}->()
3287 if $self->{binding_cancel}; 3086 if $self->{binding_cancel};
3288 } 3087 }
3289} 3088}
3290 3089
3307 $rec = $::CONN->stop_record if $::CONN; 3106 $rec = $::CONN->stop_record if $::CONN;
3308 return unless ref $rec eq 'ARRAY'; 3107 return unless ref $rec eq 'ARRAY';
3309 $self->set_command_list ($rec); 3108 $self->set_command_list ($rec);
3310} 3109}
3311 3110
3111# if $commit is true, the binding will be set after the user entered a key combo
3312sub ask_for_bind { 3112sub ask_for_bind {
3313 my ($self, $commit) = @_; 3113 my ($self, $commit) = @_;
3314 3114
3315 CFClient::Binder::open_binding_dialog (sub { 3115 CFClient::Binder::open_binding_dialog (sub {
3316 my ($mod, $sym) = @_; 3116 my ($mod, $sym) = @_;
3318 $self->update_binding_widgets; 3118 $self->update_binding_widgets;
3319 $self->commit if $commit; 3119 $self->commit if $commit;
3320 }); 3120 });
3321} 3121}
3322 3122
3123# $mod and $sym are the modifiers and key symbol
3124# $cmds is a array ref of strings (the commands)
3125# $cb is the callback that is executed on OK
3126# $ccb is the callback that is executed on CANCEL and
3127# when the binding was unsuccessful on OK
3323sub set_binding { 3128sub set_binding {
3324 my ($self, $mod, $sym, $cmds, $cb, $ccb) = @_; 3129 my ($self, $mod, $sym, $cmds, $cb, $ccb) = @_;
3325 3130
3326 $self->clear_command_list; 3131 $self->clear_command_list;
3327 $self->{recording} = 0; 3132 $self->{recording} = 0;
3332 3137
3333 $self->{binding_change} = $cb; 3138 $self->{binding_change} = $cb;
3334 $self->{binding_cancel} = $ccb; 3139 $self->{binding_cancel} = $ccb;
3335 3140
3336 $self->update_binding_widgets; 3141 $self->update_binding_widgets;
3142}
3143
3144# this is a shortcut method that asks for a binding
3145# and then just binds it.
3146sub do_quick_binding {
3147 my ($self, $cmds) = @_;
3148 $self->set_binding (undef, undef, $cmds, sub {
3149 $::CFG->{bindings}->{$_[0]}->{$_[1]} = $_[2];
3150 });
3151 $self->ask_for_bind (1);
3337} 3152}
3338 3153
3339sub update_binding_widgets { 3154sub update_binding_widgets {
3340 my ($self) = @_; 3155 my ($self) = @_;
3341 my ($mod, $sym, $cmds) = $self->get_binding; 3156 my ($mod, $sym, $cmds) = $self->get_binding;
3367 3182
3368 for (@$cmds) { 3183 for (@$cmds) {
3369 $self->{cmdbox}->add (my $hb = new CFClient::UI::HBox); 3184 $self->{cmdbox}->add (my $hb = new CFClient::UI::HBox);
3370 3185
3371 my $i = $idx; 3186 my $i = $idx;
3187 $hb->add (new CFClient::UI::Label text => $_);
3372 $hb->add (new CFClient::UI::Button 3188 $hb->add (new CFClient::UI::Button
3373 text => "delete", 3189 text => "delete",
3374 tooltip => "Deletes the action from the record", 3190 tooltip => "Deletes the action from the record",
3375 on_activate => sub { 3191 on_activate => sub {
3376 $self->{cmdbox}->remove ($hb); 3192 $self->{cmdbox}->remove ($hb);
3377 $cmds->[$i] = undef; 3193 $cmds->[$i] = undef;
3378 }); 3194 });
3379 3195
3380 $hb->add (new CFClient::UI::Label text => $_);
3381 3196
3382 $idx++ 3197 $idx++
3383 } 3198 }
3384} 3199}
3385 3200
3201#############################################################################
3202
3203package CFClient::UI::SpellList;
3204
3205our @ISA = CFClient::UI::FancyFrame::;
3206
3207sub new {
3208 my $class = shift;
3209
3210 my $self = $class->SUPER::new (binding => [], commands => [], @_);
3211
3212 $self->add (new CFClient::UI::ScrolledWindow
3213 scrolled => $self->{spellbox} = new CFClient::UI::Table);
3214
3215 $self;
3216}
3217
3218# XXX: Do sorting? Argl...
3219sub add_spell {
3220 my ($self, $spell) = @_;
3221 $self->{spells}->{$spell->{name}} = $spell;
3222
3223 $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face
3224 face => $spell->{face},
3225 can_hover => 1,
3226 can_events => 1,
3227 tooltip => $spell->{message});
3228
3229 $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label
3230 text => $spell->{name},
3231 can_hover => 1,
3232 can_events => 1,
3233 tooltip => $spell->{message},
3234 expand => 1);
3235
3236 $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label
3237 text => (sprintf "lvl: %2d sp: %2d dmg: %2d",
3238 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}),
3239 expand => 1);
3240
3241 $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button
3242 text => "bind to key",
3243 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) });
3244}
3245
3246sub rebuild_spell_list {
3247 my ($self) = @_;
3248 $self->{tbl_idx} = 0;
3249 $self->add_spell ($_) for values %{$self->{spells}};
3250}
3251
3252sub remove_spell {
3253 my ($self, $spell) = @_;
3254 delete $self->{spells}->{$spell->{name}};
3255 $self->rebuild_spell_list;
3256}
3257
3258#############################################################################
3259
3260package CFClient::UI::Root;
3261
3262our @ISA = CFClient::UI::Container::;
3263
3264use CFClient::OpenGL;
3265
3266sub new {
3267 my $class = shift;
3268
3269 my $self = $class->SUPER::new (
3270 visible => 1,
3271 @_,
3272 );
3273
3274 Scalar::Util::weaken ($self->{root} = $self);
3275
3276 $self
3277}
3278
3279sub size_request {
3280 my ($self) = @_;
3281
3282 ($self->{w}, $self->{h})
3283}
3284
3285sub _to_pixel {
3286 my ($coord, $size, $max) = @_;
3287
3288 $coord =
3289 $coord eq "center" ? ($max - $size) * 0.5
3290 : $coord eq "max" ? $max
3291 : $coord;
3292
3293 $coord = 0 if $coord < 0;
3294 $coord = $max - $size if $coord > $max - $size;
3295
3296 int $coord + 0.5
3297}
3298
3299sub size_allocate {
3300 my ($self, $w, $h) = @_;
3301
3302 for my $child ($self->children) {
3303 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
3304
3305 $X = $child->{force_x} if exists $child->{force_x};
3306 $Y = $child->{force_y} if exists $child->{force_y};
3307
3308 $X = _to_pixel $X, $W, $self->{w};
3309 $Y = _to_pixel $Y, $H, $self->{h};
3310
3311 $child->configure ($X, $Y, $W, $H);
3312 }
3313}
3314
3315sub coord2local {
3316 my ($self, $x, $y) = @_;
3317
3318 ($x, $y)
3319}
3320
3321sub coord2global {
3322 my ($self, $x, $y) = @_;
3323
3324 ($x, $y)
3325}
3326
3327sub update {
3328 my ($self) = @_;
3329
3330 $::WANT_REFRESH++;
3331}
3332
3333sub add {
3334 my ($self, @children) = @_;
3335
3336 $_->{is_toplevel} = 1
3337 for @children;
3338
3339 $self->SUPER::add (@children);
3340}
3341
3342sub remove {
3343 my ($self, @children) = @_;
3344
3345 $self->SUPER::remove (@children);
3346
3347 delete $self->{is_toplevel}
3348 for @children;
3349
3350 while (@children) {
3351 my $w = pop @children;
3352 push @children, $w->children;
3353 $w->set_invisible;
3354 }
3355}
3356
3357sub on_refresh {
3358 my ($self, $id, $cb) = @_;
3359
3360 $self->{refresh_hook}{$id} = $cb;
3361}
3362
3363sub on_post_alloc {
3364 my ($self, $id, $cb) = @_;
3365
3366 $self->{post_alloc_hook}{$id} = $cb;
3367}
3368
3369sub draw {
3370 my ($self) = @_;
3371
3372 while ($self->{refresh_hook}) {
3373 $_->()
3374 for values %{delete $self->{refresh_hook}};
3375 }
3376
3377 if ($self->{realloc}) {
3378 my %queue;
3379 my @queue;
3380 my $widget;
3381
3382 outer:
3383 while () {
3384 if (my $realloc = delete $self->{realloc}) {
3385 for $widget (values %$realloc) {
3386 $widget->{visible} or next; # do not resize invisible widgets
3387
3388 $queue{$widget+0}++ and next; # duplicates are common
3389
3390 push @{ $queue[$widget->{visible}] }, $widget;
3391 }
3392 }
3393
3394 while () {
3395 @queue or last outer;
3396
3397 $widget = pop @{ $queue[-1] || [] }
3398 and last;
3399
3400 pop @queue;
3401 }
3402
3403 delete $queue{$widget+0};
3404
3405 my ($w, $h) = $widget->size_request;
3406
3407 $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2;
3408 $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2;
3409
3410 $w = $widget->{force_w} if exists $widget->{force_w};
3411 $h = $widget->{force_h} if exists $widget->{force_h};
3412
3413 if ($widget->{req_w} != $w || $widget->{req_h} != $h
3414 || delete $widget->{force_realloc}) {
3415 $widget->{req_w} = $w;
3416 $widget->{req_h} = $h;
3417
3418 $self->{size_alloc}{$widget+0} = $widget;
3419
3420 if (my $parent = $widget->{parent}) {
3421 $self->{realloc}{$parent+0} = $parent
3422 unless $queue{$parent+0};
3423
3424 $parent->{force_size_alloc} = 1;
3425 $self->{size_alloc}{$parent+0} = $parent;
3426 }
3427 }
3428
3429 delete $self->{realloc}{$widget+0};
3430 }
3431 }
3432
3433 while (my $size_alloc = delete $self->{size_alloc}) {
3434 my @queue = sort { $b->{visible} <=> $a->{visible} }
3435 values %$size_alloc;
3436
3437 while () {
3438 my $widget = pop @queue || last;
3439
3440 my ($w, $h) = @$widget{qw(alloc_w alloc_h)};
3441
3442 $w = 0 if $w < 0;
3443 $h = 0 if $h < 0;
3444
3445 $w = int $w + 0.5;
3446 $h = int $h + 0.5;
3447
3448 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) {
3449 $widget->{old_w} = $widget->{w};
3450 $widget->{old_h} = $widget->{h};
3451
3452 $widget->{w} = $w;
3453 $widget->{h} = $h;
3454
3455 $widget->emit (size_allocate => $w, $h);
3456 }
3457 }
3458 }
3459
3460 while ($self->{post_alloc_hook}) {
3461 $_->()
3462 for values %{delete $self->{post_alloc_hook}};
3463 }
3464
3465
3466 glViewport 0, 0, $::WIDTH, $::HEIGHT;
3467 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
3468 glClear GL_COLOR_BUFFER_BIT;
3469
3470 glMatrixMode GL_PROJECTION;
3471 glLoadIdentity;
3472 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
3473 glMatrixMode GL_MODELVIEW;
3474 glLoadIdentity;
3475
3476 $self->_draw;
3477}
3386 3478
3387############################################################################# 3479#############################################################################
3388 3480
3389package CFClient::UI; 3481package CFClient::UI;
3390 3482

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines