extern crate sdl2;
use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use sdl2::pixels::Color;
use sdl2::rect::Point;
use std::time::Duration;
#[cfg(target_os = "android")]
use android_activity::{AndroidApp, MainEvent, PollEvent};
#[cfg(target_os = "android")]
#[no_mangle]
fn android_main(_app: AndroidApp) {
main();
}
fn main() {
println!("🤖 SevenX Android SDL2 Demo");
let sdl_context = sdl2::init().unwrap();
let video_subsystem = sdl_context.video().unwrap();
#[cfg(target_os = "android")]
let window = video_subsystem
.window("SevenX Android SDL2", 0, 0)
.fullscreen_desktop()
.build()
.unwrap();
#[cfg(not(target_os = "android"))]
let window = video_subsystem
.window("SevenX Android SDL2", 800, 600)
.position_centered()
.build()
.unwrap();
let mut canvas = window.into_canvas().build().unwrap();
let mut event_pump = sdl_context.event_pump().unwrap();
let mut score = 0;
let mut touches: Vec<Point> = Vec::new();
println!("✅ SDL2 inicializado!");
'running: loop {
for event in event_pump.poll_iter() {
match event {
Event::Quit { .. }
| Event::KeyDown {
keycode: Some(Keycode::Escape),
..
} => break 'running,
Event::MouseButtonDown { x, y, .. } => {
println!("👆 Touch/Click: ({}, {})", x, y);
touches.push(Point::new(x, y));
score += 10;
}
Event::MouseMotion { x, y, mousestate, .. } => {
if mousestate.left() {
touches.push(Point::new(x, y));
}
}
Event::FingerDown { x, y, .. } => {
let (w, h) = canvas.output_size().unwrap();
let px = (x * w as f32) as i32;
let py = (y * h as f32) as i32;
println!("👆 Touch: ({}, {})", px, py);
touches.push(Point::new(px, py));
score += 10;
}
Event::FingerMotion { x, y, .. } => {
let (w, h) = canvas.output_size().unwrap();
let px = (x * w as f32) as i32;
let py = (y * h as f32) as i32;
touches.push(Point::new(px, py));
}
_ => {}
}
}
canvas.set_draw_color(Color::RGB(20, 25, 35));
canvas.clear();
canvas.set_draw_color(Color::RGB(255, 100, 100));
for touch in &touches {
for angle in 0..360 {
let rad = (angle as f32).to_radians();
let x = touch.x + (rad.cos() * 20.0) as i32;
let y = touch.y + (rad.sin() * 20.0) as i32;
canvas.draw_point(Point::new(x, y)).ok();
}
}
canvas.set_draw_color(Color::RGB(255, 255, 255));
let score_text = format!("Score: {}", score);
println!("{} | Touches: {}", score_text, touches.len());
canvas.set_draw_color(Color::RGB(100, 200, 255));
for i in 0..5 {
canvas.draw_line(Point::new(10 + i, 10), Point::new(200 + i, 10)).ok();
}
canvas.present();
if touches.len() > 100 {
touches.drain(0..50);
}
::std::thread::sleep(Duration::from_millis(16));
}
println!("👋 Encerrando SDL2");
}