mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 03:35:51 +03:00
make the color tuner actually change things live
This commit is contained in:
parent
348f9a0a0f
commit
2770b59f85
3
TODO.md
3
TODO.md
@ -45,8 +45,7 @@
|
||||
- https://gis-kingcounty.opendata.arcgis.com/datasets/traffic-signs--sign-point/
|
||||
|
||||
- multiple lanes
|
||||
- live color tuner
|
||||
- mutate color scheme
|
||||
- make a smaller GUI where it's easy to explore solving the multiline problem
|
||||
|
||||
- model bikes in driving lanes (as slow cars)
|
||||
- add random bike lanes, figure out how turns would work
|
||||
|
@ -10,7 +10,7 @@ use std::io::{Error, Read, Write};
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, EnumIter, EnumString, ToString,
|
||||
PartialOrd, Ord)]
|
||||
PartialOrd, Ord, Clone, Copy)]
|
||||
pub enum Colors {
|
||||
Debug,
|
||||
BrightDebug,
|
||||
@ -88,4 +88,8 @@ impl ColorScheme {
|
||||
// TODO make sure this isn't slow; maybe back this with an array
|
||||
*self.map.get(&c).unwrap()
|
||||
}
|
||||
|
||||
pub fn set(&mut self, c: Colors, value: Color) {
|
||||
self.map.insert(c, value);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
use colors::Colors;
|
||||
use colors::{ColorScheme, Colors};
|
||||
use ezgui::canvas::{Canvas, GfxCtx};
|
||||
use ezgui::input::UserInput;
|
||||
use ezgui::menu;
|
||||
@ -20,7 +20,8 @@ const TILE_DIMS: u32 = 2;
|
||||
pub enum ColorPicker {
|
||||
Inactive,
|
||||
Choosing(menu::Menu),
|
||||
PickingColor(Colors),
|
||||
// Remember the original color, in case we revert
|
||||
PickingColor(Colors, graphics::types::Color),
|
||||
}
|
||||
|
||||
impl ColorPicker {
|
||||
@ -28,7 +29,12 @@ impl ColorPicker {
|
||||
ColorPicker::Inactive
|
||||
}
|
||||
|
||||
pub fn handle_event(self, input: &mut UserInput, window_size: &Size) -> ColorPicker {
|
||||
pub fn handle_event(
|
||||
self,
|
||||
input: &mut UserInput,
|
||||
window_size: &Size,
|
||||
cs: &mut ColorScheme,
|
||||
) -> ColorPicker {
|
||||
match self {
|
||||
ColorPicker::Inactive => {
|
||||
if input.unimportant_key_pressed(Key::D8, "Press 8 to configure colors") {
|
||||
@ -44,13 +50,28 @@ impl ColorPicker {
|
||||
menu::Result::Canceled => ColorPicker::Inactive,
|
||||
menu::Result::StillActive => ColorPicker::Choosing(menu),
|
||||
menu::Result::Done(choice) => {
|
||||
ColorPicker::PickingColor(Colors::from_str(&choice).unwrap())
|
||||
let c = Colors::from_str(&choice).unwrap();
|
||||
ColorPicker::PickingColor(c, cs.get(c))
|
||||
}
|
||||
}
|
||||
}
|
||||
ColorPicker::PickingColor(color) => {
|
||||
// TODO be able to confirm a choice and edit the ColorScheme
|
||||
if input.key_pressed(Key::D8, "Press 8 to stop configuring colors") {
|
||||
ColorPicker::PickingColor(c, orig_color) => {
|
||||
if input.key_pressed(
|
||||
Key::Escape,
|
||||
&format!(
|
||||
"Press escape to stop configuring color for {:?} and revert",
|
||||
c
|
||||
),
|
||||
) {
|
||||
cs.set(c, orig_color);
|
||||
return ColorPicker::Inactive;
|
||||
}
|
||||
|
||||
if input.key_pressed(
|
||||
Key::Return,
|
||||
&format!("Press enter to finalize new color for {:?}", c),
|
||||
) {
|
||||
println!("Setting color for {:?}", c);
|
||||
return ColorPicker::Inactive;
|
||||
}
|
||||
|
||||
@ -60,11 +81,12 @@ impl ColorPicker {
|
||||
let x = (pos[0] - (start_x as f64)) / (TILE_DIMS as f64) / 255.0;
|
||||
let y = (pos[1] - (start_y as f64)) / (TILE_DIMS as f64) / 255.0;
|
||||
if x >= 0.0 && x <= 1.0 && y >= 0.0 && y <= 1.0 {
|
||||
println!("current color is {:?}", get_color(x as f32, y as f32));
|
||||
cs.set(c, get_color(x as f32, y as f32));
|
||||
return ColorPicker::PickingColor(c, orig_color);
|
||||
}
|
||||
}
|
||||
|
||||
ColorPicker::PickingColor(color)
|
||||
ColorPicker::PickingColor(c, orig_color)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -78,7 +100,7 @@ impl ColorPicker {
|
||||
// TODO would be nice to display the text in the current color
|
||||
canvas.draw_mouse_tooltip(g, &menu.lines_to_display());
|
||||
}
|
||||
ColorPicker::PickingColor(_) => {
|
||||
ColorPicker::PickingColor(_, _) => {
|
||||
let (start_x, start_y) = get_screen_offset(&g.window_size);
|
||||
|
||||
for x in 0..WIDTH {
|
||||
|
@ -189,6 +189,11 @@ impl UI {
|
||||
}
|
||||
}
|
||||
|
||||
if !edit_mode {
|
||||
self.color_picker = self.color_picker
|
||||
.handle_event(input, window_size, &mut self.cs);
|
||||
}
|
||||
|
||||
self.current_search_state = self.current_search_state.event(input);
|
||||
|
||||
if !edit_mode
|
||||
@ -235,7 +240,6 @@ impl UI {
|
||||
self.steepness_active.handle_event(input);
|
||||
self.osm_classifier_active.handle_event(input);
|
||||
self.debug_mode.handle_event(input);
|
||||
self.color_picker = self.color_picker.handle_event(input, window_size);
|
||||
}
|
||||
|
||||
if old_zoom >= MIN_ZOOM_FOR_MOUSEOVER && new_zoom < MIN_ZOOM_FOR_MOUSEOVER {
|
||||
|
Loading…
Reference in New Issue
Block a user