Add some commentoriorio
This commit is contained in:
parent
2ba7fd0536
commit
a11ca66819
2 changed files with 13 additions and 1 deletions
|
@ -35,6 +35,8 @@ impl Widget for PaletteEditorWidget {
|
||||||
|
|
||||||
fn init_view(&mut self) {
|
fn init_view(&mut self) {
|
||||||
self.model.draw_handler.init(&self.drawing_area);
|
self.model.draw_handler.init(&self.drawing_area);
|
||||||
|
|
||||||
|
// Tell the DrawingArea that we're interested in ButtonPress events.
|
||||||
self.drawing_area
|
self.drawing_area
|
||||||
.add_events(gdk::EventMask::BUTTON_PRESS_MASK.bits() as i32);
|
.add_events(gdk::EventMask::BUTTON_PRESS_MASK.bits() as i32);
|
||||||
}
|
}
|
||||||
|
@ -69,6 +71,7 @@ impl Widget for PaletteEditorWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
PaletteEditorMsg::ButtonPress(event) => {
|
PaletteEditorMsg::ButtonPress(event) => {
|
||||||
|
// Calculate the palette index from the mouse coordinates.
|
||||||
let scale = self.get_scale();
|
let scale = self.get_scale();
|
||||||
let (x, y) = event.get_coords().unwrap();
|
let (x, y) = event.get_coords().unwrap();
|
||||||
|
|
||||||
|
@ -77,6 +80,7 @@ impl Widget for PaletteEditorWidget {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Open the ColorChooserDialog.
|
||||||
if let Some(window) = &self.model.window {
|
if let Some(window) = &self.model.window {
|
||||||
let dialog = gtk::ColorChooserDialog::new(Some("Select a color"), Some(window));
|
let dialog = gtk::ColorChooserDialog::new(Some("Select a color"), Some(window));
|
||||||
dialog.set_rgba(&util::palette_to_gdk_rgba(&self.model.palette, i));
|
dialog.set_rgba(&util::palette_to_gdk_rgba(&self.model.palette, i));
|
||||||
|
@ -84,6 +88,9 @@ impl Widget for PaletteEditorWidget {
|
||||||
let result = dialog.run();
|
let result = dialog.run();
|
||||||
if result == gtk_sys::GTK_RESPONSE_OK {
|
if result == gtk_sys::GTK_RESPONSE_OK {
|
||||||
let new_color = util::gdk_rgba_to_r5g5b5(&dialog.get_rgba());
|
let new_color = util::gdk_rgba_to_r5g5b5(&dialog.get_rgba());
|
||||||
|
|
||||||
|
// Emit a PaletteUpdate message with the new color so
|
||||||
|
// all relevant widgets can update their palettes.
|
||||||
self.model
|
self.model
|
||||||
.relm
|
.relm
|
||||||
.stream()
|
.stream()
|
||||||
|
@ -113,7 +120,9 @@ impl Widget for PaletteEditorWidget {
|
||||||
#[name="drawing_area"]
|
#[name="drawing_area"]
|
||||||
gtk::DrawingArea {
|
gtk::DrawingArea {
|
||||||
draw(_, _) => (PaletteEditorMsg::Draw, Inhibit(false)),
|
draw(_, _) => (PaletteEditorMsg::Draw, Inhibit(false)),
|
||||||
button_press_event(_, event) => (PaletteEditorMsg::ButtonPress(event.clone()), Inhibit(false)),
|
|
||||||
|
button_press_event(_, event) =>
|
||||||
|
(PaletteEditorMsg::ButtonPress(event.clone()), Inhibit(false)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,8 @@ impl Widget for SpriteEditorWidget {
|
||||||
fn model() -> SpriteEditorModel {
|
fn model() -> SpriteEditorModel {
|
||||||
SpriteEditorModel {
|
SpriteEditorModel {
|
||||||
draw_handler: DrawHandler::new().unwrap(),
|
draw_handler: DrawHandler::new().unwrap(),
|
||||||
|
|
||||||
|
// TODO Replace with real sprite data.
|
||||||
sprite_data: vec![
|
sprite_data: vec![
|
||||||
vec![0, 2, 2, 2, 2, 2, 2, 2],
|
vec![0, 2, 2, 2, 2, 2, 2, 2],
|
||||||
vec![0, 0, 0, 0, 14, 2, 14, 2],
|
vec![0, 0, 0, 0, 14, 2, 14, 2],
|
||||||
|
@ -35,6 +37,7 @@ impl Widget for SpriteEditorWidget {
|
||||||
vec![0, 0, 0, 2, 2, 2, 2, 14],
|
vec![0, 0, 0, 2, 2, 2, 2, 14],
|
||||||
vec![0, 0, 0, 0, 0, 10, 3, 3],
|
vec![0, 0, 0, 0, 0, 10, 3, 3],
|
||||||
],
|
],
|
||||||
|
|
||||||
sprite_size: 8,
|
sprite_size: 8,
|
||||||
palette: vec![0; 16],
|
palette: vec![0; 16],
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue