Cross-platform C SDK logo

Cross-platform C SDK

Hello 2D Collisions!

❮ Back
Next ❯
This page has been automatically translated using the Google Translate API services. We are working on improving texts. Thank you for your understanding and patience.

Col2dHello is a small environment for experimentation with 2D collision detection algorithms. It allows you to create different types of volumes, move them with the mouse and edit them through the side panel. The details of the functions can be found in 2D Collisions.

Screenshot of a 2D collision detection application. Windows version.
Figure 1: Windows version.
Screenshot of a 2D collision detection application. MacOS version.
Figure 2: MacOS version.
Screenshot of a 2D collision detection application. Linux version.
Figure 3: Linux version.
Listing 1: howto/col2dhello/col2dhello.c
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
/* 2D collision detection demo */

#include "nappgui.h"
#include "col2dgui.h"

/*---------------------------------------------------------------------------*/

static void i_OnClose(App *app, Event *e)
{
    osapp_finish();
    unref(app);
    unref(e);
}

/*---------------------------------------------------------------------------*/

static ArrSt(Shape) *i_shapes(void) 
{
    ArrSt(Shape) *shapes = arrst_create(Shape);
    Shape *shape = arrst_new_n(shapes, 9, Shape);
    shape[0].type = ekCIRCLE;
    shape[0].mouse = FALSE;
    shape[0].collisions = 0;
    shape[0].body.cir.r = 50;
    shape[0].body.cir.c.x = 100;
    shape[0].body.cir.c.y = 100;
    shape[1].type = ekCIRCLE;
    shape[1].mouse = FALSE;
    shape[1].collisions = 0;
    shape[1].body.cir.r = 20;
    shape[1].body.cir.c.x = 300;
    shape[1].body.cir.c.y = 200;
    shape[2].type = ekOBB;
    shape[2].mouse = FALSE;
    shape[2].collisions = 0;
    shape[2].body.obb.center.x = 150;
    shape[2].body.obb.center.y = 350;
    shape[2].body.obb.angle = 200 * kBMATH_DEG2RADf;
    shape[2].body.obb.width = 200;
    shape[2].body.obb.height = 20;
    shape[2].body.obb.obb = NULL;
    shape[3].type = ekOBB;
    shape[3].mouse = FALSE;
    shape[3].collisions = 0;
    shape[3].body.obb.center.x = 460;
    shape[3].body.obb.center.y = 90;
    shape[3].body.obb.angle = 15 * kBMATH_DEG2RADf;
    shape[3].body.obb.width = 200;
    shape[3].body.obb.height = 60;
    shape[3].body.obb.obb = NULL;
    shape[4].type = ekPOINT;
    shape[4].mouse = FALSE;
    shape[4].collisions = 0;
    shape[4].body.pnt.x = 520;
    shape[4].body.pnt.y = 230;
    shape[5].type = ekPOINT;
    shape[5].mouse = FALSE;
    shape[5].collisions = 0;
    shape[5].body.pnt.x = 220;
    shape[5].body.pnt.y = 205;
    shape[6].type = ekBOX;
    shape[6].mouse = FALSE;
    shape[6].collisions = 0;
    shape[6].body.box.center.x = 100;
    shape[6].body.box.center.y = 225;
    shape[6].body.box.width = 100;
    shape[6].body.box.height = 50;
    shape[7].type = ekSEGMENT;
    shape[7].mouse = FALSE;
    shape[7].collisions = 0;
    shape[7].body.seg.center.x = 420;
    shape[7].body.seg.center.y = 280;
    shape[7].body.seg.length = 190;
    shape[7].body.seg.angle = 2.2f;
    shape[8].type = ekPOLY;
    shape[8].mouse = FALSE;
    shape[8].collisions = 0;
    shape[8].body.pol.center.x = 535;
    shape[8].body.pol.center.y = 325;
    shape[8].body.pol.angle = .55f;
    shape[8].body.pol.scale = 15;
    shape[8].body.pol.pol = NULL;
    col2dhello_update_obb(&shape[2].body.obb);
    col2dhello_update_obb(&shape[3].body.obb);
    col2dhello_update_box(&shape[6].body.box);
    col2dhello_update_seg(&shape[7].body.seg);
    col2dhello_update_pol(&shape[8].body.pol);
    return shapes;
}

/*---------------------------------------------------------------------------*/

static App *i_create(void)
{
    App *app = heap_new0(App);
    col2dhello_dbind();
    app->shapes = i_shapes();
    app->dists = arrst_create(Dist);
    app->seltype = ekOBB;
    app->selshape = UINT32_MAX;
    app->show_seg_pt = TRUE;
    app->window = col2dhello_window(app);
    window_title(app->window, "2D Collision Detection");
    window_origin(app->window, v2df(500, 200));
    window_OnClose(app->window, listener(app, i_OnClose, App));
    window_show(app->window);
    col2dhello_dbind_shape(app);
    col2dhello_collisions(app);
    return app;
}

/*---------------------------------------------------------------------------*/

static void i_remove_shape(Shape *shape)
{
    cassert_no_null(shape);
    if (shape->type == ekOBB)
        obb2d_destroyf(&shape->body.obb.obb);
    else if (shape->type == ekPOLY)
        pol2d_destroyf(&shape->body.pol.pol);
}

/*---------------------------------------------------------------------------*/

static void i_destroy(App **app)
{
    arrst_destroy(&(*app)->shapes, i_remove_shape, Shape);
    arrst_destroy(&(*app)->dists, NULL, Dist);
    window_destroy(&(*app)->window);
    heap_delete(app, App);
}

/*---------------------------------------------------------------------------*/

