Skip to content

Commit

Permalink
Merge branch 'fixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
phil294 committed Jul 3, 2023
2 parents 9f976a5 + 0824212 commit 3a1d075
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 17 deletions.
3 changes: 2 additions & 1 deletion build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ These are the steps required to build this project locally, such as if you want
1. `shards install`
1. `bin/gi-crystal`
1. Remove the `private` from `private getter xdo_p : LibXDo::XDo*` in `lib/x_do/src/x_do.cr` (this is a temporary fix)
1. In `lib/gtk3/lib/gi-crystal/src/auto/gtk-3.0/gtk.cr`, replace all usages of `Glib::String` with `::String` (this is a temporary fix)
1. In `lib/gi-crystal/src/auto/gtk-3.0/gtk.cr`, replace all usages of `Glib::String` with `::String` (this is a temporary fix)
1. In `lib/gi-crystal/src/auto/gdk_pixbuf-2.0/pixbuf.cr`, change `def pixbuf=(value : GdkPixbuf::Pixbuf?) : GdkPixbuf::Pixbuf?` to `def pixbuf=(value : GdkPixbuf::Pixbuf : GdkPixbuf::Pixbuf?` (this is a temporary fix)
1. Now everything is ready for local use with `shards build -Dpreview_mt`, *if* you have `libxdo` (xdotool) version 2021* upwards installed. For version 2016*, you'll need to upgrade this dependency somehow. One way to achieve this is explained below.
1. Find your final binary in the `./bin` folder, it's about 4 MiB in size.

Expand Down
20 changes: 15 additions & 5 deletions src/cmd/gtk/gui/gui-add.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Cmd::Gtk::Gui::GuiAdd < Cmd::Base
type = args[1]
options = args[2]? || ""
text = args[3]? || ""

opt = thread.parse_word_options options
runner = thread.runner
g_label = opt["g"]?.try &.[:v].downcase
Expand All @@ -16,7 +16,10 @@ class Cmd::Gtk::Gui::GuiAdd < Cmd::Base
runner.add_thread g_label, 0
end
}


w = (opt["w"]?.try &.[:n] || -1).to_i
h = (opt["h"]?.try &.[:n] || -1).to_i

thread.runner.display.gtk.gui(thread, gui_id) do |gui|
widget : ::Gtk::Widget? = nil
case type.downcase
Expand Down Expand Up @@ -63,6 +66,15 @@ class Cmd::Gtk::Gui::GuiAdd < Cmd::Base
widget.has_window = true
widget.events = ::Gdk::EventMask::ButtonPressMask.to_i
widget.button_press_event_signal.connect run_g_label.unsafe_as(Proc(Gdk::EventButton, Bool))
if (pixbuf = widget.pixbuf) && (w > -1 || h > -1)
if w == -1
w = (h * pixbuf.width / pixbuf.height).to_i
elsif h == -1
h = (w * pixbuf.height / pixbuf.width).to_i
end
pixbuf_scaled = pixbuf.scale_simple w, h, GdkPixbuf::InterpType::Bilinear
widget.pixbuf = pixbuf_scaled if pixbuf_scaled
end
else
widget = ::Gtk::Label.new text
widget.has_window = true
Expand Down Expand Up @@ -128,14 +140,12 @@ class Cmd::Gtk::Gui::GuiAdd < Cmd::Base
gui.last_y + 12 + gui.padding # TODO:
end
end

if opt["section"]?
gui.last_section_x = x
gui.last_section_y = y
end

w = (opt["w"]?.try &.[:n] || -1).to_i
h = (opt["h"]?.try &.[:n] || -1).to_i
if w > -1 || h > -1
widget.style_context.add_class("no-padding")
end
Expand Down
15 changes: 15 additions & 0 deletions src/cmd/gtk/gui/gui-control.cr
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ class Cmd::Gtk::Gui::GuiControl < Cmd::Base
ctrl.label = value
when ::Gtk::Entry
ctrl.text = value
when ::Gtk::Image
pixbuf_before = ctrl.pixbuf
LibGtk.gtk_widget_get_size_request(ctrl.to_unsafe, out w, out h)
ctrl.from_file = value
if (pixbuf_after = ctrl.pixbuf) && (w > -1 || h > -1)
if w == -1
w = (h * pixbuf_after.width / pixbuf_after.height).to_i
elsif h == -1
h = (w * pixbuf_after.height / pixbuf_after.width).to_i
end
pixbuf_after_scaled = pixbuf_after.scale_simple w, h, GdkPixbuf::InterpType::Bilinear
ctrl.pixbuf = pixbuf_after_scaled if pixbuf_after_scaled
end
else
raise Run::RuntimeException.new "GuiControl not yet supported for element of type #{ctrl.class}, sorry."
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions src/cmd/math/env-add.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ class Cmd::Math::EnvAdd < Cmd::Base
def run(thread, args)
var, add_value = args
time_units = args[2]?

current_value = thread.runner.get_user_var(var)
pure_int = ! current_value.includes?('.') && ! add_value.includes?('.')
add_value = add_value.to_f?
add_value = add_value.to_f64?

if time_units
new_value = ""
Expand All @@ -36,13 +36,13 @@ class Cmd::Math::EnvAdd < Cmd::Base
end
end
else
current_value = current_value.to_f? || 0
current_value = current_value.to_f64? || 0
add_value = add_value || 0
new_value = current_value + add_value
new_value = new_value.to_i if pure_int
new_value = new_value.to_i64 if pure_int
new_value = new_value.to_s
end

thread.runner.set_user_var(var, new_value)
end
end
6 changes: 3 additions & 3 deletions src/cmd/math/env-div.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class Cmd::Math::EnvDiv < Cmd::Base
var, div_value = args
current_value = thread.runner.get_user_var(var)
pure_int = ! current_value.includes?('.') && ! div_value.includes?('.')
div_value = div_value.to_f? || 0
current_value = current_value.to_f? || 0
div_value = div_value.to_f64? || 0
current_value = current_value.to_f64? || 0
new_value = current_value / div_value
new_value = new_value.to_i if pure_int
new_value = new_value.to_i64 if pure_int
new_value = new_value.to_s
thread.runner.set_user_var(var, new_value)
end
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/math/env-mult.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class Cmd::Math::EnvMult < Cmd::Base
var, mult_value = args
current_value = thread.runner.get_user_var(var)
pure_int = ! current_value.includes?('.') && ! mult_value.includes?('.')
mult_value = mult_value.to_f? || 0
current_value = current_value.to_f? || 0
mult_value = mult_value.to_f64? || 0
current_value = current_value.to_f64? || 0
new_value = current_value * mult_value
new_value = new_value.to_i if pure_int
new_value = new_value.to_i64 if pure_int
new_value = new_value.to_s
thread.runner.set_user_var(var, new_value)
end
Expand Down

0 comments on commit 3a1d075

Please sign in to comment.