Support choosing colors
This commit is contained in:
+42
-2
@@ -3,7 +3,7 @@ use crate::{
|
||||
emulator::{EmulatorClient, EmulatorCommand, SimId},
|
||||
};
|
||||
use egui::{
|
||||
menu, Button, CentralPanel, Color32, Context, Frame, Response, TopBottomPanel, Ui,
|
||||
menu, Button, CentralPanel, Color32, Context, Frame, Response, Sense, TopBottomPanel, Ui, Vec2,
|
||||
ViewportBuilder, ViewportCommand, ViewportId, WidgetText,
|
||||
};
|
||||
use winit::event_loop::EventLoopProxy;
|
||||
@@ -13,11 +13,27 @@ use super::{
|
||||
AppWindow,
|
||||
};
|
||||
|
||||
const COLOR_PRESETS: [[Color32; 2]; 3] = [
|
||||
[
|
||||
Color32::from_rgb(0xff, 0x00, 0x00),
|
||||
Color32::from_rgb(0x00, 0xc6, 0xf0),
|
||||
],
|
||||
[
|
||||
Color32::from_rgb(0x00, 0xb4, 0x00),
|
||||
Color32::from_rgb(0xc8, 0x00, 0xff),
|
||||
],
|
||||
[
|
||||
Color32::from_rgb(0xb4, 0x9b, 0x00),
|
||||
Color32::from_rgb(0x00, 0x00, 0xff),
|
||||
],
|
||||
];
|
||||
|
||||
pub struct GameWindow {
|
||||
client: EmulatorClient,
|
||||
proxy: EventLoopProxy<UserEvent>,
|
||||
sim_id: SimId,
|
||||
display_mode: DisplayMode,
|
||||
colors: [Color32; 2],
|
||||
screen: Option<GameScreen>,
|
||||
}
|
||||
|
||||
@@ -28,6 +44,7 @@ impl GameWindow {
|
||||
proxy,
|
||||
sim_id,
|
||||
display_mode: DisplayMode::Anaglyph,
|
||||
colors: COLOR_PRESETS[0],
|
||||
screen: None,
|
||||
}
|
||||
}
|
||||
@@ -104,6 +121,13 @@ impl GameWindow {
|
||||
ui.close_menu();
|
||||
}
|
||||
});
|
||||
ui.menu_button("Colors", |ui| {
|
||||
for preset in COLOR_PRESETS {
|
||||
if ui.color_pair_button(preset[0], preset[1]).clicked() {
|
||||
self.colors = preset;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.menu_button("Audio", |ui| {
|
||||
let p1_enabled = self.client.is_audio_enabled(SimId::Player1);
|
||||
@@ -175,7 +199,7 @@ impl AppWindow for GameWindow {
|
||||
let frame = Frame::central_panel(&ctx.style()).fill(Color32::BLACK);
|
||||
CentralPanel::default().frame(frame).show(ctx, |ui| {
|
||||
if let Some(screen) = self.screen.as_mut() {
|
||||
screen.display_mode = self.display_mode;
|
||||
screen.update(self.display_mode, self.colors);
|
||||
ui.add(screen);
|
||||
}
|
||||
});
|
||||
@@ -209,6 +233,8 @@ trait UiExt {
|
||||
}
|
||||
response
|
||||
}
|
||||
|
||||
fn color_pair_button(&mut self, left: Color32, right: Color32) -> Response;
|
||||
}
|
||||
|
||||
impl UiExt for Ui {
|
||||
@@ -219,4 +245,18 @@ impl UiExt for Ui {
|
||||
let mut selected = selected;
|
||||
self.checkbox(&mut selected, text)
|
||||
}
|
||||
|
||||
fn color_pair_button(&mut self, left: Color32, right: Color32) -> Response {
|
||||
let button_size = Vec2::new(60.0, 20.0);
|
||||
let (rect, response) = self.allocate_at_least(button_size, Sense::click());
|
||||
let center_x = rect.center().x;
|
||||
let left_rect = rect.with_max_x(center_x);
|
||||
self.painter().rect_filled(left_rect, 0.0, left);
|
||||
let right_rect = rect.with_min_x(center_x);
|
||||
self.painter().rect_filled(right_rect, 0.0, right);
|
||||
|
||||
let style = self.style().interact(&response);
|
||||
self.painter().rect_stroke(rect, 0.0, style.fg_stroke);
|
||||
response
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user