¶óº§Àº GTK¿¡¼ ÀÚÁÖ ¾²ÀÌ°í ºñ±³Àû °£´ÜÇÑ °ÍÀÌ´Ù. À̵éÀº °ü·ÃµÈ XÀ©µµ°¡ ¾øÀ¸¹Ç·Î ½Ã±×³ÎÀ» ¹ß»ýÇÏÁö ¾Ê´Â´Ù. ¸¸¾à ½Ã±×³ÎÀ» Àâ¾Æ³»°Å³ª Ŭ¸®ÇÎÀ» ÇÒ ¸ñÀûÀ̶ó¸é EventBox widgetÀ» ÀÌ¿ëÇ϶ó.
»õ·Î¿î ¶óº§À» ¸¸µé±â À§ÇØ ÀÌ°ÍÀ» ÀÌ¿ëÇÑ´Ù.
GtkWidget* gtk_label_new (char *str);
ÇϳªÀÇ ÀÎÀÚ´Â ¿ì¸®°¡ ³ªÅ¸³»°íÀÚ ÇÏ´Â ¶óº§ÀÇ ¹®ÀÚ¿ÀÌ´Ù.
¶óº§À» ¸¸µç ÀÌÈÄ¿¡ ÀÌ ¶óº§ÀÇ ÅؽºÆ®¸¦ ¹Ù²Ù·Á¸é ÀÌ°ÍÀ» ÀÌ¿ëÇÑ´Ù.
void gtk_label_set (GtkLabel *label,
char *str);
ù¹ø° ÀÎÀÚ´Â ÀÌÀü¿¡ ¸¸µé¾îÁ® ÀÖ´Â ¶óº§(GTK_LABEL()¸ÅÅ©·Î·Î½á ij½ºÆ®µÊ) ÀÌ°í, µÎ¹ø°´Â »õ·Î¿î ¹®ÀÚ¿ÀÌ´Ù.
»õ·Î¿î ¶óº§À» À§ÇÑ °ø°£Àº ÇÊ¿äÇÒ °æ¿ì¿¡ ÀÚµ¿ÀûÀ¸·Î Á¶ÀýµÈ´Ù.
ÇöÀçÀÇ ¹®ÀÚ¿À» µÇã°í ½Í´Ù¸é ÀÌ°ÍÀ» ÀÌ¿ëÇÑ´Ù.
void gtk_label_get (GtkLabel *label,
char **str);
ù¹ø° ÀÎÀÚ´Â ¸¸µé¾îÁ³´ø ¶óº§ÀÌ°í, µÎ¹ø°´Â µÇ»ì¸®°íÀÚ ÇÏ´Â ¹®ÀÚ¿ÀÌ´Ù.
¸¶¿ì½ºÆ÷ÀÎÅ͸¦ ¾î¶² ¹öÆ°À̳ª ´Ù¸¥ widget À§¿¡ ¸î ÃÊ ¸Ó¹«¸£°Ô Çϸé ÀÛÀº ÅؽºÆ® ¹®ÀÚ¿ÀÌ Æ¢¾î³ª¿À´Â °æ¿ì°¡ ÀÖ´Ù. ÀÌ°ÍÀº °£´ÜÇÑ °ÍÀ̸ç, ±×·¡¼ ¿©±â¼ ¿¹Á¦¾øÀÌ ¼³¸íÇÏ°Ú´Ù. ½ÇÁ¦·Î Äڵ带 º¸°í½Í´Ù¸é GDK¿Í ÇÔ²² ¹èÆ÷µÇ´Â testgtk.c ÇÁ·Î±×·¥À» ÂüÁ¶Ç϶ó.
¶óº§ µî ¾î¶² widget¿¡´Â ÀÌ tooltipÀÌ ¾²ÀÌÁö ¾Ê´Â´Ù.
¿ì¸®°¡ óÀ½ ÀÌ¿ëÇÒ ÇÔ¼ö´Â »õ·Î¿î tooltipÀ» ¸¸µå´Â °ÍÀÌ´Ù. ÀÌ°ÍÀº ÁÖ¾îÁø
ÇÔ¼ö¿¡¼ Çѹø¸¸ ÇØÁÖ¸é µÈ´Ù. ÀÌ ÇÔ¼ö°¡ ¸®ÅÏÇÏ´Â GtkTooltip
˼
´ÙÁßÀÇ tooltipµéÀ» ¸¸µå´Âµ¥µµ ÀÌ¿ëµÉ ¼ö ÀÖ´Ù.
GtkTooltips *gtk_tooltips_new (void);
ÀÏ´Ü »õ·Î¿î tooltip°ú ±×°ÍÀ» »ç¿ëÇÒ widgetÀ» ¸¸µé¾úÀ¸¸é, ±×°ÍÀ» ¼¼ÆÃÇϱâ À§ÇØ ÀÌ ÇÔ¼ö¸¦ ÀÌ¿ëÇ϶ó.
void gtk_tooltips_set_tip (GtkTooltips *tooltips,
GtkWidget *widget,
const gchar *tip_text,
const gchar *tip_private);
ù¹ø° ÀÎÀÚ´Â ¿ì¸®°¡ ¸¸µç tooltipÀÌ°í, ´ÙÀ½Àº ÀÌ tooltipÀ» Æ÷ÇÔÇÏ°Ô µÉ widgetÀÌ´Ù. ¼¼¹ø° ÀÎÀÚÀÎ ÅؽºÆ®´Â ¿ì¸®°¡ tooltip¿¡¼ ¸»ÇÏ°íÀÚ ÇÏ´Â °ÍÀÌ´Ù. ¸¶Áö¸· ÀÎÀÚ´Â NULL·Î ÁÙ ¼ö ÀÖ´Ù.
ÀÌ°ÍÀº ªÀº ¿¹´Ù.
GtkTooltips *tooltips;
GtkWidget *button;
...
tooltips = gtk_tooltips_new ();
button = gtk_button_new_with_label ("button 1");
...
gtk_tooltips_set_tip (tooltips, button, "This is button 1", NULL);
Tooltip¿¡ ¾²ÀÌ´Â ´Ù¸¥ ÇÔ¼öµéµµ ÀÖ´Ù. ¿©±â¼ ±×µéÀ» °£´ÜÈ÷ ¼Ò°³ÇÏ°Ú´Ù.
void gtk_tooltips_destroy (GtkTooltips *tooltips);
¸¸µé¾îÁø tooltipÀ» Á¦°ÅÇÑ´Ù.
void gtk_tooltips_enable (GtkTooltips *tooltips);
Disable·Î ¼³Á¤µÈ tooltipÀ» enableÇÑ´Ù.
void gtk_tooltips_disable (GtkTooltips *tooltips);
Enable·Î ¼³Á¤µÈ tooltipÀ» disableÇÑ´Ù.
void gtk_tooltips_set_delay (GtkTooltips *tooltips,
gint delay);
TooltipÀÌ Æ¢¾î¿À¸£±â À§ÇØ ¾ó¸¶³ª ¸¶¿ì½ºÆ÷ÀÎÅ͸¦ widgetÀ§¿¡ ¸Ó¹«¸£°Ô ÇؾßÇÏ´Â Áö¸¦, millisecond´ÜÀ§·Î ¼¼ÆÃÇÑ´Ù. µðÆúÆ®·Î 1000millisecond, Áï 1ÃÊ´Ù.
void gtk_tooltips_set_tips (GtkTooltips *tooltips,
GtkWidget *widget,
gchar *tips_text);
ÀÌ¹Ì ¸¸µé¾îÁø tooltipÀÇ ÅؽºÆ® ³»¿ëÀ» ¹Ù²Û´Ù.
void gtk_tooltips_set_colors (GtkTooltips *tooltips,
GdkColor *background,
GdkColor *foreground);
TooltipÀÇ Ç¥Çö»ö°ú ¹è°æ»öÀ» ¹Ù²Û´Ù. ¾î¶»°Ô »ö±òÀ» ¼³Á¤ÇÏ´ÂÁö¿¡ ´ëÇؼ´Â ¸ð¸£°Ú´Ù.
Tooltip¿¡ °ü·ÃµÈ ÇÔ¼ö´Â ÀÌ°ÍÀÌ ÀüºÎ´Ù. ´õÀÌ»ó ¾Ë °Íµµ ¾ø´Ù. :)
ÁøÇื´ë´Â ÀÛ¾÷ÀÇ »óȲÀ» ³ªÅ¸³»±â À§ÇØ ¾²ÀδÙ. ÀÌÁ¦ Äڵ带 º¸¸é ¾Ë°ÚÁö¸¸, ÀÌ°ÍÀº ²Ï °£´ÜÇÏ´Ù. ±×·¯³ª ¸ÕÀú »õ·Î¿î ÁøÇื´ë¸¦ ¸¸µé¾îÁÖ´Â ÇÔ¼ö¸¦ »ìÆì º¸´Â °ÍÀ¸·Î ½ÃÀÛÇÏÀÚ.
GtkWidget *gtk_progress_bar_new (void);
ÀÌÁ¦ ÁøÇื´ë°¡ ¸¸µé¾îÁ³°í ¿ì¸®´Â ±×°ÍÀ» ÀÌ¿ëÇÒ ¼ö ÀÖ´Ù.
void gtk_progress_bar_update (GtkProgressBar *pbar, gfloat percentage);
ù¹ø° ÀÎÀÚ´Â µ¿ÀÛ½Ãų ÁøÇื´ë°¡ µÇ°í, µÎ¹ø° ÀÎÀÚ´Â '¿Ï·áµÈ' ºÐ·®À» ³ªÅ¸³½´Ù. ÀÌ°ÍÀº ½ÇÁ¦ ¼ýÀÚ·Î 0ºÎÅÍ 1±îÁö°í, 0ºÎÅÍ 100ÆÛ¼¾Æ®¸¦ ÀǹÌÇÏ´Â °ÍÀÌ´Ù.
ÁøÇื´ë´Â º¸Åë ŸÀӾƿôÀ̳ª ¶Ç´Â ¸ÖƼŽºÅ·ÇÏ´Â Âø°¢À» ÀÏÀ¸Å°°Ô ÇÏ´Â ÇÔ¼öµé°ú ÇÔ²² ¾²ÀδÙ. (section ŸÀӾƿô, ±×¸®°í I/O¿Í Idle ÇÔ¼öµéÀ» ÂüÁ¶Ç϶ó.) ¸ðµç °æ¿ì¿¡ gtk_progress_bar_updateÇÔ¼ö°¡ µ¿ÀÏÇÑ ¹æ½ÄÀ¸·Î ¾²ÀÌ°Ô µÈ´Ù.
ÀÌ°ÍÀº ŸÀӾƿôÀ» ÀÌ¿ëÇØ ¾÷µ¥ÀÌÆ®µÇ´Â ÁøÇื´ë¸¦ º¸ÀÎ ¿¹Á¦´Ù. ÀÌ°ÍÀº ¶ÇÇÑ ÁøÇื´ë¸¦ ¸®¼Â, Áï ÃʱâÈÇÏ´Â ¹æ¹ýµµ º¸¿©ÁÙ °ÍÀÌ´Ù.
/* progressbar.c */
#include <gtk/gtk.h>
static int ptimer = 0;
int pstat = TRUE;
/* ÀÌ ÇÔ¼ö´Â ÁøÇื´ë¸¦ Áõ°¡½ÃÅ°°í ¾÷µ¥ÀÌÆ®ÇÑ´Ù. ¶Ç pstat°¡ FALSE·Î µÇ¸é
* ÁøÇื´ë¸¦ ¸®¼Â, Áï ÃʱâÈÇÑ´Ù. */
gint progress (gpointer data)
{
gfloat pvalue;
/* ÁøÇื´ëÀÇ ÇöÀç°ªÀ» ¾Ë¾Æ³½´Ù. */
pvalue = GTK_PROGRESS_BAR (data)->percentage;
if ((pvalue >= 1.0) || (pstat == FALSE)) {
pvalue = 0.0;
pstat = TRUE;
}
pvalue += 0.01;
gtk_progress_bar_update (GTK_PROGRESS_BAR (data), pvalue);
return TRUE;
}
/* ÀÌ ÇÔ¼ö´Â ÁøÇื´ëÀÇ ¸®¼ÂÀ» À§ÇÑ ½Ã±×³ÎÀ» ³½´Ù. */
void progress_r (void)
{
pstat = FALSE;
}
void destroy (GtkWidget *widget, gpointer data)
{
gtk_main_quit ();
}
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *label;
GtkWidget *table;
GtkWidget *pbar;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
GTK_SIGNAL_FUNC (destroy), NULL);
gtk_container_border_width (GTK_CONTAINER (window), 10);
table = gtk_table_new(3,2,TRUE);
gtk_container_add (GTK_CONTAINER (window), table);
label = gtk_label_new ("Progress Bar Example");
gtk_table_attach_defaults(GTK_TABLE(table), label, 0,2,0,1);
gtk_widget_show(label);
/* »õ·Î¿î ÁøÇื´ë¸¦ ¸¸µé°í, ±×°ÍÀ» Å×ÀÌºí¿¡ ÆÐÅ·ÇÏ¿© º¸¿©ÁØ´Ù. */
pbar = gtk_progress_bar_new ();
gtk_table_attach_defaults(GTK_TABLE(table), pbar, 0,2,1,2);
gtk_widget_show (pbar);
/* ÁøÇื´ëÀÇ ÀÚµ¿ ¾÷µ¥ÀÌÆ®¸¦ À§ÇÑ timeoutÀ» ¼³Á¤ÇÑ´Ù. */
ptimer = gtk_timeout_add (100, progress, pbar);
/* ÀÌ ¹öÆ°ÀÌ ÁøÇื´ë¸¦ ¸®¼ÂÇÏ´Â ½Ã±×³ÎÀ» À§ÇÑ °ÍÀÌ´Ù. */
button = gtk_button_new_with_label ("Reset");
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (progress_r), NULL);
gtk_table_attach_defaults(GTK_TABLE(table), button, 0,1,2,3);
gtk_widget_show(button);
button = gtk_button_new_with_label ("Cancel");
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (destroy), NULL);
gtk_table_attach_defaults(GTK_TABLE(table), button, 1,2,2,3);
gtk_widget_show (button);
gtk_widget_show(table);
gtk_widget_show(window);
gtk_main ();
return 0;
}
ÀÌ ÀÛÀº ÇÁ·Î±×·¥¿¡´Â ÁøÇื´ëÀÇ ÀϹÝÀûÀÎ µ¿ÀÛ°ú °ü·ÃµÈ ³× °³ÀÇ ¿µ¿ªÀÌ ÀÖ´Ù. ±×µéÀÌ ¾²¿©Áø ¼ø¼¿¡ µû¶ó ¾Ë¾Æº¸µµ·Ï ÇÏÀÚ.
pbar = gtk_progress_bar_new ();
ÀÌ ÄÚµå´Â pbar¶ó´Â À̸§ÀÇ »õ·Î¿î ÁøÇื´ë¸¦ ¸¸µé°í ÀÖ´Ù.
ptimer = gtk_timeout_add (100, progress, pbar);
ÀÌ Äڵ忡¼ ÀÏÁ¤ÇÑ ½Ã°£°£°ÝÀÇ Å¸ÀӾƿôÀ» ÀÌ¿ëÇϴµ¥, ÁøÇื´ëÀÇ ÀÌ¿ë¿¡ ²À ŸÀӾƿôÀ» ½á¾ß µÇ´Â °ÍÀº ¾Æ´Ï´Ù.
pvalue = GTK_PROGRESS_BAR (data)->percentage;
¿©±â¼ pvalue¸¦ ÇâÇÑ percentage barÀÇ ÇöÀç °ªÀ» ÁöÁ¤ÇØ ÁÖ°í ÀÖ´Ù.
gtk_progress_bar_update (GTK_PROGRESS_BAR (data), pvalue);
³¡À¸·Î, pvalueÀÇ °ª¿¡ ÀÇÇØ ÁøÇื´ë¸¦ ¾÷µ¥ÀÌÆ®ÇÑ´Ù.
±×¸®°í ÁøÇื´ë¿¡ ´ëÇØ ¾Ë °ÍÀº ÀÌ°ÍÀÌ ÀüºÎ´Ù, Áñ°Üº¸±â¸¦ !
´ëÈ»óÀÚ widgetÀº ¸Å¿ì °£´ÜÇÑ °ÍÀε¥, ½ÇÁ¦·Î ÀÌ°ÍÀº ¸î°¡Áö°¡ ¹Ì¸® ÆÐÅ·µÇ¾î ÀÖ´Â ÇϳªÀÇ À©µµÀÏ »ÓÀÌ´Ù. Dialog¸¦ À§ÇÑ ±¸Á¶Ã¼´Â ÀÌ°ÍÀÌ´Ù.
struct GtkDialog
{
GtkWindow window;
GtkWidget *vbox;
GtkWidget *action_area;
};
º¸´Ù½ÃÇÇ ÀÌ°ÍÀº ´Ü¼øÈ÷ À©µµ¸¦ ¸¸µé°í, ±×¸®°í´Â vbox¸¦ ¸Ç À§·Î ÆÐÅ·ÇÏ°í, ´ÙÀ½À¸·Î separator¸¦, ±×¸®°í ³ª¼ "action_area"¸¦ À§ÇÑ hbox¸¦ ÆÐÅ·ÇÑ´Ù.
´ëÈ»óÀÚwidgetÀº »ç¿ëÀÚ¿¡°Ô Æ˾÷ ¸Þ½ÃÁö¸¦ º¸À̰ųª ÇÏ´Â µîÀÇ ¸ñÀûÀ¸·Î ¾²ÀÏ ¼ö ÀÖ´Ù. ÀÌ°ÍÀº Á¤¸» ±âº»ÀûÀÎ °ÍÀ¸·Î, ´ëȹڽº¸¦ À§ÇÑ ÇÔ¼ö´Â ÀÌ°Í Çϳª »ÓÀÌ´Ù.
GtkWidget* gtk_dialog_new (void);
±×·¡¼ »õ·Î¿î ´ëȹڽº¸¦ ¸¸µé·Á¸é ÀÌ·¸°Ô ÇÑ´Ù.
GtkWidget *window;
window = gtk_dialog_new ();
ÀÌ°ÍÀº ´ëÈ»óÀÚ¸¦ ¸¸µé °ÍÀÌ°í, ¾î¶»°Ô ÀÌ¿ëÇÒÁö´Â °¢ÀÚ¿¡°Ô ´Þ·ÁÀÖ´Ù. ¿ì¸®´Â ÀÌ·± ½ÄÀ¸·Î Çؼ action_area ¾È¿¡ ¹öÆ°À» ÆÐÅ·ÇÒ ¼ö ÀÖ´Ù.
button = ...
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), button,
TRUE, TRUE, 0);
gtk_widget_show (button);
±×¸®°í ¿ì¸®´Â ÆÐÅ·¿¡ ÀÇÇÏ¿© vbox ¿µ¿ª¿¡ ¶óº§ µîÀ» Ãß°¡ÇÒ ¼ö ÀÖ´Ù. ¾Æ·¡¿Í °°ÀÌ Çغ¸ÀÚ.
label = gtk_label_new ("Dialogs are groovy");
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), label, TRUE,
TRUE, 0);
gtk_widget_show (label);
´ëÈ»óÀÚ¸¦ ÀÌ¿ëÇÑ ¿¹Á¦¿¡¼Ã³·³, ¿ì¸®´Â action_area¿¡ Cancel°ú OkÀÇ µÎ ¹öÆ°À», ±×¸®°í vbox¿µ¿ª¿£ »ç¿ëÀÚ¿¡°Ô ¹°¾îº¸°Å³ª ¿¡·¯¸Þ½ÃÁö¸¦ ³»°Å³ª ÇÏ´Â ¸ñÀûÀÇ ¶óº§À» ¸¸µé ¼ö ÀÖÀ» °ÍÀÌ´Ù. ±×¸®°í ³ª¼ »ç¿ëÀÚÀÇ ¼±Åÿ¡ µû¶ó ÀÛµ¿Çϵµ·Ï ¹öÆ° °¢°¢¿¡ ¼·Î ´Ù¸¥ ½Ã±×³ÎÀ» ¼³Á¤ÇØ µÑ ¼ö ÀÖ´Ù.
ÇȽº¸ÊÀº ±×¸²À» Æ÷ÇÔÇÏ°í ÀÖ´Â ÀÚ·á ±¸Á¶ÀÌ´Ù. ÀÌ·± ±×¸²Àº ¿©·¯°¡Áö·Î ¾²ÀÏ ¼ö Àִµ¥, °¡Àå ´«¿¡ ¶ç´Â ÀÌ¿ëÀº XÀ©µµ µ¥½ºÅ©ÅéÀÇ ¾ÆÀÌÄÜÀ̳ª Ä¿¼ÀÏ °ÍÀÌ´Ù. ºñÆ®¸ÊÀ̶õ 2»öÀÇ ÇȽº¸ÊÀÌ´Ù.
GTK¿¡¼ ÇȽº¸ÊÀ» ÀÌ¿ëÇϱâ À§ÇØ, ¿ì¸®´Â ¸ÕÀú GDK ¼öÁØÀÇ ÇÔ¼öµé·Î½á GdkPixmap ±¸Á¶Ã¼¸¦ ¸¸µé¾î¾ß ÇÑ´Ù. ÇȽº¸ÊÀº ¸Þ¸ð¸®ÀÇ ÀÚ·á ȤÀº ÆÄÀϷκÎÅÍ ÀоîµéÀÎ ÀÚ·á·ÎºÎÅÍ ¸¸µé¾îÁú ¼ö ÀÖ´Ù. ¿ì¸®´Â ÇȽº¸ÊÀ» ¸¸µé±â À§ÇÑ °¢°¢ÀÇ ÇÔ¼ö¸¦ Áö±ÝºÎÅÍ »ìÆ캼 °ÍÀÌ´Ù.
GdkPixmap *gdk_bitmap_create_from_data( GdkWindow *window,
gchar *data,
gint width,
gint height );
ÀÌ ÇÔ¼ö´Â ¸Þ¸ð¸®ÀÇ µ¥ÀÌÅÍ·Î 2»öÀÇ single-plane ÇȽº¸ÊÀ» ¸¸µé±â À§ÇÑ °ÍÀ¸·Î, µ¥ÀÌÅÍÀÇ °¢°¢ÀÇ ºñÆ®´Â Çȼ¿ÀÇ on/off ¿©ºÎ¸¦ ³ªÅ¸³½´Ù. width/height´Â Çȼ¿ ´ÜÀ§´Ù. ÇȽº¸Ê ¸®¼Ò½º´Â ±×°ÍÀÌ º¸¿©Áú ½ºÅ©¸°ÀÇ ¹è°æ¿¡¼¸¸ Àǹ̰¡ ÀÖÀ¸¹Ç·Î, GdkWindow Çü Æ÷ÀÎÅÍ´Â ÇöÀçÀÇ À©µµ¸¦ °¡¸®Å°°Ô µÈ´Ù.
GdkPixmap* gdk_pixmap_create_from_data( GdkWindow *window,
gchar *data,
gint width,
gint height,
gint depth,
GdkColor *fg,
GdkColor *bg );
ÀÌ°ÍÀº ÁÖ¾îÁø ºñÆ®¸Ê µ¥ÀÌŸ·ÎºÎÅÍ ÀÓÀÇÀÇ depth(»öÀÇ °¹¼ö)¸¦ °¡Áø ÇȽº¸ÊÀ» ¸¸µé ¶§ ¾²ÀδÙ. fg¿Í bg´Â ÀÌ¿ëÇÒ foreground ¹× background »ö±òÀÌ´Ù.
GdkPixmap* gdk_pixmap_create_from_xpm( GdkWindow *window,
GdkBitmap **mask,
GdkColor *transparent_color,
const gchar *filename );
XPM Æ÷¸ËÀº XÀ©µµ½Ã½ºÅÛ¿¡¼ ÀоîµéÀÏ ¼ö ÀÖ´Â ÇϳªÀÇ ÇȽº¸Ê ÇüÅ´Ù. ÀÌ°ÍÀº ³Î¸® ¾²ÀÌ°í ÀÖÀ¸¸ç À̹ÌÁö ÆÄÀÏÀ» ÀÌ Æ÷¸ËÀ¸·Î ¸¸µé¾î ÁÖ´Â ¼ö¸¹Àº À¯Æ¿¸®Æ¼µéÀÌ ÀÖ´Ù. ÆÄÀÏÀ̸§À¸·Î ºÒ¸®¾îÁø ÀÌ ÆÄÀÏÀº ±× Æ÷¸ËÀÇ À̹ÌÁö¸¦ Æ÷ÇÔÇÏ°í ÀÖ¾î¾ß ÇÏ°í, ±×°ÍÀº ÇȽº¸Ê ±¸Á¶Ã¼ ¾ÈÀ¸·Î ·ÎµåµÈ´Ù. ±× ÇȽº¸ÊÀÇ ¾î¶² ºñÆ®°¡ ºÒÅõ¸í ÇØ¾ß ÇÏ´ÂÁö´Â mask°¡ °áÁ¤ÇÑ´Ù. ³ª¸ÓÁö ¸ðµç ºñÆ®µéÀº transparent_color¿¡ ÀÇÇØ Á¤ÇØÁø »ö±òÀ» °¡Áö°Ô µÈ´Ù. ÀÌ°ÍÀ» ÀÌ¿ëÇÏ´Â ¿¹Á¦°¡ ¾Æ·¡¿¡ µÚµû¸¦ °ÍÀÌ´Ù.
GdkPixmap* gdk_pixmap_create_from_xpm_d (GdkWindow *window,
GdkBitmap **mask,
GdkColor *transparent_color,
gchar **data);
ÀÛÀº À̹ÌÁö´Â XPM Æ÷¸ËÀÇ µ¥ÀÌÅͷμ ÇÁ·Î±×·¥ ³»ºÎ¿¡ Æ÷ÇԵǾî ÀÖÀ» ¼ö°¡ ÀÖ´Ù. ¾î¶² ÇȽº¸ÊÀº ÆÄÀϷκÎÅÍ µ¥ÀÌÅ͸¦ ÀоîµéÀÌ´Â ´ë½Å ÀÌ·± µ¥ÀÌÅ͸¦ ÀÌ¿ëÇØ ¸¸µé¾îÁø´Ù. ÀÌ µ¥ÀÌÅÍÀÇ ¿¹´Â ÀÌ·± °ÍÀÌ´Ù.
/* XPM */
static const char * xpm_data[] = {
"16 16 3 1",
" c None",
". c #000000000000",
"X c #FFFFFFFFFFFF",
" ",
" ...... ",
" .XXX.X. ",
" .XXX.XX. ",
" .XXX.XXX. ",
" .XXX..... ",
" .XXXXXXX. ",
" .XXXXXXX. ",
" .XXXXXXX. ",
" .XXXXXXX. ",
" .XXXXXXX. ",
" .XXXXXXX. ",
" .XXXXXXX. ",
" ......... ",
" ",
" "};
void gdk_pixmap_destroy( GdkPixmap *pixmap );
¿ì¸®°¡ ¾î¶² ÇȽº¸ÊÀ» ÀÌ¿ëÇß°í ¶Ç ´çºÐ°£ ´Ù½Ã ÀÌ¿ëÇÒ ÇÊ¿ä°¡ ¾øÀ» °æ¿ì, ÀÌ ¸®¼Ò½º¸¦ gdk_pixmap_destory·Î ¸Þ¸ð¸®¿¡ ¹Ý³³ÇØÁÖ´Â °Íµµ ÁÁÀº »ý°¢ÀÌ´Ù. ÇȽº¸ÊÀº Áß¿äÇÑ ¸®¼Ò½º·Î °£ÁֵǾî¾ß ÇÑ´Ù.
¿ì¸®°¡ ÀÏ´Ü ÇȽº¸ÊÀ» ¸¸µé¸é, ±×°ÍÀ» GTK widgetó·³ º¸¿©ÁÙ ¼ö ÀÖ´Ù. ¿ì¸®´Â GDK ÇȽº¸ÊÀ» Æ÷ÇÔ½ÃÅ°±â À§Çؼ ÇȽº¸ÊwidgetÀ» ¸¸µé¾î¾ß¸¸ ÇÑ´Ù. ÀÌ°ÍÀ» ÀÌ¿ë Çؼ ±×·¸°Ô ÇÒ ¼ö ÀÖ´Ù.
GtkWidget* gtk_pixmap_new( GdkPixmap *pixmap,
GdkBitmap *mask );
¶Ç´Ù¸¥ ÇȽº¸Êwidget ÇÔ¼öµéÀº ´ÙÀ½°ú °°´Ù.
guint gtk_pixmap_get_type( void );
void gtk_pixmap_set( GtkPixmap *pixmap,
GdkPixmap *val,
GdkBitmap *mask);
void gtk_pixmap_get( GtkPixmap *pixmap,
GdkPixmap **val,
GdkBitmap **mask);
gtk_pixmap_setÀº widgetÀÌ ÇöÀç ´Ù·ç°í ÀÖ´Â ÇȽº¸ÊÀ» º¯È½ÃÅ°±â À§ÇØ ÀÌ¿ëÇÑ´Ù. ÀÎÀÚ valÀº GDK¸¦ ÀÌ¿ëÇØ ¸¸µé¾îÁø ÇȽº¸ÊÀÌ´Ù.
ÀÌ ¿¹Á¦´Â ¹öÆ° ¾È¿¡ ÇȽº¸ÊÀ» ³Ö´Â ¿¹Á¦ÀÌ´Ù.
#include <gtk/gtk.h>
/* Open-File ¾ÆÀÌÄÜÀ» À§ÇÑ XPM µ¥ÀÌÅÍ */
static const char * xpm_data[] = {
"16 16 3 1",
" c None",
". c #000000000000",
"X c #FFFFFFFFFFFF",
" ",
" ...... ",
" .XXX.X. ",
" .XXX.XX. ",
" .XXX.XXX. ",
" .XXX..... ",
" .XXXXXXX. ",
" .XXXXXXX. ",
" .XXXXXXX. ",
" .XXXXXXX. ",
" .XXXXXXX. ",
" .XXXXXXX. ",
" .XXXXXXX. ",
" ......... ",
" ",
" "};
/* ÀÌ°ÍÀÌ È£ÃâµÇ¸é(delete_event ½Ã±×³ÎÀ» ÅëÇØ) ¾îÇÃÀÌ Á¾·áµÈ´Ù. */
void close_application( GtkWidget *widget, GdkEvent *event, gpointer data )
{
gtk_main_quit();
}
/* ¹öÆ°ÀÌ Å¬¸¯µÇ¸é È£ÃâµÇ¾î ¸Þ½ÃÁö¸¦ ÇÁ¸°Æ®ÇÑ´Ù. */
void button_clicked( GtkWidget *widget, gpointer data )
{
printf( "button clicked\n" );
}
int main( int argc, char *argv[] )
{
/* GtkWidgetÀº widgetÀ» À§ÇÑ ±â¾ïÀå¼Ò ŸÀÔÀÌ´Ù. */
GtkWidget *window, *pixmapwid, *button;
GdkPixmap *pixmap;
GdkBitmap *mask;
GtkStyle *style;
/* main À©µµ¸¦ ¸¸µé°í, ¾îÇÃÀ» ³¡³»±â À§ÇÑ delete_event ½Ã±×³ÎÀ»
* ¿¬°á½ÃÄÑ µÐ´Ù. */
gtk_init( &argc, &argv );
window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtk_signal_connect( GTK_OBJECT (window), "delete_event",
GTK_SIGNAL_FUNC (close_application), NULL );
gtk_container_border_width( GTK_CONTAINER (window), 10 );
gtk_widget_show( window );
/* gdkÇÔ¼ö·Î ÇȽº¸ÊÀ» ¸¸µé±â À§ÇÑ °ÍÀÌ´Ù. */
style = gtk_widget_get_style( window );
pixmap = gdk_pixmap_create_from_xpm_d( window->window, &mask,
&style->bg[GTK_STATE_NORMAL],
(gchar **)xpm_data );
/* ÇȽº¸ÊÀ» ´Ù·ê pixmap widgetÀÌ´Ù. */
pixmapwid = gtk_pixmap_new( pixmap, mask );
gtk_widget_show( pixmapwid );
/* pixmap widgetÀ» °¡Áö°Ô µÇ´Â ¹öÆ°ÀÌ´Ù. */
button = gtk_button_new();
gtk_container_add( GTK_CONTAINER(button), pixmapwid );
gtk_container_add( GTK_CONTAINER(window), button );
gtk_widget_show( button );
gtk_signal_connect( GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(button_clicked), NULL );
/* À©µµ¸¦ º¸ÀδÙ. */
gtk_main ();
return 0;
}
ÇöÀç µð·ºÅ丮ÀÇ icon0.xpm À̶ó´Â XPM µ¥ÀÌÅÍÆÄÀÏÀ» ºÒ·¯¿À±â À§Çؼ, ¿ì¸®´Â ÇȽº¸ÊÀ» ¸¸µé¾î¾ß ÇÑ´Ù.
/* ÆÄÀϷκÎÅÍ ÇȽº¸ÊÀ» ºÒ·¯¿Â´Ù. */
pixmap = gdk_pixmap_create_from_xpm( window->window, &mask,
&style->bg[GTK_STATE_NORMAL],
"./icon0.xpm" );
pixmapwid = gtk_pixmap_new( pixmap, mask );
gtk_widget_show( pixmapwid );
gtk_container_add( GTK_CONTAINER(window), pixmapwid );
ÇȽº¸ÊÀ» ÀÌ¿ëÇÒ ¶§ ´ÜÁ¡ Çϳª´Â À̹ÌÁö¿¡ °ü°è¾øÀÌ ¸ðµç ´ë»óÀÌ Á÷»ç°¢Çü À̶ó´Â °ÍÀÌ´Ù. ¿ì¸®´Â µ¥½ºÅ©Åé°ú ¾îÇÿ¡¼ ¾ÆÀÌÄÜÀÌ Á»´õ ÀÚ¿¬½º·¯¿î ¸ð¾çÀ» °¡Áöµµ·Ï ÇÏ°í½Í´Ù. ¿¹¸¦µé¾î ¾î¶² °ÔÀÓ ÀÎÅÍÆäÀ̽º¿¡¼, ¿ì¸®´Â ´©¸¦ ¹öÆ°ÀÌ µÕ±Ù ¸ð¾çÀ» °¡Áöµµ·Ï ÇÏ°í ½Í¾îÇÑ´Ù. ÀÌ·¸°Ô Çϱâ À§Çؼ´Â ƯÁ¤ÇÑ ¸ð¾çÀ» °®Ãá À©µµ¸¦ ÀÌ¿ëÇÑ´Ù.
ƯÁ¤ÇÑ ¸ð¾çÀ» °®Ãá À©µµ¶õ °£´ÜÈ÷ ¹è°æÀ» ÀÌ·ç´Â Çȼ¿µéÀÌ Åõ¸íÇÑ °ÍÀ» ¸»ÇÑ´Ù. ¹è°æ À̹ÌÁö°¡ ¿©·¯ »öÀ» ¶ì°í ÀÖ´Ù¸é, ÀÌ·¸°Ô ¿ì¸®´Â ¿ì¸®ÀÇ ¾ÆÀÌÄÜÀ» µÑ·¯½Ñ µé¾î¸ÂÁö ¾Ê´Â °æ°èÀÎ Á÷»ç°¢ÇüÀ¸·Î °ãÃÄ ±×¸®Áö ¾Ê´Â´Ù. À̹ø ¿¹Á¦´Â ÀÌ·± ½ÄÀ¸·Î Çؼ µ¥½ºÅ©Åé¿¡ ¼ö·¹¹ÙÄû À̹ÌÁö¸¦ º¸¿©ÁØ´Ù.
/* wheelbarrow.c */
#include <gtk/gtk.h>
/* XPM */
static char * WheelbarrowFull_xpm[] = {
"48 48 64 1",
" c None",
". c #DF7DCF3CC71B",
"X c #965875D669A6",
"o c #71C671C671C6",
"O c #A699A289A699",
"+ c #965892489658",
"@ c #8E38410330C2",
"# c #D75C7DF769A6",
"$ c #F7DECF3CC71B",
"% c #96588A288E38",
"& c #A69992489E79",
"* c #8E3886178E38",
"= c #104008200820",
"- c #596510401040",
"; c #C71B30C230C2",
": c #C71B9A699658",
"> c #618561856185",
", c #20811C712081",
"< c #104000000000",
"1 c #861720812081",
"2 c #DF7D4D344103",
"3 c #79E769A671C6",
"4 c #861782078617",
"5 c #41033CF34103",
"6 c #000000000000",
"7 c #49241C711040",
"8 c #492445144924",
"9 c #082008200820",
"0 c #69A618611861",
"q c #B6DA71C65144",
"w c #410330C238E3",
"e c #CF3CBAEAB6DA",
"r c #71C6451430C2",
"t c #EFBEDB6CD75C",
"y c #28A208200820",
"u c #186110401040",
"i c #596528A21861",
"p c #71C661855965",
"a c #A69996589658",
"s c #30C228A230C2",
"d c #BEFBA289AEBA",
"f c #596545145144",
"g c #30C230C230C2",
"h c #8E3882078617",
"j c #208118612081",
"k c #38E30C300820",
"l c #30C2208128A2",
"z c #38E328A238E3",
"x c #514438E34924",
"c c #618555555965",
"v c #30C2208130C2",
"b c #38E328A230C2",
"n c #28A228A228A2",
"m c #41032CB228A2",
"M c #104010401040",
"N c #492438E34103",
"B c #28A2208128A2",
"V c #A699596538E3",
"C c #30C21C711040",
"Z c #30C218611040",
"A c #965865955965",
"S c #618534D32081",
"D c #38E31C711040",
"F c #082000000820",
" ",
" .XoO ",
" +@#$%o& ",
" *=-;#::o+ ",
" >,<12#:34 ",
" 45671#:X3 ",
" +89<02qwo ",
"e* >,67;ro ",
"ty> 459@>+&& ",
"$2u+ ><ipas8* ",
"%$;=* *3:.Xa.dfg> ",
"Oh$;ya *3d.a8j,Xe.d3g8+ ",
" Oh$;ka *3d$a8lz,,xxc:.e3g54 ",
" Oh$;kO *pd$%svbzz,sxxxxfX..&wn> ",
" Oh$@mO *3dthwlsslszjzxxxxxxx3:td8M4 ",
" Oh$@g& *3d$XNlvvvlllm,mNwxxxxxxxfa.:,B* ",
" Oh$@,Od.czlllllzlmmqV@V#V@fxxxxxxxf:%j5& ",
" Oh$1hd5lllslllCCZrV#r#:#2AxxxxxxxxxcdwM* ",
" OXq6c.%8vvvllZZiqqApA:mq:Xxcpcxxxxxfdc9* ",
" 2r<6gde3bllZZrVi7S@SV77A::qApxxxxxxfdcM ",
" :,q-6MN.dfmZZrrSS:#riirDSAX@Af5xxxxxfevo",
" +A26jguXtAZZZC7iDiCCrVVii7Cmmmxxxxxx%3g",
" *#16jszN..3DZZZZrCVSA2rZrV7Dmmwxxxx&en",
" p2yFvzssXe:fCZZCiiD7iiZDiDSSZwwxx8e*>",
" OA1<jzxwwc:$d%NDZZZZCCCZCCZZCmxxfd.B ",
" 3206Bwxxszx%et.eaAp77m77mmmf3&eeeg* ",
" @26MvzxNzvlbwfpdettttttttttt.c,n& ",
" *;16=lsNwwNwgsvslbwwvccc3pcfu<o ",
" p;<69BvwwsszslllbBlllllllu<5+ ",
" OS0y6FBlvvvzvzss,u=Blllj=54 ",
" c1-699Blvlllllu7k96MMMg4 ",
" *10y8n6FjvllllB<166668 ",
" S-kg+>666<M<996-y6n<8* ",
" p71=4 m69996kD8Z-66698&& ",
" &i0ycm6n4 ogk17,0<6666g ",
" N-k-<> >=01-kuu666> ",
" ,6ky& &46-10ul,66, ",
" Ou0<> o66y<ulw<66& ",
" *kk5 >66By7=xu664 ",
" <<M4 466lj<Mxu66o ",
" *>> +66uv,zN666* ",
" 566,xxj669 ",
" 4666FF666> ",
" >966666M ",
" oM6668+ ",
" *4 ",
" ",
" "};
/* ÀÌ°ÍÀÌ È£ÃâµÇ¸é(delete_event ½Ã±×³ÎÀ» ÅëÇØ) ¾îÇÃÀÌ Á¾·áµÈ´Ù. */
void close_application( GtkWidget *widget, GdkEvent *event, gpointer data )
{
gtk_main_quit();
}
int main (int argc, char *argv[])
{
GtkWidget *window, *pixmap, *fixed;
GdkPixmap *gdk_pixmap;
GdkBitmap *mask;
GtkStyle *style;
GdkGC *gc;
/* mainÀ©µµ¸¦ ¸¸µé°í, ¾îÇÃÀ» ³¡³»±â À§ÇÑ delete_event ½Ã±×³ÎÀ» °Å±â¿¡
* ¿¬°á½ÃÄÑ µÐ´Ù. main À©µµ´Â ¿ì¸®°¡ popup¸¸ µÇµµ·Ï ¸¸µé¾ú±â ¶§¹®¿¡
* ŸÀÌƲ¹Ù¸¦ °¡ÁöÁö ¾ÊÀ» °ÍÀÌ´Ù. */
gtk_init (&argc, &argv);
window = gtk_window_new( GTK_WINDOW_POPUP );
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
GTK_SIGNAL_FUNC (close_application), NULL);
gtk_widget_show (window);
/* ÇȽº¸Ê°ú pixmap widgetÀ» À§ÇÑ °ÍÀÌ´Ù. */
style = gtk_widget_get_default_style();
gc = style->black_gc;
gdk_pixmap = gdk_pixmap_create_from_xpm_d( window->window, &mask,
&style->bg[GTK_STATE_NORMAL],
WheelbarrowFull_xpm );
pixmap = gtk_pixmap_new( gdk_pixmap, mask );
gtk_widget_show( pixmap );
/* ÇȽº¸ÊÀ» º¸À̱â À§ÇØ, ¿ì¸®´Â ÇȽº¸ÊÀ» ³õ¾ÆµÑ fixed widgetÀ»
* ÀÌ¿ëÇÑ´Ù. */
fixed = gtk_fixed_new();
gtk_widget_set_usize( fixed, 200, 200 );
gtk_fixed_put( GTK_FIXED(fixed), pixmap, 0, 0 );
gtk_container_add( GTK_CONTAINER(window), fixed );
gtk_widget_show( fixed );
/* ÀÌ°ÍÀº À̹ÌÁö ÀÚ½ÅÀ» Á¦¿ÜÇÑ ´Ù¸¥ ¸ðµç °ÍÀ» ÀºÆóÇÑ´Ù. */
gtk_widget_shape_combine_mask( window, mask, 0, 0 );
/* À©µµ¸¦ º¸ÀδÙ. */
gtk_widget_set_uposition( window, 20, 400 );
gtk_widget_show( window );
gtk_main ();
return 0;
}
¼ö·¹¹ÙÄû À̹ÌÁö¸¦ ´õ ¼¶¼¼ÇÏ°Ô ¸¸µé±â À§ÇØ, ¿ì¸®´Â ¹öÆ°ÀÌ ´·ÁÁø À̺¥Æ®ÀÇ ½Ã±×³ÎÀÌ ¼ö·¹¹ÙÄû¿¡ ¾î¶² µ¿ÀÛÀ» Çϵµ·Ï ¿«¾îÁÙ ¼ö ÀÖ´Ù. ¿©±â º¸ÀÌ´Â ¸î ÁÙÀÇ ÄÚµå´Â ¸¶¿ì½º¹öÆ°ÀÌ ´·ÁÁ³À» ¶§ ¾îÇÃÀÌ ³¡³ªµµ·Ï ÇØÁØ´Ù.
gtk_widget_set_events( window,
gtk_widget_get_events( window ) |
GDK_BUTTON_PRESS_MASK );
gtk_signal_connect( GTK_OBJECT(window), "button_press_event",
GTK_SIGNAL_FUNC(close_application), NULL );
·ê·¯ widgetÀº ÁÖ¾îÁø ÇÑ À©µµ¿¡¼ ¸¶¿ì½º Æ÷ÀÎÅÍÀÇ À§Ä¡¸¦ °¡¸®Å°´Âµ¥ ¾²ÀδÙ. À©µµ´Â ÆøÀ» °¡·ÎÁö¸£´Â ¼öÆò ·ê·¯¿Í ³ôÀ̸¦ °¡·ÎÁö¸£´Â ¼öÁ÷·ê·¯¸¦ °¡Áú ¼ö ÀÖ´Ù. ·ê·¯ À§ÀÇ Á¶±×¸¸ »ï°¢Çü Ç¥½Ã±â(indicator)°¡ ·ê·¯¿¡ ´ëÇÑ Æ÷ÀÎÅÍÀÇ Á¤È®ÇÑ À§Ä¡¸¦ º¸¿©ÁØ´Ù.
·ê·¯´Â ¹Ýµå½Ã ¹Ì¸® ¸ÕÀú ¸¸µé¾îÁ®¾ß¸¸ ÇÑ´Ù. ¼öÆò ¹× ¼öÁ÷ ·ê·¯´Â ´ÙÀ½ ÇÔ¼öµéÀ» ÀÌ¿ëÇؼ ¸¸µé¾îÁø´Ù.
GtkWidget *gtk_hruler_new(void); /* ¼öÆò ·ê·¯ */
GtkWidget *gtk_vruler_new(void); /* ¼öÁ÷ ·ê·¯ */
·ê·¯°¡ Çѹø ¸¸µé¾îÁö¸é ÃøÁ¤´ÜÀ§¸¦ Á¤ÀÇÇÒ ¼ö ÀÖ´Ù. ·ê·¯ÀÇ ÃøÁ¤´ÜÀ§´Â GTK_PIXELS³ª GTK_INCHES, GTK_CENTIMETERS ÁßÀÇ Çϳª°¡ µÈ´Ù.
void gtk_ruler_set_metric( GtkRuler *ruler,
GtkMetricType metric );
±âº» ¼³Á¤ ´ÜÀ§´Â GTK_PIXELSÀÌ´Ù.
gtk_ruler_set_metric( GTK_RULER(ruler), GTK_PIXELS );
¶Ç´Ù¸¥ Áß¿äÇÑ ·ê·¯ÀÇ Æ¯¼ºÀº ¾î¶»°Ô Å©±â ´ÜÀ§¸¦ ³ªÅ¸³»´À³Ä ÇÏ´Â Á¡°ú Ç¥½Ã±â°¡ óÀ½ ¾îµð¿¡ ³õÀ̳ÄÇÏ´Â Á¡ÀÌ´Ù. À̵éÀº ´ÙÀ½ ÇÔ¼ö·Î °áÁ¤ÇÑ´Ù.
void gtk_ruler_set_range (GtkRuler *ruler,
gfloat lower,
gfloat upper,
gfloat position,
gfloat max_size);
ÀÎÀÚ lower¿Í upper´Â ·ê·¯ÀÇ ¹üÀ§¸¦ Á¤ÀÇÇÏ°í max_size´Â Ãâ·Â °¡´ÉÇÑ °¡Àå Å« ¼ö¸¦ ¼³Á¤ÇÑ´Ù. PositionÀº ·ê·¯ ³»ÀÇ Ç¥½Ã±â Ãʱâ À§Ä¡ÀÌ´Ù.
800 Çȼ¿ÀÇ ¼öÁ÷ ·ê·¯´Â ÀÌ·¸°Ô µÈ´Ù.
gtk_ruler_set_range( GTK_RULER(vruler), 0, 800, 0, 800);
0ºÎÅÍ 800±îÁö ¸Å 100 Çȼ¿¸¶´Ù Ç¥Áö(marking)°¡ Ãâ·ÂµÉ °ÍÀÌ´Ù. ¸¸ÀÏ ·ê·¯ÀÇ ¹üÀ§¸¦ 7ºÎÅÍ 16À¸·Î ¹Ù²Ù·Á¸é ´ÙÀ½°ú °°ÀÌ ÇÑ´Ù.
gtk_ruler_set_range( GTK_RULER(vruler), 7, 16, 0, 20);
·ê·¯ÀÇ Ç¥½Ã±â´Â Æ÷ÀÎÅÍÀÇ »ó´ëÀûÀÎ À§Ä¡¸¦ °¡¸®Å°´Â Á¶±×¸¸ »ï°¢Çü Ç¥ÁöÀÌ´Ù. ¸¸ÀÏ ·ê·¯°¡ ¸¶¿ì½º Æ÷ÀÎÅ͸¦ µû¸£°Ô ÇÏ°í ½Í´Ù¸é motion_notify_event ½Ã±×³ÎÀÌ ·ê·¯ÀÇ motion_notify_event method¿Í ¿¬°áµÇ¾î¾ß¸¸ ÇÑ´Ù. ƯÁ¤ À©µµ ¿µ¿ª ³»ÀÇ ¸ðµç ¸¶¿ì½º ¿òÁ÷ÀÓÀ» µû¸£°Ô Çϱâ À§ÇØ ´ÙÀ½°ú °°ÀÌ ÇÑ´Ù.
#define EVENT_METHOD(i, x) GTK_WIDGET_CLASS(GTK_OBJECT(i)->klass)->x
gtk_signal_connect_object( GTK_OBJECT(area), "motion_notify_event",
(GtkSignalFunc)EVENT_METHOD(ruler, motion_notify_event),
GTK_OBJECT(ruler) );
´ÙÀ½ ¿¹Á¦´Â ¼öÆò ·ê·¯¸¦ À§¿¡ ¼öÁ÷ ·ê·¯¸¦ ¿ÞÂÊ¿¡ °¡Áø drawing area¸¦ ¸¸µç´Ù. ÀÌ drawing area´Â 600 Çȼ¿ÀÇ Æø°ú 400 Çȼ¿ÀÇ ³ôÀ̸¦ °¡Áø´Ù. ¼öÆò ·ê·¯´Â 7ºÎÅÍ 13ÀÇ ¹üÀ§¿¡ ¸Å 100 Çȼ¿¸¶´Ù Ç¥Áö¸¦ ÇÏ°í ¼öÁ÷ ·ç·¯´Â 0ºÎÅÍ 400ÀÇ ¹üÀ§¿¡ ¸¶Âù°¡Áö·Î ¸Å 100 Çȼ¿¸¶´Ù Ç¥Áö¸¦ ÇÑ´Ù. ·ê·¯µé°ú drawing areaÀÇ À§Ä¡ ¼³Á¤Àº Å×À̺íÀ» »ç¿ëÇÑ´Ù.
/* rulers.c */
#include <gtk/gtk.h>
#define EVENT_METHOD(i, x) GTK_WIDGET_CLASS(GTK_OBJECT(i)->klass)->x
#define XSIZE 600
#define YSIZE 400
/* ´Ý±â ¹öÆ°(close button)ÀÌ ´·¯Áö¸é ÀÌ ÇÔ¼ö°¡ ºÒ¸°´Ù.
*/
void close_application( GtkWidget *widget, gpointer data ) {
gtk_main_quit();
}
/* ¸ÞÀÎ ÇÔ¼ö
*/
int main( int argc, char *argv[] ) {
GtkWidget *window, *table, *area, *hrule, *vrule;
/* gtk¸¦ ÃʱâÈÇÏ°í ¸ÞÀÎ À©µµ¸¦ ¸¸µç´Ù.*/
gtk_init( &argc, &argv );
window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
GTK_SIGNAL_FUNC( close_application ), NULL);
gtk_container_border_width (GTK_CONTAINER (window), 10);
/* ·ê·¯¿Í drawing area¸¦ ³õÀº Å×À̺íÀ» ¸¸µç´Ù */
table = gtk_table_new( 3, 2, FALSE );
gtk_container_add( GTK_CONTAINER(window), table );
area = gtk_drawing_area_new();
gtk_drawing_area_size( (GtkDrawingArea *)area, XSIZE, YSIZE );
gtk_table_attach( GTK_TABLE(table), area, 1, 2, 1, 2,
GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0 );
gtk_widget_set_events( area, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK );
/* ¼öÆò ·ê·¯´Â °¡Àå À§¿¡ ³õÀδÙ. ¸¶¿ì½º°¡ drawing area À§¸¦ ¿òÁ÷À̸é,
motion_notify_event °¡ ·ê·¯ÀÇ ÀûÀýÇÑ À̺¥Æ® Çڵ鷯¿¡°Ô Àü´ÞµÈ´Ù.
*/
hrule = gtk_hruler_new();
gtk_ruler_set_metric( GTK_RULER(hrule), GTK_PIXELS );
gtk_ruler_set_range( GTK_RULER(hrule), 7, 13, 0, 20 );
gtk_signal_connect_object( GTK_OBJECT(area), "motion_notify_event",
(GtkSignalFunc)EVENT_METHOD(hrule, motion_notify_event),
GTK_OBJECT(hrule) );
/* GTK_WIDGET_CLASS(GTK_OBJECT(hrule)->klass)->motion_notify_event, */
gtk_table_attach( GTK_TABLE(table), hrule, 1, 2, 0, 1,
GTK_EXPAND|GTK_SHRINK|GTK_FILL, GTK_FILL, 0, 0 );
/* ¼öÁ÷ ·ê·¯´Â Á¦ÀÏ ¿ÞÂÊ¿¡ ³õÀδÙ. ¸¶¿ì½º°¡ drawing area À§¸¦ ¿òÁ÷À̸é,,
motion_notify_event °¡ ·ê·¯ÀÇ ÀûÀýÇÑ À̺¥Æ® Çڵ鷯¿¡°Ô Àü´ÞµÈ´Ù.
*/
vrule = gtk_vruler_new();
gtk_ruler_set_metric( GTK_RULER(vrule), GTK_PIXELS );
gtk_ruler_set_range( GTK_RULER(vrule), 0, YSIZE, 10, YSIZE );
gtk_signal_connect_object( GTK_OBJECT(area), "motion_notify_event",
(GtkSignalFunc)
GTK_WIDGET_CLASS(GTK_OBJECT(vrule)->klass)->motion_notify_event,
GTK_OBJECT(vrule) );
gtk_table_attach( GTK_TABLE(table), vrule, 0, 1, 1, 2,
GTK_FILL, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0 );
/* ÀÌÁ¦ ¸ðµç °ÍÀ» º¸¿©ÁØ´Ù */
gtk_widget_show( area );
gtk_widget_show( hrule );
gtk_widget_show( vrule );
gtk_widget_show( table );
gtk_widget_show( window );
gtk_main();
return 0;
}
»óÅÂÇ¥½ÃÁÙÀº ÅؽºÆ® ¸Þ½ÃÁö¸¦ º¸¿©Áִµ¥ ¾²ÀÌ´Â °£´ÜÇÑ widgetÀÌ´Ù. ÀÌ widgetÀº ÅؽºÆ® ¸Þ½ÃÁöµéÀ» ½ºÅÿ¡ º¸°üÇÑ´Ù. µû¶ó¼ ÇöÀçÀÇ ¸Þ½ÃÁö¸¦ ²¨³»¸é ¹Ù·Î ÀÌÀüÀÇ ¸Þ½ÃÁö¸¦ ´Ù½Ã º¸¿©ÁÖ°Ô µÈ´Ù.
ÇÑ ¾îÇø®ÄÉÀ̼ÇÀÇ ¿©·¯ ºÎºÐµéÀÌ ¸Þ½ÃÁö¸¦ Ç¥½ÃÇϴµ¥ °°Àº »óÅÂÇ¥½ÃÁÙÀ» »ç¿ëÇؾßÇÏ´Â °æ¿ì, »óÅÂÇ¥½ÃÁÙ widgetÀº ¿©·¯ '»ç¿ëÀÚ'µéÀ» ±¸ºÐÇϴµ¥ ¾²ÀÌ´Â Context Identifier¸¦ ¹ßÇàÇÑ´Ù. ¾î¶² context¸¦ °¡Á³´À³Ä¿¡ »ó°ü¾øÀÌ ½ºÅà Á¦ÀÏ À§ÀÇ ¸Þ½ÃÁö°¡ º¸¿©Áø´Ù. ¸Þ½ÃÁöµéÀº Context IdentifierÀÇ ¼ø¼°¡ ¾Æ´Ï¶ó ³ªÁß¿¡ µé¾î°£ °ÍÀÌ ¸ÕÀú ³ª¿À´Â ¼ø¼·Î ½ºÅÿ¡ ½×ÀδÙ.
»óÅÂÇ¥½ÃÁÙÀº ´ÙÀ½ ÇÔ¼ö¸¦ ÅëÇØ ¸¸µé¾îÁø´Ù.
GtkWidget* gtk_statusbar_new (void);
»õ·Î¿î Context Identifier´Â °£´ÜÇÑ context¿¡ °üÇÑ ¼³¸í°ú ÇÔ²² ´ÙÀ½ ÇÔ¼ö¸¦ È£ÃâÇÏ¿© ¾òÀ» ¼ö ÀÖ´Ù.
guint gtk_statusbar_get_context_id (GtkStatusbar *statusbar,
const gchar *context_description);
»óÅÂÇ¥½ÃÁÙÀ» ´Ù·ç´Â ´ÙÀ½°ú °°Àº ÇÔ¼öµéÀÌ ÀÖ´Ù.
guint gtk_statusbar_push (GtkStatusbar *statusbar,
guint context_id,
gchar *text);
void gtk_statusbar_pop (GtkStatusbar *statusbar)
guint context_id);
void gtk_statusbar_remove (GtkStatusbar *statusbar,
guint context_id,
guint message_id);
¸ÕÀú gtk_statusbar_push´Â »óÅÂÇ¥½ÃÁÙ¿¡ »õ·Î¿î ¸Þ½ÃÁö¸¦ Ãß°¡Çϴµ¥ ¾²ÀδÙ. ÀÌ ÇÔ¼ö´Â ³ªÁß¿¡ gtk_statusbar_remove¸¦ È£ÃâÇϴµ¥ ¾²ÀÏ ¼ö ÀÖ´Â Message Identifier¸¦ ¸®ÅÏÇÑ´Ù. gtk_statusbar_remove´Â ÁÖ¾îÁø Message¿Í Context IdentifierÀÇ ¸Þ½ÃÁö¸¦ »óÅÂÇ¥½ÃÁÙ¿¡¼ Á¦°ÅÇÑ´Ù.
gtk_statusbar_popÀº ÁÖ¾îÁø Context IdentifierÀÇ ½ºÅà Á¦ÀÏ À§ ¸Þ½ÃÁö¸¦ ²¨³» »èÁ¦ÇÑ´Ù.
´ÙÀ½ ¿¹Á¦´Â ¹öÆ° 2°³¿Í »óÅÂÇ¥½ÃÁÙ Çϳª¸¦ ¸¸µç´Ù. ºÆ° Çϳª´Â »óÅÂÇ¥½ÃÁÙ¿¡ »õ ¸Þ½ÃÁö¸¦ ³Ö°í ³ª¸ÓÁö ´Ù¸¥ ¹öÆ°Àº ¸¶Áö¸·À¸·Î ³Ö¾îÁø ¸Þ½ÃÁö¸¦ Á¦°ÅÇÑ´Ù.
/* statusbar.c */
#include <gtk/gtk.h>
#include <glib.h>
GtkWidget *status_bar;
void push_item (GtkWidget *widget, gpointer data)
{
static int count = 1;
char buff[20];
g_snprintf(buff, 20, "Item %d", count++);
gtk_statusbar_push( GTK_STATUSBAR(status_bar), (guint) &data, buff);
return;
}
void pop_item (GtkWidget *widget, gpointer data)
{
gtk_statusbar_pop( GTK_STATUSBAR(status_bar), (guint) &data );
return;
}
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *button;
int context_id;
gtk_init (&argc, &argv);
/* »õ À©µµ¸¦ Çϳª ¸¸µç´Ù */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize( GTK_WIDGET (window), 200, 100);
gtk_window_set_title(GTK_WINDOW (window), "GTK Statusbar Example");
gtk_signal_connect(GTK_OBJECT (window), "delete_event",
(GtkSignalFunc) gtk_exit, NULL);
vbox = gtk_vbox_new(FALSE, 1);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show(vbox);
status_bar = gtk_statusbar_new();
gtk_box_pack_start (GTK_BOX (vbox), status_bar, TRUE, TRUE, 0);
gtk_widget_show (status_bar);
context_id = gtk_statusbar_get_context_id( GTK_STATUSBAR(status_bar), "Statusbar example");
button = gtk_button_new_with_label("push item");
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC (push_item), &context_id);
gtk_box_pack_start(GTK_BOX(vbox), button, TRUE, TRUE, 2);
gtk_widget_show(button);
button = gtk_button_new_with_label("pop last item");
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC (pop_item), &context_id);
gtk_box_pack_start(GTK_BOX(vbox), button, TRUE, TRUE, 2);
gtk_widget_show(button);
/* ´Ù¸¥ ¸ðµç °ÍµéÀÌ Çѹø¿¡ ¸ðµÎ ´Ù º¸À̵µ·Ï Çϱâ À§Çؼ
* Ç×»ó À©µµ¸¦ Á¦ÀÏ ¸¶Áö¸·¿¡ º¸¿©ÁØ´Ù. */
gtk_widget_show(window);
gtk_main ();
return 0;
}
ÅؽºÆ® ÀÔ·Â widgetÀº ÇÑÁÙÂ¥¸® ÅؽºÆ® »óÀÚ ¾È¿¡ ¹®ÀÚ¸¦ ŸÀÌÇÁÇØ ³Ö°Å³ª ¶Ç´Â ±×³É º¸¿©ÁÙ ¼ö ÀÖ°Ô ÇØÁØ´Ù. ÅؽºÆ®´Â Çö ÀÔ·Â widgetÀÇ ³»¿ëÀ» Ãß°¡Çϰųª ¶Ç´Â ¿ÏÀüÈ÷ ´ëüÇÏ´Â ÇÔ¼ö È£Ãâµé¿¡ ÀÇÇØ °áÁ¤µÈ´Ù.
ÅؽºÆ® ÀÔ·Â widgetÀ» ¸¸µå´Âµ¥´Â ´ÙÀ½ µÎ ÇÔ¼ö¸¦ »ç¿ëÇÑ´Ù.
GtkWidget* gtk_entry_new (void);
GtkWidget* gtk_entry_new_with_max_length (guint16 max);
óÀ½ °ÍÀº ´Ü¼øÈ÷ »õ·Î¿î ÀÔ·Â widgetÀ» Çϳª ¸¸µç´Ù. ±×¿¡ ¹ÝÇØ µÎ¹ø° °ÍÀº ÆíÁý°¡´ÉÇÑ ÅؽºÆ®ÀÇ ±æÀÌ Á¦ÇÑÀ» °¡Áø ÀÔ·Â widgetÀ» ¸¸µç´Ù.
Çö ÀÔ·ÂÀÇ ÅؽºÆ®¸¦ º¯°æÇϴµ¥ ¾²ÀÌ´Â ¸î°¡Áö ÇÔ¼ö°¡ Á¸ÀçÇÑ´Ù.
void gtk_entry_set_text (GtkEntry *entry,
const gchar *text);
void gtk_entry_append_text (GtkEntry *entry,
const gchar *text);
void gtk_entry_prepend_text (GtkEntry *entry,
const gchar *text);
ÇÔ¼ö gtk_entry_set_textÀº ÀÔ·ÂµÈ ³»¿ëÀ» ¿ÏÀüÈ÷ º¯°æÇÑ´Ù. ÇÔ¼ö gtk_entry_append_text¿Í gtk_entry_prepend_text´Â Çö ³»¿ëÀÇ ¾Õ ¶Ç´Â µÚ¿¡ ¿øÇÏ´Â ÅؽºÆ®¸¦ µ¡ºÙÀδÙ.
´ÙÀ½ ÇÔ¼ö´Â ÇöÀçÀÇ ÅؽºÆ® ÀÔ·Â À§Ä¡¸¦ Á¤ÇÑ´Ù.
void gtk_entry_set_position (GtkEntry *entry,
gint position);
ÀÔ·Â widgetÀÇ ³»¿ëÀº ´ÙÀ½ ÇÔ¼ö È£Ãâ¿¡ ÀÇÇؼ ¾Ë ¼ö ÀÖ´Ù. ÀÌ°ÍÀº ³ªÁß¿¡ ¼³¸íÇÒ callback ÇÔ¼ö ¾È¿¡¼ »ç¿ëÇÏ´Â °ÍÀÌ À¯¿ëÇÏ´Ù.
gchar* gtk_entry_get_text (GtkEntry *entry);
¸¸ÀÏ ÀÔ·ÂµÈ ³»¿ëÀÌ Å¸ÀÌÇο¡ ÀÇÇؼ º¯°æµÇ´Â °ÍÀ» ¿øÇÏÁö ¾Ê´Â´Ù¸é ÆíÁýÀÌ ºÒ°¡´ÉÇϵµ·Ï »óŸ¦ ¹Ù²Ü ¼ö ÀÖ´Ù.
void gtk_entry_set_editable (GtkEntry *entry,
gboolean editable);
ÀÌ ÇÔ¼öÀÇ editable ÀÎÀÚ¿¡ TRUE³ª FALSE¸¦ ÁÖ¾î ÀÔ·Â widgetÀÌ ÆíÁý °¡´ÉÇÏ°Ô µÇ°Å³ª ¶Ç´Â °¡´ÉÇÏÁö ¾Êµµ·Ï º¯°æÇÒ ¼ö ÀÖ´Ù.
¸¸¾à Æнº¿öµå¸¦ ÀÔ·ÂÇÒ ¶§Ã³·³ ÀÔ·ÂÇÏ´Â ÅؽºÆ®°¡ º¸ÀÌÁö ¾Ê¾Æ¾ß ÇÑ´Ù¸é boolean flag¸¦ °®´Â ´ÙÀ½ ÇÔ¼ö¸¦ »ç¿ëÇÑ´Ù.
void gtk_entry_set_visibility (GtkEntry *entry,
gboolean visible);
´ÙÀ½ ÇÔ¼ö¸¦ ½á¼ ÅؽºÆ®ÀÇ ÀÏÁ¤ ºÎºÐÀ» ¼±ÅÃ(selected)µÇµµ·Ï ¸¸µé ¼ö ÀÖ´Ù. ÀÌ ±â´ÉÀº ¹Ì¸® ±âº» ÅؽºÆ®¸¦ Á¤ÇØ Ãâ·ÂÇÏ°í À̸¦ »ç¿ëÀÚ°¡ »õ·Î¿î ÀÔ·ÂÀ» À§Çؼ °£´ÜÈ÷ Áö¿ï ¼ö ÀÖ°Ô Çϴµ¥ ÀÚÁÖ ¾²ÀδÙ.
void gtk_entry_select_region (GtkEntry *entry,
gint start,
gint end);
¸¸¾à¿¡ »ç¿ëÀÚ°¡ ÅؽºÆ®¸¦ ÀÔ·ÂÇÏ´Â °ÍÀ» ¾Ë¾Æä°í ½Í´Ù¸é,
activate
³ª changed
½Ã±×³ÎÀ» ¿¬°áÇÒ ¼ö ÀÖ´Ù.
Activate´Â »ç¿ëÀÚ°¡ ¿£ÅÍÅ°¸¦ ŸÀÌÇÁÇϸé, Changed´Â ÅؽºÆ®°¡ ÀüºÎ ´Ù¸¥ °ÍÀ¸·Î
¹Ù²î¸é ¹ß»ýÇÑ´Ù.(¸ðµç ¹®ÀÚ°¡ ÀԷµǾú°Å³ª Áö¿öÁ³À» ¶§ µî)
´ÙÀ½Àº ÅؽºÆ® ÀÔ·Â widgetÀÇ ÇÑ ¿¹ÀÌ´Ù.
/* entry.c */
#include <gtk/gtk.h>
void enter_callback(GtkWidget *widget, GtkWidget *entry)
{
gchar *entry_text;
entry_text = gtk_entry_get_text(GTK_ENTRY(entry));
printf("Entry contents: %s\n", entry_text);
}
void entry_toggle_editable (GtkWidget *checkbutton,
GtkWidget *entry)
{
gtk_entry_set_editable(GTK_ENTRY(entry),
GTK_TOGGLE_BUTTON(checkbutton)->active);
}
void entry_toggle_visibility (GtkWidget *checkbutton,
GtkWidget *entry)
{
gtk_entry_set_visibility(GTK_ENTRY(entry),
GTK_TOGGLE_BUTTON(checkbutton)->active);
}
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *vbox, *hbox;
GtkWidget *entry;
GtkWidget *button;
GtkWidget *check;
gtk_init (&argc, &argv);
/* create a new window */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize( GTK_WIDGET (window), 200, 100);
gtk_window_set_title(GTK_WINDOW (window), "GTK Entry");
gtk_signal_connect(GTK_OBJECT (window), "delete_event",
(GtkSignalFunc) gtk_exit, NULL);
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_widget_show (vbox);
entry = gtk_entry_new_with_max_length (50);
gtk_signal_connect(GTK_OBJECT(entry), "activate",
GTK_SIGNAL_FUNC(enter_callback),
entry);
gtk_entry_set_text (GTK_ENTRY (entry), "hello");
gtk_entry_append_text (GTK_ENTRY (entry), " world");
gtk_entry_select_region (GTK_ENTRY (entry),
0, GTK_ENTRY(entry)->text_length);
gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0);
gtk_widget_show (entry);
hbox = gtk_hbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
gtk_widget_show (hbox);
check = gtk_check_button_new_with_label("Editable");
gtk_box_pack_start (GTK_BOX (hbox), check, TRUE, TRUE, 0);
gtk_signal_connect (GTK_OBJECT(check), "toggled",
GTK_SIGNAL_FUNC(entry_toggle_editable), entry);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(check), TRUE);
gtk_widget_show (check);
check = gtk_check_button_new_with_label("Visible");
gtk_box_pack_start (GTK_BOX (hbox), check, TRUE, TRUE, 0);
gtk_signal_connect (GTK_OBJECT(check), "toggled",
GTK_SIGNAL_FUNC(entry_toggle_visibility), entry);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(check), TRUE);
gtk_widget_show (check);
button = gtk_button_new_with_label ("Close");
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC(gtk_exit),
GTK_OBJECT (window));
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_widget_grab_default (button);
gtk_widget_show (button);
gtk_widget_show(window);
gtk_main();
return(0);
}
»ö¼±Åà widgetÀº, »ç½Ç ÀüÇô ³î¶øÁö ¾Ê°ÚÁö¸¸, Á÷Á¢ »öÀ» ¼±ÅÃÇϴµ¥ ¾²ÀδÙ. ÀÌ º¹ÇÕÀûÀÎ widgetÀº »ç¿ëÀÚ·Î ÇÏ¿©±Ý RGB(Red, Green, Blue)¿Í HSV (Hue, Saturation, Value) ¼¼ ¿ä¼Ò¸¦ ÅëÇØ »öÀ» °í¸£°Ô ÇÑ´Ù. ÀÌ´Â ½½¶óÀÌ´õ³ª ÀÔ·ÂâÀ» ÀÌ¿ëÇؼ °¢ ¿ä¼Ò¿¡ ƯÁ¤ °ªÀ» ÁÖ°ÔÇϰųª ¶Ç´Â, hue-saturation wheel¿¡¼ Á÷Á¢ »öÀ» ¼±ÅÃÇÏ°Ô ÇÔÀ¸·Î½á ÀÌ·ç¾îÁø´Ù. ÇÊ¿ä¿¡ µû¶ó¼´Â »öÀÇ Åõ¸íµµµµ Á¤ÇØÁÙ ¼ö ÀÖ´Ù.
ÀÌ »ö¼±Åà widgetÀº ¿ÜºÎ¿¡¼ gtk_color_selection_set_color()À» ÅëÇØ ÁöÁ¤Ç߰ųª ¶Ç´Â »ç¿ëÀÚ°¡ Á÷Á¢ ÇöÀç »öÀ» º¯°æÇÒ ¶§¸¶´Ù "color_changed"À̶ó´Â ´Ü ÇÑ°¡ÁöÀÇ ½Ã±×³Î¸¸À» ¹ß»ý½ÃŲ´Ù.
ÀÌ »ö¼±Åà widgetÀÌ ¿ì¸®¿¡°Ô ¹«¾ùÀ» ³Ñ°ÜÁÖ¾î¾ß ÇÏ´ÂÁö º¸ÀÚ. ÀÌ widgetÀº gtk_color_selection¿Í gtk_color_selection_dialogÀÇ µÎ ÇüÅ°¡ ÀÖ´Ù.
GtkWidget *gtk_color_selection_new(void);
´ë°³ ÀÌ ÇÔ¼ö¸¸À» Á÷Á¢ ¾µ ¼ö´Â ¾ø´Ù. ÀÌ°ÍÀº ³ªÁß¿¡ ¾îµò°¡·Î ¿¬°áÀ» ½ÃÄÑÁÖ¾î¾ß¸¸ ÇÏ´Â GtkColorSelection widgetÀ» ¸¸µé µû¸§ÀÌ´Ù. ÀÌ GtkColorSelection widgetÀº GtkVBox widget¿¡¼ »ó¼ÓµÈ °ÍÀÌ´Ù.
GtkWidget *gtk_color_selection_dialog_new(const gchar *title);
´ë°³ ÀÌ ÇÔ¼ö¸¦ »ö¼±Åà widgetÀ» ¸¸µå´Â µ¥ »ç¿ëÇÑ´Ù. ÀÌ´Â GtkColorSelectionDialog¶ó´Â GtkDialog¿¡¼ »ó¼ÓµÈ widgetÀ» ¸¸µç´Ù. ÀÌ widgetÀº GtkColorSelection, GtkHSeparator¿Í "Ok", "Cancel", "Help"ÀÇ ¹öÆ° ¼¼°³¸¦ °¡Áø GtkHBoxµéÀ» Æ÷ÇÔÇÑ GtkFrame widgetÀ¸·Î ÀÌ·ç¾îÁ®ÀÖ´Ù. GtkColorSelectionDialog structure¿¡¼ "ok_button", "cancel_button", "help_button" widget¿¡ Á¢±ÙÇؼ ±× ¼¼ ¹öÆ°µéÀ» Á÷Á¢ ´Ù·ê ¼ö ÀÖ´Ù. (¿¹ : GTK_COLOR_SELECTION_DIALOG(colorseldialog)->ok_button)
void gtk_color_selection_set_update_policy(GtkColorSelection *colorsel,
GtkUpdateType policy);
ÀÌ ÇÔ¼ö´Â °»½Å Á¤Ã¥À» Á¤ÇÑ´Ù. ±âº» Á¤Ã¥Àº »ç¿ëÀÚ°¡ ¹«¾ùÀÌµç º¯°æÇÏ´Â ±×¶§¸¶´Ù ¹Ù·Î Áï½Ã ÇöÀçÀÇ »öÀ» °Å±â¿¡ µû¶ó ¹Ù²Ù´Â GTK_UPDATE_CONTINOUSÀÌ´Ù. ¼º´É¹®Á¦°¡ ¹ß»ýÇϸé GTK_UPDATE_DISCONTINOUS³ª GTK_UPDATE_DELAYED·Î ¹Ù²Ù¾î ÁÙ ¼ö ÀÖ´Ù.
void gtk_color_selection_set_opacity(GtkColorSelection *colorsel,
gint use_opacity);
»ö¼±Åà widgetÀº »öÀÇ Åõ¸íµµ(¾ËÆÄä³ÎÀ̶ó°íµµ ¾Ë·ÁÁø)¸¦ Á¶Á¤ÇÏ´Â ±â´Éµµ Áö¿øÇÑ´Ù.
ÀÌ ±â´ÉÀº ±âº» ¼³Á¤¿¡¼´Â ²¨Á®ÀÖ´Ù. ÀÌ°ÍÀ» »ç¿ëÇÏ·Á¸é À§ÀÇ ÇÔ¼ö¸¦
use_opacity¸¦ TRUE·Î Çؼ È£ÃâÇÑ´Ù.
¸¶Âù°¡Áö·Î use_opacity¸¦ FALSE·Î Çؼ È£ÃâÇϸé Åõ¸íµµ Á¶Á¤ ±â´ÉÀÌ ²¨Áø´Ù.
void gtk_color_selection_set_color(GtkColorSelection *colorsel,
gdouble *color);
»ö»ó array(gdouble)¿Í ÇÔ²² À§ ÇÔ¼ö¸¦ È£ÃâÇÏ¿© ¿ÜºÎ¿¡¼ ÇöÀç »öÀ» ÁöÁ¤ÇØ ÁÙ ¼ö ÀÖ´Ù. ÀÌ arrayÀÇ ±æÀÌ´Â »ö Åõ¸íµµ Á¶Á¤ ±â´ÉÀ» Äѳõ¾Ò´ÂÁö ²¨³õ¾Ò´ÂÁö¿¡ µû¶ó ´Þ¶óÁø´Ù. À§Ä¡ 0Àº »¡°£»ö, 1Àº ³ì»ö, 2´Â ÆĶõ»öÀ̸ç 3Àº Åõ¸íµµÀÌ´Ù.(Åõ¸íµµ´Â ÀÌ ±â´ÉÀ» Äѳõ¾ÒÀ» ¶§¸¸ Àǹ̰¡ ÀÖ´Ù. ¾Õ¿¡¼ ³ª¿Â gtk_color_selection_set_opacity()¿¡ ´ëÇÑ ºÎºÐÀ» º¸¶ó.) ¸ðµç °ªÀº 0.0°ú 1.0 »çÀÌ¿¡ ÀÖ´Ù.
void gtk_color_selection_get_color(GtkColorSelection *colorsel,
gdouble *color);
¸¸ÀÏ 'color_changed" ½Ã±×³ÎÀ» ¹Þ¾ÒÀ» ¶§, ÇöÀç »öÀÌ ¾î¶² °ÍÀÌÁö ¾Ë°í ½Í´Ù¸é À§ÀÇ ÇÔ¼ö¸¦ »ç¿ëÇÏ¸é µÈ´Ù. Color´Â »ö arrayÀÌ´Ù. ÀÌ »ö array¿¡ ´ëÇÑ °ÍÀº gtk_color_selection_set_color() ÇÔ¼ö¿¡ ´ëÇÑ ºÎºÐÀ» º¸¶ó.
´ÙÀ½Àº GtkColorSelectionDialogÀ» »ç¿ëÇÏ´Â °£´ÜÇÑ ¿¹ÀÌ´Ù. ÀÌ ÇÁ·Î±×·¥Àº drawing area¸¦ °¡Áø À©µµ Çϳª¸¦ ¸¸µç´Ù. ÀÌ°ÍÀ» Ŭ¸¯Çϸé color selection dialog°¡ ¶á´Ù. À̸¦ Á¶Á¤Çؼ ¹è°æ»öÀ» ¹Ù²Ü ¼ö ÀÖ´Ù.
#include <glib.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
GtkWidget *colorseldlg = NULL;
GtkWidget *drawingarea = NULL;
/* »öÀÌ ¹Ù²î¸é ÀÌ ÇÔ¼ö¸¦ ºÎ¸¥´Ù. */
void color_changed_cb (GtkWidget *widget, GtkColorSelection *colorsel)
{
gdouble color[3];
GdkColor gdk_color;
GdkColormap *colormap;
/* drawing areaÀÇ colormapÀ» ¾ò´Â´Ù */
colormap = gdk_window_get_colormap (drawingarea->window);
/* ÇöÀç »öÀ» ¾ò´Â´Ù */
gtk_color_selection_get_color (colorsel,color);
/* unsigned 16 bit Á¤¼ö(0..65535)·Î ¹Ù²ã¼ GdkColor¿¡ ³Ö´Â´Ù */
gdk_color.red = (guint16)(color[0]*65535.0);
gdk_color.green = (guint16)(color[1]*65535.0);
gdk_color.blue = (guint16)(color[2]*65535.0);
/* »öÀ» ÇÒ´çÇÑ´Ù */
gdk_color_alloc (colormap, &gdk_color);
/* À©µµÀÇ ¹è°æ»öÀ» Á¤ÇÑ´Ù */
gdk_window_set_background (drawingarea->window, &gdk_color);
/* À©µµ¸¦ Áö¿î´Ù */
gdk_window_clear (drawingarea->window);
}
/* Drawingarea event handler */
gint area_event (GtkWidget *widget, GdkEvent *event, gpointer client_data)
{
gint handled = FALSE;
GtkWidget *colorsel;
/* ¹öÆ°ÀÌ ´·¯Á³´ÂÁö È®ÀÎÇÑ´Ù */
if (event->type == GDK_BUTTON_PRESS && colorseldlg == NULL)
{
/* Yes, we have an event and there's no colorseldlg yet! */
handled = TRUE;
/* color selection dialog¸¦ ¸¸µç´Ù */
colorseldlg = gtk_color_selection_dialog_new("Select background color");
/* GtkColorSelection widgetÀ» ±¸ÇÑ´Ù */
colorsel = GTK_COLOR_SELECTION_DIALOG(colorseldlg)->colorsel;
/* "color_changed" ½Ã±×³ÎÀ» widget¿¡ ¿¬°áÇÑ´Ù. */
gtk_signal_connect(GTK_OBJECT(colorsel), "color_changed",
(GtkSignalFunc)color_changed_cb, (gpointer)colorsel);
/* color seclection dialog¸¦ º¸Àδ٠*/
gtk_widget_show(colorseldlg);
}
return handled;
}
/* À©µµ¸¦ ´Ý°í Çڵ鷯¿¡¼ ºüÁ®³ª°£´Ù */
void destroy_window (GtkWidget *widget, gpointer client_data)
{
gtk_main_quit ();
}
/* Main */
gint main (gint argc, gchar *argv[])
{
GtkWidget *window;
/* ÅøŶÀ» ÃʱâÈÇÏ°í gtk¿Í °ü·ÃµÈ ¸í·ÉÀÔ·Â ¿ä¼ÒµéÀ» ¾ø¾Ø´Ù. */
gtk_init (&argc,&argv);
/* toplevel À©µµ¸¦ ¸¸µé°í Á¦¸ñ°ú policy¸¦ Á¤ÇÑ´Ù */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW(window), "Color selection test");
gtk_window_set_policy (GTK_WINDOW(window), TRUE, TRUE, TRUE);
/* "delete"¿Í "destroy" À̺¥Æ®¸¦ ¸¸³ª¸é Á¾·áÇÑ´Ù */
gtk_signal_connect (GTK_OBJECT(window), "delete_event",
(GtkSignalFunc)destroy_window, (gpointer)window);
gtk_signal_connect (GTK_OBJECT(window), "destroy",
(GtkSignalFunc)destroy_window, (gpointer)window);
/* drawingarea¸¦ ¸¸µç µÚ, ±× Å©±â¸¦ Á¤ÇÏ°í ¹öÆ° À̺¥Æ®¿Í ¿¬°áÇÑ´Ù */
drawingarea = gtk_drawing_area_new ();
gtk_drawing_area_size (GTK_DRAWING_AREA(drawingarea), 200, 200);
gtk_widget_set_events (drawingarea, GDK_BUTTON_PRESS_MASK);
gtk_signal_connect (GTK_OBJECT(drawingarea), "event",
(GtkSignalFunc)area_event, (gpointer)drawingarea);
/* drawingarea¸¦ ¸ÞÀÎ À©µµ¿¡ ºÙÀÌ°í µÑ ´Ù º¸¿©ÁØ´Ù. */
gtk_container_add (GTK_CONTAINER(window), drawingarea);
gtk_widget_show (drawingarea);
gtk_widget_show (window);
/* gtk main loop¿¡ µé¾î°£´Ù. (´Ù½Ã´Â µ¹¾Æ¿ÀÁö ¸øÇÑ´Ù.) */
gtk_main ();
/* ±î´Ù·Î¿î ÄÄÆÄÀÏ·¯µéÀ» ¸¸Á·½ÃŲ´Ù */
return 0;
}
ÆÄÀϼ±Åà widgetÀº ÆÄÀÏ ´ëÈ»óÀÚ¸¦ º¸ÀÌ´Â ºü¸£°í °£ÆíÇÑ °ÍÀÌ´Ù. ÀÌ°ÍÀº Ok, Cancel, Help ¹öÆ°À» °¡Áö°í ÀÖÀ¸¸ç, ÇÁ·Î±×·¡¹Ö ½Ã°£À» »ó´çÈ÷ ÁÙ¿©ÁØ´Ù.
»õ·Î¿î ÆÄÀϼ±Åà ¹Ú½º¸¦ ¸¸µé·Á¸é ÀÌ°ÍÀ» ÀÌ¿ëÇÑ´Ù.
GtkWidget* gtk_file_selection_new (gchar *title);
ÆÄÀÏÀ̸§À» ¼¼ÆÃÇϱâ À§Çؼ ÀÌ ÇÔ¼ö¸¦ ÀÌ¿ëÇÑ´Ù.
void gtk_file_selection_set_filename (GtkFileSelection *filesel, gchar *filename);
»ç¿ëÀÚ°¡ Å°º¸µå ȤÀº ¸¶¿ì½º Ŭ¸¯À¸·Î ÀÔ·ÂÇÑ ÅؽºÆ®¸¦ Æ÷ÂøÇϱâ À§Çؼ´Â ÀÌ ÇÔ¼ö¸¦ ¾´´Ù.
gchar* gtk_file_selection_get_filename (GtkFileSelection *filesel);
ÆÄÀϼ±ÅÃwidget ³»ºÎ¿¡ Æ÷ÇÔµÈ widgetµé¿¡ ´ëÇÑ Æ÷ÀÎÅ͵鵵 ÀÖ´Ù. ±×µéÀº ´ÙÀ½°ú °°´Ù.
¿ì¸®°¡ °¡Àå ¸¹ÀÌ ÀÌ¿ëÇÏ°Ô µÉ °ÍÀº ok_button, cancel_button, ±×¸®°í help_button Æ÷ÀÎÅÍ°¡ µÉ °ÍÀÌ´Ù.
ÀÌ°ÍÀº testgtk.c ¿¡¼ ¹ßÃéÇÑ °ÍÀ» ¸ñÀû¿¡ ÀÇÇØ º¯ÇüÇÑ °ÍÀÌ´Ù. º¸¸é ¾Ë°ÚÁö¸¸, ¿©±â¼´Â ÆÄÀϼ±ÅÃwidgetÀ» Çϳª ¸¸µé »ÓÀÌ´Ù. Help ¹öÆ°ÀÌ ½ºÅ©¸°¿¡ º¸ÀÌ°ÚÁö¸¸, ¾Æ¹«·± ½Ã±×³ÎÀÌ ¿¬°áµÇ¾î ÀÖÁö ¾ÊÀ¸¹Ç·Î ¾Æ¹« ±â´ÉÀÌ ¾øÀ» °ÍÀÌ´Ù.
#include <gtk/gtk.h>
/* filesel.c */
/* ¼±ÅÃµÈ ÆÄÀÏ À̸§À» ÃëÇؼ ±×°ÍÀ» ÄַܼΠÇÁ¸°Æ®ÇÑ´Ù. */
void file_ok_sel (GtkWidget *w, GtkFileSelection *fs)
{
g_print ("%s\n", gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs)));
}
void destroy (GtkWidget *widget, gpointer data)
{
gtk_main_quit ();
}
int main (int argc, char *argv[])
{
GtkWidget *filew;
gtk_init (&argc, &argv);
/* ÆÄÀϼ±Åà widgetÀ» Çϳª ¸¸µç´Ù. */
filew = gtk_file_selection_new ("File selection");
gtk_signal_connect (GTK_OBJECT (filew), "destroy",
(GtkSignalFunc) destroy, &filew);
/* file_ok_sel ÇÔ¼ö·Î ok_buttonÀ» ¿¬°á½ÃŲ´Ù. */
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
"clicked", (GtkSignalFunc) file_ok_sel, filew );
/* gtk_widget_destroy ÇÔ¼ö·Î cancel_buttonÀ» ¿¬°á½ÃŲ´Ù. */
gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button),
"clicked", (GtkSignalFunc) gtk_widget_destroy,
GTK_OBJECT (filew));
/* ÆÄÀÏÀ̸§À» ¼¼ÆÃÇÑ´Ù. */
gtk_file_selection_set_filename (GTK_FILE_SELECTION(filew),
"penguin.png");
gtk_widget_show(filew);
gtk_main ();
return 0;
}