ruby-****@sourc*****
ruby-****@sourc*****
2013年 3月 12日 (火) 14:12:31 JST
------------------------- REMOTE_ADDR = 184.145.80.119 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-dancr ------------------------- @@ -33,5 +33,19 @@ If you have worked with GTK+ in either its native C, or in its close relative C++ (gtkmm) environments, you may very well be aware of the two different ways graphic imaging and drawing is handled in GTK+. One, the older and original is the plain GTK approach, mostly utilizing the Gdk::Drawable class, which has mostly been replaced by the newer approach utilizing a third party ((*Cairo*)) 2D graphics library ( see: http://cairographics.org/ ). +:Contents At the Glance: + {{image_left("1201-img01-gtk-backgrounds-s2.png")}} + Let's look at the images here to get an idea what is going to be the starting point of our study in this chapter. + {{br} + Here on the left you see a few examples of plain original GTK approach, utilizing the Gdk::Drawable class. We manage the background image of the drawable widget. In one case the single stretchable image is used, in the other multiple tailed images appear as the background. In either case you are able to use a graphic pen/brush like feature to draw, as well as 'undo' your drawing by pressing delete key. + {{br}} + On the right you can see a few very simple Cairo sample programs, that a novice to Ruby GTK/Cairo programming may find in different 'non-Ruby' tutorials on the Internet, and that may seem to be very hard if not impossible to implement in Ruby. Yet, as you can see there is a way! + + + {{image_right("1201-img02-ruby-cairo-is-comming-s2.png")}} + + In this chapter I will attempt to highlight both of these two environments, point out how they cooperate, as well as discuss the circumstances when it looks that either one may be a better choice over the other, and even when due to some, as of yet, unexplained limitations of Ruby GTK/Cairo marriage we need to resort to some peculiar tricks not needed in straight C, or C++ (gtkmm) environments. + +Most of those familiar with GTK+ 2D graphics know that Cairo 2D library is preferable over the original GTK solutions utilizing Gdk::Drawable. Also the emphasis in this chapter will be on ((*Cairo,*)) however, the two, especially in Ruby are tightly related, in fact some of what can be considered stand alone Cairo features in native C GTK+ are not available in Ruby. Most often when some native GTK/Cairo functionality is missing, we should be able to find another 'Ruby-way' of accomplishing those things. As the matter of fact, at the beginning, when I started to learn how to manage 2D graphics in Ruby, I often studied examples native C GTK, only to discover that there were no Cairo or GTK primitives available in Ruby, when trying to port the examples from those tutorials in other programming languages to Ruby. It took me a lot of time to figure out 'the Ruby ways in GTK+/Cairo'.