; charset=UTF-8 Last-Modified: Mon, 02 Nov 2026 09:39:42 GMT Expires: Thu, 30 Oct 2036 09:39:42 GMT Make bgcolor tint button background images (#9818) - minetest.git - modified minetest for gpcfs purposes
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugues Ross <hugues.ross@gmail.com>2020-08-29 11:41:19 -0400
committerGitHub <noreply@github.com>2020-08-29 16:41:19 +0100
commit9976f36b18b8d227e3240feb24000dda0916ee44 (patch)
tree253d3c39dba2a95137b392937287dd7d1dafdc57
parent3693b6871eba268ecc79b3f52d00d3cefe761131 (diff)
Make bgcolor tint button background images (#9818)
-rw-r--r--games/devtest/mods/testformspec/formspec.lua2
-rw-r--r--src/client/guiscalingfilter.cpp5
-rw-r--r--src/client/guiscalingfilter.h3
-rw-r--r--src/gui/guiButton.cpp21
-rw-r--r--src/gui/guiButton.h1
5 files changed, 19 insertions, 13 deletions
diff --git a/games/devtest/mods/testformspec/formspec.lua b/games/devtest/mods/testformspec/formspec.lua
index 08c1b6dc0..87a05fc96 100644
--- a/games/devtest/mods/testformspec/formspec.lua
+++ b/games/devtest/mods/testformspec/formspec.lua
@@ -164,7 +164,7 @@ local style_fs = [[
style[one_btn14:hovered+pressed;textcolor=purple]
image_button[0,9.6;1,1;testformspec_button_image.png;one_btn14;Bg]
- style[one_btn15;border=false;bgimg=testformspec_bg.png;bgimg_hovered=testformspec_bg_hovered.png;bgimg_pressed=testformspec_bg_pressed.png]
+ style[one_btn15;border=false;bgcolor=#1cc;bgimg=testformspec_bg.png;bgimg_hovered=testformspec_bg_hovered.png;bgimg_pressed=testformspec_bg_pressed.png]
item_image_button[1.25,9.6;1,1;testformspec:item;one_btn15;Bg]
style[one_btn16;border=false;bgimg=testformspec_bg_9slice.png;bgimg_hovered=testformspec_bg_9slice_hovered.png;bgimg_pressed=testformspec_bg_9slice_pressed.png;bgimg_middle=4,6]
diff --git a/src/client/guiscalingfilter.cpp b/src/client/guiscalingfilter.cpp
index 4262331bd..406c096e6 100644
--- a/src/client/guiscalingfilter.cpp
+++ b/src/client/guiscalingfilter.cpp
@@ -172,11 +172,8 @@ void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
void draw2DImage9Slice(video::IVideoDriver *driver, video::ITexture *texture,
const core::rect<s32> &rect, const core::rect<s32> &middle,
- const core::rect<s32> *cliprect)
+ const core::rect<s32> *cliprect, const video::SColor *const colors)
{
- const video::SColor color(255,255,255,255);
- const video::SColor colors[] = {color,color,color,color};
-
auto originalSize = texture->getOriginalSize();
core::vector2di lowerRightOffset = core::vector2di(originalSize.Width, originalSize.Height) - middle.LowerRightCorner;
diff --git a/src/client/guiscalingfilter.h b/src/client/guiscalingfilter.h
index b703d91f0..379a4bdb0 100644
--- a/src/client/guiscalingfilter.h
+++ b/src/client/guiscalingfilter.h
@@ -54,4 +54,5 @@ void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
*/
void draw2DImage9Slice(video::IVideoDriver *driver, video::ITexture *texture,
const core::rect<s32> &rect, const core::rect<s32> &middle,
- const core::rect<s32> *cliprect = nullptr);
+ const core::rect<s32> *cliprect = nullptr,
+ const video::SColor *const colors = nullptr);
diff --git a/src/gui/guiButton.cpp b/src/gui/guiButton.cpp
index e0d6337cd..b98e5de82 100644
--- a/src/gui/guiButton.cpp
+++ b/src/gui/guiButton.cpp
@@ -313,11 +313,12 @@ void GUIButton::draw()
// PATCH
video::ITexture* texture = ButtonImages[(u32)imageState].Texture;
+ video::SColor image_colors[] = { BgColor, BgColor, BgColor, BgColor };
if (BgMiddle.getArea() == 0) {
driver->draw2DImage(texture,
ScaleImage? AbsoluteRect : core::rect<s32>(pos, sourceRect.getSize()),
sourceRect, &AbsoluteClippingRect,
- 0, UseAlphaChannel);
+ image_colors, UseAlphaChannel);
} else {
core::rect<s32> middle = BgMiddle;
// `-x` is interpreted as `w - x`
@@ -327,7 +328,7 @@ void GUIButton::draw()
middle.LowerRightCorner.Y += texture->getOriginalSize().Height;
draw2DImage9Slice(driver, texture,
ScaleImage ? AbsoluteRect : core::rect<s32>(pos, sourceRect.getSize()),
- middle, &AbsoluteClippingRect);
+ middle, &AbsoluteClippingRect, image_colors);
}
// END PATCH
}
@@ -722,6 +723,8 @@ GUIButton* GUIButton::addButton(IGUIEnvironment *environment,
void GUIButton::setColor(video::SColor color)
{
+ BgColor = color;
+
float d = 0.65f;
for (size_t i = 0; i < 4; i++) {
video::SColor base = Environment->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i);
@@ -750,22 +753,26 @@ void GUIButton::setFromStyle(const StyleSpec& style)
bool pressed = (style.getState() & StyleSpec::STATE_PRESSED) != 0;
if (style.isNotDefault(StyleSpec::BGCOLOR)) {
-
setColor(style.getColor(StyleSpec::BGCOLOR));
// If we have a propagated hover/press color, we need to automatically
// lighten/darken it
if (!Styles[style.getState()].isNotDefault(StyleSpec::BGCOLOR)) {
- for (size_t i = 0; i < 4; i++) {
if (pressed) {
- Colors[i] = multiplyColorValue(Colors[i], COLOR_PRESSED_MOD);
+ BgColor = multiplyColorValue(BgColor, COLOR_PRESSED_MOD);
+
+ for (size_t i = 0; i < 4; i++)
+ Colors[i] = multiplyColorValue(Colors[i], COLOR_PRESSED_MOD);
} else if (hovered) {
- Colors[i] = multiplyColorValue(Colors[i], COLOR_HOVERED_MOD);
+ BgColor = multiplyColorValue(BgColor, COLOR_HOVERED_MOD);
+
+ for (size_t i = 0; i < 4; i++)
+ Colors[i] = multiplyColorValue(Colors[i], COLOR_HOVERED_MOD);
}
- }
}
} else {
+ BgColor = video::SColor(255, 255, 255, 255);
for (size_t i = 0; i < 4; i++) {
video::SColor base =
Environment->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i);
diff --git a/src/gui/guiButton.h b/src/gui/guiButton.h
index 95fa1a2a1..4e1b04aac 100644
--- a/src/gui/guiButton.h
+++ b/src/gui/guiButton.h
@@ -338,5 +338,6 @@ private:
core::rect<s32> BgMiddle;
core::rect<s32> Padding;
core::vector2d<s32> ContentOffset;
+ video::SColor BgColor;
// END PATCH
};
> $1; $root_path =~ s|\\|/|g; our %config = ( #debug => 1, list_full => $root_path . 'list_full', list_pub => $root_path . 'list', time_purge => 86400 * 30, time_alive => 650, source_check => 1, ping_timeout => 3, ping => 1, mineping => 1, pingable => 1, trusted => [qw( 176.9.122.10 )], #masterserver self ip - if server on same ip with masterserver doesnt announced #blacklist => [], # [qw(2.3.4.5 4.5.6.7 8.9.0.1), '1.2.3.4', qr/^10\.20\.30\./, ], # list, or quoted, ips, or regex ); do($root_path . 'config.pl'); our $ping = Net::Ping->new("udp", $config{ping_timeout}); $ping->hires(); sub get_params_one(@) { local %_ = %{ref $_[0] eq 'HASH' ? shift : {}}; for (@_) { tr/+/ /, s/%([a-f\d]{2})/pack 'H*', $1/gei for my ($k, $v) = /^([^=]+=?)=(.+)$/ ? ($1, $2) : (/^([^=]*)=?$/, /^-/); $_{$k} = $v; } wantarray ? %_ : \%_; } sub get_params(;$$) { #v7 my ($string, $delim) = @_; $delim ||= '&'; read(STDIN, local $_ = '', $ENV{'CONTENT_LENGTH'}) if !$string and $ENV{'CONTENT_LENGTH'}; local %_ = $string ? get_params_one split $delim, $string : (get_params_one(@ARGV), map { get_params_one split $delim, $_ } split(/;\s*/, $ENV{'HTTP_COOKIE'}), $ENV{'QUERY_STRING'}, $_); wantarray ? %_ : \%_; } sub get_params_utf8(;$$) { local $_ = &get_params; utf8::decode $_ for %$_; wantarray ? %$_ : $_; } sub file_rewrite(;$@) { local $_ = shift; return unless open my $fh, '>', $_; print $fh @_; } sub file_read ($) { open my $f, '<', $_[0] or return; local $/ = undef; my $ret = <$f>; close $f; return \$ret; } sub read_json { my $ret = {}; eval { $ret = JSON->new->utf8->relaxed(1)->decode(${ref $_[0] ? $_[0] : file_read($_[0]) or \''} || '{}'); }; #'mc warn "json error [$@] on [", ${ref $_[0] ? $_[0] : \$_[0]}, "]" if $@; $ret; } sub printu (@) { for (@_) { print($_), next unless utf8::is_utf8($_); my $s = $_; utf8::encode($s); print($s); } } sub name_to_ip_noc($) { my ($name) = @_; unless ($name =~ /^\d+\.\d+\.\d+\.\d+$/) { local $_ = (gethostbyname($name))[4]; return ($name, 1) unless length($_) == 4; $name = inet_ntoa($_); } return $name; } sub float { return ($_[0] < 8 and $_[0] - int($_[0])) ? sprintf('%.' . ($_[0] < 1 ? 3 : ($_[0] < 3 ? 2 : 1)) . 'f', $_[0]) : int($_[0]); } sub mineping ($$) { my ($addr, $port) = @_; warn "mineping($addr, $port)" if $config{debug}; my $data; my $time = time; eval { my $socket = IO::Socket::INET->new( 'PeerAddr' => $addr, 'PeerPort' => $port, 'Proto' => 'udp', 'Timeout' => $config{ping_timeout}, ); $socket->send("\x4f\x45\x74\x03\x00\x00\x00\x01"); local $SIG{ALRM} = sub { die "alarm time out"; }; alarm $config{ping_timeout}; $socket->recv($data, POSIX::BUFSIZ) or die "recv: $!"; alarm 0; 1; # return value from eval on normalcy } or return 0; return 0 unless length $data; $time = float(time - $time); warn "recvd: ", length $data, " [$time]" if $config{debug}; return $time; } sub request (;$) { my ($r) = @_; $r ||= \%ENV; my $param = get_params_utf8; my $after = sub { if ($param->{json}) { my $j = {}; eval { $j = JSON->new->decode($param->{json}) || {} }; $param->{$_} = $j->{$_} for keys %$j; delete $param->{json}; } if (%$param) { s/^false$// for values %$param; $param->{ip} = $r->{REMOTE_ADDR}; for (@{$config{blacklist}}) { return if $param->{ip} ~~ $_; } $param->{address} ||= $param->{ip}; if ($config{source_check} and name_to_ip_noc($param->{address}) ne $param->{ip} and !($param->{ip} ~~ $config{trusted})) { warn("bad address [$param->{address}] ne [$param->{ip}]") if $config{debug}; return; } $param->{port} ||= 30000; $param->{key} = "$param->{ip}:$param->{port}"; $param->{off} = time if $param->{action} ~~ 'delete'; if ($config{ping} and $param->{action} ne 'delete') { if ($config{mineping}) { $param->{ping} = mineping($param->{ip}, $param->{port}); } else { $ping->port_number($param->{port}); $ping->service_check(0); my ($pingret, $duration, $ip) = $ping->ping($param->{address}); if ($ip ne $param->{ip} and !($param->{ip} ~~ $config{trusted})) { warn "strange ping ip [$ip] != [$param->{ip}]" if $config{debug}; return if $config{source_check} and !($param->{ip} ~~ $config{trusted}); } $param->{ping} = $duration if $pingret; warn " PING t=$config{ping_timeout}, $param->{address}:$param->{port} = ( $pingret, $duration, $ip )" if $config{debug}; } } my $list = read_json($config{list_full}) || {}; warn "readed[$config{list_full}] list size=", scalar @{$list->{list}}; my $listk = {map { $_->{key} => $_ } @{$list->{list}}}; my $old = $listk->{$param->{key}}; $param->{time} = $old->{time} if $param->{off}; $param->{time} ||= int time; $param->{start} = $param->{action} ~~ 'start' ? $param->{time} : $old->{start} || $param->{time}; delete $param->{start} if $param->{off}; $param->{first} ||= $old->{first} || $old->{time} || $param->{time}; $param->{clients_top} = $old->{clients_top} if $old->{clients_top} > $param->{clients}; $param->{clients_top} ||= $param->{clients} || 0; delete $param->{action}; $listk->{$param->{key}} = $param; $list->{list} = [grep { $_->{time} > time - $config{time_purge} } values %$listk]; file_rewrite($config{list_full}, JSON->new->encode($list)); warn "writed[$config{list_full}] list size=", scalar @{$list->{list}}; $list->{list} = [ sort { $b->{clients} <=> $a->{clients} || $a->{start} <=> $b->{start} } grep { $_->{time} > time - $config{time_alive} and !$_->{off} and (!$config{ping} or !$config{pingable} or $_->{ping}) } @{$list->{list}} ]; file_rewrite($config{list_pub}, JSON->new->encode($list)); warn "writed[$config{list_pub}] list size=", scalar @{$list->{list}}; } }; return [200, ["Content-type", "application/json"], [JSON->new->encode({})]], $after; } sub request_cgi { my ($p, $after) = request(@_); shift @$p; printu join "\n", map { join ': ', @$_ } shift @$p; printu "\n\n"; printu join '', map { join '', @$_ } @$p; if (fork) { unless ($config{debug}) { close STDOUT; close STDERR; } } else { $after->() if ref $after ~~ 'CODE'; } } request_cgi() unless caller;