{"id":2281,"date":"2021-10-21T19:07:18","date_gmt":"2021-10-21T10:07:18","guid":{"rendered":"https:\/\/sirius10.net\/blog\/wordpress\/?p=2281"},"modified":"2021-10-21T19:11:08","modified_gmt":"2021-10-21T10:11:08","slug":"post-2281","status":"publish","type":"post","link":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/2021\/10\/21\/2281\/","title":{"rendered":"SDL2 \u3067 GUI \u90e8\u54c1\u3092\u4f5c\u308b(\u30dc\u30bf\u30f3\u3001\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9)"},"content":{"rendered":"\n<p>\u3000GUI \u90e8\u54c1\u306e\u30dc\u30bf\u30f3\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002\u30de\u30a6\u30b9\u64cd\u4f5c\u3067\u30dc\u30bf\u30f3\u3082\u6d45\u308c\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002\u3053\u308c\u3092\u72ec\u7acb\u3057\u305f\u30bd\u30fc\u30b9\u306b\u307e\u3068\u3081\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u307e\u305a\u3001GUI \u90e8\u54c1\u3092\u4f5c\u308b\u305f\u3081\u306e\u30c7\u30fc\u30bf\u3092\u6c7a\u3081\u307e\u3059\u3002\u5fc5\u8981\u306a\u30c7\u30fc\u30bf\u306f\u3001GUI \u90e8\u54c1\u306e\u7a2e\u985e\u3001\u90e8\u54c1\u306e\u5de6\u4e0a\u306e x, y \u5ea7\u6a19\u3001\u5e45\u3001\u9ad8\u3055\u3001\u30dc\u30bf\u30f3\u306b\u5272\u308a\u5f53\u3066\u308b\u5024\u3001\u30c6\u30ad\u30b9\u30c8\u3092\u8868\u793a\u3059\u308b\u4f4d\u7f6e\u3001\u8868\u793a\u3059\u308b\u30c6\u30ad\u30b9\u30c8\u3001\u30de\u30a6\u30b9\u306e\u72b6\u614b\u3001\u30af\u30ea\u30c3\u30af\u3055\u308c\u305f\u3068\u304d\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u3001\u30dc\u30bf\u30f3\u306e\u8272\u3001\u6587\u5b57\u306e\u30d5\u30a9\u30f3\u30c8\u3067\u3059\u3002\u3053\u308c\u3089\u3092\u69cb\u9020\u4f53\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30dc\u30bf\u30f3\u306e\u7a2e\u985e<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted file\">typedef enum _parts_type {\n    LABEL,\n    BUTTON,\n    CHECKBOX,\n} PARTS_TYPE;<\/pre>\n\n\n\n<p>\u3000\u30e9\u30d9\u30eb\u3001\u30dc\u30bf\u30f3\u3001\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u3092\u4f5c\u308a\u307e\u3059\u3002\u5f8c\u3067\u90e8\u54c1\u306e\u7a2e\u985e\u306f\u5897\u3084\u305d\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6587\u5b57\u4f4d\u7f6e<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted file\">typedef enum _text_align {\n    TEXT_LEFT,\n    TEXT_CENTER,\n    TEXT_RIGHT\n} TEXT_ALIGN;<\/pre>\n\n\n\n<p>\u3000\u6587\u5b57\u4f4d\u7f6e\u306f\u3001\u5de6\u63c3\u3048\u3001\u4e2d\u592e\u63c3\u3048\u3001\u53f3\u63c3\u3048\u304c\u51fa\u6765\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">GUI \u90e8\u54c1\u306e\u30c7\u30fc\u30bf\u3092\u69cb\u9020\u4f53\u306b\u307e\u3068\u3081\u308b<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted file\">typedef struct _parts {\n    Uint32 id;         \/\/ \u30c1\u30a7\u30c3\u30af\u7528\n    int x;             \/\/ \u90e8\u54c1\u306e\u5de6\u4e0a\u306e x \u5ea7\u6a19\n    int y;             \/\/ \u90e8\u54c1\u306e\u5de6\u4e0a\u306e y \u5ea7\u6a19 \n    int w;             \/\/ \u90e8\u54c1\u306e\u5e45\n    int h;             \/\/ \u90e8\u54c1\u306e\u9ad8\u3055\n    void *value;       \/\/ \u90e8\u54c1\u56fa\u6709\u306e\u5024\n    PARTS_TYPE type;   \/\/ \u90e8\u54c1\u306e\u7a2e\u985e(LABEL, BUTTON, CHECKBOX)\n    int mouse;         \/\/ \u30de\u30a6\u30b9\u306e\u72b6\u614b\uff08\u521d\u671f\u5024\u306f\u5fc5\u305a 0 \u306b\u3059\u308b\uff09\n    TEXT_ALIGN align;  \/\/ \u30c6\u30ad\u30b9\u30c8\u306e\u8868\u793a\u4f4d\u7f6e\n    char *string;      \/\/ \u90e8\u54c1\u306b\u8868\u793a\u3059\u308b\u6587\u5b57\u5217\uff08\u7121\u3051\u308c\u3070 NULL\uff09\n    TTF_Font *font;    \/\/ \u30c6\u30ad\u30b9\u30c8\u63cf\u753b\u306b\u4f7f\u7528\u3059\u308b\u30d5\u30a9\u30f3\u30c8\n    SDL_Color *color;  \/\/ \u90e8\u54c1\u306e\u57fa\u672c\u8272\n    \/\/ \u30de\u30a6\u30b9\u30af\u30ea\u30c3\u30af\u3055\u308c\u305f\u3068\u304d\u306b\u547c\u3076\u95a2\u6570\n    void (*execute)(void *);\n    \/\/ \u90e8\u54c1\u306e\u8868\u793a\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3059\u308b\u95a2\u6570\uff08\u672a\u4f7f\u7528\uff09\n    void (*draw)(SDL_Renderer *renderer, Uint32);\n    struct _parts *next; \/\/ \u6b21\u306e\u30c7\u30fc\u30bf\u3078\u306e\u30dd\u30a4\u30f3\u30bf\n} PARTS;<\/pre>\n\n\n\n<p>\u3000GUI \u90e8\u54c1\u306e\u30c7\u30fc\u30bf\u306f\u30ea\u30b9\u30c8\u306b\u3059\u308b\u306e\u3067\u3001\u6700\u5f8c\u306b\u6b21\u306e\u30c7\u30fc\u30bf\u3078\u306e\u30dd\u30a4\u30f3\u30bf\u3092\u8ffd\u52a0\u3057\u3066\u3044\u307e\u3059\u3002\u3042\u3068\u306f\u3001\u30dc\u30bf\u30f3\u306e\u8868\u793a\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3067\u304d\u308b\u3088\u3046\u306b\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u7528\u306e\u95a2\u6570\u3082\u8ffd\u52a0\u3057\u307e\u3057\u305f\u3002\u3053\u308c\u306f\u666e\u901a\u306f\u4f7f\u308f\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u30dc\u30bf\u30f3\u306b\u753b\u50cf\u3092\u8868\u793a\u3059\u308b\u5834\u5408\u306b\u4f7f\u3048\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u69cb\u9020\u4f53\u306e\u30e1\u30f3\u30d0\u3078\u30a2\u30af\u30bb\u30b9\u3059\u308b\u30de\u30af\u30ed<\/h2>\n\n\n\n<p>\u3000\u69cb\u60f3\u4f53\u306e\u30e1\u30f3\u30d0\u3078\u76f4\u63a5\u30a2\u30af\u30bb\u30b9\u3059\u3059\u306e\u306f\u5371\u967a\u3060\u3068\u8a00\u308f\u308c\u307e\u3059\u3002\u95a2\u6570\u7d4c\u7531\u3067\u30a2\u30af\u30bb\u30b9\u3092\u63d0\u4f9b\u3057\u3001\u30e1\u30f3\u30d0\u81ea\u4f53\u306f\u5916\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u304b\u3089\u96a0\u853d\u3059\u3079\u304d\u3067\u3059\u3002\u3057\u304b\u3057\u3001\u95a2\u6570\u547c\u3073\u51fa\u3057\u306f\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u304c\u304b\u304b\u308b\u306e\u3067\u3001\u30de\u30af\u30ed\u3067\u4f5c\u3063\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted file\">\/* \u30bb\u30c3\u30bf\u30fc *\/\n#define parts_set_x(a, b) \\\n   ((((PARTS *)(a))-&gt;id == (Uint32)(a)) ? (((PARTS *)(a))-&gt;x = (b)):0)\n#define parts_set_y(a, b) \\\n   ((((PARTS *)(a))-&gt;id == (Uint32)(a)) ? (((PARTS *)(a))-&gt;y = (b)):0)\n#define parts_set_width(x, y) \\\n   ((((PARTS *)(x))-&gt;id == (Uint32)(x)) ? (((PARTS *)(x))-&gt;w = (y)):0)\n#define parts_set_height(x, y) \\\n   ((((PARTS *)(x))-&gt;id == (Uint32)(x)) ? (((PARTS *)(x))-&gt;h = (y)):0)\n#define parts_set_text(x, y) \\\n   ((((PARTS *)(x))-&gt;id == (Uint32)(x)) ? (((PARTS *)(x))-&gt;string = (y)):NULL)\n#define parts_set_callback(x, y) \\\n   ((((PARTS *)(x))-&gt;id == (Uint32)(x)) ? (((PARTS *)(x))-&gt;execute = (y)):NULL)\n#define parts_set_font(x, y) \\\n   ((((PARTS *)(x))-&gt;id == (Uint32)(x)) ? (((PARTS *)(x))-&gt;font = (y)):NULL)\n#define parts_set_color(x, y) \\\n   ((((PARTS *)(x))-&gt;id == (Uint32)(x)) ? (((PARTS *)(x))-&gt;color = (y)):NULL)\n#define parts_set_value(x, y) \\\n   ((((PARTS *)(x))-&gt;id == (Uint32)(x)) ? (((PARTS *)(x))-&gt;value = (y)):NULL)\n#define parts_set_draw(x, y) \\\n   ((((PARTS *)(x))-&gt;id == (Uint32)(x)) ? (((PARTS *)(x))-&gt;draw = (y)):NULL)\n#define parts_set_next(x, y) \\\n   ((((PARTS *)(x))-&gt;id == (Uint32)(x)) ? (((PARTS *)(x))-&gt;next = (y)):NULL)\n#define parts_set_mouse(x, y) \\\n   ((((PARTS *)(x))-&gt;id == (Uint32)(x)) ? (((PARTS *)(x))-&gt;mouse = (y)):0)\n#define parts_set_type(x, y) \\\n   ((((PARTS *)(x))-&gt;id == (Uint32)(x)) ? (((PARTS *)(x))-&gt;type = (y)):0)\n#define parts_set_align(x, y) \\\n   ((((PARTS *)(x))-&gt;id == (Uint32)(x)) ? (((PARTS *)(x))-&gt;align = (y)):0)\n\n\/* \u30b2\u30c3\u30bf\u30fc *\/\n#define parts_get_x(a) \\\n     (((PARTS *)(a))-&gt;id == (Uint32)(a) ? ((PARTS *)(a))-&gt;x:-1)\n#define parts_get_y(a) \\\n     (((PARTS *)(a))-&gt;id == (Uint32)(a) ? ((PARTS *)(a))-&gt;y:-1)\n#define parts_get_width(x) \\\n     (((PARTS *)(x))-&gt;id == (Uint32)(x) ? ((PARTS *)(x))-&gt;w:-1)\n#define parts_get_height(x) \\\n     (((PARTS *)(x))-&gt;id == (Uint32)(x) ? ((PARTS *)(x))-&gt;h:-1)\n#define parts_get_text(x) \\\n     (((PARTS *)(x))-&gt;id == (Uint32)(x) ? ((PARTS *)(x))-&gt;string:NULL)\n#define parts_get_callback(x) \\\n     (((PARTS *)(x))-&gt;id == (Uint32)(x) ? ((PARTS *)(x))-&gt;execute:NULL)\n#define parts_get_font(x) \\\n     (((PARTS *)(x))-&gt;id == (Uint32)(x) ? ((PARTS *)(x))-&gt;font:NULL)\n#define parts_get_color(x) \\\n     (((PARTS *)(x))-&gt;id == (Uint32)(x) ? ((PARTS *)(x))-&gt;color:NULL)\n#define parts_get_value(x) \\\n     (((PARTS *)(x))-&gt;id == (Uint32)(x) ? ((PARTS *)(x))-&gt;value:NULL)\n#define parts_get_draw(x) \\\n     (((PARTS *)(x))-&gt;id == (Uint32)(x) ? ((PARTS *)(x))-&gt;draw:NULL)\n#define parts_get_next(x) \\\n     (((PARTS *)(x))-&gt;id == (Uint32)(x) ? ((PARTS *)(x))-&gt;next:NULL)\n#define parts_get_mouse(x) \\\n     (((PARTS *)(x))-&gt;id == (Uint32)(x) ? ((PARTS *)(x))-&gt;mouse:-1)\n#define parts_get_type(x) \\\n     (((PARTS *)(x))-&gt;id == (Uint32)(x) ? ((PARTS *)(x))-&gt;type:-1)\n#define parts_get_align(x) \\\n     (((PARTS *)(x))-&gt;id == (Uint32)(x) ? ((PARTS *)(x))-&gt;align:-1)<\/pre>\n\n\n\n<p>\u3000\u5f15\u6570\u306b PARTS * \u3092\u60f3\u5b9a\u3057\u305f\u30de\u30af\u30ed\u3067\u3059\u3002\u30de\u30af\u30ed\u306f\u5b89\u5168\u306e\u305f\u3081\u306b\u62ec\u5f27\u3092\u591a\u7528\u3057\u307e\u3059\u304c\u305d\u306e\u305b\u3044\u3067\u308f\u304b\u308a\u306b\u304f\u304f\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30de\u30a6\u30b9\u30cf\u30f3\u30c9\u30e9<\/h2>\n\n\n\n<p>\u3000\u30de\u30a6\u30b9\u306e\u52d5\u4f5c\u306b\u5408\u308f\u305b\u3066\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u3092\u547c\u3093\u3060\u308a\u3001\u8868\u793a\u3092\u5909\u3048\u308b\u306e\u3067\u30de\u30a6\u30b9\u30cf\u30f3\u30c9\u30e9\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u30de\u30a6\u30b9\u30a4\u30d9\u30f3\u30c8\u306f\u3001SDL_MOUSEMOTION, SDL_MOUSEBUTTONUP, SDL_MOUSEBUTTONDOWN \u3067\u3059\u3002\u305d\u308c\u305e\u308c\u3001\u30de\u30a6\u30b9\u30a4\u30d9\u30f3\u30c8\u304c\u767a\u751f\u3057\u305f\u5ea7\u6a19\u3092\u53d7\u3051\u53d6\u308a\u3001\u3069\u306e\u90e8\u54c1\u4e0a\u3067\u767a\u751f\u3057\u305f\u30a4\u30d9\u30f3\u30c8\u304b\u5224\u65ad\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted file\">mouse_motion_parts(event.button.x, event.button.y);\nmouse_button_up_parts(event.button.x, event.button.y);\nmouse_button_down_parts(event.button.x, event.button.y);<\/pre>\n\n\n\n<p>\u3000\u4e0a\u306e\u95a2\u6570\u3092\u305d\u308c\u305e\u308c\u306e\u30a4\u30d9\u30f3\u30c8\u3067\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">GUI \u90e8\u54c1\u3092\u4f5c\u308b\u95a2\u6570<\/h2>\n\n\n\n<p>\u3000GUI \u90e8\u54c1\u3092\u767b\u9332\u3059\u308b\u95a2\u6570\u3067\u90e8\u54c1\u30c7\u30fc\u30bf\u3092\u767b\u9332\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted file\">Uint32 add_parts(SDL_Rect *, void *, PARTS_TYPE, char *, TTF_Font *, SDL_Color *);<\/pre>\n\n\n\n<p>\u3000\u6700\u521d\u306e\u5f15\u6570\u306f\u90e8\u54c1\u306e\u4f4d\u7f6e\u3068\u5e45\u3001\u9ad8\u3055\u3092\u8868\u3059 SDL_Rect \u306e\u30dd\u30a4\u30f3\u30bf\u3001\u6b21\u306e\u5f15\u6570\u306f\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u3078\u6e21\u3059\u5024\u3001\u90e8\u54c1\u306e\u30bf\u30a4\u30d7\u3001\u90e8\u54c1\u306b\u8868\u793a\u3059\u308b\u6587\u5b57\u5217\u3078\u306e\u30dd\u30a4\u30f3\u30bf\u3001\u4f7f\u7528\u3059\u308b\u30d5\u30a9\u30f3\u30c8\u3068\u3001\u90e8\u54c1\u306e\u8272\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u3084\u30c6\u30ad\u30b9\u30c8\u914d\u7f6e\u306a\u3069\u306f\u3001\u5fc5\u305a\u3057\u3082\u5fc5\u8981\u306a\u3044\u3082\u306e\u306a\u306e\u3067\u3001\u305d\u308c\u3089\u306f\u3001\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u4f5c\u6210\u3057\u305f\u5f8c\u3067\u3001\u623b\u308a\u5024\u3092\u5229\u7528\u3057\u3066\u30bb\u30c3\u30bf\u30fc\u3067\u8a2d\u5b9a\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u623b\u308a\u5024\u306f\u4f5c\u6210\u3057\u305f\u90e8\u54c1\u3092\u8868\u3059 32bit \u5024\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u307e\u305f\u3001\u6587\u5b57\u8272\u3084\u30a6\u30a3\u30f3\u30c9\u30a6\u30b5\u30a4\u30ba\u306f\u95a2\u6570\u3092\u7528\u610f\u3057\u3066\u8a2d\u5b9a\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">GUI \u90e8\u54c1\u63cf\u753b\u95a2\u6570<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted file\">void draw_parts(SDL_Renderer *);<\/pre>\n\n\n\n<p>\u3000\u63cf\u753b\u51e6\u7406\u4e2d\u306b\u4e0a\u306e\u95a2\u6570\u3092\u547c\u3073\u51fa\u305b\u3070\u3001GUI \u90e8\u54c1\u304c\u63cf\u753b\u3055\u308c\u307e\u3059\u3002\u3000\u3053\u308c\u3089\u306e\u95a2\u6570\u3068\u5fc5\u8981\u306a\u5185\u90e8\u95a2\u6570\u3092 SDL_gui.c \u306b\u307e\u3068\u3081\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f7f\u3063\u3066\u307f\u308b<\/h2>\n\n\n\n<p>\u3000\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30bd\u30fc\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted file\">#include &lt;stdio.h&gt;\n#include &lt;SDL.h&gt;\n#include &lt;SDL_ttf.h&gt;\n#include \"SDL_gui.h\"\n\n#define SCR_WIDTH  320\n#define SCR_HEIGHT 240\n\n\/* \u30d5\u30a9\u30f3\u30c8\u30d5\u30a1\u30a4\u30eb\uff08\u5b9f\u5728\u3059\u308b\u30d5\u30a9\u30f3\u30c8\u306b\u5909\u3048\u3066\u304f\u3060\u3055\u3044\uff09 *\/\nstatic char *font_path =\"\/usr\/share\/fonts\/truetype\/fonts-japanese-gothic.ttf\";\n\n\/* GUI \u90e8\u54c1\u306e\u8272\u306e\u5b9a\u7fa9 *\/\nstatic SDL_Color text_color = {0x1f, 0x1f, 0x1f, 0xff};\nstatic SDL_Color label_color = {0xaf, 0x80, 0x80, 0xff};\nstatic SDL_Color button_color = {0xaf, 0xaf, 0xaf, 0xff};\nstatic SDL_Color checkbox_color = {0xaf, 0xaf, 0x8f, 0xff};\n\n\/* \u30a6\u30a3\u30f3\u30c9\u30a6\u5185\u63cf\u753b *\/\nvoid draw(void *parm) {\n    SDL_Renderer *renderer;\n    SDL_Rect rect;\n\n    renderer = (SDL_Renderer *)parm;\n\n    SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);\n    SDL_SetRenderDrawColor(renderer, 0xaf, 0xaf, 0x8f, SDL_ALPHA_OPAQUE);\n    SDL_RenderClear(renderer);\n\n    \/* GUI \u90e8\u54c1\u306e\u63cf\u753b *\/\n    draw_parts(renderer);\n\n    SDL_RenderPresent(renderer);\n}\n\nUint32 callbackfunc(Uint32 interval, void *param)\n{\n    SDL_Event event;\n    SDL_UserEvent userevent;\n\n    \/* \u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u3067SDL_USEREVENT\u30a4\u30d9\u30f3\u30c8\u3092\u30ad\u30e5\u30fc\u306b\u5165\u308c\u308b\u3002\n    \u3053\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u306f\u4e00\u5b9a\u306e\u5468\u671f\u3067\u518d\u3073\u547c\u3070\u308c\u308b *\/\n\n    userevent.type = SDL_USEREVENT;\n    userevent.code = 0;\n    userevent.data1 = &amp;draw;\n    userevent.data2 = param;\n\n    event.type = SDL_USEREVENT;\n    event.user = userevent;\n\n    SDL_PushEvent(&amp;event);\n    return(interval);\n}\n\nint main(int argc, char* argv[]){\n    SDL_Window *window;\n    SDL_Renderer *renderer;\n    TTF_Font *font;\n    SDL_Event event;\n    SDL_TimerID my_timer_id;\n    SDL_Rect rect;\n    int quit_flg;\n\n    \/* \u521d\u671f\u5316 *\/\n    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) &lt; 0) {\n        fprintf(stderr, \"SDL_Init(): %s\\n\", SDL_GetError());\n        exit(1);\n    }\n    TTF_Init();\n\n    \/* \u30d5\u30a9\u30f3\u30c8\u53d6\u5f97 *\/\n    font = TTF_OpenFont(font_path, 18);\n    if( font == NULL ) {\n        printf(\"Can not open font(%s)\\n\", font_path);\n        exit(1);\n    }\n    \/* \u30a6\u30a3\u30f3\u30c9\u30a6\u4f5c\u6210 *\/\n    window = SDL_CreateWindow(\"GUI Test\", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCR_WIDTH, SCR_HEIGHT, SDL_WINDOW_OPENGL);\n    if( window == NULL ) {\n        printf(\"Can not create window\\n\");\n        exit(1);\n    }\n    renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);\n    if( renderer == NULL ) {\n        printf(\"Can not create renderer\\n\");\n        exit(1);\n    }\n    SDL_RenderSetLogicalSize(renderer, SCR_WIDTH, SCR_HEIGHT);\n\n    my_timer_id = SDL_AddTimer(100, callbackfunc, (void *)renderer);\n    quit_flg = 1;\n\n    \/* GUI \u90e8\u54c1\u8a2d\u5b9a *\/\n    parts_set_textcolor(text_color);  \/\/ \u30c6\u30ad\u30b9\u30c8\u30ab\u30e9\u30fc\u3092\u8a2d\u5b9a\u3059\u308b\n    parts_set_windowsize(SCR_WIDTH, SCR_HEIGHT); \/\/ \u30a6\u30a3\u30f3\u30c9\u30a6\u30b5\u30a4\u30ba\u3092\u8a2d\u5b9a\u3059\u308b\n    \/* \u30dc\u30bf\u30f3\u4f5c\u6210 *\/\n    rect.x = 10;\n    rect.y = 10;\n    rect.w = 90;\n    rect.h = 30;\n    add_parts(&amp;rect, (void *)1, BUTTON, \"\u30dc\u30bf\u30f3\", font, &amp;button_color);\n    \/* \u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u4f5c\u6210 *\/\n    rect.x = 10;\n    rect.y = 80;\n    rect.w = 200;\n    rect.h = 30;\n    add_parts(&amp;rect, (void *)0, CHECKBOX, \"\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\", font, &amp;checkbox_color);\n    \/* \u30e9\u30d9\u30eb\u4f5c\u6210 *\/\n    rect.x = 10;\n    rect.y = 220;\n    rect.w = 310;\n    rect.h = 20;\n    add_parts(&amp;rect, NULL, LABEL, \"\u30e9\u30d9\u30eb\", font, &amp;label_color);\n\n    \/* \u30a4\u30d9\u30f3\u30c8\u30eb\u30fc\u30d7 *\/\n    while( quit_flg == 1 ) {\n        if( SDL_PollEvent(&amp;event) ) {\n            switch (event.type) {\n            case SDL_USEREVENT: {\n                void (*p) (void*) = event.user.data1;\n                p(event.user.data2);\n                break;\n            }\n\n            case SDL_MOUSEMOTION:\n                mouse_motion_parts(event.button.x, event.button.y);\n                break;\n\n            case SDL_MOUSEBUTTONUP:\n                mouse_button_up_parts(event.button.x, event.button.y);\n                break;\n\n            case SDL_MOUSEBUTTONDOWN:\n                mouse_button_down_parts(event.button.x, event.button.y);\n                break;\n\n            \/* \u30eb\u30fc\u30d7\u7d42\u4e86 *\/\n            case SDL_QUIT:\n                quit_flg = 0;\n                break;\n            }\n        } else\n            SDL_Delay(100);\n    }\n\n    \/* \u7d42\u4e86\u51e6\u7406 *\/\n    if( my_timer_id ) SDL_RemoveTimer(my_timer_id);\n    if( font ) TTF_CloseFont(font);\n    if( renderer ) SDL_DestroyRenderer(renderer);\n    if( window ) SDL_DestroyWindow(window);\n    free_parts();\n    SDL_Quit();\n\n    return 0;\n}\n<\/pre>\n\n\n\n<p>\u3000\u4e0a\u8a18\u30bd\u30fc\u30b9\u3068\u3001SDL_gui.o \u3092\u30ea\u30f3\u30af\u3057\u3066\u3067\u304d\u305f\u5b9f\u884c\u30d5\u30a1\u30a4\u30eb\u3092\u52d5\u304b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"320\" height=\"240\" src=\"https:\/\/sirius10.net\/blog\/wordpress\/wp-content\/uploads\/2021\/10\/test1.png\" alt=\"\" class=\"wp-image-2282\" srcset=\"https:\/\/sirius10.net\/blog\/wordpress\/wp-content\/uploads\/2021\/10\/test1.png 320w, https:\/\/sirius10.net\/blog\/wordpress\/wp-content\/uploads\/2021\/10\/test1-300x225.png 300w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><figcaption>\u30e9\u30d9\u30eb\u3001\u30dc\u30bf\u30f3\u3001\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"320\" height=\"240\" src=\"https:\/\/sirius10.net\/blog\/wordpress\/wp-content\/uploads\/2021\/10\/text2.png\" alt=\"\" class=\"wp-image-2283\" srcset=\"https:\/\/sirius10.net\/blog\/wordpress\/wp-content\/uploads\/2021\/10\/text2.png 320w, https:\/\/sirius10.net\/blog\/wordpress\/wp-content\/uploads\/2021\/10\/text2-300x225.png 300w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><figcaption>\u62bc\u3055\u308c\u305f\u30dc\u30bf\u30f3\u3068\u30c1\u30a7\u30c3\u30af\u3092\u4ed8\u3051\u305f\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9<\/figcaption><\/figure><\/div>\n\n\n\n<p>\u3000\u30c0\u30a4\u30a2\u30ed\u30b0\u3063\u307d\u304f\u306a\u308a\u307e\u3057\u305f\u304c\u3001\u305b\u3081\u3066\u3001\u30c9\u30ed\u30c3\u30d7\u30c0\u30a6\u30f3\u30ea\u30b9\u30c8\u3068\u30c6\u30ad\u30b9\u30c8\u5165\u529b\u30dc\u30c3\u30af\u30b9\u304f\u3089\u3044\u306f\u4f5c\u308a\u305f\u3044\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000GUI \u90e8\u54c1\u306e\u30dc\u30bf\u30f3\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002\u30de\u30a6\u30b9\u64cd\u4f5c\u3067\u30dc\u30bf\u30f3\u3082\u6d45\u308c\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002\u3053\u308c\u3092\u72ec\u7acb\u3057\u305f\u30bd\u30fc\u30b9\u306b\u307e\u3068\u3081\u307e\u3059\u3002 \u3000\u307e\u305a\u3001GUI \u90e8\u54c1\u3092\u4f5c\u308b\u305f\u3081\u306e\u30c7\u30fc\u30bf\u3092\u6c7a\u3081\u307e\u3059\u3002\u5fc5\u8981\u306a\u30c7\u30fc\u30bf\u306f\u3001GUI \u90e8\u54c1\u306e\u7a2e\u985e\u3001\u90e8\u54c1\u306e\u5de6\u4e0a\u306e x,  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"class_list":["post-2281","post","type-post","status-publish","format-standard","hentry","category-sdl2"],"_links":{"self":[{"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/2281","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=2281"}],"version-history":[{"count":5,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/2281\/revisions"}],"predecessor-version":[{"id":2288,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/2281\/revisions\/2288"}],"wp:attachment":[{"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=2281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=2281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=2281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}