Grafické Rozhraní

Most applications will need to provide a graphical interface to interact with users. Graphical interfaces can create an intuitive and discoverable medium for people to interact with software, and users expect applications to provide usable and attractive user interfaces.

The GNOME Platform features sophisticated graphics and user interface technology, from standard user interface controls to an API for drawing high-quality graphics to the screen. Using the graphics technologies in GNOME allows you to create applications that are consistent, intuitive, and aesthetically pleasing.

Obrázek 3-1Layered Look at Graphics Libraries

3.1.1. GTK+

GTK+ je základním stavebním kamenem pro tvorbu uživatelského rozhraní v prostředí GNOME. Nabízí všechny uživatelské ovládací prvky, widgety, používané v aplikacích pro grafický režim. Jeho moderní a objektově orientované API vám umožňuje tvořit atraktivní a sofistikovaná uživatelská rozhraní aniž se musýte potýkat s nizkoúrovňovými problémy jako vykreslování nebo práce se zařízeními.

K základním prvkům jako tlačítka, zaškrtávací pole a textová pole přidává GTK+ mocné API k Model-View-Controller (MVC) pro stromové zobrazení, víceřádková textová pole a operace s nástrojovými lištami a nabídkami.

Widgety jsou v GTK+ umisťovány do okna s využitím modelu box-packing. Programátoři pouze udají, jak chtějí "zabalit" widgety dohromady do kontejnerových boxů namísto určování absolutního umístění. GTK+ zajišťuje, že mají okna správné rozměry vzhledem k požadavkům obsahu a automaticky obsluhuje změny velikosti okna.

Protože GTK+ nabízí flexibilní API, je vývoj dalších widgetů pro aplikace vytvořené nad GTK+ velmi snadné. Existuje množství knihoven s dalšími ovládacími prvky třetích stran a mnoho vývojářů si vytvořilo pro své aplikace vlastní specifické widgety.

GTK+ obsluhuje různé věci související s uživatelským prostředím a interakcí s uživatelem, nabízí mocné API umožňující vývojářům zaměřit se na detaily jejich aplikací. Při vývoji pomocí knihovny GTK+ máte jistotu, že vaše aplikace budou odrážet nastavení uživatelova motivu a písem, budou schopny pracovat a technologiemi zpřístupnění a budou se chovat tak, jak uživatel očekává.

Více informací o knihovně GTK+ můžete najít v Referenční příručce GTK+ nebo na WWW stránkách GTK+.

3.1.2. Libglade

Note that Libglade has been deprecated in favor of GtkBuilder. Newly written code should use GtkBuilder instead.

Libglade is a library for constructing user interfaces dynamically from XML descriptions. You can use a graphical interface builder like Glade to construct your user interface, and then import the interface description into your application. This makes it easy to construct complex layouts and adjust layout details.

Libglade allows programmers to focus their code on the logic of their applications, keeping it uncluttered by the actual construction of the interface. Graphical interface builders also make it easy for dedicated interface designers to construct the interfaces without having to know how to program.

For more information on Libglade, see the Libglade Reference Manual.

3.1.3. Pango

Pango is the core text and font handling library in the GNOME platform. It is responsible for laying out and rendering text, and is used throughout GTK+.1

Pango has extensive support for the various writing systems used throughout the world. Many of the writing systems used for languages have complex rules for laying out glyphs and composing characters. With Pango, nearly all languages can be written and displayed correctly, allowing users everywhere to view text in their native languages. Pango support for multiple writing systems is automatic; application developers do not have to write any special code to support other languages.

Obrázek 3-2Displaying Multiple Languages With Pango

Pango supports the text styling used in typical documents and interfaces, including italics, font weights, and underlines. Pango uses a simple XML-like vocabulary called PangoMarkup which enables you to set font size, color, styles, and other text attributes. Using PangoMarkup, you can specify inline styles without manually iterating over text blocks. PangoMarkup can be used directly from GTK+, enabling you to style text in your graphical interfaces easily.

You should use Pango directly whenever you need to lay text out on the screen or on a different medium. Using Pango will allow your text layout to work seamlessly with GTK+ and the rest of the GNOME platform. It will help you create portable code, and most importantly, it will ensure that your application can render text correctly in hundreds of different languages.

Více informací o knihovně Pango popisuje stránka Referenční příručka Pango.

3.1.4. GDK

GDK is the low-level library used by GTK+ to interact with the system for graphics and input devices. Although you will rarely use GDK directly in application code, it contains all the necessary functionality to draw objects and text to the screen and to interact with the user with various input devices.2

GDK features a graphics context and drawing primitives that are suitable for drawing simple objects and rendering images on the screen. Since a more extensive drawing system is provided by Cairo, GDK provides hooks to use Cairo contexts within GDK.

GDK enables you to access events from keyboards, mice, and other input devices, rather than connect to the high-level signals used in GTK+. GDK also provides low-level routines to access drag and drop and clipboard data from the system. When implementing custom controls, you may need to access these features to implement proper user interaction behavior.

GDK provides other functionality which is needed to implement a complete graphical toolkit like GTK+. Since GDK acts as a platform abstraction, allowing GTK+ to run under multiple environments, it provides an API for all of the system functionality needed by GTK+. This includes information about multi-head displays, resolution and color depth, colormaps, and cursors.

You should use GDK whenever you need low-level access to the underlying windowing system, including low-level access to events, windows, and the clipboard. Using GDK for these tasks ensures that your code is portable and integrates with the rest of your GTK+ code. The simple drawing routines in GDK should generally not be used. Instead, you should use the extensive functionality provide by Cairo.

Více informací o knihovně GDK popisuje stránka Referenční příručka knihovny GDK.

3.1.5. Cairo

Cairo is a 2D graphics library featuring a sophisticated API for drawing vector graphics, compositing images, and rendering anti-aliased text. Cairo provides support for multiple output devices, including the X Window System, Microsoft Windows, and image buffers, allowing you to write platform-independent code to draw graphics on different media.

The Cairo drawing model is similar to those provided by PostScript and PDF. The Cairo API provides such drawing operations as stroking and filling cubic Bézier splines, compositing images, and performing affine transformations. These vector operations allow for rich, anti-aliased graphics without using expensive pixel-based drawing in your application code.

Cairo's rich drawing model allows for high-quality rendering to multiple media. The same API can be used to create stunning on-screen graphics and text, to render images, or create crisp output suitable for printing.

You should use Cairo whenever you need to draw graphics in your application beyond the widgets provided by GTK+. Much of the drawing inside GTK+ is done using Cairo. Using Cairo for your custom drawing will allow your application to have high-quality, anti-aliased, and resolution-independent graphics.

For more information on Cairo, see Cairo: A Vector Graphics Library.

1

The Pango layout engine can be used with different font backends and drawing backends. On most GNOME systems, Pango will use FreeType, fontconfig, and Cairo to access fonts and render text. On other systems, Pango will use the native font systems, such as Uniscribe on Microsoft Windows and ATSUI on MacOS

2

GDK runs on a number of different platforms, including the X Window System, Microsoft Windows, DirectFB, and Quartz. On any platform, GDK provides the same consistent API, allowing GTK+ and GTK+ applications to run unmodified.