| 1 | <!doctype html public "-//w3c//dtd html 4.0 transitional//en"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-Type" content="text/html; charset=euc-jp"> |
| 5 | <meta name="GENERATOR" content="emacs"> |
| 6 | <meta name="Author" content="kacchan"> |
| 7 | <title>It makes for the time being</title> |
| 8 | </head> |
| 9 | <body text="#000000" bgcolor="#f0f0dc" link="#3366FF" vlink="#3366FF" alink="#FF0000"> |
| 10 | |
| 11 | <a href="./outline.html">Prev</a> |
| 12 | <a href="./KXL.html">Top</a> |
| 13 | <a href="./vkxleventmask.html">Next</a> |
| 14 | <hr> |
| 15 | |
| 16 | <font size=+2>It makes for the time being</font><br><br> |
| 17 | |
| 18 | <pre> |
| 19 | // sample.c |
| 20 | #include < KXL.h> |
| 21 | |
| 22 | int main(void) |
| 23 | { |
| 24 | Bool flag = False ; |
| 25 | |
| 26 | // Create a window by 100x100. |
| 27 | // event receives only the bottom of a re-drawing event and key presss. |
| 28 | // If return key is pushed, it will end. |
| 29 | KXL_CreateWindow(100, 100, "sample" |
| 30 | KXL_EVENT_EXPOSURE_MASK | |
| 31 | KXL_EVENT_KEY_PRESS_MASK); |
| 32 | |
| 33 | while(flag != True ){ |
| 34 | // event loop |
| 35 | while(KXL_CheckEvents()) { |
| 36 | // which acquires a event |
| 37 | switch(KXL_GetEvents()) { |
| 38 | case KXL_EVENT_EXPOSE: // event of re-drawing |
| 39 | // A frame is cleared |
| 40 | KXL_ClearFrameImm(0, 0, 100, 100); |
| 41 | // "sample" is drawn |
| 42 | KXL_PutText(30, 50, "sample"); |
| 43 | / A frame is made to reflect in a window |
| 44 | KXL_UpDateImm(0, 0, 100, 100); |
| 45 | break; |
| 46 | case KXL_EVENT_KEY_PRESS: // event of key press |
| 47 | // If a return key was pushed, it will end |
| 48 | if (KXL_GetKey() == KXL_KEY_Return) |
| 49 | flag = True; |
| 50 | break ; |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | // A window is closed |
| 55 | KXL_DeleteWindow(); |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | gcc sample.c -o sample -L/usr/X11R6/lib -lX11 -lKXL |
| 60 | ./sample |
| 61 | </pre> |
| 62 | <hr> |
| 63 | First of all, a window is created. |
| 64 | <pre> |
| 65 | KXL_CreateWindow(100, 100, "sample" |
| 66 | KXL_EVENT_EXPOSURE_MASK | |
| 67 | KXL_EVENT_KEY_PRESS); |
| 68 | </pre> |
| 69 | It is a setup that this is window of the size of width 100 and height |
| 70 | 100, display it on a title bar as "sample", and it receives re-drawing |
| 71 | and key press as an event. At this time, pixmap (referred to as |
| 72 | frame below) of the same size is created. Once it does not draw |
| 73 | directly to window fundamentally but draws on a frame, a frame is made |
| 74 | to reflect in window. |
| 75 | <br><br> |
| 76 | |
| 77 | Next, an event is received. |
| 78 | <pre> |
| 79 | while(KXL_CheckEvents()){ |
| 80 | switch(KXL_GetEvents()){ |
| 81 | case KXL_EVENT_EXPOSE: // event of re-drawing |
| 82 | : |
| 83 | case KXL_EVENT_KEY_PRESS: // event of key press |
| 84 | : |
| 85 | } |
| 86 | } |
| 87 | </pre> |
| 88 | It is confirmed whether the event occurred in KXL_CheckEvents(). If |
| 89 | anything does not have an event, it will escape from while. If an |
| 90 | event occurs, it will investigate which event it is by |
| 91 | KXL_GetEvents(). |
| 92 | <br><br> |
| 93 | |
| 94 | Event of Re-drawing(KXL_EVENT_EXPOSE) If it generates, a thing required |
| 95 | for a frame will be drawn. The whole frame is cleared first. |
| 96 | <pre> |
| 97 | KXL_ClearFrameImm(0, 0, 100, 100); |
| 98 | </pre> |
| 99 | A frame is cleared here (the left 0, top 0, width 100, height 100). |
| 100 | <br><br> |
| 101 | |
| 102 | A character sequence will be drawn if a frame is cleared. |
| 103 | <pre> |
| 104 | KXL_PutText(30,50, "sample"); |
| 105 | </pre> |
| 106 | The character which this calls to the left as 30 from the upper left |
| 107 | of a frame, and calls "sample" below in the position of 50 is |
| 108 | drawn. A default font set |
| 109 | "-adobe-courier-bold-r-normal--14-*-*-*-*-*-iso8859-1 " Coming out, |
| 110 | the color has become white. |
| 111 | <br><br> |
| 112 | |
| 113 | If drawing to a frame finishes, a frame is made to reflect in a |
| 114 | window. |
| 115 | <pre> |
| 116 | KXL_UpDateImm(0, 0, 100, 100); |
| 117 | </pre> |
| 118 | A frame (the left 0, top 0, width 100, height 100) is transmitted to a window here. |
| 119 | <br><br> |
| 120 | |
| 121 | Event of key press(KXL_EVENT_KEY_PRESS) If it generates, it will |
| 122 | judge which key was pushed. |
| 123 | <pre> |
| 124 | if (KXL_GetKey() == KXL_KEY_Return) |
| 125 | flag = True; |
| 126 | </pre> |
| 127 | KXL_GetKey() The key come out of and pushed is acquired and it is a |
| 128 | return key. KXL_KEY_Return True will be set to flag if it becomes. It |
| 129 | escapes from a loop now. |
| 130 | <br><br> |
| 131 | |
| 132 | Finally a window is closed. |
| 133 | <pre> |
| 134 | KXL_DeleteWindow(); |
| 135 | </pre> |
| 136 | |
| 137 | |
| 138 | |
| 139 | </body> |
| 140 | </html> |