WINGs: Better presentation for example code in the tutorial
[whome.git] / WINGs_tutorial / SeventhWindow.c
blobd315c6ca7713ec15a3953b1f3277fc1cdeb85079
1 #include <WINGs/WINGs.h>
2 #include <WINGs/WINGsP.h>
4 #define HOFF 40
5 #define VOFF 160
6 #define WINWIDTH 180
7 #define WINHEIGHT 300
9 Display *display;
10 WMScreen *screen;
11 WMPixmap* pixmap;
13 struct _pict {
14 Drawable dwin;
15 XSegment segments[40];
16 int seglen;
17 } pic;
19 GC gc, g3;
21 void closeAction(WMWidget *self,void *data)
23 WMDestroyWidget(self);
24 exit(0);
27 void drawProcedure(XEvent *event, void *data)
29 struct _pict *p = (struct _pict *) data;
31 WMDrawPixmap(pixmap, p->dwin, HOFF, 30);
32 XDrawRectangle(display, p->dwin, g3, HOFF, VOFF, 100, 100);
33 XFillRectangle(screen->display, p->dwin, WMColorGC(screen->white), HOFF, VOFF, 100, 100);
34 XDrawSegments(display, p->dwin, WMColorGC(screen->black), p->segments, p->seglen);
38 int main(int argc, char **argv)
40 int i, j;
41 WMColor *color;
42 WMWindow *win;
43 RImage *image;
44 struct _pict pict;
45 Drawable de;
47 RColor one = { 247, 251, 107, 0xFF },
48 two = { 0xAF, 0x0F, 0xFF, 0x33 };
50 WMInitializeApplication("DrawWin", &argc, argv);
51 display = XOpenDisplay("");
52 screen = WMCreateScreen(display, DefaultScreen(display));
53 win = WMCreateWindow(screen, "");
54 WMResizeWidget(win, WINWIDTH, WINHEIGHT);
55 WMSetWindowCloseAction(win, closeAction, NULL);
56 WMSetWindowTitle(win, "Graphics");
57 color = WMCreateRGBColor(screen, 124<<9, 206<<8, 162<<8, False);
58 WMSetWidgetBackgroundColor((WMWidget *)win, color);
59 /* end setup main window */
61 image = RCreateImage(100, 100, 0.5);
62 RFillImage(image, &two);
63 RDrawLine(image, 50, 10, 90, 90, &one);
64 RDrawLine(image, 10, 90, 50, 10, &one);
65 RDrawLine(image, 10, 90, 90, 90, &one);
67 g3 = WMColorGC(screen->gray);
68 XSetLineAttributes(display, g3, 3, LineSolid, CapButt, JoinMiter);
70 pict.segments[1].x1 = pict.segments[0].x1 = HOFF;
71 pict.segments[0].x2 = HOFF;
72 pict.segments[0].y1 = VOFF;
73 pict.segments[1].y2 = pict.segments[0].y2 = VOFF;
74 pict.segments[1].x2 = HOFF + 10;
75 pict.segments[1].y1 = VOFF + 10;
76 pict.seglen = 2;
77 for (i = 9; i > 0; i--) {
78 j = 2 * (10 - i);
79 pict.segments[j+1].x1 = pict.segments[j].x1 = HOFF;
80 pict.segments[j+1].y2 = pict.segments[j].y2 = VOFF;
81 pict.segments[j ].x2 = i + pict.segments[j-1].x2;
82 pict.segments[j ].y1 = i + pict.segments[j-1].y1;
83 pict.segments[j+1].x2 = i + pict.segments[j ].x2;
84 pict.segments[j+1].y1 = i + pict.segments[j ].y1;
85 pict.seglen += 2;
88 WMRealizeWidget(win);
90 pict.dwin = W_VIEW_DRAWABLE(WMWidgetView(win));
91 pixmap = WMCreatePixmapFromRImage(screen, image, 1);
93 WMCreateEventHandler(WMWidgetView(win), ExposureMask, drawProcedure, &pict);
95 WMMapWidget(win);
96 WMScreenMainLoop(screen);