• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

SOLVED [DISCUSSION] I need opinions (and help) regarding building an interface (views, surfaces, cameras, Draw GUI...)

FoxyOfJungle

Kazan Games
Hello !
Look at this interface image:

This is an interface.




I want to use the DRAW GUI event to draw ALL the interface of the program I'm doing (everything inside it...), however, I need to draw the camera view in this middle area (where is the rabbit).


The questions:

1 - How would I do to draw the camera view in that area? (I want to draw the camera view on the surface. This camera will see a part of the room, which is not the GUI).
2 - How many cameras will I need to do all this? Just one, right?
(EDIT: I SOLVED THE 1 AND 2)

3 - If I change the window size, how do I keep the aspect ratio of the camera (that is inside the surface)?



I was looking at view_surface_id, but I don't know if it is exactly like that... (maybe it is but I need opinions). I need opinions to find out the best way.


See, I managed to get the GUI to 1:1 scale:




I did it this way:

GML:
/// ======= CREATE EVENT =======
// get current window size
window_old_width = window_get_width();
window_old_height = window_get_width();


// init camera
target_view = 0;
click_x = 0;
click_y = 0;
zoom_level = 1;

// enable the use of views
view_enabled = true;

// make view 0 visible
view_set_visible(target_view, true);

// set the port bounds of view 0 to 1280x720
view_set_wport(target_view, 1280);
view_set_hport(target_view, 720);

// resize and center
window_set_rectangle((display_get_width() - view_wport[target_view]) * 0.5, (display_get_height() - view_hport[target_view]) * 0.5, view_wport[target_view], view_hport[target_view]);
surface_resize(application_surface, view_wport[target_view], view_hport[target_view]);


// Camera Creation
// build a camera at (0,0), with size 640x480, 0 degrees of angle, no target instance, instant-jupming hspeed and vspeed, with a 32 pixel border
camera = camera_create_view(32, 32, 1280, 720, 0, -1, -1, -1, 32, 32);

// set view0 to use the camera "camera"
view_set_camera(target_view, camera);

// bind the bad screenshake
// camera_set_begin_script(view_camera[target_view],-1);

// zoom variables
zoom_level = 1;
default_zoom_width = camera_get_view_width(view_camera[0]);
default_zoom_height = camera_get_view_height(view_camera[0]);




/// ======= STEP EVENT =======

// WINDOW MANAGE
// limite size
var _ww = window_get_width()
var _hh = window_get_height()

if (_ww < 640)
{
    window_set_size(640, window_get_height());
}

if (_hh < 480)
{
    window_set_size(window_get_width(), 480);
}

// auto resize
if !(window_old_width == _ww) || !(window_old_height == _hh)
{
    display_set_gui_size(_ww,_hh);
    surface_resize(application_surface,_ww,_hh);
    window_old_width = _ww;
    window_old_height = _hh;
}


/// CONTROL WORKPLACE CAMERA
// check if the mouse is clicked. If so, update the click position.
if (mouse_check_button_pressed(mb_middle))
{
    click_x = mouse_x;
    click_y = mouse_y;
}


// get target view position and size. size is halved so the view will focus around its center
var vpos_x = camera_get_view_x(view_camera[target_view]);
var vpos_y = camera_get_view_y(view_camera[target_view]);
var vpos_w = camera_get_view_width(view_camera[target_view]) /2;
var vpos_h = camera_get_view_height(view_camera[target_view]) /2;


// the interpolation rate
var rate = 0.2;


// interpolate the view position to the new, relative position.
var new_x = lerp(vpos_x, click_x - vpos_w, rate);
var new_y = lerp(vpos_y, click_y - vpos_h, rate);


// update the viewposition
camera_set_view_pos(view_camera[target_view], new_x, new_y);


// move the zoom level based on mouse scrolling. Clamp the value so stuff doesn't get too silly.
zoom_level = clamp(zoom_level + (((mouse_wheel_down() - mouse_wheel_up())) / 8), 0.1, 3);


// get current size
var view_w = camera_get_view_width(view_camera[target_view]);
var view_h = camera_get_view_height(view_camera[target_view]);


// set the rate of interpolation
var rate = 0.2;


// get new sizes by lerping current and target zoomed size
var new_w = lerp(view_w, zoom_level * default_zoom_width, rate);
var new_h = lerp(view_h, zoom_level * default_zoom_height, rate);


// apply the new size
camera_set_view_size(view_camera[target_view], new_w, new_h);


// get the shift necessary to re-align the view.
var shift_x = camera_get_view_x(view_camera[target_view]) - (new_w - view_w) /2;
var shift_y = camera_get_view_y(view_camera[target_view]) - (new_h - view_h) /2;


// update the view position
camera_set_view_pos(view_camera[target_view],shift_x, shift_y);

Thank you very much for any help!
 
Last edited:

FoxyOfJungle

Kazan Games
I solved this:





However, I have a problem locating the mouse position in the room, so I created a different new topic:

 
Top