¾ÆÁ÷ â¿¡ ´ëÇÏ¿© ÇÒ À̾߱âµéÀº ¸¹ÀÌ ³²¾Æ ÀÖÁö¸¸, ½ä··ÇÑ Ã¢¸¸ °¡Áö°í À̸® Àú¸® Àå³Ä¡´Â °ÍÀº ±×¸¸µÎ°í ´çºÐ°£Àº GRAPHICS ¿¡ ´ëÇÏ¿© °øºÎÇغ¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.
¹¹, ³Ê¹« ´ç¿¬ÇÑ °Í ¾Æ´Ï°Ú¾î¿ä? â(Window) ¾È¿¡´Ù ±×¸²À» ±×¸®°ÚÁö¿ä. ÇÏÁö¸¸, ¿ÀÁ÷ ±×°Í¸¸Àº ¾Æ´Ï¶ø´Ï´Ù. â ¸»°íµµ ±×¸± ¼ö ÀÖ´Â °÷ÀÌ Àִµ¥, ±×°ÍÀ» Pixmap À̶ó°í ÇÕ´Ï´Ù. Áß¿äÇÑ ÀÚ·áÇü(Variable Type) Áß¿¡ Window¿Í Pixmap ÀÌ µÎ °¡Áö°¡ Àִµ¥, ÀÌ µÎ °³¸¦ ÇÕÃļ ÀÚ·áÇü DrawableÀ̶ó°í ÇÕ´Ï´Ù. Drawable? ÀÚ, ±×¸²À» ±×¸®´Â °ÍÀÌ °¡´ÉÇÏ´Ù´Â ¶æÀÌÁÒ? ¾îµð¼ º» °Íµµ °°ÁÒ? ¹Ù·Î Àü¹ø °ÀÇ XGetGeometry ÇÔ¼ö¿¡¼ Àá±ñ ³ª¿Ô´ø ³à¼®ÀÔ´Ï´Ù. ´çºÐ°£ °è¼Ó â¿¡´Ù¸¸ ±×¸± °ÍÀÌ¿À´Ï, Pixmap¿¡ ´ëÇÑ ¼³¸íÀ» ´ÙÀ½À¸·Î ¹Ì·ì´Ï´Ù. ÀÌ·¸°Ô ¹Ì·ïµµ µÇ³Ä±¸¿ä? °ÆÁ¤ÇÏÁö ¸¶½Ê½Ã¿ä. Drawable ÀÚ·áÇüÀ̶ó°í µÇ¾î ÀÖ´Â °ÍÀº Window³ª Pixmap µÎ °¡Áö¿¡ ¶È°°ÀÌ Àû¿ëµÇ¹Ç·Î »õ·Ó°Ô ¹è¿ì½Ç ÇÊ¿ä°¡ ¾ø°í ÀÌÇØÇϽñ⵵ ½¬¿ï °Ì´Ï´Ù.
Å« º×, ÀÛÀº º× ... »¡°£»ö, ³ë¶õ»ö, ÁÖȲ»ö ... ¹«¾ùÀΰ¡¸¦ ±×¸± ¶§ ÀÚ½ÅÀÇ ±¸¹Ì¿¡ ¸Â°Ô ´Ù¾çÇÑ µµ±¸¸¦ ¼±ÅÃÇÒ ¼ö ÀÖ¾î¾ß ÇÏ°ÚÁÒ? X À©µµ¿ì ½Ã½ºÅÛÀº Graphics Context ù±ÛÀÚ¸¸ µû¼ GC¶ó°í ÇÏ´Â ¾ÆÁÖ Æ¯º°ÇÑ ÀÚ¿ø(Resource)À» °¡Áö°í ÀÖ½À´Ï´Ù. ¿ä GC¶ó°í ÇÏ´Â °Í¿¡ °ú¿¬ ¾î¶»°Ô(How) ±×¸± °ÍÀΰ¡? ¶ó´Â ¹®Á¦¿¡ ´ëÇÑ Á¤º¸¸¦ ÀüÀûÀ¸·Î(!) °¡Áö°í ÀÖ½À´Ï´Ù. Ç×»ó ÀÚ¿øÀº ¼¹ö°¡ µ¶ÀçÀûÀ¸·Î(!) °ü¸®¸¦ ÇÏ´Â ¸ð½ÀÀ» ¿©±â¼µµ ¿³º¼ ¼ö ÀÖ±º¿ä. :)
±×·¡ÇÈ¿¡ ±âº»ÀÎ Á¡(Point), ¼±(Line)À» ±×¸± ¼ö ÀÖ½À´Ï´Ù. ÇϳªÀÇ Á¡, ÇϳªÀÇ ¼±À» ±×¸®¶ó°í ¼¹ö¿¡°Ô ¿äûÇÏ´Â ÇÔ¼öµéÀÌ ´ç¿¬È÷ ±¸ºñµÇ¾î ÀÖ°í, ¿©±â¿¡ °³¹ßÀÚ Æí¸®¸¦ À§Çؼ ¿©·¯ °³ÀÇ Á¡, ¿©·¯ °³ÀÇ ¼±À» ±×¸®´Â ÇÔ¼ö, »ç°¢Çü, ¿øÈ£ µîµîÀ» ±×¸®µµ·Ï ¿äûÇÏ´Â ÇÔ¼ö°¡ ¶ÇÇÑ ÁغñµÇ¾î ÀÖ½À´Ï´Ù. ¸¶Áö¸·À¸·Î ÅؽºÆ® ¹®ÀÚ¸¦ ±×·Á³¾ ¼ö ÀÖ´Â ÇÔ¼öµéÀÌ ÀÖ¾î¼ ¿øÇÏ´Â ÆùÆ®¸¦ °¡Áö°í ¹®ÀÚ¸¦ Ç¥ÇöÇÒ ¼ö ÀÖ½À´Ï´Ù. X À©µµ¿ì´Â GUI üÁ¦À̹ǷΠ±ÛÀÚ ¶ÇÇÑ ¾²´Â °Ô ¾Æ´Ï¶ó ´Ù¸¥ µµÇü°ú ¸¶Âù°¡Áö·Î ±×¸®´Â °ÍÀÌÁÒ. Âü°í·Î ¿©·¯ºÐÀÌ ½½·¢À» ¼³Ä¡ÇÒ ¶§ PEX ¶óÀ̺귯¸®¸¦ ¼³Ä¡Çϼ̴ٸé 3Â÷¿ø ±×·¡ÇÈÀ» ¾ÆÁÖ ½±°Ô ±×¸± ¼ö ÀÖ½À´Ï´Ù. ³ªÁß¿¡ ±âȸ°¡ µÇ¸é ¾à°£ ¼³¸íÀ» µå¸± ¿¹Á¤ÀÔ´Ï´Ù¸¸...
¾î¶² ÇÁ·Î±×·¡¹ÖÀÌµç ¸¶Âù°¡ÁöÀÌ°ÚÁö¸¸, X À©µµ¿ì ÇÁ·Î±×·¡¹ÖÀº ¾î¶² ÀÏÀ» ¼öÇàÇϵçÁö Á¤ÇØÁ® ÀÖ´Â ¸î ´Ü°èÀÇ ÀýÂ÷¸¦ µû¶ó¾ß ÇÕ´Ï´Ù. ÀÌ·¯ÇÑ ÀýÂ÷¸¦ ¸Ó¸® ¼Ó¿¡ Ç×»ó ±â¾ïÇÏ½Ç ¼ö ÀÖ´Â ºÐµéÀ̾߸»·Î X À©µµ¿ì ÇÁ·Î±×·¡¹Ö µµ»çµéÀÌ µÇ½Ã´Â °Ì´Ï´Ù.
Áö±ÝºÎÅÍ´Â ÀÌ ¼ø¼ ±×´ë·Î ¼³¸íÀ» Çسª°¥ °ÍÀÔ´Ï´Ù. À§ ±âº»ÀýÂ÷¸¦ ²À ±â¾ïÇϼ¼¿ä.
±âº» ÀýÂ÷ 1 ¿¡ ´ëÇؼ´Â ¼³¸íµå¸®Áö ¾Ê½À´Ï´Ù. â ¸¸µå´Â °Å Áö±Ý±îÁö ÇØ¿ÔÀݾƿä?
ÇÔ¼öÀÇ ¿øÇü : <X11/Xlib.h>
GC XCreateGC ( Display *display,
Drawable drw,
unsigned long bitmask,
XGCValues *values
);
bitmask, XGCValues Çü º¯¼ö values¿¡ ´ëÇÑ ¼³¸í¸¸ÀÌ ÇÊ¿äÇÏ°Ú±º¿ä.
--------------------------------------------------------------------
# ¸â ¹ö ¸í ºñÆ® ¸Å½ºÆ® ±âº»°ª
--------------------------------------------------------------------
1 int function GCFunction GXCopy
2 unsigned long plane_mask GCPlaneMask ¸ðµÎ 1
3 unsigned long foreground GCForeground 0
4 unsigned long background GCBackground 1
5 int line_width GCLineWidth 0
6 int line_style GCLineStyle LineSolid
7 int cap_style GCCapStyle CapButt
8 int join_style GCJoinStyle JoinMiter
9 int fill_style GCFillStyle FillSolid
10 int fill_rule GCFillRule EvenOddRule
11 int arc_mode GCArcMode ArcPieSlice
12 Pixmap tile GCTile ?
13 Pixmap stipple GCStipple ?
14 int ts_x_origin GCTileStipXOrigin 0
15 int ts_y_origin GCTileStipYOrigin 0
16 Font font GCFont ?
17 int subwindow_mode GCSubwindowMode ClipByChildren
18 Bool graphics_exposures GCGraphicsExposures True
19 int clip_x_origin GCClipXOrigin 0
20 int clip_y_origin GCClipYOrigin 0
21 Pixmap clip_mask GCClipMask None
22 int dash_offset GCDashOffset 0
23 char dashes GCDashList 4
ºñÆ® ¸Å½ºÅ© ¸ÅÅ©·Î¿Í ±âº»°ª¿¡¼ÀÇ ¸ÅÅ©·Î´Â <X11/Xlib.h> ÈÀÏ¿¡¼ ÀÚµ¿À¸·Î Æ÷ÇÔ(#include)ÇÏ´Â <X11/X.h> ÈÀÏÀÇ GRAPHICS DEFINITION ºÎºÐ¿¡ Á¤ÀǵǾî ÀÖÀ¸´Ï ±× ºÎºÐÀ» ã¾Æº¸½Ã±â ¹Ù¶ø´Ï´Ù. ? Ç¥ÇÑ ºÎºÐÀº ¾ÆÁ÷Àº ¾Ë ÇÊ¿ä°¡ ¾ø°Å³ª 16¹ø FontÀÇ °æ¿ì¿¡´Â ½Ã½ºÅÛ¸¶´Ù ´Ù¸¥ ´Ù¸¥ °ªÀ̹ǷΠÁ¤ÇØÁöÁö ¾ÊÀº °ªÀ̶ó´Â ¶æÀÔ´Ï´Ù.
À§ µµÇ¥¸¦ ÁÖÀDZí°Ô »ìÆ캸½Ê½Ã¿ä. ¸â¹ö¸í°ú ºñÆ® ¸Å½ºÅ©¸í »çÀÌ¿¡´Â ÇÑ ´«¿¡µµ ô ¾Ë¾Æº¼ ¼ö ÀÖ´Â ¸í¸í±ÔÄ¢ÀÌ ÀÖ½À´Ï´Ù. ºñÆ® ¸Å½º¸íÀº Ç×»ó GC·Î ½ÃÀÛÇÏ°í ¸â¹ö¸íÀÌ ¼Ò¹®ÀÚÀÎ °Í°ú ´Þ¸® Ç×»ó ´ë¹®ÀÚ, ±×¸®°í ´Ü¾î¸¶´Ù ´ë¹®ÀÚ¸¦ ¾¹´Ï´Ù. ¸â¹ö¸í¿¡ ÀÖ´Â ´ë½¬(-) ¹®ÀÚ´Â ¾ø¾Û´Ï´Ù. ¸â¹ö¸íÀ» ¼Ò¹®Àڷθ¸ ½è±â ¶§¹®¿¡ ´Ü¾î±¸º°À» À§ÇØ ´ë½¬°¡ µé¾î°£ °Í¿¡ ºÒ°úÇϴϱî¿ä. ÀÌ·¯ÇÑ ¸í¸í ¹æ½ÄÀº X Àü¹Ý¿¡ »ç¿ëµÇ°í ÀÖÀ¸´Ï ¼ÒȦÈ÷ ³Ñ±âÁö ¸¶½Ã±â ¹Ù¶ø´Ï´Ù.
ÇÁ·Î±×·¥ ³»¿¡¼ º¸Åë ´ÙÀ½°ú °°Àº °úÁ¤À» ÅëÇØ GC¸¦ ¼¹ö Ãø¿¡ »ý¼º,µî·Ï½ÃÅ°°í ID¸¦ ÀÔ¼öÇÕ´Ï´Ù.
Display *display; /* µð½ºÇ÷¹ÀÌ ¼¹öÀÇ ID */
Window window; /* »ý¼ºµÉ âÀÇ ID */
GC gc; /* ¿ì¸®°¡ »ç¿ëÇÒ º× */
XGCValues gvalue; /* º×ÀÇ ¼Ó¼ºÀ» ÁöÁ¤ÇÒ ¶§ ±× ¼Ó¼ºÀ» ÀúÀåÇØµÑ º¯¼ö */
...
/* ¿ì¸®°¡ ¿øÇÏ´Â ±×·¡ÇÈ ¼Ó¼º¸¸À» ¼ÂÆÃÇÑ´Ù */
gvalue.line_width = 20;
gvalue.line_style = LineOnOffDash;
gvalue.cap_style = CapRound;
gvalue.join_style = JoinRound; /* ÁÖÀÇ */
gc = XCreateGC ( display, window, GCLineWidth | GCLineStyle | GCCapStyle,
&gvalue );
/* ¿©±â¼ ´«¿©°Ü º¼ °ÍÀº GCLineWidth | GCLineStyle | GCCapStyle ºÎºÐÀÌ´Ù.
¿ì¸®°¡ XGCValues Çü º¯¼ö gvalue¿¡ ¼ÂÆÃÇÑ ¼Ó¼ºÀÇ ¸Å½ºÅ©¸¦ OR Çü½ÄÀ¸·Î
ÁöÁ¤ÇØÁÖ¾î¾ß ÇÑ´Ù. */
º×À» óÀ½ ¸¸µé ¶§ºÎÅÍ ¹Ì¸® ¸î °¡Áö ¼Ó¼ºÀ» ¸¸µé¾î ³õ°í ½ÃÀÛÇÏ´Â ÀüÇüÀûÀÎ ¹æ½Ä ÀÔ´Ï´Ù. ºñÆ® ¸Å½ºÅ© ¾´ ¹æ½ÄÀ» Á¤¸»·Î À¯½ÉÈ÷ »ìÆ캸½Ê½Ã¿ä. ±×·¯¸é ÇÑ °¡Áö »ç½ÇÀ» ´«Ä¡Ã¤½Ç ¼ö ÀÖ½À´Ï´Ù. /* ÁÖÀÇ */¶ó°í ÇÑ ÁÙ¿¡¼ µÎ ÁÙÀÌ À̾îÁú ¶§ ¾î¶² ¸ð¾çÀ¸·Î À̾îÁúÁö¿¡ ´ëÇÏ¿© Á¤ÇØÁÖ¾úÁö¸¸ GC¸¦ ¸¸µé ¶§ ºñÆ® ¸Å½ºÅ©¿¡¼ GCJoinStyle À» ³Ö¾îÁÖÁö ¾Ê¾Ò±â ¶§¹®¿¡ ¼Ó¼ºÀÌ µÇÁö ¸øÇÕ´Ï´Ù. ¾î¶»°Ô º¸¸é ´ç¿¬ÇÏÁÒ? ÄÄÇ»ÅÍ°¡ ¹«½¼ ÀçÁÖ·Î ¿ì¸®°¡ ¹«½¼ °ªÀ» ¿øÇÏ´ÂÁö ¾Ë°Ú½À´Ï´Ù. ÀÌ·¯Àú·¯ÇÑ °ÍÀ» ÁöÁ¤ÇØ µÎ¾úÀ¸´Ï ±×°ÍÀ» ¼ÂÆÃÇ϶ó. ÀÌ·± ½ÄÀ¸·Î ÀÚ¼¼È÷ ¾Ë·ÁÁÖÁö ¾ÊÀ¸¸é ¾ÈµË´Ï´Ù.
¸Å¹ø GC¸¦ ¸¸µé ¶§¸¸ ¼Ó¼ºÀ» Á¤ÇÒ ¼ö ÀÖ´Â °ÍÀº ¾Æ´Õ´Ï´Ù. ÀÌ¹Ì »¡° ¹°°¨À» Àû½Å º×À̶ó ÇÏ´õ¶óµµ ¹°¿¡ ¾Ä¾î³»°í ÆĶû ¹°°¨À» Àû½Ç ¼öµµ ÀÖ´Â °Í ¾Æ´Ï°Ú½À´Ï±î?
ÇÔ¼öÀÇ ¿øÇü : <X11/Xlib.h>
XChangeGC ( Display *display,
GC gc,
unsigned long mask,
XGCValues *gvalues
);
»ç¿ë¹ýÀº À§¿¡¼¿Í °°½À´Ï´Ù. º×ÀÇ ¼Ó¼ºÀ» ¹Ù²Ù°í ½ÍÀ» ¶§´Â XGCValues Çü º¯¼öÀÇ ¸â¹ö¿¡ ÀûÀýÇÑ °ªÀ» ¼ÂÆÃÇÑ ÈÄ, ÀÌ ÇÔ¼ö¸¦ ºÎ¸£¸é µË´Ï´Ù. ºñÆ®¸Å½ºÅ©¸¦ Àß ¾²¼Å¾ß°ÚÁÒ?
ÇÔ¼ö ¿øÇü : <X11/Xlib.h>
XDrawPoint( Display *display, Drawable d, GC gc, int x, int y );
XDrawPoints ( Display *display, Drawable d, GC gc, XPoint *points,
int npoints, int mode );
typedef struct {
short x, y;
} XPoint;
/* Âü°í : XSegment, XRectangle, XArc */
XDrawPoints ÇÔ¼ö´Â µÚ¿¡ º¹¼öÇüÀÓÀ» ÀǹÌÇÏ´Â s°¡ ºÙÀº °Í¿¡ À¯ÀÇÇսôÙ. ¿©·¯ °³ÀÇ Á¡À» XPoint Çü ±¸Á¶Ã¼ ¹è¿¿¡ ³Ö¾î¼ ÇÑ ¹øÀÇ ÇÔ¼ö ºÎ¸£±â·Î ±×¸®°íÀÚ ÇÒ ¶§ À¯¿ëÇÕ´Ï´Ù. ¸ðµç ½ºÅ¸ÀÏ¿¡ ´ëÇÑ ¼ÂÆÃÀº Ç×»ó GC Çü º¯¼ö°¡ °¡¸®Å°´Â ¼¹öÀÇ ¸Þ¸ð¸®¿¡ ÀÖ´Ù´Â °ÍÀ» ±â¾ïÇսôÙ. npoints º¯¼ö´Â Á¡ ¹è¿ÀÇ °¹¼ö¸¦ ÁöÁ¤ÇØÁÝ´Ï´Ù. mode ¿¡´Â ´ÙÀ½ µÎ °¡Áö°¡ Àִµ¥ CoordModeOriginÀº ÁÖ¾îÁø ¸ðµç ÁÂÇ¥°¡ DrawableÀÇ ¿øÁ¡¿¡ ´ëÇÑ ÁÂÇ¥·Î ÁÖ¾îÁ³À½À» ÀǹÌÇϸç, CoorDModePrevious´Â ÃÖÃÊÀÇ Á¡¸¸ Drawable ¿øÁ¡¿¡ ´ëÇÑ ÁÂÇ¥ÀÌ¸ç ³ª¸ÓÁö´Â ¹Ù·Î Á÷ÀüÀÇ Á¡¿¡ ´ëÇÑ »ó´ë ÁÂÇ¥·Î Ç¥½ÃµÇ¾î ÀÖÀ½À» ³ªÅ¸³»ÁÝ´Ï´Ù.
ÇÔ¼ö ¿øÇü : <X11/Xlib.h>
XDrawLine( Display *display, Drawable d, GC gc, int x1, int y1,
int x2, int y2 );
XDrawLines( Display *display, Drawable d, GC gc, XPoints *points,
int npoints, int mode );
XDrawSegments( Display *display, Drawable d, GC gc, XSegment *segments,
int nsegments );
ù¹ø° ÇÔ¼ö´Â Drawable ³»¿¡¼ ( x1, y1 )¿¡¼ ( x2, y2 ) ÁÂÇ¥±îÁö ¼±À» ±ß´Â ¾ÆÁÖ ÀϹÝÀûÀÎ ÇÔ¼öÀÔ´Ï´Ù. µÎ¹ø° ÇÔ¼ö´Â ¿¬ÇÊ ¶¼Áö ¾Ê°í ±×¸®±â¸¦ ¸»ÇÕ´Ï´Ù. XPoint ±¸Á¶Ã¼ ¹è¿ÀÇ Á¡µéÀÌ °è¼Ó À̾îÁö´Â ÇüÅ·Π±×·ÁÁø´Ù. ÁÂÇ¥¿¡ ´ëÇÑ Ç¥±â´Â mode °ªÀ¸·Î ÇÕ´Ï´Ù. Á¡ ±×¸®´Â ÇÔ¼ö XDrawPoints¿¡¼¿Í °°½À´Ï´Ù. ¼¼¹ø° XDrawSegments´Â µÎ¹ø° ÇÔ¼ö¿Í ´Þ¸® ¿¬¼ÓµÈ ¹è¿ÀÇ Á¡µéÀ» ÇÑ ½Ö ¾¿ ¹¾î¼ ¼±À» ¿©·¯ °³ ±×¸°´Ù. (x1,y1)¿¡¼ (x2,y2)¿¡ ±ß°í, ´Ù½Ã (x3,y3)¿¡¼ (x4,y4)¿¡ ±ß´Â ¹æ½ÄÀÔ´Ï´Ù.
¼± ½ºÅ¸ÀÏÀÌ ¸¹À¸¹Ç·Î Xlib¿¡ ´ëÇÑ ·¹ÆÛ·±½º PS ÈÀÏ µîÀ» ±¸ÇÏ´Â °ÍÀÌ ÁÁ½À´Ï´Ù. Ã¥À» »çÁö ¾Ê¾Æµµ ¿Ïº®ÇÑ ¼³¸í¼°¡ µÉ ¸¸Å Àß ¸¸µé¾îÁ® ÀÖ½À´Ï´Ù.
Âü°í ÇÔ¼ö : XSetLineAttributes ()
XSetDash ()
ÇÔ¼ö ¿øÇü : <X11/Xlib.h>
XDrawRectangle ( Display *display, Drawable d, GC gc, int x, int y,
unsigned int width, unsigned int height );
XDrawRectangles( Display *display, Drawable d, GC gc,
XRectangle rectangels[], int nrectangles );
±×·¡ÇÈ¿¡ °ü½ÉÀÌ ¸¹À¸½Å ºÐµéÀº ½º½º·Î ³ª¸ÓÁö ÇÔ¼öµéÀ» Á¶»çÇϽñ⠹ٶø´Ï´Ù. ÀÌ°Í¿¡ ¸¸Á·ÇϽÃÁö ¸øÇÏ´Â ºÐµéÀº 3D ±×·¡ÇÈ ¶óÀ̺귯¸®ÀÎ PEXlib ¿¡ ´ëÇÑ °øºÎ¸¦ ÇÏ½Ã¸é µË´Ï´Ù. ÀÌ°Í¿¡ ´ëÇÑ ³»¿ëÀº Xlib ÇÁ·Î±×·¡¹Ö ¼öÁØÀ» ³Ñ¾î¼°í ±× ÀÚü·Îµµ ¹æ´ëÇϱ⠶§¹®¿¡ ¿©·¯ºÐÀÇ ÀÇÁö¿¡ ¸Ã±é´Ï´Ù.
À§¿¡¼ ¼³¸íÇÑ ÇÔ¼öµéÀ» °¡Áö°í ´ÙÀ½¿¡´Â ½Ç½ÀÀ» Çغ¸±â·Î ÇսôÙ. ±×¸®°í °£·«ÇÏ°Ô ÆùÆ®¸¦ °¡Áö°í ¹®ÀÚ¿ ³ªÅ¸³»±â¸¦ ´Ù·ç¾îº¸°Ú½À´Ï´Ù.
Xlib ±×·¡ÇÈÀº X ÇÁ·Î±×·¡¹ÖÀÇ ±âÃÊ°¡ µÇ¾îÁÖ´Â ¾ÆÁÖ ±âº»ÀûÀÎ ±â´ÉÀÔ´Ï´Ù. X À©µµ¿ì´Â ¿ÂÅë ±×·¡ÇÈÀ¸·Î °¡µæ Â÷ ÀÖ´Ù°í »ý°¢ÇÏ½Ã¸é µË´Ï´Ù. Á¡ ÇϳªºÎÅÍ ¸ðµç º¹ÀâÇÑ µµÇüÀº °á±¹ Xlib ÀÇ ÇÔ¼ö¸¦ ÅëÇؼ °¡´ÉÇÑ °ÍÀÔ´Ï´Ù. Á¦ °èȹÀ¸·Î´Â ¾öû³ ¼Óµµ·Î Xlib ÇÁ·Î±×·¡¹ÖÀ» ¸¶Ä¡°í ¾î¼ »¡¸® ¿©·¯ºÐÀÌ Àç¹ÌÀÖ¾î ÇÒ Xt ÇÁ·Î±×·¡¹ÖÀ¸·Î ³Ñ¾î°¡°í ½ÍÀºµ¥¿ä, ¹Ù·Î ±× °÷¿¡¼ À§Á¬À» »õ·Î ¸¸µç´Ùµç°¡ ÇÒ ¶§ ¾ÆÁÖ À¯¿ëÇÏ°Ô ¾²ÀÔ´Ï´Ù. Àú¸¦ µû¶ó ¿À½Ã¸é ¿©·¯ºÐ¸¸ÀÇ ¸ÚÁø À§Á¬À» ¸¸µé ¼ö ÀÖµµ·Ï ¾È³»Çص帮°Ú½À´Ï´Ù. ¶Ç ¸ð¸£ÁÒ. ¿©·¯ºÐ Áß¿¡¼ Á¤¸»·Î »ó»ó·ÂÀÌ ¶Ù¾î³ª°í ¸ÚÁø À§Á¬ÀÌ ³ª¿À¸é FWF(Free Widget Foundation)ÀÇ À§Á¬¼Â¿¡ Æ÷ÇԵǾî Àü¼¼°èÀÇ ÇÁ·Î±×·¡¸Óµé¿¡°Ô ¾Ë·ÁÁú ¼öµµ ÀÖ½À´Ï´Ù. ¼Ò½º°¡ °ø°³µÇ¾î ÀÖÁö ¾Ê´Â ´Ù¸¥ ½Ã½ºÅÛ¿¡¼´Â ºÒ°¡´ÉÇÑ ÀÏ ¾Æ´Ï°Ú½À´Ï±î?
´Ù½Ã ÇÑ ¹ø È®ÀÎÇÕ´Ï´Ù! Xlib ±×·¡ÇÈÀº Ç×»ó GC ¶ó°í ÇÏ´Â ¸®¼Ò½º¸¦ °¡Áö°í ÇÕ´Ï´Ù. ±× GC´Â ±×·¡ÇÈ¿¡ °üÇÑ ¿©·¯ Á¤º¸¸¦ Áö´Ï°í ÀÖ´Â ³à¼®Àä, ´ç¿¬È÷ ¼¹ö Ãø¿¡´Ù GC »ý¼ºÀ» ÀÇ·ÚÇÏ°í ¿ì¸®´Â ±× GCÀÇ ID¸¸À» ¹Þ¾Æ¿É´Ï´Ù. ÀÌ°ÍÀº X À©µµ¿ìÀÇ ³×Æ®¿öÅ© ÁöÇâÀû Ư¼º¿¡¼ ³ª¿À´Â °ÍÀ¸·Î¼, ³×Æ®¿öÅ©¸¦ ÅëÇؼ ÃÖ¼ÒÀÇ Á¤º¸¸¦ ÀüÇϸ鼵µ ¿øÇÏ´Â ±â´ÉÀ» ¾ò°íÀÚ Çϱ⠶§¹®ÀÔ´Ï´Ù. ¿¹¸¦ µé¾î ¸Å¹ø red ¶ó´Â »ö»óÀ¸·Î ¼±À» ±×À¸¶ó´Â 100¹øÀÇ ¸í·ÉÀÌ ÀÖ´Ù¸é, red·Î ±×¸®¶ó°í´Â ¸í·ÉÀÌ °è¼Ó ³×Æ®¿öÅ©¸¦ Ÿ°í ¼¹ö·Î ÀüÇØÁ®¾ß ÇÒ °ÍÀÔ´Ï´Ù. ¿©·¯ °¡Áö ÁÖ¹®»çÇ×À» ¹Ì¸® µî·ÏÇسõ°í °£´ÜÈ÷ ±× ID¸¸À» Àü¼ÛÇÏ´Â ¹æ½ÄÀÌ ÈξÀ ³×Æ®¿öÅ©ÀÇ ·Îµå¸¦ ÁÙÀÌ´Â ¹æ¹ýÀÌ µÇ°ÚÁÒ? ¹°·Ð Á׾´Â °ÍÀº Ç×»ó ¼¹öÀÔ´Ï´Ù. :)
ÀÌÁ¦ºÎÅÍ ±×·¡ÇÈÀ» ¿¬½ÀÇغ¾½Ã´Ù
#include <X11/Xlib.h>
/* »ö»ó À̸§¿¡ ÇØ´çÇÏ´Â Çȼ¿°ª ¹ÝȯÇÏ´Â ÇÔ¼ö */
unsigned long UsrColorPixel( Display*, char* );
/* ¿äûÀ» Ç÷¯½¬ÇÏ°í ÁöÁ¤µÈ Ãʸ¸Å Áö¿¬½ÃÅ°´Â ÇÔ¼ö */
void Pause( Display*, int );
static XPoint points[] = {{ 200, 50 },{ 100, 150 },{ 300, 150 },{ 200, 50 }};
static XSegment segs[] = {{ 10, 10, 390, 190 },{ 10, 190, 390, 10 }};
static char dash_list[] = { 20, 5, 10, 5 };
int main()
{
Display *d;
Window w; /* One TopLevel Window & Two Child Windows */
GC gc;
XGCValues gv;
/* ¼¹ö¿Í Á¢¼ÓÇϱ⠱׸®°í º¯¼öµéÀ» ÃʱâÈ */
d = XOpenDisplay ( NULL );
/* ÀÚ, ½ÃÀÛÇغ¼±î¿ä? */
w = XCreateSimpleWindow ( d, DefaultRootWindow( d ),
100, 100, 400, 200, 1,
BlackPixel(d,0), WhitePixel(d,0) );
XMapWindow( d, w );
Pause( d, 2 );
/*
* [1] Á¡(Point)À» Âï¾îº¾´Ï´Ù. XDrawPoint(s) ÇÔ¼ö »ç¿ë
*/
gv.foreground = UsrColorPixel( d, "red" );
gc = XCreateGC( d, w, GCForeground, &gv );
XDrawPoint ( d, w, gc, 200, 100 );
Pause( d, 3 );
gv.foreground = UsrColorPixel( d, "blue" );
XChangeGC ( d, gc, GCForeground, &gv );
XDrawPoints ( d, w, gc, points, 3, CoordModeOrigin );
Pause( d, 3 );
/*
* °íÇػ󵵿¡¼´Â ¹¹ °ÅÀÇ ¾Èº¸ÀÏ Á¤µµ·Î RED»öÀÇ ÀÛÀº Á¡ Çϳª,
* ±×¸®°í ³ª¼ BLUE»öÀÇ Á¡ 3°³¸¦ Âï°í ÀÖ½À´Ï´Ù. Á¤¸»·Î ÁýÁßÇؼ
* º¸¼Å¾ß ÇÒ °Ì´Ï´Ù. ¸ð´ÏÅÍ°¡ ´õ·¯¿ì¸é ¸ÕÁö¿Í ±¸º°ÀÌ ¾ÈµÉÁöµµ... :)
*/
XClearWindow( d, w );
{
int i, j;
for ( j = 0; j < 200 ; j++ )
for ( i = 0; i < 400 ; i++ )
{
XDrawPoint( d, w, gc, i, j );
XFlush ( d );
}
}
Pause( d, 3 );
/*
* BLUE Á¡À¸·Î â Çϳª °¡µæÈ÷ Ä¥Çغ¾´Ï´Ù. XFlush ÇÔ¼ö¸¦ °íÀÇ·Î ½á¼
* ±× °úÁ¤À» ¾Ë¾Æº¼ ¼ö ÀÖµµ·Ï ÇÏ¿´½À´Ï´Ù. »ý°¢º¸´Ù ºü¸£°Ô ÂïÈú °Ì´Ï´Ù.
* ¸®´ª½º´Â ¿ÏÀüÇÑ ÀǹÌÀÇ 32ºñÆ® OS À̴ϱî¿ä.
*/
/*
* [2] ¼±(Line)À» ±×·Áº¾´Ï´Ù.
*/
XSetWindowBackground ( d, w, UsrColorPixel( d, "blue" ) );
gv.foreground = WhitePixel( d, 0 );
gv.background = UsrColorPixel( d, "red" );
gv.line_width = 20;
XChangeGC( d, gc, GCForeground|GCBackground|GCLineWidth, &gv );
XDrawLine ( d, w, gc, 20, 20, 380, 180 ); /* CapButt */
Pause ( d, 3 );
gv.cap_style = CapRound;
XChangeGC( d, gc, GCCapStyle, &gv );
XClearWindow( d, w );
XDrawLine ( d, w, gc, 380, 20, 20, 180 );
Pause ( d, 3 );
gv.cap_style = CapProjecting;
XChangeGC( d, gc, GCCapStyle, &gv );
XClearWindow( d, w );
XDrawLine ( d, w, gc, 20, 20, 380, 180 );
Pause ( d, 3 );
/*
* ¿©±â±îÁö´Â XDrawLine ÇÔ¼ö¸¦ »ç¿ëÇÏ¿´½À´Ï´Ù. ĸ ½ºÅ¸ÀÏ(Cap)ÀÌ ¼·Î
* ¾î¶»°Ô ´Ù¸¥Áö È®ÀÎÇØ º¸½Ê½Ã¿ä.
*/
XSetLineAttributes ( d, gc, 10, LineDoubleDash, CapRound, JoinRound );
XSetDashes( d, gc, 0, dash_list, 4 );
XClearWindow( d, w );
XDrawSegments ( d, w, gc, segs, 2 );
Pause ( d, 3 );
XClearWindow ( d, w );
XSetLineAttributes ( d, gc, 15, LineOnOffDash, CapButt, JoinBevel );
XDrawLines( d, w, gc, points, 4, CoordModeOrigin );
Pause ( d, 3 );
/*
* ¼±³¡Á¡ ½ºÅ¸ÀÏ¿¡´Â CapButt, CapRound, CapProjecting 3 °¡Áö°¡ ÀÖ½À´Ï´Ù.
* ¼±°ú ¼±ÀÌ ¸¸³ª´Â ¹æ½Ä¿¡µµ ¼¼ °¡Áö°¡ ÀÖ½À´Ï´Ù. JoinMiter, JoinRound,
* ±×¸®°í JoinBevel ÀÌ ±×°ÍÀÌÁÒ.
* Áß¿äÇÑ °Í! ¼±ÀÇ ½ºÅ¸ÀÏ¿¡´Â ±×³É LineSolid, LineOnOffDash, LineDouble-
* Dash °¡ ÀÖ½À´Ï´Ù.
* XSetLineAttributes(), XSetDashes()´Â ¿¬±¸°úÁ¦ÀÔ´Ï´Ù.
*/
/*
* [3] ÀÌÁ¦ 2Â÷¿øÀ¸·Î °¡º¾½Ã´Ù. »ç°¢ÇüºÎÅÍ ½ÃÀÛ!
*/
XClearWindow( d, w );
XSetLineAttributes ( d, gc, 5, LineSolid, CapButt, JoinRound );
XDrawRectangle( d, w, gc, 50 /* X */, 50 /* Y */,
300 /* width */, 100 /* height */ );
Pause( d, 3 );
{
XRectangle rect[7];
int i;
for ( i = 0; i < 7 ; i ++ )
{
rect[i].x = 10 + i * 50; rect[i].y = 20;
rect[i].width = 40 ; rect[i].height = 150;
}
XClearWindow( d, w );
XSetLineAttributes(d,gc,1,LineDoubleDash,CapProjecting,JoinMiter);
XDrawRectangles ( d, w, gc, rect, 7 );
Pause ( d, 3 );
}
/*
* ÀÚ, XDrawRectangle(s)ÀÇ »ç¿ë¹ýÀ» ¾Æ¼Ì³ª¿ä? ±×·¸´Ù¸é ¿¬±¸°úÁ¦°¡ ÀÖ½º
* ´Ï´Ù. ÀÌµé ´ë½Å¿¡ XFillRectangle(s)¸¦ ½áº¸½Ê½Ã¿ä. ¾î¶² ÀÏÀÌ ÀϾ
* ´Ï±î?
*/
/*
* [4] µÕ±×·± °Íµµ ±×·Áº¾½Ã´Ù.
*/
{
int i, radi;
XArc arc[2];
XClearWindow ( d, w );
XSetLineAttributes(d,gc,10,LineSolid,CapRound,JoinRound);
for ( radi = 0 ; radi <= 360 ; radi += 90 )
{
XDrawArc ( d, w, gc, 10, 10, 380, 180, 0 * 64, radi * 64 );
Pause( d, 1 );
}
for ( i = 0 ; i < 2 ; i ++ ) {
arc[i].x = 30 + 200 * i;
arc[i].y = 30;
arc[i].width = arc[i].height = 100;
arc[i].angle1 = 0 * 64;
arc[i].angle2 = 90 * ( i + 1 ) * 64;
}
XClearWindow ( d, w );
XDrawArcs( d, w, gc, arc, 2 );
Pause( d, 1 );
XSetForeground( d, gc, UsrColorPixel(d,"yellow") );
for ( i = 0 ; i < 2 ; i ++ ) {
XClearWindow ( d, w );
XSetArcMode ( d, gc, i == 0 ? ArcPieSlice : ArcChord );
for ( radi = 0 ; radi <= 360 ; radi += 90 )
{
XFillArc ( d, w, gc, 10, 10, 380, 180, 0 * 64, radi * 64 );
Pause( d, 1 );
}
XClearWindow( d, w );
XFillArcs( d, w, gc, arc, 2 );
Pause( d, 1 );
}
}
/* GC, â Æı« & ¼¹ö¿ÍÀÇ Á¢¼Ó ÇØÁ¦ */
XFreeGC( d, gc );
XUnmapWindow( d, w );
XDestroyWindow( d, w );
XCloseDisplay( d );
return 0;
}
/*
UsrColorPixel() : ÁÖ¾îÁø À̸§ÀÇ »ö»ó¿¡ ´ëÇÑ ±âº» Ä÷¯¸ÊÀÇ Çȼ¿°ª ¹Ýȯ
*/
unsigned long UsrColorPixel( display, name )
Display *display;
char *name;
{
Colormap cmap;
XColor c0, c1;
cmap = DefaultColormap( display, 0 );
XAllocNamedColor( display, cmap, name, &c0, &c1 );
return ( c0.pixel );
}
void Pause( Display *d, int secs )
{
XFlush ( d );
sleep( secs );
}
ÄÄÆÄÀÏÀº -lX11 ¿É¼ÇÀ» Áּż Xlib ¿Í ¸µÅ©½ÃÄÑ ÁÖ½Ã¸é µË´Ï´Ù.
ÃÖ´ëÇÑ Xlib ±×·¡ÇÈ ÇÔ¼öµéÀÇ ±â´ÉÀ» º¸ÀÌ·Á°í ³ë·ÂÇß½À´Ï´Ù. ÇÏÁö¸¸ À§¿¡¼ º¸¿©µå¸° °Í¸¸À¸·Î´Â ¸¹ÀÌ ºÎÁ·ÇÕ´Ï´Ù. ¿¹¸¦ µé¾î ÀÚÀ¯·Î¿î ´Ù°¢ÇüÀ» ±×¸®¸é¼ »ö»óÀ» Ä¥ÇÒ ¼ö ÀÖ´Â XFillPolygon()°ú °°ÀÌ À¯¿ëÇÑ ÇÔ¼ö´Â ¼³¸íµå¸®Áö ¾Ê¾Ò½À´Ï´Ù. ÀÚ¼¼ÇÑ °ÍÀº ¿©·¯ºÐÀÇ Å½±¸¿¡ ´Þ·Á ÀÖ½À´Ï´Ù.
´ÙÀ½ ¹ø¿¡´Â ÆùÆ® Ãâ·ÂÇÏ´Â ¹ý¿¡ ´ëÇؼ ¾Ë¾Æº¸±â·Î ÇսôÙ. ¿µ¹®ÀÚ Ãâ·Â°ú ´ç¿¬È÷ ÇÑ±Û Ãâ·Â¿¡ °üÇÑ ¾ê±â¸¦ Çغ¸µµ·Ï ÇÏÁÒ. ÆùÆ® °ÀǸ¦ ¸¶Ä¡¸é ÀÌÁ¦ X À©µµ¿ì´Ù¿î ÇÁ·Î±×·¥À» © ¼ö ÀÖ´Â "À̺¥Æ®"¸¦ ´Ù·ê ¼ö ÀÖ°Ô µÇ°Ú±º¿ä. Xlib µµ ¾ó¸¶ ³²Áö ¾Ê¾Ò½À´Ï´Ù. Èû³»¼¼¿ä. :)