void col2dhello_update_seg(Seg *seg)
{
    V2Df hvec;
    cassert_no_null(seg);
    hvec.x = seg->length / 2;
    hvec.y = 0;
    v2d_rotatef(&hvec, seg->angle);
    seg->seg.p0.x = seg->center.x - hvec.x;
    seg->seg.p0.y = seg->center.y - hvec.y;
    seg->seg.p1.x = seg->center.x + hvec.x;
    seg->seg.p1.y = seg->center.y + hvec.y;
}

/*---------------------------------------------------------------------------*/

void col2dhello_update_box(Box *box)
{
    cassert_no_null(box);
    box->box.min.x = box->center.x - box->width / 2;
    box->box.min.y = box->center.y - box->height / 2;
    box->box.max.x = box->center.x + box->width / 2;
    box->box.max.y = box->center.y + box->height / 2;
}

/*---------------------------------------------------------------------------*/

void col2dhello_update_obb(OBB *obb)
{
    cassert_no_null(obb);
    if (obb->obb == NULL)
        obb->obb = obb2d_createf(&obb->center, obb->width, obb->height, obb->angle);
    else
        obb2d_updatef(obb->obb, &obb->center, obb->width, obb->height, obb->angle);
}

/*---------------------------------------------------------------------------*/

void col2dhello_update_pol(Pol *pol)
{
    const V2Df verts[5] = { {4,1}, {2,5}, {-3,5}, {-4,2}, {0,-3} };
    V2Df tverts[5];
    T2Df t2d;

    cassert_no_null(pol);
    t2d_movef(&t2d, kT2D_IDENTf, pol->center.x, pol->center.y);
    t2d_rotatef(&t2d, &t2d, pol->angle);
    t2d_scalef(&t2d, &t2d, pol->scale, pol->scale);
    t2d_vmultnf(tverts, &t2d, verts, 5);

    if (pol->pol == NULL)
        pol->pol = pol2d_createf(tverts, 5);
    else
        pol2d_updatef(pol->pol, tverts);
}

/*---------------------------------------------------------------------------*/

static bool_t i_mouse_inside(const Shape *shape, const real32_t mouse_x, const real32_t mouse_y)
{
    V2Df m = v2df(mouse_x, mouse_y);

    switch(shape->type) {
    case ekPOINT:
        return col2d_point_pointf(&shape->body.pnt, &m, CENTER_RADIUS, NULL);

    case ekSEGMENT:
        return col2d_segment_pointf(&shape->body.seg.seg, &m, CENTER_RADIUS, NULL);

    case ekCIRCLE:
        return col2d_circle_pointf(&shape->body.cir, &m, NULL);

    case ekBOX:
        return col2d_box_pointf(&shape->body.box.box, &m, NULL);

    case ekOBB:
        return col2d_obb_pointf(shape->body.obb.obb, &m, NULL);

    case ekPOLY:
        return col2d_poly_pointf(shape->body.pol.pol, &m, NULL);

    cassert_default();
    }

    return FALSE;
}

/*---------------------------------------------------------------------------*/

void col2dhello_mouse_collisions(App *app, const real32_t mouse_x, const real32_t mouse_y)
{
    arrst_foreach(shape, app->shapes, Shape)
        shape->mouse = i_mouse_inside(shape, mouse_x, mouse_y);
    arrst_end();
}

/*---------------------------------------------------------------------------*/

static void i_point_segment_dist(const Seg2Df *seg, const V2Df *pnt, ArrSt(Dist) *dists)
{
    Dist *dist = arrst_new(dists, Dist);
    real32_t t = seg2d_close_paramf(seg, pnt);
    dist->p0 = *pnt;
    dist->p1 = seg2d_evalf(seg, t);
}

/*---------------------------------------------------------------------------*/

