From 17f5abe8735156c14eb7a56c802bb563e3b32ee7 Mon Sep 17 00:00:00 2001
From: phil294 The "Last Found" Window
The Hotkey control has limited capabilities. For example, it does not support mouse/joystick hotkeys or the Windows key (LWin and RWin). One way to work around this is to provide one or more checkboxes as a means for the user to enable extra modifiers such as the Windows key.
- # Picture (or Pic): An area containing an image (see last paragraph for supported file types). The Text parameter is the filename of the image, which is assumed to be in %A_WorkingDir% if an absolute path isn't specified. To retain the image's actual width and/or height, omit the W and/or H options. Otherwise, the image is scaled to the specified width and/or height. To shrink or enlarge the image while preserving its aspect ratio, specify -1 for one of the dimensions and a positive number for the other. For example, specifying "w200 h-1" would make the image 200 pixels wide and cause its height to be set automatically. If the picture cannot be loaded or displayed (e.g. file not found), the control is left empty and its height and width are set to zero.
+ # Picture (or Pic): An area containing an image (see last paragraph for supported file types). The Text parameter is the filename of the image, which is assumed to be in %A_WorkingDir% if an absolute path isn't specified. You can also specify a standard icon name by prefixing it with "icon:". Example: Gui, Add, Picture, , icon:appointment-new. To retain the image's actual width and/or height, omit the W and/or H options. Otherwise, the image is scaled to the specified width and/or height. To shrink or enlarge the image while preserving its aspect ratio, specify -1 for one of the dimensions and a positive number for the other. For example, specifying "w200 h-1" would make the image 200 pixels wide and cause its height to be set automatically. If the picture cannot be loaded or displayed (e.g. file not found), the control is left empty and its height and width are set to zero.
To use a picture as a background for other controls, the picture should normally be added prior to those controls. However, if those controls are input-capable and the picture has a g-label, create the picture after the other controls and include +0x4000000 (which is WS_CLIPSIBLINGS) in the picture's Options. This trick also allows a picture to be the background behind a Tab control.
Sub-commands
(Blank): Leave Sub-command blank to put new contents into the control via Param3. All control types are self-explanatory except the following:
-Picture: Param3 should be the filename of the new image to load (see Gui for supported file types). In v1.0.24+, one or more of the following options may be specified immediately in front of the filename: *wN (width N), *hN (height N), and *IconN (icon number N). In the following example, the second icon is loaded with a width of 100 and an automatic height to "keep aspect ratio": GuiControl,, MyPic, *icon2 *w100 *h-1 C:\My Application.exe. Specify *w0 *h0 to use the image's actual width and height. If *w and *h are omitted, the image will be scaled to fit the current size of the control. Note: Use only one space or tab between the final option and the filename itself; any other spaces and tabs are treated as part of the filename.
+Picture: Param3 should be the filename of the new image to load (see Gui for supported file types). In v1.0.24+, one or more of the following options may be specified immediately in front of the filename: *wN (width N), *hN (height N), and *IconN (icon number N). In the following example, the second icon is loaded with a width of 100 and an automatic height to "keep aspect ratio": GuiControl,, MyPic, *icon2 *w100 *h-1 C:\My Application.exe. Specify *w0 *h0 to use the image's actual width and height. If *w and *h are omitted, the image will be scaled to fit the current size of the control. Note: Use only one space or tab between the final option and the filename itself; any other spaces and tabs are treated as part of the filename.
Edit: Any linefeeds (`n) in Param3 that lack a preceding carriage return (`r) are automatically translated to CR+LF (`r`n) to make them display properly. However, this is usually transparent because the "Gui Submit" and "GuiControlGet OutputVar" commands will automatically undo this translation by replacing CR+LF with LF (`n).
Hotkey: Param3 can be blank to clear the control, or a set of modifiers with a key name. Examples: ^!c, ^Numpad1, +Home. The only modifiers supported are ^ (Control), ! (Alt), and + (Shift). See the key list for available key names.
Checkbox: Param3 can be 0 to uncheck the button, 1 to check it, or -1 to give it a gray checkmark. Otherwise, Param3 is assumed to be the control's new caption/text. See Text below for how to override this behavior.
diff --git a/src/cmd/gtk/gui/gui-add.cr b/src/cmd/gtk/gui/gui-add.cr index fdec24f..194cf19 100644 --- a/src/cmd/gtk/gui/gui-add.cr +++ b/src/cmd/gtk/gui/gui-add.cr @@ -62,14 +62,27 @@ class Cmd::Gtk::Gui::GuiAdd < Cmd::Base widget.active = ((opt["choose"][:n] || 1_i64) - 1).to_i if opt["choose"]? widget.changed_signal.connect run_g_label when "picture", "pic" - widget = ::Gtk::Image.new_from_file text + if text.starts_with?("icon:") + size = case w > 1 ? w : h > 1 ? h : 48 + when 16 then ::Gtk::IconSize::Menu + when 24 then ::Gtk::IconSize::LargeToolbar + when 32 then ::Gtk::IconSize::Dnd + when 48 then ::Gtk::IconSize::Dialog + else + raise Run::RuntimeException.new "For Gui pictures with icon paths, the height/width needs to be either 16, 24, 32, 48 or unspecified." + end + widget = ::Gtk::Image.new_from_icon_name text[5..], size.value.to_i + else + widget = ::Gtk::Image.new_from_file text + end 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)) + # Icon pictures have no pixbuf, so this applies only to external files if (pixbuf = widget.pixbuf) && (w > -1 || h > -1) - if w == -1 + if w == -1 || w == 1 w = (h * pixbuf.width / pixbuf.height).to_i - elsif h == -1 + elsif h == -1 || h == 1 h = (w * pixbuf.height / pixbuf.width).to_i end pixbuf_scaled = pixbuf.scale_simple w, h, GdkPixbuf::InterpType::Bilinear