viachpaliy / cairo-gobject Goto Github PK
View Code? Open in Web Editor NEWCairo bindings for applying with crystal-gobject
License: MIT License
Cairo bindings for applying with crystal-gobject
License: MIT License
Linux Mint 18.2, 64 bits
Followed the instructions
$ sudo apt-get install libgirepository1.0-dev libgtk-3-dev libcairo-gobject2 gir1.2-freedesktop
Reading package lists... Done
Building dependency tree
Reading state information... Done
gir1.2-freedesktop is already the newest version (1.46.0-3ubuntu1).
libcairo-gobject2 is already the newest version (1.14.6-1).
libgirepository1.0-dev is already the newest version (1.46.0-3ubuntu1).
libgtk-3-dev is already the newest version (3.18.9-1ubuntu3.3).
shards.yml
name: test
version: 0.0.1
dependencies:
gobject:
github: jhass/crystal-gobject
version: ~> 0.8.0
cairo-gobject:
github: viachpaliy/cairo-gobject
cd cairo-gobject
shards install
crystal run samples/gtk_sample.cr
I got the following error
Showing last frame. Use --error-trace for full trace.
In lib/cairo/lib_cairo.cr:26:14
26 | status : LibCairo::Status
^---------------
Error: undefined constant LibCairo::Status
Working on a small program which loads an image into a Gtk::Image.
I am trying to get the mouse (x,y) position when I click on the image and moves
the mouse. Using a Gtk::EventBox around the Gtk::Image.
Things seem to work, loading and displaying the image, capturing the mouse down and mouse move events
except I am not getting the correct x,y values.
Either these values are not set or most likely I am doing something wrong.
Here is the code
require "gobject/gtk/autorun"
builder = Gtk::Builder.new_from_file("#{__DIR__}/main.glade")
builder.connect_signals
window = Gtk::Window.cast builder["window1"]
# close application when window's 'x' button is clicked
window.connect("destroy", &->Gtk.main_quit)
window.set_default_size(1920,1080)
menu_filequit = Gtk::MenuItem.cast(builder["file_quit"])
menu_fileopen = Gtk::MenuItem.cast(builder["file_open"])
viewport = Gtk::Viewport.cast(builder["viewport1"])
imagebuffer = Gtk::Image.cast(builder["image1"])
eventbox = Gtk::EventBox.cast(builder["eventbox1"])
eventbox.events = Gdk::EventMask::EXPOSURE_MASK | Gdk::EventMask::LEAVE_NOTIFY_MASK | Gdk::EventMask::BUTTON_PRESS_MASK | Gdk::EventMask::POINTER_MOTION_MASK | Gdk::EventMask::POINTER_MOTION_HINT_MASK
statusbar1 = Gtk::Statusbar.cast(builder["statusbar1"])
filechooser_open = Gtk::Button.cast(builder["filechooser_open"])
filechooser_cancel = Gtk::Button.cast(builder["filechooser_cancel"])
filechooser_dialog = Gtk::FileChooserDialog.cast(builder["filechooserdialog1"])
# event is of type Gdk::EventButton
# callback needs to return true
eventbox.on_button_press_event do |widget,eventbutton|
context_id = statusbar1.context_id("statusbar")
statusbar1.push(context_id, "mouse moved (#{eventbutton.x},#{eventbutton.y})")
true
end
# event is of type Gdk::EventMotion
# callback needs to return true
eventbox.on_motion_notify_event do |widget,eventmotion|
context_id = statusbar1.context_id("statusbar")
statusbar1.push(context_id, "mouse moved (#{eventmotion.x},#{eventmotion.y})")
true
end
# exit application
menu_filequit.on_activate do |button|
exit
end
# file chooser dialog
menu_fileopen.on_activate do |button|
filechooser_dialog.show
end
filechooser_open.on_clicked do |button|
x = filechooser_dialog.filename()
if File.directory?(x) == false && File.readable?(x)
filechooser_dialog.hide()
window.title = window.title + " | " + "loaded image #{x}"
imagebuffer.file = x
end
end
filechooser_cancel.on_clicked do |button|
filechooser_dialog.hide()
end
# maximize shows title and window buttons
window.maximize
window.show_all
Hello! I want to port my ruby-based XScreenSaver mod to crystal. The main question is - how to embed gtk3 window into XScreenSaver window. In gtk2 it could be done by this trick:
self.window=Gdk::Window.foreign_new(xid)
where xid
is passed in XSCREENSAVER_WINDOW environment variable.
Is possible to make something like this in gtk3 crystal implementation?
hello
first of all thank for this great work
trying the sample gtk_sample.cr I got this error
crystal run samples/gtk_sample.cr
Showing last frame. Use --error-trace for full trace.
In src/lib_cairo.cr:20:18
20 | rectangles : LibCairo::Rectangle*
^------------------
Error: undefined constant LibCairo::Rectangle
please note that crystal-gobject (another great work) samples work on my machine
is it a problem with my cairo release ?
my env. is
Linux Mint19 5.3.0-40-generic #32~18.04.1-Ubuntu SMP
libgtk 3.22.30 (standard installed)
libcairo, libcairo-gobject2 1.15.10
thanks for help
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.