Skip to content

Commit

Permalink
use eframe 0.27
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDavenport committed Apr 23, 2024
1 parent 8d31ea0 commit 525f0f6
Show file tree
Hide file tree
Showing 18 changed files with 156 additions and 445 deletions.
383 changes: 38 additions & 345 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion gamercade_editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ gamercade_sound_engine = { path = "../gamercade_sound_engine" }
serde = { version = "1.0.198", features = ["derive"] }

# Window and Rendering
eframe = "0.22.0"
eframe = "0.27.2"
egui_plot = "0.27.2"

# File Dialogs
rfd = "0.14.1"
Expand Down
6 changes: 4 additions & 2 deletions gamercade_editor/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use eframe::epaint::Vec2;
use eframe::{egui::ViewportBuilder, epaint::Vec2};
use ui::Editor;

mod ui;

fn main() {
let viewport = ViewportBuilder::default().with_inner_size(Vec2::new(1366.0, 768.0));

let options = eframe::NativeOptions {
vsync: true,
initial_window_size: Some(Vec2::new(1366.0, 768.0)),
viewport,
..Default::default()
};

Expand Down
5 changes: 3 additions & 2 deletions gamercade_editor/src/ui/audio/instrument_editor/fm_editor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use eframe::{
egui::{ComboBox, Image, Slider, TextureFilter, TextureOptions, Ui, Window},
egui::{ComboBox, Image, Slider, TextureFilter, TextureOptions, TextureWrapMode, Ui, Window},
epaint::{ColorImage, TextureHandle, Vec2},
};
use gamercade_audio::{
Expand Down Expand Up @@ -54,12 +54,13 @@ impl FMHelp {
TextureOptions {
magnification: TextureFilter::Nearest,
minification: TextureFilter::Nearest,
wrap_mode: TextureWrapMode::ClampToEdge,
},
)
});

