Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
d8efd1b
Add Play button and grid size change button
tobbi Jun 3, 2025
796038a
Add offset to tilemaps in order to have space for displaying toolbar …
tobbi Jun 3, 2025
cd63904
Fix offset calculations for tilemaps when saving
tobbi Jun 3, 2025
a619be8
Include "Don't show grid" in grid toggle button
tobbi Jun 3, 2025
42d8a84
Add save button
tobbi Jun 3, 2025
00de793
Improve logical statement
tobbi Jun 4, 2025
a57f6da
Add button to switch between tile and object mode
tobbi Jun 15, 2025
4d395db
Add support for help texts for editor buttons
tobbi Jun 15, 2025
7b91ace
Update play and save editor icons
tobbi Jun 15, 2025
f0bc09e
Change font to small font, replace grid button
tobbi Jun 15, 2025
ddfb8c9
Make button icons smaller, add function to ToolIcon class for setting…
tobbi Jun 15, 2025
ae1f3ba
Make mode buttons actually work
tobbi Jun 15, 2025
ba7b357
Change icon for toggling between tile and object mode.
tobbi Jun 20, 2025
a23e3ed
WIP: Add editor controls for objects on mouse click
tobbi Jun 21, 2025
187a755
Change layer for properties panel background, add background for toolbar
tobbi Jun 21, 2025
2d5e37c
Add more edit capabilities to sidebar
tobbi Jun 21, 2025
553df0e
Add "edit script" button for script properties
tobbi Jun 23, 2025
583e027
Move positioning code over to overlay_widget and editor
tobbi Jul 3, 2025
2254450
Fix screen coordinates for new positions
tobbi Jul 3, 2025
3d8e69a
Fix initial camera position
tobbi Jul 3, 2025
3821512
Label and control classes: code style
tobbi Jul 3, 2025
599d672
Base work to support adding descriptions to editor properties to be s…
tobbi Jul 3, 2025
86844e0
Added example descriptions per data type
tobbi Jul 3, 2025
9d1a362
Add WIP code for viewing the text of a level
tobbi Jul 3, 2025
a06c500
Fix bugs in ControlTextbox when binding a value
tobbi Jul 4, 2025
e926d93
Add textbox elements for string properties
tobbi Jul 4, 2025
838cef7
Rudimentary support for making editor buttons invisible on mode change
tobbi Jul 4, 2025
5533630
Add test from here button to sidebar
tobbi Jul 4, 2025
c180d53
First support for enum options
tobbi Jul 5, 2025
3f0fed5
Try to update object after changing e.g. crusher size
tobbi Jul 5, 2025
644c6ce
Move `update_properties_panel` method out into own function
tobbi Jul 5, 2025
ff334ed
WIP: Properties for clicked layer items
tobbi Jul 5, 2025
039d972
Fix Checkbox position and dimensions
tobbi Jul 5, 2025
745b923
Fix tooltip z position and use normal font for better readability
tobbi Jul 5, 2025
0208773
WIP: Direction property left sidebar control
tobbi Jul 5, 2025
483d7b5
Delete properties when object is deleted
tobbi Jul 5, 2025
7ed9eda
Add mouse "select" button
tobbi Jul 5, 2025
08627fa
Add object selection modes to top menu bar
tobbi Jul 5, 2025
32d2f18
Move duplicated objects down by half a tile, change overlay texts
tobbi Jul 5, 2025
466a466
Small code style
tobbi Jul 5, 2025
776185b
Set most buttons invisible, only show them on mode select
tobbi Jul 6, 2025
c9272a1
Merge branch 'master' of https://github.com/supertux/supertux into to…
swagtoy Aug 19, 2025
6926df0
Merge some stuff from the editor2 branch
swagtoy Aug 19, 2025
79b398c
Warn user about testing an unsaved level until I fix that
swagtoy Aug 19, 2025
9b3acfa
Temporarily reload level for now
swagtoy Aug 19, 2025
9fbc955
Fix size of undo/redo buttons
swagtoy Aug 19, 2025
5be2ea2
Camera overscroll; Tilemap outer shading
swagtoy Aug 19, 2025
a2d958f
Ctrl-x to toggle between tile/object
swagtoy Aug 20, 2025
ad619b0
Shift+scroll to scroll horizontally
swagtoy Aug 20, 2025
d5260ab
Remember last used tile-group/object-group
swagtoy Aug 20, 2025
a010c0d
Scroll mouse wheel to select item in menu
swagtoy Aug 20, 2025
9e3b347
Initialize m_shift_pressed
swagtoy Aug 20, 2025
1e22ada
Focus current object/tilegroup in menu
swagtoy Aug 20, 2025
5318eb4
Show notification upon save via menubar
swagtoy Aug 20, 2025
62389bc
Save temp level as stringstream for testing
swagtoy Aug 20, 2025
f3d9a1d
Clear & seek istreams on restart
swagtoy Aug 20, 2025
e993b2a
Option to hide properties sidebar
swagtoy Aug 20, 2025
8324e95
Option to hide toolbar
swagtoy Aug 20, 2025
ff617d6
Scroll on tiles/objects buttons to switch categories
swagtoy Aug 20, 2025
aefc4f7
Ctrl+shift+t to spawn player at cursor
swagtoy Aug 20, 2025
16565ab
Fix building on hostile operating systems
swagtoy Aug 20, 2025
6c06dfa
Edit scripts with external editors
swagtoy Aug 20, 2025
a326b94
Store new settings
swagtoy Aug 20, 2025
910ec9b
Edit level button with dev mode enabled
swagtoy Aug 21, 2025
dbab053
Properly start level from menu
swagtoy Aug 21, 2025
0ef5d1d
Fix windows build
swagtoy Aug 21, 2025
0ddf1d0
Really fix Windows builds
swagtoy Aug 21, 2025
eb68524
ButtonWidget: Use normal font to render help text
Vankata453 Aug 21, 2025
119f636
Fix incorrect spawn position based on cursor position with applied zoom
Vankata453 Aug 21, 2025
868b9b2
strip_leading_dirs
swagtoy Aug 22, 2025
ce146e3
Use correct path for returning from editor; cleanup code
swagtoy Aug 22, 2025
2c124c8
ScreenManager: Don't draw if there are pending actions
swagtoy Aug 22, 2025
8728fff
Start level again (accidentally removed)
swagtoy Aug 22, 2025
d1f49f0
Skip level intro when returning from editor
swagtoy Aug 22, 2025
52fe715
Skip level intro in editor
swagtoy Aug 22, 2025
a46310b
Really skip level intro in editor
swagtoy Aug 22, 2025
ce32cf3
Fix tilemap shading when zoomed
swagtoy Aug 22, 2025
8bf039f
Fix starting editor on Windows/mac(?)
swagtoy Aug 22, 2025
83402ba
Fix Edit level button still showing when in editor
swagtoy Aug 22, 2025
50d7678
Return of bullshit
swagtoy Aug 22, 2025
6070e9c
Revert "Return of bullshit"
Vankata453 Aug 22, 2025
3658125
Editor: Improve properties panel code, show position/size related opt…
Vankata453 Aug 22, 2025
863d22c
More `ObjectOption`s now support being interface controls
Vankata453 Aug 22, 2025
4334174
Do not propagate mouse events to editor or its widgets when hovering …
Vankata453 Aug 22, 2025
0c81c78
Clicking off from object now hides properties panel
Vankata453 Aug 22, 2025
67f79d5
Editor: Do not save pointers to some toolbar button widgets
Vankata453 Aug 22, 2025
09486c1
Fix build on MacOS
tobbi Aug 22, 2025
eaf748b
Fix tile selection being off (and other things)
swagtoy Aug 22, 2025
de4ff63
Fix editor hint text position
swagtoy Aug 22, 2025
b29d373
Support undo/redo with properties sidebar
Vankata453 Aug 22, 2025
08961d1
Editor: Add indicator around selected object, use TypedUID to prevent…
Vankata453 Aug 22, 2025
9a20651
Use the game's regular "small" font for interface controls for consis…
Vankata453 Aug 22, 2025
fee2885
Ability to Save temporary levels
swagtoy Aug 23, 2025
2a45860
Notification on level create/change saving
swagtoy Aug 23, 2025
2f84c3d
Move Editor settings into own submenu
swagtoy Aug 23, 2025
d35de9b
Get rid of Share Level button
swagtoy Aug 23, 2025
7eae427
Update that stupid fucking help menu
swagtoy Aug 23, 2025
2da2525
Hide unnecessary buttons (some of which crash the game)
swagtoy Aug 23, 2025
43bf49d
Refactor editor toolbar initialization code
swagtoy Aug 23, 2025
d876fe5
Always show undo/redo and fade buttons instead of hiding
swagtoy Aug 23, 2025
085b007
Fix undo buttons always being pressed
swagtoy Aug 23, 2025
63a7bb3
Ctrl+alt+shift+T to test at last tested position
swagtoy Aug 23, 2025
ddae3ea
Also store literal spawnpoint test as last pos
swagtoy Aug 23, 2025
0b2eb0a
Don't show empty name in GameMenu
swagtoy Aug 23, 2025
ba2c01a
No shift for grid shapping
swagtoy Aug 23, 2025
1b97c96
Merge branch 'master' of github.com:SuperTux/supertux into tobbi-edit…
swagtoy Aug 24, 2025
5caa4a6
Merge branch 'tobbi-editor-ui-experiment' of github.com:SuperTux/supe…
swagtoy Aug 24, 2025
21c476d
Industrial autotile stuff
swagtoy Aug 24, 2025
f9a6c40
Improve tile placing performance
swagtoy Aug 24, 2025
cc51890
Use UID for external scripts; squirrel get_uid method
swagtoy Aug 25, 2025
f18176d
Don't show big boss healthbar in editor
swagtoy Aug 25, 2025
3644162
Fix object grid drag feeling off (round, not floor)
swagtoy Aug 25, 2025
46bc330
Prevent buttons from having mouse focus after being clicked
tobbi Aug 25, 2025
93534af
Add delete tool to top editor toolbar
tobbi Aug 25, 2025
5d60e78
MenuManager: Only reactivate Editor when menu stack is empty; Editor …
Vankata453 Aug 25, 2025
fd1c6a3
Set mouse tool when opening editor
tobbi Aug 25, 2025
f44df0b
Merge branch 'master' of github.com:SuperTux/supertux into tobbi-edit…
swagtoy Aug 26, 2025
61a526d
Merge branch 'tobbi-editor-ui-experiment' of github.com:SuperTux/supe…
swagtoy Aug 26, 2025
e4add8f
Blur effect
swagtoy Aug 26, 2025
bce44bf
Shadow and lines on sidebar/layers widget
swagtoy Aug 26, 2025
38015d0
Show scroll shadow in tilebox
swagtoy Aug 26, 2025
0191b3e
ControlTextbox: Pressing return reliinquishes focus
tobbi Aug 27, 2025
429b4f8
Merge branch 'master' into tobbi-editor-ui-experiment
Vankata453 Aug 28, 2025
e7d649a
Editor: Never accept events if MenuManager has active menu or dialog
Vankata453 Aug 28, 2025
687cffc
Translation fix with "Save Level as" menu label
Vankata453 Aug 28, 2025
5886b6e
`Notification`: Support automatically fading out and closing after a …
Vankata453 Aug 29, 2025
ae505c7
Show blur even if displacement texture is drawn
swagtoy Aug 29, 2025
26c96b5
Don't flip back renderer
swagtoy Aug 29, 2025
393614f
Notification: Don't calculate mini text height if there's no mini text
swagtoy Aug 29, 2025
956c73b
Notification: Drag to close
swagtoy Aug 29, 2025
020cfbe
Notification: Close animation
swagtoy Aug 29, 2025
588a85f
Notification: Remove debug print & print disabled notification as debug
swagtoy Aug 29, 2025
b46bf52
Make toolbar prettier
swagtoy Aug 29, 2025
c2ac52e
Notification: Open animation
swagtoy Aug 29, 2025
90e0148
Fix notifications
swagtoy Aug 29, 2025
64e3c20
Fix notifications being activated without being hovered
swagtoy Aug 29, 2025
a499684
Slight code improvement in notification.cpp [ci skip]
Vankata453 Aug 30, 2025
f577909
Return added options from all add_* calls in ObjectSettings class
tobbi Sep 1, 2025
36ff0c5
Remove placeholders
tobbi Sep 1, 2025
e713d15
Add example descriptions for darttrap
tobbi Sep 1, 2025
9713af3
Help texts for Badguy and MovingSprite settings
tobbi Sep 1, 2025
7f5e14a
Experiment: layers box at the bottom left corner displaying the layer…
tobbi Sep 3, 2025
d06640b
Fix performance issue
tobbi Sep 6, 2025
6c69831
Add editor setting for rendering animations
tobbi Sep 6, 2025
2bcfedb
Initialize m_scrollbar in initialization list
tobbi Sep 6, 2025
6453109
Fix tile animations when animation display setting was disabled
tobbi Sep 7, 2025
6e3ebbc
Add more descriptions for editor settings
tobbi Sep 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions data/images/autotiles.satc
Original file line number Diff line number Diff line change
Expand Up @@ -10849,6 +10849,56 @@

)


