examples: support better placment and scaling on nonsquare viewports in cube.v (#8513)
parent
17062dc5c8
commit
975206f38e
|
@ -270,14 +270,16 @@ fn cube_field(app App){
|
|||
}
|
||||
|
||||
fn frame(mut app App) {
|
||||
dw := app.gg.width
|
||||
dh := app.gg.height
|
||||
ww := dh/2 /* not a bug */
|
||||
hh := dh/2
|
||||
x0 := dw/2 - hh
|
||||
ws := gg.window_size()
|
||||
ratio := f32(ws.width)/ws.height
|
||||
dw := ws.width
|
||||
dh := ws.height
|
||||
ww := int(dh/3) /* not a bug */
|
||||
hh := int(dh/3)
|
||||
x0 := int(f32(dw) * 0.05)
|
||||
//x1 := dw/2
|
||||
y0 := 0
|
||||
y1 := dh/2
|
||||
y1 := int(f32(dh) * 0.5)
|
||||
|
||||
app.gg.begin()
|
||||
//sgl.defaults()
|
||||
|
@ -291,11 +293,11 @@ fn frame(mut app App) {
|
|||
draw_cubes(app)
|
||||
|
||||
// textured cubed with viewport
|
||||
sgl.viewport(0, 0, dw, dh, true)
|
||||
sgl.viewport(0, int(dh/5), dw, int(dh*ratio), true)
|
||||
draw_texture_cubes(app)
|
||||
|
||||
// textured field of cubes with viewport
|
||||
sgl.viewport(0, 0, dw, dh, true)
|
||||
sgl.viewport(0, int(dh/5), dw, int(dh*ratio), true)
|
||||
cube_field(app)
|
||||
|
||||
app.frame_count++
|
||||
|
@ -386,6 +388,13 @@ fn my_event_manager(mut ev sapp.Event, mut app App) {
|
|||
app.mouse_x = int(ev.mouse_x)
|
||||
app.mouse_y = int(ev.mouse_y)
|
||||
}
|
||||
if ev.typ == .touches_began || ev.typ == .touches_moved {
|
||||
if ev.num_touches > 0 {
|
||||
touch_point := ev.touches[0]
|
||||
app.mouse_x = int(touch_point.pos_x)
|
||||
app.mouse_y = int(touch_point.pos_y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
|
|
Loading…
Reference in New Issue