panel->close_cb = NULL;
panel->min_w = w;
panel->min_h = h;
+ panel->corner = 0;
if( flags & VG_MAGI_PERSISTENT )
strcpy( panel->cmd, vg_console.input );
return panel;
}
+void _vg_magi_area_change( i32 d[2] )
+{
+ for( u32 i=0; i<_vg_magi.panel_count; i ++ )
+ {
+ struct vg_magi_panel *panel = &_vg_magi.panels[ i ];
+ if( panel->corner & 0x1 )
+ panel->rect[0] += d[0];
+ if( panel->corner & 0x2 )
+ panel->rect[1] += d[1];
+ }
+}
+
+static void vg_magi_getcorner( ui_rect rect, u32 id, ui_px corner[2] )
+{
+ corner[0] = rect[0];
+ corner[1] = rect[1];
+ if( id&0x1 ) corner[0] += rect[2];
+ if( id&0x2 ) corner[1] += rect[3];
+}
+
void _vg_magi_render( ui_context *ctx )
{
if( _vg_magi.panel_count == 0 ) return;
{
ptop->rect[0] = _vg_magi.drag_original[0] + ctx->mouse_delta[0];
ptop->rect[1] = _vg_magi.drag_original[1] + ctx->mouse_delta[1];
+
+ ui_rect vp = { 0,0, ctx->area[0],ctx->area[1] };
+
+ f32 min2 = 9999999.9f;
+ for( u32 i=0; i<4; i ++ )
+ {
+ ui_px c0[2], c1[2];
+ vg_magi_getcorner( vp, i, c0 );
+ vg_magi_getcorner( ptop->rect, i, c1 );
+
+ f32 dx = c0[0]-c1[0],
+ dy = c0[1]-c1[1],
+ d2 = dx*dx + dy*dy;
+
+ if( d2 < min2 )
+ {
+ min2 = d2;
+ ptop->corner = i;
+ }
+ }
}
else if( _vg_magi.mode == k_magi_mode_resize )
{
if( magi->flags & VG_MAGI_PERSISTENT )
{
+ ui_rect vp = {0,0,vg.window_x,vg.window_y};
+ ui_px c[2], p[2];
+ vg_magi_getcorner( vp, magi->corner, c );
+ p[0] = magi->rect[0] - c[0];
+ p[1] = magi->rect[1] - c[1];
+
fprintf( fp, "%s\n", magi->cmd );
- fprintf( fp, "magi_pos %d %d %d %d %d\n",
- magi->rect[0], magi->rect[1], magi->rect[2],
+ fprintf( fp, "magi_pos %d %d %d %d %d %d\n",
+ p[0], p[1], magi->rect[2],
magi->minimized? magi->sh: magi->rect[3],
- (i32)magi->minimized );
+ (i32)magi->minimized, magi->corner );
}
}
}
}
+ if( argc >= 6 )
+ {
+ ui_rect vp = {0,0,vg.window_x,vg.window_y};
+ ui_px c[2];
+ magi->corner = atoi( argv[5] );
+ vg_magi_getcorner( vp, magi->corner, c );
+ magi->rect[0] += c[0];
+ magi->rect[1] += c[1];
+ }
+
return 1;
}