void col2dhello_collisions(App *app)
{
    Shape *shape = arrst_all(app->shapes, Shape);
    uint32_t n = arrst_size(app->shapes, Shape);
    uint32_t i, j;

    arrst_clear(app->dists, NULL, Dist);

    for (i = 0; i < n; ++i)
        shape[i].collisions = 0;

    for (i = 0; i < n; ++i)
    for (j = i + 1; j < n; ++j)
    {
        bool_t col = FALSE;
        switch(shape[i].type) {
        case ekPOINT:
            switch(shape[j].type) {
            case ekPOINT:
                col = col2d_point_pointf(&shape[i].body.pnt, &shape[j].body.pnt, CENTER_RADIUS, NULL);
                break;

            case ekSEGMENT:
                col = col2d_segment_pointf(&shape[j].body.seg.seg, &shape[i].body.pnt, CENTER_RADIUS, NULL);
                i_point_segment_dist(&shape[j].body.seg.seg, &shape[i].body.pnt, app->dists);
                break;

            case ekCIRCLE:
                col = col2d_circle_pointf(&shape[j].body.cir, &shape[i].body.pnt, NULL);
                break;

            case ekBOX:
                col = col2d_box_pointf(&shape[j].body.box.box, &shape[i].body.pnt, NULL);
                break;

            case ekOBB:
                col = col2d_obb_pointf(shape[j].body.obb.obb, &shape[i].body.pnt, NULL);
                break;

            case ekPOLY:
                col = col2d_poly_pointf(shape[j].body.pol.pol, &shape[i].body.pnt, NULL);
                break;

            cassert_default();
            }
            break;

        case ekSEGMENT:
            switch(shape[j].type) {
            case ekPOINT:
                col = col2d_segment_pointf(&shape[i].body.seg.seg, &shape[j].body.pnt, CENTER_RADIUS, NULL);
                i_point_segment_dist(&shape[i].body.seg.seg, &shape[j].body.pnt, app->dists);
                break;

            case ekSEGMENT:
                col = col2d_segment_segmentf(&shape[i].body.seg.seg, &shape[j].body.seg.seg, NULL);
                break;

            case ekCIRCLE:
                col = col2d_circle_segmentf(&shape[j].body.cir, &shape[i].body.seg.seg, NULL);
                break;

            case ekBOX:
                col = col2d_box_segmentf(&shape[j].body.box.box, &shape[i].body.seg.seg, NULL);
                break;

            case ekOBB:
                col = col2d_obb_segmentf(shape[j].body.obb.obb, &shape[i].body.seg.seg, NULL);
                break;

            case ekPOLY:
                col = col2d_poly_segmentf(shape[j].body.pol.pol, &shape[i].body.seg.seg, NULL);
                break;

            cassert_default();
            }
            break;

        case ekCIRCLE:
            switch(shape[j].type) {
            case ekPOINT:
                col = col2d_circle_pointf(&shape[i].body.cir, &shape[j].body.pnt, NULL);
                break;

            case ekSEGMENT:
                col = col2d_circle_segmentf(&shape[i].body.cir, &shape[j].body.seg.seg, NULL);
                break;

            case ekCIRCLE:
                col = col2d_circle_circlef(&shape[i].body.cir, &shape[j].body.cir, NULL);
                break;

            case ekBOX:
                col = col2d_box_circlef(&shape[j].body.box.box, &shape[i].body.cir, NULL);
                break;

            case ekOBB:
                col = col2d_obb_circlef(shape[j].body.obb.obb, &shape[i].body.cir, NULL);
                break;

            case ekPOLY:
                col = col2d_poly_circlef(shape[j].body.pol.pol, &shape[i].body.cir, NULL);
                break;

            cassert_default();
            }
            break;

        case ekBOX:
            switch(shape[j].type) {
            case ekPOINT:
                col = col2d_box_pointf(&shape[i].body.box.box, &shape[j].body.pnt, NULL);
                break;

            case ekSEGMENT:
                col = col2d_box_segmentf(&shape[i].body.box.box, &shape[j].body.seg.seg, NULL);
                break;

            case ekCIRCLE:
                col = col2d_box_circlef(&shape[i].body.box.box, &shape[j].body.cir, NULL);
                break;

            case ekBOX:
                col = col2d_box_boxf(&shape[i].body.box.box, &shape[j].body.box.box, NULL);
                break;

            case ekOBB:
                col = col2d_obb_boxf(shape[j].body.obb.obb, &shape[i].body.box.box, NULL);
                break;

            case ekPOLY:
                col = col2d_poly_boxf(shape[j].body.pol.pol, &shape[i].body.box.box, NULL);
                break;

            cassert_default();
            }
            break;

        case ekOBB:
            switch(shape[j].type) {
            case ekPOINT:
                col = col2d_obb_pointf(shape[i].body.obb.obb, &shape[j].body.pnt, NULL);
                break;

            case ekSEGMENT:
                col = col2d_obb_segmentf(shape[i].body.obb.obb, &shape[j].body.seg.seg, NULL);
                break;

            case ekCIRCLE:
                col = col2d_obb_circlef(shape[i].body.obb.obb, &shape[j].body.cir, NULL);
                break;

            case ekBOX:
                col = col2d_obb_boxf(shape[i].body.obb.obb, &shape[j].body.box.box, NULL);
                break;

            case ekOBB:
                col = col2d_obb_obbf(shape[i].body.obb.obb, shape[j].body.obb.obb, NULL);
                break;

            case ekPOLY:
                col = col2d_poly_obbf(shape[j].body.pol.pol, shape[i].body.obb.obb, NULL);
                break;

            cassert_default();
            }
            break;

        case ekPOLY:
            switch(shape[j].type) {
            case ekPOINT:
                col = col2d_poly_pointf(shape[i].body.pol.pol, &shape[j].body.pnt, NULL);
                break;

            case ekSEGMENT:
                col = col2d_poly_segmentf(shape[i].body.pol.pol, &shape[j].body.seg.seg, NULL);
                break;

            case ekCIRCLE:
                col = col2d_poly_circlef(shape[i].body.pol.pol, &shape[j].body.cir, NULL);
                break;

            case ekBOX:
                col = col2d_poly_boxf(shape[i].body.pol.pol, &shape[j].body.box.box, NULL);
                break;

            case ekOBB:
                col = col2d_poly_obbf(shape[i].body.pol.pol, shape[j].body.obb.obb, NULL);
                break;

            case ekPOLY:
                col = col2d_poly_polyf(shape[i].body.pol.pol, shape[j].body.pol.pol, NULL);
                break;

            cassert_default();
            }
            break;

        cassert_default();
        }

        if (col == TRUE)
        {
            shape[i].collisions += 1;
            shape[j].collisions += 1;
        }
    }
}

/*---------------------------------------------------------------------------*/

#include "osmain.h"
osmain(i_create, i_destroy, "", App)
Listing 2: howto/col2dhello/col2dhello.hxx
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
/* 2D collision detection demo */

#ifndef __COL2DHELLO_HXX__
#define __COL2DHELLO_HXX__

#include "gui.hxx"

#define CENTER_RADIUS   3

typedef struct _shape_t Shape;
typedef struct _dist_t Dist;
typedef struct _box_t Box;
typedef struct _seg_t Seg;
typedef struct _obb_t OBB;
typedef struct _pol_t Pol;
typedef struct _app_t App;

typedef enum _shtype_t
{
    ekPOINT,
    ekSEGMENT,
    ekCIRCLE,
    ekBOX,
    ekOBB,
    ekPOLY
} shtype_t;

