box swap
This commit is contained in:
+35
-22
@@ -5,31 +5,44 @@ use emmaemu::{
|
||||
use imgui::*;
|
||||
use ratatui::symbols::half_block;
|
||||
use sys::{ImColor, ImVec2, ImVector_ImU32};
|
||||
|
||||
use support::emmagui_support::EmmaGui;
|
||||
mod support;
|
||||
fn main() {
|
||||
let system = Chip8Computer::default();
|
||||
|
||||
fn hello_world_window(ui: &Ui) {
|
||||
|
||||
let mut value = 1;
|
||||
let choices = ["test test this is 1", "test test this is 2"];
|
||||
support::simple_init(file!(), move |_, ui| {
|
||||
ui.window("EmmaGui")
|
||||
.size([300.0, 110.0], Condition::FirstUseEver)
|
||||
.build(|| {
|
||||
system.memory.gui_render(ui);
|
||||
ui.text_wrapped("Hello world!");
|
||||
ui.text_wrapped("こんにちは世界!");
|
||||
if ui.button(choices[value]) {
|
||||
value += 1;
|
||||
value %= 2;
|
||||
}
|
||||
ui.window("EmmaGui")
|
||||
.size([300.0, 110.0], Condition::FirstUseEver)
|
||||
.build(|| {
|
||||
ui.text_wrapped("Hello world!");
|
||||
ui.text_wrapped("こんにちは世界!");
|
||||
if ui.button(choices[value]) {
|
||||
value += 1;
|
||||
value %= 2;
|
||||
}
|
||||
|
||||
ui.button("This...is...imgui-rs!");
|
||||
ui.separator();
|
||||
let mouse_pos = ui.io().mouse_pos;
|
||||
ui.text(format!(
|
||||
"Mouse Position: ({:.1},{:.1})",
|
||||
mouse_pos[0], mouse_pos[1]
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
let system = Chip8Computer::default();
|
||||
support::simple_init(file!(), move |_, ui| {
|
||||
|
||||
hello_world_window(ui);
|
||||
|
||||
EmmaGui::SystemMemoryRender(system.memory, ui);
|
||||
|
||||
|
||||
system.memory.gui_render(ui);
|
||||
|
||||
ui.button("This...is...imgui-rs!");
|
||||
ui.separator();
|
||||
let mouse_pos = ui.io().mouse_pos;
|
||||
ui.text(format!(
|
||||
"Mouse Position: ({:.1},{:.1})",
|
||||
mouse_pos[0], mouse_pos[1]
|
||||
));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
use imgui::{Condition, ImColor32, Ui};
|
||||
use emmaemu::chip8::system_memory::Chip8SystemMemory;
|
||||
use emmaemu::constants::{CHIP8_VIDEO_HEIGHT, CHIP8_VIDEO_WIDTH};
|
||||
|
||||
pub struct EmmaGui {}
|
||||
const cell_width: i32 = 5i32;
|
||||
const cell_height: i32 = 5i32;
|
||||
|
||||
impl EmmaGui {
|
||||
pub fn SystemMemoryRender(memory: Chip8SystemMemory, ui: &Ui) {
|
||||
ui.window("System Memory")
|
||||
.size([300.0, 100.0], Condition::FirstUseEver)
|
||||
.build(|| {
|
||||
ui.text("Rendering System Memory Here");
|
||||
let draw_list = ui.get_foreground_draw_list();
|
||||
let mut idx = 0;
|
||||
for row in 0..CHIP8_VIDEO_HEIGHT {
|
||||
for column in 0..CHIP8_VIDEO_WIDTH {
|
||||
let x_offset = column * cell_width;
|
||||
let y_offset = row * cell_width;
|
||||
let start_point = [x_offset as f32, y_offset as f32];
|
||||
let end_point = [(x_offset + cell_width) as f32,
|
||||
(y_offset + cell_height) as f32
|
||||
];
|
||||
let memory_offset = (row * CHIP8_VIDEO_WIDTH) + column;
|
||||
let target_color = if memory.peek(memory_offset as u16) == 0 {
|
||||
ImColor32::BLACK
|
||||
} else {
|
||||
ImColor32::WHITE
|
||||
};
|
||||
draw_list.add_rect([x_offset as f32, y_offset as f32],
|
||||
[(x_offset + cell_width) as f32, (y_offset + cell_height) as f32],
|
||||
target_color).build();
|
||||
idx += 1;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ use std::path::Path;
|
||||
use std::time::Instant;
|
||||
|
||||
pub mod clipboard;
|
||||
pub mod emmagui_support;
|
||||
|
||||
pub const FONT_SIZE: f32 = 13.0;
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use imgui::Ui;
|
||||
use glium::RawUniformValue::Vec2;
|
||||
use imgui::sys::ImColor;
|
||||
use imgui::{ImColor32, Ui};
|
||||
use ratatui::{style::Style, widgets::Widget};
|
||||
|
||||
use crate::constants::{CHIP8_MEMORY_SIZE, CHIP8_VIDEO_HEIGHT, CHIP8_VIDEO_WIDTH};
|
||||
@@ -52,25 +54,6 @@ const cell_height: i32 = 5i32;
|
||||
|
||||
impl Chip8SystemMemory {
|
||||
pub fn gui_render(self, ui: &Ui) {
|
||||
let draw_list = ui.get_foreground_draw_list();
|
||||
let mut idx = 0;
|
||||
for row in 0..CHIP8_VIDEO_HEIGHT {
|
||||
for column in 0..CHIP8_VIDEO_HEIGHT {
|
||||
let x_offset = (row * cell_width) + column;
|
||||
let y_offset = (row * cell_width);
|
||||
let memory_offset = (row * CHIP8_VIDEO_WIDTH) + column;
|
||||
println!(
|
||||
"DRAWING IDX: {} {}x{} to {}x{} with {}",
|
||||
idx,
|
||||
x_offset,
|
||||
y_offset,
|
||||
x_offset + cell_width,
|
||||
y_offset + cell_height,
|
||||
self.memory[memory_offset as usize]
|
||||
);
|
||||
idx += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn peek(self, address: u16) -> u8 {
|
||||
|
||||
Reference in New Issue
Block a user