make the color tuner actually change things live

This commit is contained in:
Dustin Carlino 2018-06-21 17:02:18 -07:00
parent 348f9a0a0f
commit 2770b59f85
4 changed files with 43 additions and 14 deletions

View File

@ -45,8 +45,7 @@
- https://gis-kingcounty.opendata.arcgis.com/datasets/traffic-signs--sign-point/ - https://gis-kingcounty.opendata.arcgis.com/datasets/traffic-signs--sign-point/
- multiple lanes - multiple lanes
- live color tuner - make a smaller GUI where it's easy to explore solving the multiline problem
- mutate color scheme
- model bikes in driving lanes (as slow cars) - model bikes in driving lanes (as slow cars)
- add random bike lanes, figure out how turns would work - add random bike lanes, figure out how turns would work

View File

@ -10,7 +10,7 @@ use std::io::{Error, Read, Write};
use strum::IntoEnumIterator; use strum::IntoEnumIterator;
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, EnumIter, EnumString, ToString, #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, EnumIter, EnumString, ToString,
PartialOrd, Ord)] PartialOrd, Ord, Clone, Copy)]
pub enum Colors { pub enum Colors {
Debug, Debug,
BrightDebug, BrightDebug,
@ -88,4 +88,8 @@ impl ColorScheme {
// TODO make sure this isn't slow; maybe back this with an array // TODO make sure this isn't slow; maybe back this with an array
*self.map.get(&c).unwrap() *self.map.get(&c).unwrap()
} }
pub fn set(&mut self, c: Colors, value: Color) {
self.map.insert(c, value);
}
} }

View File

@ -1,6 +1,6 @@
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0 // 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::canvas::{Canvas, GfxCtx};
use ezgui::input::UserInput; use ezgui::input::UserInput;
use ezgui::menu; use ezgui::menu;
@ -20,7 +20,8 @@ const TILE_DIMS: u32 = 2;
pub enum ColorPicker { pub enum ColorPicker {
Inactive, Inactive,
Choosing(menu::Menu), Choosing(menu::Menu),
PickingColor(Colors), // Remember the original color, in case we revert
PickingColor(Colors, graphics::types::Color),
} }
impl ColorPicker { impl ColorPicker {
@ -28,7 +29,12 @@ impl ColorPicker {
ColorPicker::Inactive 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 { match self {
ColorPicker::Inactive => { ColorPicker::Inactive => {
if input.unimportant_key_pressed(Key::D8, "Press 8 to configure colors") { 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::Canceled => ColorPicker::Inactive,
menu::Result::StillActive => ColorPicker::Choosing(menu), menu::Result::StillActive => ColorPicker::Choosing(menu),
menu::Result::Done(choice) => { 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) => { ColorPicker::PickingColor(c, orig_color) => {
// TODO be able to confirm a choice and edit the ColorScheme if input.key_pressed(
if input.key_pressed(Key::D8, "Press 8 to stop configuring colors") { 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; return ColorPicker::Inactive;
} }
@ -60,11 +81,12 @@ impl ColorPicker {
let x = (pos[0] - (start_x as f64)) / (TILE_DIMS as f64) / 255.0; 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; 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 { 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 // TODO would be nice to display the text in the current color
canvas.draw_mouse_tooltip(g, &menu.lines_to_display()); canvas.draw_mouse_tooltip(g, &menu.lines_to_display());
} }
ColorPicker::PickingColor(_) => { ColorPicker::PickingColor(_, _) => {
let (start_x, start_y) = get_screen_offset(&g.window_size); let (start_x, start_y) = get_screen_offset(&g.window_size);
for x in 0..WIDTH { for x in 0..WIDTH {

View File

@ -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); self.current_search_state = self.current_search_state.event(input);
if !edit_mode if !edit_mode
@ -235,7 +240,6 @@ impl UI {
self.steepness_active.handle_event(input); self.steepness_active.handle_event(input);
self.osm_classifier_active.handle_event(input); self.osm_classifier_active.handle_event(input);
self.debug_mode.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 { if old_zoom >= MIN_ZOOM_FOR_MOUSEOVER && new_zoom < MIN_ZOOM_FOR_MOUSEOVER {