struct _seg_t
{
    V2Df center;
    real32_t length;
    real32_t angle;
    Seg2Df seg;
};

struct _box_t
{
    V2Df center;
    real32_t width;
    real32_t height;
    Box2Df box;
};

struct _obb_t
{
    V2Df center;
    real32_t width;
    real32_t height;
    real32_t angle;
    OBB2Df *obb;
};

struct _pol_t
{
    V2Df center;
    real32_t angle;
    real32_t scale;
    Pol2Df *pol;
};

struct _shape_t
{
    shtype_t type;
    bool_t mouse;
    uint32_t collisions;

    union {
        V2Df pnt;
        Seg seg;
        Cir2Df cir;
        Box box;
        OBB obb;
        Pol pol;
    } body;
};

struct _dist_t
{
    V2Df p0;
    V2Df p1;
};

struct _app_t
{
    Window *window;
    View *view;
    Layout *pnt_layout;
    Layout *seg_layout;
    Layout *cir_layout;
    Layout *box_layout;
    Layout *obb_layout;
    Layout *pol_layout;
    Panel *obj_panel;
    ArrSt(Shape) *shapes;
    ArrSt(Dist) *dists;
    shtype_t seltype;
    uint32_t selshape;
    bool_t show_seg_pt;
    V2Df mouse_pos;
    V2Df obj_pos;
};

#endif
Listing 3: howto/col2dhello/col2dgui.c
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
/* Col2D Hello GUI */

#include "nappgui.h"
#include "col2dgui.h"

/*---------------------------------------------------------------------------*/

void col2dhello_dbind(void)
{
    dbind_enum(shtype_t, ekPOINT);
    dbind_enum(shtype_t, ekSEGMENT);
    dbind_enum(shtype_t, ekCIRCLE);
    dbind_enum(shtype_t, ekBOX);
    dbind_enum(shtype_t, ekOBB);
    dbind_enum(shtype_t, ekPOLY);
    dbind(App, shtype_t, seltype);
    dbind(App, bool_t, show_seg_pt);
    dbind(Seg, real32_t, length);
    dbind(Seg, real32_t, angle);
    dbind(Cir2Df, real32_t, r);
    dbind(Box, real32_t, width);
    dbind(Box, real32_t, height);
    dbind(OBB, real32_t, width);
    dbind(OBB, real32_t, height);
    dbind(OBB, real32_t, angle);
    dbind(Pol, real32_t, angle);
    dbind(Pol, real32_t, scale);
    dbind_range(Seg, real32_t, length, 20, 300);
    dbind_range(Seg, real32_t, angle, 0, 360 * kBMATH_DEG2RADf);
    dbind_range(Cir2Df, real32_t, r, 5, 100);
    dbind_range(Box, real32_t, width, 20, 300);
    dbind_range(Box, real32_t, height, 20, 300);
    dbind_range(OBB, real32_t, width, 20, 300);
    dbind_range(OBB, real32_t, height, .2f, 300);
    dbind_range(OBB, real32_t, angle, 0, 360 * kBMATH_DEG2RADf);
    dbind_range(Pol, real32_t, angle, 0, 360 * kBMATH_DEG2RADf);
    dbind_range(Pol, real32_t, scale, 5, 30);
}

/*---------------------------------------------------------------------------*/

static void i_OnSeg(App *app, Event *e)
{
    Shape *shape = arrst_get(app->shapes, app->selshape, Shape);
    cassert(shape->type == ekSEGMENT);
    col2dhello_update_seg(&shape->body.seg);
    col2dhello_collisions(app);
    view_update(app->view);
    unref(e);
}

/*---------------------------------------------------------------------------*/

static void i_OnCircle(App *app, Event *e)
{
    col2dhello_collisions(app);
    view_update(app->view);
    unref(e);
}

/*---------------------------------------------------------------------------*/

static void i_OnBox(App *app, Event *e)
{
    Shape *shape = arrst_get(app->shapes, app->selshape, Shape);
    cassert(shape->type == ekBOX);
    col2dhello_update_box(&shape->body.box);
    col2dhello_collisions(app);
    view_update(app->view);
    unref(e);
}

/*---------------------------------------------------------------------------*/

static void i_OnOBB(App *app, Event *e)
{
    Shape *shape = arrst_get(app->shapes, app->selshape, Shape);
    cassert(shape->type == ekOBB);
    col2dhello_update_obb(&shape->body.obb);
    col2dhello_collisions(app);
    view_update(app->view);
    unref(e);
}

/*---------------------------------------------------------------------------*/

static void i_OnPoly(App *app, Event *e)
{
    Shape *shape = arrst_get(app->shapes, app->selshape, Shape);
    cassert(shape->type == ekPOLY);
    col2dhello_update_pol(&shape->body.pol);
    col2dhello_collisions(app);
    view_update(app->view);
    unref(e);
}

/*---------------------------------------------------------------------------*/

static void i_OnOpt(App *app, Event *e)
{
    view_update(app->view);
    unref(e);
}

/*---------------------------------------------------------------------------*/

static Layout *i_empty_layout(void)
{
    Layout *layout = layout_create(1, 1);
    return layout;
}

/*---------------------------------------------------------------------------*/

static Layout *i_point_layout(App *app)
{
    Layout *layout = layout_create(1, 1);
    Label *label = label_create();
    label_text(label, "Selected Point");
    layout_label(layout, label, 0, 0);
    app->pnt_layout = layout;
    return layout;
}

/*---------------------------------------------------------------------------*/

