use rustraight::prelude::*;
const TRANSPARENT: bool = false;
const TOPMOST: bool = false;
const DECORATIONS: bool = true;
const RESIZABLE: bool = true;
const VSYNC: bool = true;
fn main() {
init(WindowConfig {
title: String::from("01_window"),
width: 800,
height: 600,
screen_width: 400,
screen_height: 300,
transparent: TRANSPARENT,
topmost: TOPMOST,
decorations: DECORATIONS,
resizable: RESIZABLE,
vsync: VSYNC,
..Default::default()
});
log_info!(
"初期化完了: transparent={TRANSPARENT} topmost={TOPMOST} decorations={DECORATIONS} resizable={RESIZABLE} vsync={VSYNC}"
);
let mut cursor_visible = true;
while advance_frame() {
draw_fill(MAIN_SCREEN, Color::rgb(20, 20, 30));
let dt = delta_time();
let et = elapsed_time();
let (wx, wy) = window_position();
let (ww, wh) = window_size();
let (sw, sh) = screen_size();
draw_text(MAIN_SCREEN, 10, 10, format!("delta_time: {dt:.4}s"), Color::WHITE);
draw_text(MAIN_SCREEN, 10, 30, format!("elapsed_time: {et:.2}s"), Color::WHITE);
draw_text(MAIN_SCREEN, 10, 50, format!("window_position: ({wx}, {wy})"), Color::WHITE);
draw_text(MAIN_SCREEN, 10, 70, format!("window_size: ({ww}, {wh})"), Color::WHITE);
draw_text(MAIN_SCREEN, 10, 90, format!("screen_size: ({sw}, {sh})"), Color::WHITE);
draw_text(
MAIN_SCREEN, 10, 120,
"矢印: 移動 W/S: ウィンドウサイズ A/D: 仮想解像度 C: カーソル切替",
Color::YELLOW,
);
let move_speed = 4;
if is_pressed(KeyCode::ArrowLeft) { set_window_position(wx - move_speed, wy); }
if is_pressed(KeyCode::ArrowRight) { set_window_position(wx + move_speed, wy); }
if is_pressed(KeyCode::ArrowUp) { set_window_position(wx, wy - move_speed); }
if is_pressed(KeyCode::ArrowDown) { set_window_position(wx, wy + move_speed); }
if is_just_pressed(KeyCode::KeyW) { set_window_size(ww + 40, wh + 30); }
if is_just_pressed(KeyCode::KeyS) { set_window_size((ww - 40).max(160), (wh - 30).max(120)); }
if is_just_pressed(KeyCode::KeyD) { set_screen_size(sw + 40, sh + 30); }
if is_just_pressed(KeyCode::KeyA) { set_screen_size((sw - 40).max(80), (sh - 30).max(60)); }
if is_just_pressed(KeyCode::KeyC) {
cursor_visible = !cursor_visible;
show_cursor(cursor_visible);
}
draw_rectangle(MAIN_SCREEN, 0, 0, sw, sh, Color::CYAN, false);
}
}