Skip to content

WIP: more work towards implementing pan/zoom in a pure-Reactive framework #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: reactive
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
55 changes: 39 additions & 16 deletions src/GtkUtilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,21 @@ __precompile__()

module GtkUtilities

using Cairo, Gtk.ShortNames, Colors

using Graphics
using Cairo, Gtk.ShortNames, Colors, Reactive, Graphics
import Gtk.GConstants.GdkEventMask: KEY_PRESS, SCROLL

export
# Link
AbstractState,
State,
link,
disconnect,
get,
set!,
set_quietly!,
widget,
id,
lLabel,
lEntry,
lScale,
# general
keysignal,
mouseposition,
# GUIData
guidata,
trigger,
# Rubberband
rubberband_start,
# PanZoom
Interval,
ViewROI,
interior,
fullview,
panzoom,
Expand All @@ -44,6 +34,39 @@ include("panzoom.jl")
using .PanZoom
import .PanZoom: interior, fullview # for extensions

"""
signal = keysignal(widget, [setfocus=true])

Create a signal for monitoring keypresses on a canvas or other
`widget`. The signal fires every time a key is pressed. At least for
some widgets (e.g., canvases), `setfocus` must be true or the widget
will not process key press events.

The signal value is a GdkEventKey; the `keyval` and `state` fields can
be used to monitor the pressed key and any held modifiers,
respectively.
"""
function keysignal(widget::Gtk.GtkWidget, setfocus::Bool=true)
add_events(widget, KEY_PRESS)
if setfocus
setproperty!(widget, :can_focus, true)
setproperty!(widget, :has_focus, true)
end
evt = Gtk.GdkEventKey()
sig = Signal(evt)
id = signal_connect(widget, :key_press_event) do widget, event
push!(sig, event)
end
return sig
end

"""
signal = mouseposition(canvas)

Creates a Reactive signal that updates whenever the mouse pointer
position changes within the canvas.
"""

function Base.copy!{C<:Colorant}(ctx::CairoContext, img::AbstractArray{C})
save(ctx)
Cairo.reset_transform(ctx)
Expand Down
Loading