static Layout *i_segment_layout(App *app)
{
    Layout *layout = layout_create(1, 5);
    Label *label1 = label_create();
    Label *label2 = label_create();
    Label *label3 = label_create();
    Slider *slider1 = slider_create();
    Slider *slider2 = slider_create();
    label_text(label1, "Selected Segment");
    label_text(label2, "Length:");
    label_text(label3, "Angle:");
    layout_label(layout, label1, 0, 0);
    layout_label(layout, label2, 0, 1);
    layout_label(layout, label3, 0, 3);
    layout_slider(layout, slider1, 0, 2);
    layout_slider(layout, slider2, 0, 4);
    layout_vmargin(layout, 0, 5);
    layout_vmargin(layout, 2, 10);
    cell_dbind(layout_cell(layout, 0, 2), Seg, real32_t, length);
    cell_dbind(layout_cell(layout, 0, 4), Seg, real32_t, angle);
    layout_dbind(layout, listener(app, i_OnSeg, App), Seg);
    app->seg_layout = layout;
    return layout;
}

/*---------------------------------------------------------------------------*/

static Layout *i_circle_layout(App *app)
{
    Layout *layout = layout_create(1, 3);
    Label *label1 = label_create();
    Label *label2 = label_create();
    Slider *slider = slider_create();
    label_text(label1, "Selected Circle");
    label_text(label2, "Radix:");
    layout_label(layout, label1, 0, 0);
    layout_label(layout, label2, 0, 1);
    layout_slider(layout, slider, 0, 2);
    layout_vmargin(layout, 0, 5);
    cell_dbind(layout_cell(layout, 0, 2), Cir2Df, real32_t, r);
    layout_dbind(layout, listener(app, i_OnCircle, App), Cir2Df);
    app->cir_layout = layout;
    return layout;
}

/*---------------------------------------------------------------------------*/

static Layout *i_box_layout(App *app)
{
    Layout *layout = layout_create(1, 5);
    Label *label1 = label_create();
    Label *label2 = label_create();
    Label *label3 = label_create();
    Slider *slider1 = slider_create();
    Slider *slider2 = slider_create();
    label_text(label1, "Selected Box");
    label_text(label2, "Width:");
    label_text(label3, "Height:");
    layout_label(layout, label1, 0, 0);
    layout_label(layout, label2, 0, 1);
    layout_label(layout, label3, 0, 3);
    layout_slider(layout, slider1, 0, 2);
    layout_slider(layout, slider2, 0, 4);
    layout_vmargin(layout, 0, 5);
    layout_vmargin(layout, 2, 10);
    cell_dbind(layout_cell(layout, 0, 2), Box, real32_t, width);
    cell_dbind(layout_cell(layout, 0, 4), Box, real32_t, height);
    layout_dbind(layout, listener(app, i_OnBox, App), Box);
    app->box_layout = layout;
    return layout;
}

/*---------------------------------------------------------------------------*/

static Layout *i_obb_layout(App *app)
{
    Layout *layout = layout_create(1, 7);
    Label *label1 = label_create();
    Label *label2 = label_create();
    Label *label3 = label_create();
    Label *label4 = label_create();
    Slider *slider1 = slider_create();
    Slider *slider2 = slider_create();
    Slider *slider3 = slider_create();
    label_text(label1, "Selected Oriented Box");
    label_text(label2, "Width:");
    label_text(label3, "Height:");
    label_text(label4, "Angle:");
    layout_label(layout, label1, 0, 0);
    layout_label(layout, label2, 0, 1);
    layout_label(layout, label3, 0, 3);
    layout_label(layout, label4, 0, 5);
    layout_slider(layout, slider1, 0, 2);
    layout_slider(layout, slider2, 0, 4);
    layout_slider(layout, slider3, 0, 6);
    layout_vmargin(layout, 0, 5);
    layout_vmargin(layout, 2, 10);
    layout_vmargin(layout, 4, 10);
    cell_dbind(layout_cell(layout, 0, 2), OBB, real32_t, width);
    cell_dbind(layout_cell(layout, 0, 4), OBB, real32_t, height);
    cell_dbind(layout_cell(layout, 0, 6), OBB, real32_t, angle);
    layout_dbind(layout, listener(app, i_OnOBB, App), OBB);
    app->obb_layout = layout;
    return layout;
}

/*---------------------------------------------------------------------------*/

static Layout *i_pol_layout(App *app)
{
    Layout *layout = layout_create(1, 5);
    Label *label1 = label_create();
    Label *label2 = label_create();
    Label *label3 = label_create();
    Slider *slider1 = slider_create();
    Slider *slider2 = slider_create();
    label_text(label1, "Selected Polygon");
    label_text(label2, "Angle:");
    label_text(label3, "Scale:");
    layout_label(layout, label1, 0, 0);
    layout_label(layout, label2, 0, 1);
    layout_label(layout, label3, 0, 3);
    layout_slider(layout, slider1, 0, 2);
    layout_slider(layout, slider2, 0, 4);
    layout_vmargin(layout, 0, 5);
    layout_vmargin(layout, 2, 10);
    cell_dbind(layout_cell(layout, 0, 2), Pol, real32_t, angle);
    cell_dbind(layout_cell(layout, 0, 4), Pol, real32_t, scale);
    layout_dbind(layout, listener(app, i_OnPoly, App), Pol);
    app->pol_layout = layout;
    return layout;
}

/*---------------------------------------------------------------------------*/