(autotileset
(name "industrial_horiz")
(default 3170)
(autotile
(id 3183)
(solid #t)
(mask "***01***")
)
(autotile
(id 4623)
(solid #t)
(mask "***11***")
)
(autotile
(id 3184)
(solid #t)
(mask "***10***")
)
(autotile
(id 3170)
(solid #t)
(mask "***00***")
)
)

(autotileset
(name "industrial_vert")
(default 3170)
(autotile
(id 3189)
(solid #t)
(mask "*0****1*")
)
(autotile
(id 4627)
(solid #t)
(mask "*1****1*")
)
(autotile
(id 3190)
(solid #t)
(mask "*1****0*")
)
(autotile
(id 3170)
(solid #t)
(mask "*0****0*")
)
)
;; SUPPORT MULTIPLE AUTOTILESETS PER TILE - END

)
Binary file added data/images/engine/editor/grid_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/engine/editor/play_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/images/engine/editor/redo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/engine/editor/save.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/engine/editor/shadow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/engine/editor/shadow2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/images/engine/editor/undo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 27 additions & 3 deletions data/shader/shader330.frag
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ uniform float game_time;
uniform vec2 animate;
uniform vec2 displacement_animate;
uniform bool is_displacement;
uniform int blur;

in vec4 diffuse_var;
in vec2 texcoord_var;
Expand All @@ -17,10 +18,33 @@ out vec4 fragColor;

void main(void)
{
if (backbuffer == 0.0 || !is_displacement)
if (backbuffer == 0.0 || !is_displacement || blur != 0.0)
{
vec4 color = diffuse_var * texture(diffuse_texture, texcoord_var.st + (animate * game_time));
fragColor = color;
vec4 color = diffuse_var * texture(diffuse_texture, texcoord_var.st + (animate * game_time));
if (blur != 0.0)
{
vec2 uv = (fragcoord2uv * gl_FragCoord.xyw).xy;
uv.y = 1.0 - uv.y;
vec2 texel = vec2(fragcoord2uv[0].x, fragcoord2uv[1].y);
float num = 0.0;
vec4 sum = vec4(0.0);

for (float y = -blur; y <= blur; ++y)
{
for (float x = -blur; x <= blur; ++x)
{
vec2 offset = vec2(x, y) * texel;
sum += texture(framebuffer_texture, uv + offset);
num++;
}
}

fragColor = vec4(mix(color.rgb, (sum/num).rgb * 1.05, color.a), 1.0);
}
else
{
fragColor = color;
}
}
else if (is_displacement)
{
Expand Down
6 changes: 4 additions & 2 deletions src/badguy/badguy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1267,8 +1267,10 @@ BadGuy::get_settings()
ObjectSettings result = MovingSprite::get_settings();

if (!get_allowed_directions().empty())
result.add_direction(_("Direction"), &m_start_dir, get_allowed_directions(), "direction");
result.add_script(_("Death script"), &m_dead_script, "dead-script");
result.add_direction(_("Direction"), &m_start_dir, get_allowed_directions(), "direction")
->set_description(_("The direction the badguy is facing at the start of the level. AUTO makes the badguy face towards the player when activated."));
result.add_script(get_uid(), _("Death script"), &m_dead_script, "dead-script")
->set_description(_("Script that is executed when the badguy dies."));

result.reorder({"direction", "sprite", "x", "y"});

Expand Down
15 changes: 10 additions & 5 deletions src/badguy/boss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace

#include "badguy/boss.hpp"

#include "editor/editor.hpp"
#include "object/player.hpp"
#include "sprite/sprite.hpp"
#include "supertux/sector.hpp"
Expand Down Expand Up @@ -67,7 +68,7 @@ Boss::draw(DrawingContext& context)
void
Boss::draw_hit_points(DrawingContext& context)
{
if (m_hud_head)
if (m_hud_head && !Editor::is_active())
{
context.push_transform();
context.set_translation(Vector(0, 0));
Expand All @@ -91,19 +92,23 @@ Boss::get_settings()
{
ObjectSettings result = BadGuy::get_settings();

result.add_text("hud-icon", &m_hud_icon, "hud-icon", "images/creatures/yeti/hudlife.png", OPTION_HIDDEN);
result.add_int(_("Lives"), &m_lives, "lives", DEFAULT_LIVES);
result.add_text("hud-icon", &m_hud_icon, "hud-icon", "images/creatures/yeti/hudlife.png", OPTION_HIDDEN)
->set_description(_("The icon that is displayed at the top indicating how many lives this boss has left"));
result.add_int(_("Lives"), &m_lives, "lives", DEFAULT_LIVES)
->set_description(_("The maximum number of lives this boss has"));

/* l10n: Pinch Mode refers to a particular boss mode that gets
activated once the boss has lost the specified amounts of lives.
This setting specifies how many lives need to be spent until pinch
mode is activated. */
result.add_int(_("Lives to Pinch Mode"), &m_pinch_lives, "pinch-lives", DEFAULT_PINCH_LIVES);
result.add_int(_("Lives to Pinch Mode"), &m_pinch_lives, "pinch-lives", DEFAULT_PINCH_LIVES)
->set_description(_("Specifies how many lives need to be spent until pinch mode (a special boss mode) is activated"));

/* l10n: Pinch Mode refers to a particular boss mode that gets
activated once the boss has lost the specified amounts of lives.
This setting specifies the squirrel script that gets run to activate boss mode. */
result.add_script(_("Pinch Mode Activation Script"), &m_pinch_activation_script, "pinch-activation-script");
result.add_script(get_uid(), _("Pinch Mode Activation Script"), &m_pinch_activation_script, "pinch-activation-script")
->set_description(_("The script that gets run when pinch mode is activated"));

return result;
}
2 changes: 1 addition & 1 deletion src/badguy/crusher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ Crusher::get_settings()
static_cast<int>(CrusherDirection::DOWN),
"direction");

result.add_script(_("Crush script"), &m_crush_script, "crush-script");
result.add_script(get_uid(), _("Crush script"), &m_crush_script, "crush-script");
result.reorder({ "direction", "sprite", "crush-script", "x", "y" });

return result;
Expand Down
15 changes: 10 additions & 5 deletions src/badguy/darttrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,16 @@ DartTrap::get_settings()
{
ObjectSettings result = StickyBadguy::get_settings();

result.add_float(_("Initial delay"), &m_initial_delay, "initial-delay");
result.add_bool(_("Enabled"), &m_enabled, "enabled", true);
result.add_float(_("Fire delay"), &m_fire_delay, "fire-delay");
result.add_int(_("Ammo"), &m_ammo, "ammo");
result.add_sprite(_("Dart sprite"), &m_dart_sprite, "dart-sprite", "images/creatures/darttrap/granito/root_dart.sprite");
result.add_float(_("Initial delay"), &m_initial_delay, "initial-delay")
->set_description(_("Time until the first dart is fired after the trap is activated."));
result.add_bool(_("Enabled"), &m_enabled, "enabled", true)
->set_description(_("Whether the trap is enabled."));
result.add_float(_("Fire delay"), &m_fire_delay, "fire-delay")
->set_description(_("Time between consecutive darts."));
result.add_int(_("Ammo"), &m_ammo, "ammo")
->set_description(_("Number of darts the trap can fire. A value of -1 means infinite."));
result.add_sprite(_("Dart sprite"), &m_dart_sprite, "dart-sprite", "images/creatures/darttrap/granito/root_dart.sprite")
->set_description(_("Sprite used for the dart."));

result.reorder({"initial-delay", "fire-delay", "ammo", "sticky", "direction", "x", "y", "dart-sprite"});

Expand Down
4 changes: 2 additions & 2 deletions src/badguy/granito.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ Granito::get_settings()

settings.remove("dead-script");

settings.add_script(_("Detect script"), &m_detect_script, "detect-script");
settings.add_script(_("Carried script"), &m_carried_script, "carried-script");
settings.add_script(get_uid(), _("Detect script"), &m_detect_script, "detect-script");
settings.add_script(get_uid(), _("Carried script"), &m_carried_script, "carried-script");

return settings;
}
Expand Down
2 changes: 1 addition & 1 deletion src/badguy/granito_big.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ GranitoBig::get_settings()

// No need to make another member for the carrying script.
// Just repurpose the carried script.
settings.add_script(_("Carrying Script"), &m_carried_script, "carrying-script");
settings.add_script(get_uid(), _("Carrying Script"), &m_carried_script, "carrying-script");

return settings;
}
Expand Down
82 changes: 65 additions & 17 deletions src/editor/button_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,62 @@

#include "supertux/gameconfig.hpp"
#include "supertux/globals.hpp"
#include "supertux/resources.hpp"
#include "util/log.hpp"
#include "video/viewport.hpp"
#include "video/video_system.hpp"

ButtonWidget::ButtonWidget(SpritePtr sprite, const Vector& pos,
std::function<void()> sig_click) :
std::function<void()> sig_click, std::optional<Sizef> sprite_size) :
m_sprite(std::move(sprite)),
m_rect(pos, Sizef(static_cast<float>(m_sprite->get_width()),
static_cast<float>(m_sprite->get_height()))),
m_rect(pos, sprite_size ? *sprite_size :
Sizef(static_cast<float>(m_sprite->get_width()),
static_cast<float>(m_sprite->get_height()))),
m_grab(false),
m_hover(false),
m_sig_click(std::move(sig_click))
m_sig_click(std::move(sig_click)),
m_mouse_pos(),
m_help_text(),
m_flat(false),
m_disabled(false)
{
}

void
ButtonWidget::set_position(const Vector& pos)
{
float w = m_rect.get_width(),
h = m_rect.get_height();

m_rect.set_left(pos.x);
m_rect.set_width(w);
m_rect.set_top(pos.y);
m_rect.set_height(h);
}

void
ButtonWidget::draw(DrawingContext& context)
{
context.color().draw_filled_rect(m_rect, Color(0.0f, 0.0f, 0.0f, 0.6f), 4.0f,
LAYER_GUI-5);
if (!m_flat)
context.color().draw_filled_rect(m_rect, Color(0.0f, 0.0f, 0.0f, 0.6f), 4.0f,
LAYER_GUI-5);

if (m_sprite) {
m_sprite->draw(context.color(), m_rect.p1(), LAYER_GUI-5);
if (m_disabled) context.set_alpha(0.4);
m_sprite->draw_scaled(context.color(), m_rect.grown(-4.0f), LAYER_GUI - 5);
if (m_disabled) context.set_alpha(1.0);
}

if (m_grab) {
context.color().draw_filled_rect(m_rect, g_config->editorgrabcolor, 4.0f,
LAYER_GUI-5);
} else if (m_hover) {
} else if (m_hover && !m_disabled) {
context.color().draw_filled_rect(m_rect, g_config->editorhovercolor, 4.0f,
LAYER_GUI-5);
}

if (m_hover && !m_help_text.empty())
context.color().draw_text(Resources::normal_font, m_help_text, m_mouse_pos + Vector(32, 32), FontAlignment::ALIGN_LEFT, INT_MAX);
}

void
Expand All @@ -70,11 +95,13 @@ bool
ButtonWidget::on_mouse_button_up(const SDL_MouseButtonEvent& button)
{
if (button.button != SDL_BUTTON_LEFT) return false;

Vector mouse_pos = VideoSystem::current()->get_viewport().to_logical(button.x, button.y);
// XXX: these shouldn't pass through
if (m_disabled) return false;

m_mouse_pos = VideoSystem::current()->get_viewport().to_logical(button.x, button.y);

if (m_grab) {
if (m_rect.contains(mouse_pos)) {
if (m_rect.contains(m_mouse_pos)) {
if (m_sig_click) {
m_sig_click();
}
Expand All @@ -90,11 +117,13 @@ ButtonWidget::on_mouse_button_up(const SDL_MouseButtonEvent& button)
bool
ButtonWidget::on_mouse_button_down(const SDL_MouseButtonEvent& button)
{
if (button.button != SDL_BUTTON_LEFT) return false;
if (button.button != SDL_BUTTON_LEFT || m_disabled) return false;
// XXX: these shouldn't pass through
if (m_disabled) return false;

Vector mouse_pos = VideoSystem::current()->get_viewport().to_logical(button.x, button.y);
m_mouse_pos = VideoSystem::current()->get_viewport().to_logical(button.x, button.y);

if (m_rect.contains(mouse_pos)) {
if (m_rect.contains(m_mouse_pos)) {
m_hover = true;
m_grab = true;
return true;
Expand All @@ -107,16 +136,35 @@ ButtonWidget::on_mouse_button_down(const SDL_MouseButtonEvent& button)
bool
ButtonWidget::on_mouse_motion(const SDL_MouseMotionEvent& motion)
{
Vector mouse_pos = VideoSystem::current()->get_viewport().to_logical(motion.x, motion.y);
m_mouse_pos = VideoSystem::current()->get_viewport().to_logical(motion.x, motion.y);

if (m_grab) {
m_hover = m_rect.contains(mouse_pos);
m_hover = m_rect.contains(m_mouse_pos);
return true;
} else if (m_rect.contains(mouse_pos)) {
} else if (m_rect.contains(m_mouse_pos)) {
m_hover = true;
return false;
} else {
m_hover = false;
return false;
}
}

void
ButtonWidget::set_sprite(SpritePtr sprite)
{
m_sprite = std::move(sprite);
m_rect.set_size(sprite->get_width() * 1.0f, sprite->get_height() * 1.0f);
}

void
ButtonWidget::set_sprite(const std::string& path)
{
set_sprite(SpriteManager::current()->create(path));
}

void
ButtonWidget::set_help_text(const std::string& help_text)
{
m_help_text = help_text;
}
Loading
Loading