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