static void i_OnNewShape(App *app, Event *e)
{
    S2Df size;
    Shape *shape = arrst_new(app->shapes, Shape);
    unref(e);

    view_get_size(app->view, &size);
    shape->type = app->seltype;
    shape->collisions = 0;
    shape->mouse = FALSE;
    app->selshape = arrst_size(app->shapes, Shape) - 1;

    switch(app->seltype) {
    case ekPOINT:
        shape->body.pnt.x = size.width / 2;
        shape->body.pnt.y = size.height / 2;
        break;

    case ekSEGMENT:
        shape->body.seg.center.x = size.width / 2;
        shape->body.seg.center.y = size.height / 2;
        shape->body.seg.length = 100;
        shape->body.seg.angle = 15 * kBMATH_DEG2RADf;
        col2dhello_update_seg(&shape->body.seg);
        break;

    case ekCIRCLE:
        shape->body.cir.c.x = size.width / 2;
        shape->body.cir.c.y = size.height / 2;
        shape->body.cir.r = 30;
        break;

    case ekBOX:
        shape->body.box.center.x = size.width / 2;
        shape->body.box.center.y = size.height / 2;
        shape->body.box.width = 100;
        shape->body.box.height = 50;
        col2dhello_update_box(&shape->body.box);
        break;

    case ekOBB:
        shape->body.obb.center.x = size.width / 2;
        shape->body.obb.center.y = size.height / 2;
        shape->body.obb.width = 100;
        shape->body.obb.height = 50;
        shape->body.obb.angle = 15 * kBMATH_DEG2RADf;
        shape->body.obb.obb = NULL;
        col2dhello_update_obb(&shape->body.obb);
        break;

    case ekPOLY:
        shape->body.pol.center.x = size.width / 2;
        shape->body.pol.center.y = size.height / 2;
        shape->body.pol.angle = 0;
        shape->body.pol.scale = 10;
        shape->body.pol.pol = NULL;
        col2dhello_update_pol(&shape->body.pol);
        break;

    cassert_default();
    }

    col2dhello_dbind_shape(app);
    col2dhello_collisions(app);
    view_update(app->view);
}

/*---------------------------------------------------------------------------*/

static Layout *i_new_layout(App *app)
{
    Layout *layout = layout_create(1, 2);
    PopUp *popup = popup_create();
    Button *button = button_push();
    button_text(button, "New Shape");
    button_OnClick(button, listener(app, i_OnNewShape, App));
    layout_popup(layout, popup, 0, 0);
    layout_button(layout, button, 0, 1);
    layout_vmargin(layout, 0, 5);
    cell_dbind(layout_cell(layout, 0, 0), App, shtype_t, seltype);
    return layout;
}

/*---------------------------------------------------------------------------*/

static Layout *i_left_layout(App *app)
{
    Layout *layout1 = layout_create(1, 3);
    Layout *layout2 = i_new_layout(app);
    Layout *layout3 = i_empty_layout();
    Layout *layout4 = i_point_layout(app);
    Layout *layout5 = i_segment_layout(app);
    Layout *layout6 = i_circle_layout(app);
    Layout *layout7 = i_box_layout(app);
    Layout *layout8 = i_obb_layout(app);
    Layout *layout9 = i_pol_layout(app);
    Button *button1 = button_check();
    Panel *panel = panel_create();
    button_text(button1, "Show Segment-Point distance");
    panel_layout(panel, layout3);
    panel_layout(panel, layout4);
    panel_layout(panel, layout5);
    panel_layout(panel, layout6);
    panel_layout(panel, layout7);
    panel_layout(panel, layout8);
    panel_layout(panel, layout9);
    layout_hsize(layout1, 0, 200);
    layout_layout(layout1, layout2, 0, 0);
    layout_button(layout1, button1, 0, 1);
    layout_panel(layout1, panel, 0, 2);
    layout_vmargin(layout1, 0, 10);
    layout_vmargin(layout1, 1, 10);
    layout_margin(layout1, 10);
    app->obj_panel = panel;
    cell_dbind(layout_cell(layout1, 0, 1), App, bool_t, show_seg_pt);
    layout_dbind(layout1, listener(app, i_OnOpt, App), App);
    layout_dbind_obj(layout1, app, App);        
    return layout1;
}

/*---------------------------------------------------------------------------*/

static color_t i_color(const uint32_t collision, const bool_t mouse)
{
    if (collision > 0)
    {
        if (collision == 1)
            return color_rgb(255, 170, 0);

        if (collision == 2)
            return color_rgb(255, 127, 0);

        return color_rgb(255, 42, 0);
    }
    else
    {
        if (mouse == TRUE)
            return color_rgb(127, 85, 255);

        return color_gray(120);
    }
}

/*---------------------------------------------------------------------------*/

static void i_draw_point(DCtx *ctx, const V2Df *pt)
{
    draw_circle(ctx, ekFILL, pt->x, pt->y, CENTER_RADIUS);
}

/*---------------------------------------------------------------------------*/

static void i_draw_segment(DCtx *ctx, const Seg *seg)
{
    draw_line(ctx, seg->seg.p0.x, seg->seg.p0.y, seg->seg.p1.x, seg->seg.p1.y);
}

/*---------------------------------------------------------------------------*/

static void i_draw_circle(DCtx *ctx, const Cir2Df *circle)
{
    draw_circle(ctx, ekFILL, circle->c.x, circle->c.y, circle->r);
    draw_fill_color(ctx, kCOLOR_BLACK);
    draw_circle(ctx, ekFILL, circle->c.x, circle->c.y, CENTER_RADIUS);
}

/*---------------------------------------------------------------------------*/

static void i_draw_box(DCtx *ctx, const Box *box)
{
    draw_rect(ctx, ekFILL, box->box.min.x, box->box.min.y, box->width, box->height);
    draw_fill_color(ctx, kCOLOR_BLACK);
    draw_circle(ctx, ekFILL, box->center.x, box->center.y, CENTER_RADIUS);
}

