|
Packit |
1470ea |
|
|
Packit |
1470ea |
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" type="guide" style="task" id="colorbutton.vala" xml:lang="gl">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">ColorButton (Vala)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.vala#color-selectors"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="grid.vala"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="label.vala"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-06-07" status="draft"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Tiffany Antopolski</name>
|
|
Packit |
1470ea |
<email its:translate="no">tiffany.antopolski@gmail.com</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>Un botón para iniciar un diálogo de selección de cor</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Fran Dieguez</mal:name>
|
|
Packit |
1470ea |
<mal:email>frandieguez@gnome.org</mal:email>
|
|
Packit |
1470ea |
<mal:years>2012-2013.</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>ColorButton</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/colorbutton.png"/>
|
|
Packit |
1470ea |
Os valores RGB da cor seleccionada mostraranse na etiqueta.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* This is the application. */
|
|
Packit |
1470ea |
public class MyApplication : Gtk.Application {
|
|
Packit |
1470ea |
Gtk.Label label;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Override the 'activate' signal of GLib.Application. */
|
|
Packit |
1470ea |
protected override void activate () {
|
|
Packit |
1470ea |
/* Create the window of this application and show it. */
|
|
Packit |
1470ea |
var window = new Gtk.ApplicationWindow (this);
|
|
Packit |
1470ea |
window.title = "ColorButton";
|
|
Packit |
1470ea |
window.set_default_size (150, 50);
|
|
Packit |
1470ea |
window.set_border_width (10);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* Create a new ColorButton with default blue. */
|
|
Packit |
1470ea |
var blue = Gdk.RGBA ();
|
|
Packit |
1470ea |
blue.parse ("blue");
|
|
Packit |
1470ea |
var colorbutton = new Gtk.ColorButton.with_rgba (blue);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
label = new Gtk.Label ("Click to choose a color");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
var grid = new Gtk.Grid ();
|
|
Packit |
1470ea |
grid.attach (colorbutton, 0, 0, 1, 1);
|
|
Packit |
1470ea |
grid.attach_next_to (label, colorbutton, Gtk.PositionType.BOTTOM, 1, 1);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
colorbutton.color_set.connect (this.on_color_set);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
window.add (grid);
|
|
Packit |
1470ea |
window.show_all ();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
void on_color_set (Gtk.ColorButton button) {
|
|
Packit |
1470ea |
var color = button.get_rgba ();
|
|
Packit |
1470ea |
label.set_text ("RGBA: " + color.to_string());
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* main creates and runs the application. */
|
|
Packit |
1470ea |
public int main (string[] args) {
|
|
Packit |
1470ea |
return new MyApplication ().run (args);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Neste exemplo empregaremos o seguinte:
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://valadoc.org/gtk+-3.0/Gtk.ColorButton.html">Gtk.ColorButton</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://valadoc.org/gdk-3.0/Gdk.RGBA.html">Gdk.RGBA</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</page>
|