ui.label("Algorithm Chart:");
ui.add(Image::new(texture_id, self.diagram_size.unwrap()));
ui.add(Image::new(&*texture_id));
});
}
}
Expand Down
26 changes: 16 additions & 10 deletions gamercade_editor/src/ui/audio/instrument_editor/piano_roll.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use eframe::{
egui::{ImageButton, Key, TextureFilter, TextureOptions, Ui},
egui::{Image, ImageButton, Key, TextureFilter, TextureOptions, TextureWrapMode, Ui},
epaint::{Color32, ColorImage, TextureHandle, Vec2},
};
use gamercade_audio::{NoteColor, NoteName, NotesIter, TOTAL_NOTES_COUNT};
Expand Down Expand Up @@ -145,7 +145,7 @@ impl PianoRoll {
sync: &mut AudioSyncHelper,
selected_instrument: usize,
) {
let texture_id = self
let texture_handle = self
.default_piano_texture
.get_or_insert_with(|| {
ui.ctx().load_texture(
Expand All @@ -154,10 +154,12 @@ impl PianoRoll {
TextureOptions {
magnification: TextureFilter::Nearest,
minification: TextureFilter::Nearest,
wrap_mode: TextureWrapMode::ClampToEdge,
},
)
})
.id();
.clone();

// Draw the actual piano keys for clicking
ui.vertical(|ui| {
ui.spacing_mut().item_spacing = Vec2 {
Expand All @@ -172,26 +174,30 @@ impl PianoRoll {
all_notes_iter.for_each(|(index, (note, _octave))| {
let color = self.get_key_texture_tint(note, index);

let button_top = ImageButton::new(texture_id, TOP_KEY_SIZE).tint(color);
let button_top = ImageButton::new(
Image::new(&texture_handle)
.fit_to_exact_size(TOP_KEY_SIZE)
.maintain_aspect_ratio(false),
)
.tint(color);

if ui.add(button_top).clicked() {
sync.trigger_note(index, selected_instrument);
};
});
});

ui.spacing_mut().item_spacing = Vec2 {
x: NOTE_SPACING,
y: 0.0,
};
ui.horizontal(|ui| {
let mut white_notes_iter = NotesIter::default().enumerate();

for (index, (note, _octave)) in white_notes_iter.by_ref() {
if note.get_key_color() == NoteColor::White {
let tint = self.get_key_texture_tint(note, index);

let button_bottom =
ImageButton::new(texture_id, BOTTOM_KEY_SIZE).tint(tint);
let button_bottom = ImageButton::new(
Image::new(&texture_handle).fit_to_exact_size(BOTTOM_KEY_SIZE),
)
.tint(tint);

if ui.add(button_bottom).clicked() {
sync.trigger_note(index, selected_instrument);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use eframe::{
egui::{
plot::{HLine, Line, Plot, PlotPoint, PlotPoints, VLine},
Slider, Ui,
},
egui::{Slider, Ui},
epaint::{Color32, Vec2},
};
use egui_plot::{HLine, Line, Plot, PlotPoint, PlotPoints, VLine};

use hound::WavReader;
use rfd::FileDialog;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use eframe::{
egui::{
plot::{HLine, Line, Plot, PlotPoint, PlotPoints, VLine},
ComboBox, Slider, Ui, Window,
},
egui::{ComboBox, Slider, Ui, Window},
epaint::{Color32, Vec2},
};
use egui_plot::{HLine, Line, Plot, PlotPoint, PlotPoints, VLine};

use gamercade_audio::{
WavetableBitDepth, WavetableDefinition, WavetableGenerator, WavetableWaveform,
WAVETABLE_MAX_LENGTH,
Expand Down Expand Up @@ -82,7 +81,7 @@ impl WavetableEditor {
plot_ui.vline(VLine::new(0.0).color(Color32::RED));
plot_ui.vline(VLine::new(last_index as f64).color(Color32::RED));

if plot_ui.plot_hovered() && primary_pointer_down {
if plot_ui.response().hovered() && primary_pointer_down {
let point = plot_ui.pointer_coordinate().unwrap();
let (x, y) = plot_point_to_x_y(&point, last_index);

Expand Down
7 changes: 3 additions & 4 deletions gamercade_editor/src/ui/audio/oscilloscope.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::collections::VecDeque;

use eframe::{
egui::{
plot::{Line, Plot, PlotPoints},
Ui, Window,
},
egui::{Ui, Window},
epaint::{Color32, Vec2},
};
use egui_plot::{Line, Plot, PlotPoints};

use gamercade_audio::SFX_CHANNELS;
use gamercade_sound_engine::SoundOutputChannels;
use rtrb::Consumer;
Expand Down
42 changes: 21 additions & 21 deletions gamercade_editor/src/ui/graphics/graphics_editor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use eframe::egui::{
Color32, ColorImage, Image, Slider, TextureFilter, TextureHandle, TextureId, TextureOptions,
Ui, Vec2,
Color32, ColorImage, Image, Slider, TextureFilter, TextureHandle, TextureOptions,
TextureWrapMode, Ui, Vec2,
};

use super::{PaletteEditor, SpriteEditor, SpriteSheetEditor};
Expand Down Expand Up @@ -54,34 +54,32 @@ impl GraphicsEditor {
}

pub fn draw_contents(&mut self, ui: &mut Ui, data: &mut EditorGraphicsData) {
let texture_id = self
.default_palette_texture
.get_or_insert_with(|| {
ui.ctx().load_texture(
"default palette texture",
ColorImage::from_rgba_unmultiplied([1, 1], &[255, 255, 255, 255]),
TextureOptions {
magnification: TextureFilter::Nearest,
minification: TextureFilter::Nearest,
},
)
})
.id();
let texture_handle = self.default_palette_texture.get_or_insert_with(|| {
ui.ctx().load_texture(
"default palette texture",
ColorImage::from_rgba_unmultiplied([1, 1], &[255, 255, 255, 255]),
TextureOptions {
magnification: TextureFilter::Nearest,
minification: TextureFilter::Nearest,
wrap_mode: TextureWrapMode::ClampToEdge,
},
)
});

match self.mode {
GraphicsEditorMode::Palette => self.palette_editor.draw(
ui,
data,
&self.sprite_sheet_editor,
self.scale,
texture_id,
&texture_handle,
),
GraphicsEditorMode::SpriteSheet => self.sprite_sheet_editor.draw(
ui,
data,
&mut self.palette_editor,
self.scale,
texture_id,
&texture_handle,
),
GraphicsEditorMode::Sprite => self.sprite_editor.draw(ui),
};
Expand All @@ -95,16 +93,18 @@ impl GraphicsEditor {
}
}

pub(crate) fn draw_palette_preview(ui: &mut Ui, palette: &Palette, texture_id: TextureId) {
pub(crate) fn draw_palette_preview(ui: &mut Ui, palette: &Palette, texture_handle: &TextureHandle) {
ui.spacing_mut().item_spacing = Vec2 { x: 0.0, y: 0.0 };
ui.horizontal(|ui| {
(0..PALETTE_COLORS / ROWS_PER_PALETTE_PREVIEW).for_each(|x| {
ui.vertical(|ui| {
(0..ROWS_PER_PALETTE_PREVIEW).for_each(|y| {
let color = palette.colors[x + (y * ROWS_PER_PALETTE_PREVIEW)];
let image = Image::new(texture_id, Vec2 { x: 10.0, y: 10.0 }).tint(
Color32::from_rgba_unmultiplied(color.r, color.g, color.b, color.a),
);
let image = Image::new(texture_handle)
.tint(Color32::from_rgba_unmultiplied(
color.r, color.g, color.b, color.a,
))
.fit_to_exact_size(Vec2::new(10.0, 10.0));
ui.add(image);
});
});
Expand Down
4 changes: 3 additions & 1 deletion gamercade_editor/src/ui/graphics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod palette_editor_tab;
mod sprite_editor_tab;
mod sprite_sheet_editor_tab;

use eframe::egui::{TextureFilter, TextureOptions};
use eframe::egui::{TextureFilter, TextureOptions, TextureWrapMode};
pub use graphics_editor::*;
pub use palette_editor_tab::*;
pub use sprite_editor_tab::*;
Expand Down Expand Up @@ -76,6 +76,7 @@ pub(crate) fn load_buffered_image<'a>(
TextureOptions {
magnification: TextureFilter::Nearest,
minification: TextureFilter::Nearest,
wrap_mode: TextureWrapMode::ClampToEdge,
},
);
handle
Expand All @@ -87,6 +88,7 @@ pub(crate) fn load_buffered_image<'a>(
TextureOptions {
magnification: TextureFilter::Nearest,
minification: TextureFilter::Nearest,
wrap_mode: TextureWrapMode::ClampToEdge,
},
));
handle.as_ref().unwrap()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use eframe::egui::{Checkbox, Color32, Image, Slider, TextureId, Ui, Vec2};
use eframe::egui::{Checkbox, Color32, Image, Slider, TextureHandle, Ui, Vec2};
use gamercade_core::Color;

#[derive(Clone, Debug, Default)]
Expand All @@ -12,7 +12,7 @@ impl ColorEditor {
&mut self,
ui: &mut Ui,
current_color: &mut Color,
texture_id: TextureId,
texture_handle: &TextureHandle,
index: usize,
) {
if self.prev_color != *current_color {
Expand All @@ -26,8 +26,8 @@ impl ColorEditor {

ui.label(format!("Color index: {index}"));

draw_picker(ui, texture_id, "Current", false, current_color);
draw_picker(ui, texture_id, "Preview", true, &mut self.preview);
draw_picker(ui, texture_handle, "Current", false, current_color);
draw_picker(ui, texture_handle, "Preview", true, &mut self.preview);

ui.horizontal(|ui| {
if ui.button("Revert").clicked() {
Expand All @@ -46,7 +46,7 @@ impl ColorEditor {

fn draw_picker(
ui: &mut Ui,
texture_id: TextureId,
texture_handle: &TextureHandle,
text: &'static str,
editable: bool,
color: &mut Color,
Expand Down Expand Up @@ -86,9 +86,13 @@ fn draw_picker(
});
});

ui.add(Image::new(texture_id, Vec2 { x: 64.0, y: 64.0 }).tint(
Color32::from_rgba_unmultiplied(color.r, color.g, color.b, color.a),
));
ui.add(
Image::new(texture_handle)
.fit_to_exact_size(Vec2::new(64.0, 64.0))
.tint(Color32::from_rgba_unmultiplied(
color.r, color.g, color.b, color.a,
)),
);
});
});
}
20 changes: 12 additions & 8 deletions gamercade_editor/src/ui/graphics/palette_editor_tab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use palette_viewer::PaletteViewer;
use sprite_preview::SpritePreview;

// Externals
use eframe::egui::{SidePanel, TextureId, TopBottomPanel, Ui};
use eframe::egui::{SidePanel, TextureHandle, TopBottomPanel, Ui};

use super::SpriteSheetEditor;
use gamercade_fs::{EditorGraphicsData, EditorPalette};
Expand All @@ -30,15 +30,15 @@ impl PaletteEditor {
data: &mut EditorGraphicsData,
sprite_sheet_editor: &SpriteSheetEditor,
scale: f32,
texture_id: TextureId,
texture_handle: &TextureHandle,
) {
// Draw Palette List
SidePanel::left("palette_list_left_panel")
.resizable(false)
.show_inside(ui, |ui| {
TopBottomPanel::bottom("palette_list_bottom_panel")
.show_inside(ui, |ui| self.palette_list.draw_buttons(ui, data));
self.palette_list.draw(ui, texture_id, data);
self.palette_list.draw(ui, texture_handle, data);
});

// Draw Sprite Preview
Expand All @@ -65,24 +65,28 @@ impl PaletteEditor {
);
});

self.draw_color_editor(ui, texture_id, palette)
self.draw_color_editor(ui, texture_handle, palette)
}

// Draws the right side panel which includes palette viewer, color
// editor, and sprite preview widgets
fn draw_color_editor(
&mut self,
ui: &mut Ui,
texture_id: TextureId,
texture_handle: &TextureHandle,
palette: &mut EditorPalette,
) {
ui.vertical(|ui| {
self.palette_viewer.draw(ui, palette, texture_id);
self.palette_viewer.draw(ui, palette, texture_handle);

ui.horizontal(|ui| {
let color = self.palette_viewer.get_color_mut(&mut palette.palette);
self.color_editor
.draw(ui, color, texture_id, self.palette_viewer.selected_color);
self.color_editor.draw(
ui,
color,
texture_handle,
self.palette_viewer.selected_color,
);
});
});
}
Expand Down
Loading

0 comments on commit 525f0f6

Please sign in to comment.