/*---------------------------------------------------------------------------*/

static void i_draw_obb(DCtx *ctx, const OBB *obb)
{
    T2Df t2d;
    real32_t hwidth = obb->width / 2;
    real32_t hheight = obb->height / 2;
    t2d_movef(&t2d, kT2D_IDENTf, obb->center.x - hwidth, obb->center.y - hheight);
    t2d_movef(&t2d, &t2d, hwidth, hheight);
    t2d_rotatef(&t2d, &t2d, obb->angle);
    t2d_movef(&t2d, &t2d, -hwidth, -hheight);
    draw_matrix(ctx, &t2d);
    draw_rect(ctx, ekFILL, 0, 0, obb->width, obb->height);
    draw_matrix(ctx, kT2D_IDENTf);
    draw_fill_color(ctx, kCOLOR_BLACK);
    draw_circle(ctx, ekFILL, obb->center.x, obb->center.y, CENTER_RADIUS);
}

/*---------------------------------------------------------------------------*/

static void i_draw_poly(DCtx *ctx, const Pol *pol)
{
    const V2Df *points = pol2d_pointsf(pol->pol);
    uint32_t n = pol2d_nf(pol->pol);
    draw_polygon(ctx, ekFILL, points, n);
    draw_fill_color(ctx, kCOLOR_BLACK);
    draw_circle(ctx, ekFILL, pol->center.x, pol->center.y, CENTER_RADIUS);
}

/*---------------------------------------------------------------------------*/

static void i_draw_bbox(DCtx *ctx, const Shape *shape)
{
    Box2Df bbox = kBOX2D_NULLf;
    switch(shape->type) {
    case ekPOINT:
    {
        Cir2Df c = cir2df(shape->body.pnt.x, shape->body.pnt.y, CENTER_RADIUS);
        box2d_add_circlef(&bbox, &c);
        break;
    }

    case ekSEGMENT:
        box2d_addf(&bbox, &shape->body.seg.seg.p0);
        box2d_addf(&bbox, &shape->body.seg.seg.p1);
        break;

    case ekCIRCLE:
        box2d_add_circlef(&bbox, &shape->body.cir);
        break;

    case ekBOX:
        box2d_mergef(&bbox, &shape->body.box.box);
        break;

    case ekOBB:
    {
        const V2Df *corners = obb2d_cornersf(shape->body.obb.obb);
        box2d_addnf(&bbox, corners, 4);
        break;
    }

    case ekPOLY:
    {
        const V2Df *points = pol2d_pointsf(shape->body.pol.pol);
        uint32_t n = pol2d_nf(shape->body.pol.pol);
        box2d_addnf(&bbox, points, n);
        break;
    }

    cassert_default();
    }

    draw_line_color(ctx, color_rgb(0, 128, 0));
    draw_rect(ctx, ekSTROKE, bbox.min.x, bbox.min.y, bbox.max.x - bbox.min.x, bbox.max.y - bbox.min.y);
}

/*---------------------------------------------------------------------------*/

static void i_OnDraw(App *app, Event *e)
{
    const EvDraw *p = event_params(e, EvDraw);

    draw_clear(p->ctx, color_rgb(255, 212, 255));

    arrst_foreach(shape, app->shapes, Shape)
        draw_fill_color(p->ctx, i_color(shape->collisions, shape->mouse));
        draw_line_color(p->ctx, i_color(shape->collisions, shape->mouse));
        
        switch(shape->type) {
        case ekPOINT:
            i_draw_point(p->ctx, &shape->body.pnt);
            break;

        case ekSEGMENT:
            i_draw_segment(p->ctx, &shape->body.seg);
            break;

        case ekCIRCLE:
            i_draw_circle(p->ctx, &shape->body.cir);
            break;

        case ekBOX:
            i_draw_box(p->ctx, &shape->body.box);
            break;

        case ekOBB:
            i_draw_obb(p->ctx, &shape->body.obb);
            break;

        case ekPOLY:
            i_draw_poly(p->ctx, &shape->body.pol);
            break;

        cassert_default();
        }

        if (app->selshape == shape_i)
            i_draw_bbox(p->ctx, shape);

    arrst_end()

    if (app->show_seg_pt == TRUE)
    {
        real32_t pattern[2] = {2, 2};
        draw_line_dash(p->ctx, pattern, 2);
        draw_line_color(p->ctx, kCOLOR_MAGENTA);
        arrst_foreach(dist, app->dists, Dist)
            draw_line(p->ctx, dist->p0.x, dist->p0.y, dist->p1.x, dist->p1.y);
        arrst_end();
    }
}

/*---------------------------------------------------------------------------*/

static void i_OnMove(App *app, Event *e)
{
    const EvMouse *p = event_params(e, EvMouse);
    View *view = event_sender(e, View);
    col2dhello_mouse_collisions(app, p->x, p->y);
    view_update(view);
}

/*---------------------------------------------------------------------------*/

static void i_get_shape_pos(const Shape *shape, V2Df *pos)
{
    switch(shape->type) {
    case ekPOINT:
        pos->x = shape->body.pnt.x;
        pos->y = shape->body.pnt.y;
        break;

    case ekSEGMENT:
        pos->x = shape->body.seg.center.x;
        pos->y = shape->body.seg.center.y;
        break;

    case ekCIRCLE:
        pos->x = shape->body.cir.c.x;
        pos->y = shape->body.cir.c.y;
        break;

    case ekBOX:
        pos->x = shape->body.box.center.x;
        pos->y = shape->body.box.center.y;
        break;

    case ekOBB:
        pos->x = shape->body.obb.center.x;
        pos->y = shape->body.obb.center.y;
        break;

    case ekPOLY:
        pos->x = shape->body.pol.center.x;
        pos->y = shape->body.pol.center.y;
        break;

    cassert_default();
    }
}

