「window.dkh」のソース

  1: ////////////////////////////////////////////////////////////
  2: // Key Code
  3: ////////////////////////////////////////////////////////////
  4: enum KeyCode {
  5:     LBUTTON,
  6:     RBUTTON,
  7:     CANCEL,
  8:     MBUTTON,
  9:     BACK,
 10:     TAB,
 11:     CLEAR,
 12:     RETURN,
 13:     SHIFT,
 14:     CONTROL,
 15:     MENU,
 16:     PAUSE,
 17:     CAPITAL,
 18:     KANA,
 19:     HANGEUL,
 20:     HANGUL,
 21:     JUNJA,
 22:     FINAL,
 23:     HANJA,
 24:     KANJI,
 25:     ESCAPE,
 26:     CONVERT,
 27:     NONCONVERT,
 28:     ACCEPT,
 29:     MODECHANGE,
 30:     SPACE,
 31:     PRIOR,
 32:     NEXT,
 33:     END,
 34:     HOME,
 35:     LEFT,
 36:     UP,
 37:     RIGHT,
 38:     DOWN,
 39:     SELECT,
 40:     PRINT,
 41:     EXECUTE,
 42:     SNAPSHOT,
 43:     INSERT,
 44:     DELETE,
 45:     HELP,
 46:     D0,
 47:     D1,
 48:     D2,
 49:     D3,
 50:     D4,
 51:     D5,
 52:     D6,
 53:     D7,
 54:     D8,
 55:     D9,
 56:     A,
 57:     B,
 58:     C,
 59:     D,
 60:     E,
 61:     F,
 62:     G,
 63:     H,
 64:     I,
 65:     J,
 66:     K,
 67:     L,
 68:     M,
 69:     N,
 70:     O,
 71:     P,
 72:     Q,
 73:     R,
 74:     S,
 75:     T,
 76:     U,
 77:     V,
 78:     W,
 79:     X,
 80:     Y,
 81:     Z,
 82:     LWIN,
 83:     RWIN,
 84:     APPS,
 85:     SLEEP,
 86:     NUMPAD0,
 87:     NUMPAD1,
 88:     NUMPAD2,
 89:     NUMPAD3,
 90:     NUMPAD4,
 91:     NUMPAD5,
 92:     NUMPAD6,
 93:     NUMPAD7,
 94:     NUMPAD8,
 95:     NUMPAD9,
 96:     MULTIPLY,
 97:     ADD,
 98:     SEPARATOR,
 99:     SUBTRACT,
100:     DECIMAL,
101:     DIVIDE,
102:     F1,
103:     F2,
104:     F3,
105:     F4,
106:     F5,
107:     F6,
108:     F7,
109:     F8,
110:     F9,
111:     F10,
112:     F11,
113:     F12,
114:     F13,
115:     F14,
116:     F15,
117:     F16,
118:     F17,
119:     F18,
120:     F19,
121:     F20,
122:     F21,
123:     F22,
124:     F23,
125:     F24,
126:     NUMLOCK,
127:     SCROLL,
128:     LSHIFT,
129:     RSHIFT,
130:     LCONTROL,
131:     RCONTROL,
132:     LMENU,
133:     RMENU,
134:     OEM_1,
135:     OEM_2,
136:     OEM_3,
137:     OEM_4,
138:     OEM_5,
139:     OEM_6,
140:     OEM_7,
141:     OEM_8,
142:     PROCESSKEY,
143:     ATTN,
144:     CRSEL,
145:     EXSEL,
146:     EREOF,
147:     PLAY,
148:     ZOOM,
149:     NONAME,
150:     PA1,
151:     OEM_CLEAR,
152: }
153: 
154: ////////////////////////////////////////////////////////////
155: // Pen class
156: ////////////////////////////////////////////////////////////
157: native_pointer __pen_create(int red, int green, int blue, int width,
158: 			    PenStyle style);
159: void __pen_dispose(native_pointer pen);
160: 
161: enum PenStyle {
162:     SOLID,
163:     DASH,
164:     DOT,
165:     DASH_DOT,
166:     DASH_DOT_DOT,
167: }
168: 
169: public class Pen {
170:     native_pointer native_pen;
171:     public constructor rgb(int red, int green, int blue) {
172: 	this.native_pen
173: 	    = __pen_create(red, green, blue, 0, PenStyle.SOLID);
174:     }
175:     public constructor width(int red, int green, int blue, int width) {
176: 	this.native_pen
177: 	    = __pen_create(red, green, blue, width, PenStyle.SOLID);
178:     }
179:     public constructor style(int red, int green, int blue, PenStyle style) {
180: 	this.native_pen
181: 	    = __pen_create(red, green, blue, 0, style);
182:     }
183:     public void dispose() {
184: 	__pen_dispose(this.native_pen);
185:     }
186: }
187: 
188: ////////////////////////////////////////////////////////////
189: // Brush class
190: ////////////////////////////////////////////////////////////
191: void __brush_dispose(native_pointer brush);
192: 
193: public class Brush {
194:     native_pointer native_brush;
195:     public void dispose() {
196: 	__brush_dispose(this.native_brush);
197:     }
198: }
199: 
200: Brush create_solid_brush(int r, int g, int b);
201: 
202: ////////////////////////////////////////////////////////////
203: // Color
204: ////////////////////////////////////////////////////////////
205: public class Color {
206:     int red;
207:     int green;
208:     int blue;
209:     public constructor initialize(int red, int green, int blue) {
210: 	this.red = red;
211: 	this.green = green;
212: 	this.blue = blue;
213:     }
214: }
215: 
216: ////////////////////////////////////////////////////////////
217: // Font class
218: ////////////////////////////////////////////////////////////
219: void __font_dispose(native_pointer font);
220: 
221: public class Font {
222:     native_pointer native_font;
223:     public void dispose() {
224: 	__font_dispose(this.native_font);
225:     }
226: }
227: 
228: public class FontAttribute {
229:     public string font_name;
230:     public int width;
231:     public int orientation;
232:     public boolean bold;
233:     public boolean italic;
234:     public boolean underline;
235:     public boolean strike_out;
236: 
237:     public constructor initialize() {
238: 	this.font_name = null;
239: 	this.width = 0;
240: 	this.orientation = 0;
241: 	this.bold = false;
242: 	this.italic = false;
243: 	this.underline = false;
244: 	this.strike_out = false;
245:     }
246: }
247: 
248: Font create_font(int height, FontAttribute attr);
249: 
250: ////////////////////////////////////////////////////////////
251: // Bitmap class
252: ////////////////////////////////////////////////////////////
253: void __bitmap_dispose(native_pointer brush);
254: 
255: public class Bitmap {
256:     native_pointer native_bitmap;
257:     public void dispose() {
258: 	__brush_dispose(this.native_bitmap);
259:     }
260: }
261: 
262: Bitmap load_bitmap(string file_name);
263: 
264: ////////////////////////////////////////////////////////////
265: // Graphics class
266: ////////////////////////////////////////////////////////////
267: enum DrawMode {
268:     COPY,
269:     XOR
270: }
271: 
272: public class Point {
273:     public int x;
274:     public int y;
275:     public constructor initialize(int x, int y) {
276: 	this.x = x;
277: 	this.y = y;
278:     }
279: }
280: 
281: void __graphics_draw_line(native_pointer g, native_pointer pen,
282: 			  int x1, int y1, int x2, int y2);
283: void __graphics_draw_polyline(native_pointer g, native_pointer pen,
284: 			      Point[] points);
285: void __graphics_draw_rectangle(native_pointer g, native_pointer pen,
286: 			       int x, int y, int width, int height);
287: void __graphics_draw_ellipse(native_pointer g, native_pointer pen,
288: 			     int x, int y, int width, int height);
289: void __graphics_draw_arc(native_pointer g, native_pointer pen,
290: 			 int x, int y, int width, int height,
291: 			 double start_angle, double sweep_angle);
292: void __graphics_draw_string(native_pointer g,
293: 			    native_pointer font, Color color,
294: 			    int x, int y, string str);
295: void __graphics_draw_image(native_pointer g,
296: 			   int x, int y, native_pointer bitmap);
297: void __graphics_fill_rectangle(native_pointer g, native_pointer brush,
298: 			       int x, int y, int width, int height);
299: void __graphics_fill_ellipse(native_pointer g, native_pointer brush,
300: 			     int x, int y, int width, int height);
301: void __graphics_fill_pie(native_pointer g, native_pointer brush,
302: 			 int x, int y, int width, int height,
303: 			 double start_angle, double sweep_angle);
304: void __graphics_set_background_color(native_pointer g, Color color);
305: void __graphics_set_draw_mode(native_pointer g, DrawMode mode);
306: 
307: public interface Graphics {
308:     public void draw_line(Pen pen, int x1, int y1, int x2, int y2);
309:     public void draw_polyline(Pen pen, Point[] points);
310:     public void draw_rectangle(Pen pen, int x, int y, int width, int height);
311:     public void draw_ellipse(Pen pen, int x, int y, int width, int height);
312:     public void draw_arc(Pen pen, int x, int y, int width, int height,
313: 			 double start_angle, double end_angle);
314:     public void draw_string(Font font, Color color, int x, int y, string str);
315:     public void draw_image(int x, int y, Bitmap bitmap);
316:     public void fill_rectangle(Brush brush, int x, int y,
317: 			       int width, int height);
318:     public void fill_ellipse(Brush brush, int x, int y, int width, int height);
319:     public void fill_pie(Brush brush, int x, int y, int width, int height,
320: 			 double start_angle, double end_angle);
321:     public void set_background_color(Color color);
322:     public void set_draw_mode(DrawMode mode);
323: }
324: 
325: public class GraphicsImpl : Graphics {
326:     native_pointer native_graphics_p;
327:     public override void draw_line(Pen pen, int x1, int y1, int x2, int y2) {
328: 	native_pointer native_pen;
329: 	if (pen == null) {
330: 	    native_pen = null;
331: 	} else {
332: 	    native_pen = pen.native_pen;
333: 	}
334: 	__graphics_draw_line(this.native_graphics_p,
335: 			     native_pen, x1, y1, x2, y2);
336:     }
337: 
338:     public override void draw_polyline(Pen pen, Point[] points) {
339: 	native_pointer native_pen;
340: 	if (pen == null) {
341: 	    native_pen = null;
342: 	} else {
343: 	    native_pen = pen.native_pen;
344: 	}
345: 	__graphics_draw_polyline(this.native_graphics_p,
346: 				 native_pen, points);
347:     }
348: 
349:     public override void draw_rectangle(Pen pen, int x1, int y1,
350: 					int x2, int y2) {
351: 	native_pointer native_pen;
352: 	if (pen == null) {
353: 	    native_pen = null;
354: 	} else {
355: 	    native_pen = pen.native_pen;
356: 	}
357: 	__graphics_draw_rectangle(this.native_graphics_p,
358: 				  native_pen, x1, y1, x2, y2);
359:     }
360: 
361:     public override void draw_ellipse(Pen pen, int x, int y,
362: 				      int width, int height) {
363: 	native_pointer native_pen;
364: 	if (pen == null) {
365: 	    native_pen = null;
366: 	} else {
367: 	    native_pen = pen.native_pen;
368: 	}
369: 	__graphics_draw_ellipse(this.native_graphics_p,
370: 				native_pen, x, y, width, height);
371:     }
372: 
373:     public override void draw_arc(Pen pen, int x, int y, int width, int height,
374: 				  double start_angle, double end_angle) {
375: 	native_pointer native_pen;
376: 	if (pen == null) {
377: 	    native_pen = null;
378: 	} else {
379: 	    native_pen = pen.native_pen;
380: 	}
381: 	__graphics_draw_arc(this.native_graphics_p,
382: 			    native_pen, x, y, width, height,
383: 			    start_angle, end_angle);
384:     }
385: 
386:     public override void draw_string(Font font, Color color,
387: 				     int x, int y, string str) {
388: 	native_pointer native_font;
389: 	if (font == null) {
390: 	    native_font = null;
391: 	} else {
392: 	    native_font = font.native_font;
393: 	}
394: 	__graphics_draw_string(this.native_graphics_p,
395: 			       native_font, color, x, y, str);
396:     }
397: 
398:     public override void draw_image(int x, int y, Bitmap bitmap) {
399: 	__graphics_draw_image(this.native_graphics_p, x, y,
400: 			      bitmap.native_bitmap);
401:     }
402: 
403:     public override void fill_rectangle(Brush brush, int x, int y,
404: 					int width, int height) {
405: 	__graphics_fill_rectangle(this.native_graphics_p,
406: 				  brush.native_brush, x, y, width, height);
407:     }
408: 
409:     public override void fill_ellipse(Brush brush, int x, int y,
410: 				      int width, int height) {
411: 	__graphics_fill_ellipse(this.native_graphics_p,
412: 				brush.native_brush, x, y, width, height);
413:     }
414: 
415:     public override void fill_pie(Brush brush, int x, int y,
416: 				  int width, int height,
417: 				  double start_angle, double end_angle) {
418: 	__graphics_fill_pie(this.native_graphics_p,
419: 			    brush.native_brush, x, y, width, height,
420: 			    start_angle, end_angle);
421:     }
422: 
423:     public override void set_background_color(Color color) {
424: 	__graphics_set_background_color(this.native_graphics_p,
425: 					color);
426:     }
427: 
428:     public override void set_draw_mode(DrawMode mode) {
429: 	__graphics_set_draw_mode(this.native_graphics_p, mode);
430:     }
431: }
432: 
433: ////////////////////////////////////////////////////////////
434: // Window class
435: ////////////////////////////////////////////////////////////
436: enum MouseButton {
437:     LEFT,
438:     MIDDLE,
439:     RIGHT,
440: }
441: 
442: delegate void WindowDestroyProc();
443: delegate void WindowPaintProc(Graphics g);
444: delegate void KeyDownProc(Window window, KeyCode key_code, int repeat_count);
445: delegate void KeyUpProc(Window window, KeyCode key_code);
446: delegate void MouseButtonDownProc(Window window, int x, int y,
447: 				  MouseButton button);
448: delegate void MouseButtonUpProc(Window window, int x, int y,
449: 				MouseButton button);
450: delegate void MouseMoveProc(Window window, int x, int y);
451: delegate void MouseDragProc(Window window, int x, int y,
452: 			    MouseButton button);
453: 
454: void __window_show(native_pointer window);
455: void __window_set_paint_proc(native_pointer window, WindowPaintProc proc);
456: void __window_set_destroy_proc(native_pointer window, WindowDestroyProc proc);
457: void __window_set_key_down_proc(native_pointer window, KeyDownProc proc);
458: void __window_set_key_up_proc(native_pointer window, KeyUpProc proc);
459: void __window_set_mouse_button_down_proc(native_pointer window,
460: 					 MouseButtonDownProc proc);
461: void __window_set_mouse_button_up_proc(native_pointer window,
462: 				       MouseButtonUpProc proc);
463: void __window_set_mouse_move_proc(native_pointer window,
464: 				  MouseMoveProc proc);
465: void __window_set_mouse_drag_proc(native_pointer window,
466: 				  MouseDragProc proc);
467: Graphics __window_get_graphics(native_pointer window);
468: void post_quit_message(int status);
469: int __window_get_width(native_pointer window);
470: int __window_get_height(native_pointer window);
471: 
472: public class Window {
473:     native_pointer native_window_p;
474: 
475:     public void show() {
476: 	__window_show(this.native_window_p);
477:     }
478:     public void set_destroy_proc(WindowDestroyProc proc) {
479: 	__window_set_destroy_proc(this.native_window_p, proc);
480:     }
481:     public void set_paint_proc(WindowPaintProc proc) {
482: 	__window_set_paint_proc(this.native_window_p, proc);
483:     }
484:     public void set_key_down_proc(KeyDownProc proc) {
485: 	__window_set_key_down_proc(this.native_window_p, proc);
486:     }
487:     public void set_key_up_proc(KeyUpProc proc) {
488: 	__window_set_key_up_proc(this.native_window_p, proc);
489:     }
490:     public void set_mouse_button_down_proc(MouseButtonDownProc proc) {
491: 	__window_set_mouse_button_down_proc(this.native_window_p, proc);
492:     }
493:     public void set_mouse_button_up_proc(MouseButtonUpProc proc) {
494: 	__window_set_mouse_button_up_proc(this.native_window_p, proc);
495:     }
496:     public void set_mouse_move_proc(MouseMoveProc proc) {
497: 	__window_set_mouse_move_proc(this.native_window_p, proc);
498:     }
499:     public void set_mouse_drag_proc(MouseDragProc proc) {
500: 	__window_set_mouse_drag_proc(this.native_window_p, proc);
501:     }
502:     public Graphics get_graphics() {
503: 	return __window_get_graphics(this.native_window_p);
504:     }
505:     public int get_width() {
506: 	return __window_get_width(this.native_window_p);
507:     }
508:     public int get_height() {
509: 	return __window_get_height(this.native_window_p);
510:     }
511:     constructor initialize(native_pointer native_window_p) {
512: 	this.native_window_p = native_window_p;
513:     }
514: }
515: 
516: void window_destroy_and_exit() {
517:     post_quit_message(0);
518:     exit(0);
519: }
520: 
521: public class WindowAttribute {
522:     private boolean x_use_default;
523:     private boolean y_use_default;
524:     private int x;
525:     private int y;
526:     public Brush background;
527: 
528:     public void set_x(int x) {
529: 	this.x = x;
530: 	this.x_use_default = false;
531:     }
532:     public void set_y(int y) {
533: 	this.y = y;
534: 	this.y_use_default = false;
535:     }
536:     
537:     public constructor initialize() {
538: 	this.x_use_default = true;
539: 	this.y_use_default = true;
540: 	this.background = null;
541:     }
542: }
543: 
544: WindowAttribute create_window_attribute()
545: {
546:     return new WindowAttribute();
547: }
548: 
549: Window create_window(string title, int width, int height,
550: 		     WindowAttribute attribute);
551: 
552: ////////////////////////////////////////////////////////////
553: // message box
554: ////////////////////////////////////////////////////////////
555: int __message_box(native_pointer owner, string title,
556: 		  string caption, int flags);
557: int message_box(Window owner, string title, string caption, int flags) {
558:     native_pointer owner_np;
559:     if (owner == null) {
560: 	owner_np = null;
561:     } else {
562: 	owner_np = owner.native_window_p;
563:     }
564:     return __message_box(owner_np, title, caption, flags);
565: }
566: 
567: ////////////////////////////////////////////////////////////
568: // message loop
569: ////////////////////////////////////////////////////////////
570: void message_loop();
571: void __timed_message_loop(native_pointer native_window, int millisecond);
572: void timed_message_loop(Window window, int millisecond) {
573:     __timed_message_loop(window.native_window_p, millisecond);
574: }
575: 
576: void __message_loop_exit(native_pointer native_loop);
577: 
578: public class MessageLoop {
579:     native_pointer native_loop;
580:     public void exit() {
581: 	__message_loop_exit(this.native_loop);
582:     }
583: }
584: 
585: ////////////////////////////////////////////////////////////
586: // Keyboard
587: ////////////////////////////////////////////////////////////
588: boolean is_key_pressed(KeyCode code);
589: 
590: ////////////////////////////////////////////////////////////
591: // Exceptions
592: ////////////////////////////////////////////////////////////
593: public class WindowInternalException : RuntimeException {
594: }
595: public class WindowArgumentException : RuntimeException {
596: }

戻る