/*---------------------------------------------------------------------------*/

static void i_set_shape_pos(Shape *shape, const V2Df *pos)
{
    switch(shape->type) {
    case ekPOINT:
        shape->body.pnt.x = pos->x;
        shape->body.pnt.y = pos->y;
        break;

    case ekSEGMENT:
        shape->body.seg.center.x = pos->x;
        shape->body.seg.center.y = pos->y;
        col2dhello_update_seg(&shape->body.seg);
        break;

    case ekCIRCLE:
        shape->body.cir.c.x = pos->x;
        shape->body.cir.c.y = pos->y;
        break;

    case ekBOX:
        shape->body.box.center.x = pos->x;
        shape->body.box.center.y = pos->y;
        col2dhello_update_box(&shape->body.box);
        break;

    case ekOBB:
        shape->body.obb.center.x = pos->x;
        shape->body.obb.center.y = pos->y;
        col2dhello_update_obb(&shape->body.obb);
        break;

    case ekPOLY:
        shape->body.pol.center.x = pos->x;
        shape->body.pol.center.y = pos->y;
        col2dhello_update_pol(&shape->body.pol);
        break;

    cassert_default();
    }
}

/*---------------------------------------------------------------------------*/

static void i_OnDown(App *app, Event *e)
{
    uint32_t selshape = UINT32_MAX;
    arrst_foreach(shape, app->shapes, Shape)
        if (shape->mouse == TRUE)
        {
            selshape = shape_i;
            break;
        }
    arrst_end();

    if (selshape != app->selshape)
    {
        View *view = event_sender(e, View);
        app->selshape = selshape;
        col2dhello_dbind_shape(app);
        view_update(view);
    }

    if (app->selshape != UINT32_MAX)
    {
        const EvMouse *p = event_params(e, EvMouse);
        const Shape *shape = arrst_get(app->shapes, app->selshape, Shape);
        app->mouse_pos.x = p->x;
        app->mouse_pos.y = p->y;
        i_get_shape_pos(shape, &app->obj_pos);
    }
}

/*---------------------------------------------------------------------------*/

static void i_OnDrag(App *app, Event *e)
{
    if (app->selshape != UINT32_MAX)
    {
        const EvMouse *p = event_params(e, EvMouse);
        Shape *shape = arrst_get(app->shapes, app->selshape, Shape);
        V2Df move = v2df(app->obj_pos.x + (p->x - app->mouse_pos.x), app->obj_pos.y + (p->y - app->mouse_pos.y));
        i_set_shape_pos(shape, &move);
        col2dhello_collisions(app);
        view_update(app->view);
    }
}

/*---------------------------------------------------------------------------*/

static Layout *i_layout(App *app)
{
    Layout *layout1 = layout_create(2, 1);
    Layout *layout2 = i_left_layout(app);
    View *view = view_create();
    view_size(view, s2df(640, 480));
    view_OnDraw(view, listener(app, i_OnDraw, App));
    view_OnMove(view, listener(app, i_OnMove, App));
    view_OnDown(view, listener(app, i_OnDown, App));
    view_OnDrag(view, listener(app, i_OnDrag, App));
    layout_layout(layout1, layout2, 0, 0);
    layout_view(layout1, view, 1, 0);
    layout_valign(layout1, 0, 0, ekTOP);
    layout_hexpand(layout1, 1);
    app->view = view;
    return layout1;
}

/*---------------------------------------------------------------------------*/

Window *col2dhello_window(App *app)
{
    Panel *panel = panel_create();
    Layout *layout = i_layout(app);
    Window *window = NULL;
    panel_layout(panel, layout);
    window = window_create(ekWNSRES, &panel);
    return window;
}

/*---------------------------------------------------------------------------*/

void col2dhello_dbind_shape(App *app)
{
    if (app->selshape != UINT32_MAX)
    {
        Shape *shape = arrst_get(app->shapes, app->selshape, Shape);
        switch(shape->type) {
        case ekPOINT:
            panel_visible_layout(app->obj_panel, 1);
            break;

        case ekSEGMENT:
            layout_dbind_obj(app->seg_layout, &shape->body.seg, Seg);
            panel_visible_layout(app->obj_panel, 2);
            break;

        case ekCIRCLE:
            layout_dbind_obj(app->cir_layout, &shape->body.cir, Cir2Df);
            panel_visible_layout(app->obj_panel, 3);
            break;

        case ekBOX:
            layout_dbind_obj(app->box_layout, &shape->body.box, Box);
            panel_visible_layout(app->obj_panel, 4);
            break;

        case ekOBB:
            layout_dbind_obj(app->obb_layout, &shape->body.obb, OBB);
            panel_visible_layout(app->obj_panel, 5);
            break;

        case ekPOLY:
            layout_dbind_obj(app->pol_layout, &shape->body.pol, Pol);
            panel_visible_layout(app->obj_panel, 6);
            break;

        cassert_default();
        }
    }
    else
    {
        layout_dbind_obj(app->seg_layout, NULL, Seg);
        layout_dbind_obj(app->cir_layout, NULL, Cir2Df);
        layout_dbind_obj(app->box_layout, NULL, Box);
        layout_dbind_obj(app->obb_layout, NULL, OBB);
        layout_dbind_obj(app->pol_layout, NULL, Pol);
        panel_visible_layout(app->obj_panel, 0);
    }

    panel_update(app->obj_panel);
}
❮ Back
Next ❯