yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::editor::PixelEditorView Class Reference

Main pixel editing view for graphics sheets. More...

#include <pixel_editor_view.h>

Inheritance diagram for yaze::editor::PixelEditorView:

Public Member Functions

 PixelEditorView (GraphicsEditorState *state, Rom *rom, UndoManager *undo_manager=nullptr)
 
std::string GetId () const override
 Unique identifier for this panel.
 
std::string GetDisplayName () const override
 Human-readable name shown in menus and title bars.
 
std::string GetIcon () const override
 Material Design icon for this panel.
 
std::string GetEditorCategory () const override
 Editor category this panel belongs to.
 
int GetPriority () const override
 Get display priority for menu ordering.
 
bool IsVisibleByDefault () const override
 Whether this panel should be visible by default.
 
float GetPreferredWidth () const override
 Get preferred width for this panel (optional)
 
void Initialize ()
 Initialize the view.
 
void Draw (bool *p_open) override
 Draw the pixel editor UI (WindowContent interface)
 
absl::Status Update ()
 Legacy Update method for backward compatibility.
 
- Public Member Functions inherited from yaze::editor::WindowContent
virtual ~WindowContent ()=default
 
virtual void OnFirstDraw ()
 Called once before the first Draw() in a session.
 
virtual bool RequiresLazyInit () const
 Whether this panel uses lazy initialization.
 
void InvalidateLazyInit ()
 Reset lazy init state so OnFirstDraw() runs again.
 
virtual void OnOpen ()
 Called when panel becomes visible.
 
virtual void OnClose ()
 Called when panel is hidden.
 
virtual void OnFocus ()
 Called when panel receives focus.
 
virtual WindowLifecycle GetWindowLifecycle () const
 Get the lifecycle category for this window.
 
virtual WindowContextScope GetContextScope () const
 Optional context binding for this window (room/selection/etc)
 
virtual WindowScope GetScope () const
 Get the registration scope for this window.
 
virtual bool IsEnabled () const
 Check if this panel is currently enabled.
 
virtual std::string GetDisabledTooltip () const
 Get tooltip text when panel is disabled.
 
virtual std::string GetShortcutHint () const
 Get keyboard shortcut hint for display.
 
virtual std::string GetWorkflowGroup () const
 Optional workflow group for hack-centric actions.
 
virtual std::string GetWorkflowLabel () const
 Optional workflow label for menus/command palette.
 
virtual std::string GetWorkflowDescription () const
 Optional workflow description for menus/command palette.
 
virtual int GetWorkflowPriority () const
 Optional workflow ordering priority (lower sorts first).
 
virtual bool PreferAutoHideTabBar () const
 Whether the dock node hosting this panel should auto-hide its tab bar.
 
virtual std::string GetParentPanelId () const
 Get parent panel ID for cascade behavior.
 
virtual bool CascadeCloseChildren () const
 Whether closing this panel should close child panels.
 
void DrawWithLazyInit (bool *p_open)
 Execute lazy initialization if needed, then call Draw()
 

Private Member Functions

void DrawToolbar ()
 Draw the toolbar with tool selection.
 
void DrawViewControls ()
 Draw zoom and view controls.
 
void DrawCanvas ()
 Draw the main editing canvas.
 
void DrawColorPicker ()
 Draw the color palette picker.
 
void DrawStatusBar ()
 Draw the status bar with cursor position.
 
void DrawMiniMap ()
 Draw the mini navigation map.
 
void HandleCanvasInput ()
 Handle canvas mouse input for current tool.
 
void ApplyPencil (int x, int y)
 Apply pencil tool at position.
 
void ApplyBrush (int x, int y)
 Apply brush tool at position.
 
void ApplyEraser (int x, int y)
 Apply eraser tool at position.
 
void ApplyFill (int x, int y)
 Apply flood fill starting at position.
 
void ApplyEyedropper (int x, int y)
 Apply eyedropper tool at position.
 
void DrawLine (int x1, int y1, int x2, int y2)
 Draw line from start to end.
 
void DrawRectangle (int x1, int y1, int x2, int y2, bool filled)
 Draw rectangle from start to end.
 
void BeginSelection (int x, int y)
 Start a new selection.
 
void UpdateSelection (int x, int y)
 Update selection during drag.
 
void EndSelection ()
 Finalize the selection.
 
void CopySelection ()
 Copy selection to clipboard.
 
void PasteSelection (int x, int y)
 Paste clipboard at position.
 
void FlipSelectionHorizontal ()
 Flip selection horizontally.
 
void FlipSelectionVertical ()
 Flip selection vertically.
 
void SaveUndoState ()
 Save current state for undo (captures before-snapshot)
 
void FinalizeUndoAction ()
 Finalize the current undo action by capturing the after-snapshot and pushing a GraphicsPixelEditAction to the UndoManager.
 
ImVec2 ScreenToPixel (ImVec2 screen_pos)
 Convert screen coordinates to pixel coordinates.
 
ImVec2 PixelToScreen (int x, int y)
 Convert pixel coordinates to screen coordinates.
 
void DrawTransparencyGrid (float canvas_width, float canvas_height)
 Draw checkerboard pattern for transparent pixels.
 
void DrawCursorCrosshair ()
 Draw crosshair at cursor position.
 
void DrawBrushPreview ()
 Draw brush size preview circle.
 
void DrawPixelInfoTooltip (const gfx::Bitmap &sheet)
 Draw tooltip with pixel information.
 
void DrawTileHighlight (const gfx::Bitmap &sheet)
 Draw a transient highlight for a target tile.
 

Private Attributes

GraphicsEditorStatestate_
 
Romrom_
 
UndoManagerundo_manager_ = nullptr
 
gui::Canvas canvas_
 
bool has_pending_undo_ = false
 
uint16_t pending_undo_sheet_id_ = 0
 
std::vector< uint8_t > pending_undo_before_data_
 
bool is_drawing_ = false
 
ImVec2 last_mouse_pixel_ = {-1, -1}
 
ImVec2 tool_start_pixel_ = {-1, -1}
 
bool show_tool_preview_ = false
 
ImVec2 preview_end_ = {0, 0}
 
int cursor_x_ = 0
 
int cursor_y_ = 0
 
bool cursor_in_canvas_ = false
 

Additional Inherited Members

- Protected Member Functions inherited from yaze::editor::WindowContent
void InvalidateCache ()
 Invalidate all cached computations.
 
template<typename T >
T & GetCached (const std::string &key, std::function< T()> compute)
 Get or compute a cached value.
 
bool IsCacheValid () const
 Check if cache has been invalidated.
 
void ClearCache ()
 Clear all cached values (more aggressive than InvalidateCache)
 

Detailed Description

Main pixel editing view for graphics sheets.

Provides a full-featured pixel editor with tools for drawing, selecting, and manipulating graphics data.

Definition at line 22 of file pixel_editor_view.h.

Constructor & Destructor Documentation

◆ PixelEditorView()

yaze::editor::PixelEditorView::PixelEditorView ( GraphicsEditorState * state,
Rom * rom,
UndoManager * undo_manager = nullptr )
inlineexplicit

Definition at line 24 of file pixel_editor_view.h.

Member Function Documentation

◆ GetId()

std::string yaze::editor::PixelEditorView::GetId ( ) const
inlineoverridevirtual

Unique identifier for this panel.

Returns
Panel ID in format "{category}.{name}" (e.g., "dungeon.room_selector")

IDs should be:

  • Lowercase with underscores
  • Prefixed with editor category
  • Unique across all panels

Implements yaze::editor::WindowContent.

Definition at line 32 of file pixel_editor_view.h.

◆ GetDisplayName()

std::string yaze::editor::PixelEditorView::GetDisplayName ( ) const
inlineoverridevirtual

Human-readable name shown in menus and title bars.

Returns
Display name (e.g., "Room Selector")

Implements yaze::editor::WindowContent.

Definition at line 33 of file pixel_editor_view.h.

◆ GetIcon()

std::string yaze::editor::PixelEditorView::GetIcon ( ) const
inlineoverridevirtual

Material Design icon for this panel.

Returns
Icon constant (e.g., ICON_MD_LIST)

Implements yaze::editor::WindowContent.

Definition at line 34 of file pixel_editor_view.h.

References ICON_MD_BRUSH.

◆ GetEditorCategory()

std::string yaze::editor::PixelEditorView::GetEditorCategory ( ) const
inlineoverridevirtual

Editor category this panel belongs to.

Returns
Category name matching EditorType (e.g., "Dungeon", "Overworld")

Implements yaze::editor::WindowContent.

Definition at line 35 of file pixel_editor_view.h.

◆ GetPriority()

int yaze::editor::PixelEditorView::GetPriority ( ) const
inlineoverridevirtual

Get display priority for menu ordering.

Returns
Priority value (lower = higher in list, default 50)

Reimplemented from yaze::editor::WindowContent.

Definition at line 36 of file pixel_editor_view.h.

◆ IsVisibleByDefault()

bool yaze::editor::PixelEditorView::IsVisibleByDefault ( ) const
inlineoverridevirtual

Whether this panel should be visible by default.

Returns
true if panel should be visible when editor first opens

Override this to set panels as visible by default. Most panels default to hidden to reduce UI clutter.

Reimplemented from yaze::editor::WindowContent.

Definition at line 37 of file pixel_editor_view.h.

◆ GetPreferredWidth()

float yaze::editor::PixelEditorView::GetPreferredWidth ( ) const
inlineoverridevirtual

Get preferred width for this panel (optional)

Returns
Preferred width in pixels, or 0 to use default (250px)

Override this to specify content-based sizing. For example, a tile selector with 8 tiles at 16px × 2.0 scale would return ~276px.

Reimplemented from yaze::editor::WindowContent.

Definition at line 38 of file pixel_editor_view.h.

◆ Initialize()

void yaze::editor::PixelEditorView::Initialize ( )

Initialize the view.

Definition at line 22 of file pixel_editor_view.cc.

◆ Draw()

void yaze::editor::PixelEditorView::Draw ( bool * p_open)
overridevirtual

Draw the pixel editor UI (WindowContent interface)

Implements yaze::editor::WindowContent.

Definition at line 26 of file pixel_editor_view.cc.

References Update().

Here is the call graph for this function:

◆ Update()

absl::Status yaze::editor::PixelEditorView::Update ( )

Legacy Update method for backward compatibility.

Returns
Status of the render operation

Definition at line 31 of file pixel_editor_view.cc.

References DrawCanvas(), DrawColorPicker(), DrawMiniMap(), DrawStatusBar(), DrawToolbar(), and DrawViewControls().

Referenced by Draw().

◆ DrawToolbar()

◆ DrawViewControls()

◆ DrawCanvas()

void yaze::editor::PixelEditorView::DrawCanvas ( )
private

Draw the main editing canvas.

Definition at line 172 of file pixel_editor_view.cc.

References yaze::gui::BeginThemedTabBar(), canvas_, yaze::editor::GraphicsEditorState::CloseSheet(), yaze::editor::GraphicsEditorState::current_sheet_id, yaze::editor::GraphicsEditorState::current_tool, cursor_in_canvas_, yaze::gui::Canvas::draw_list(), yaze::gui::Canvas::DrawBackground(), DrawBrushPreview(), DrawCursorCrosshair(), yaze::gui::Canvas::DrawGrid(), yaze::gui::Canvas::DrawOverlay(), DrawPixelInfoTooltip(), DrawTileHighlight(), DrawTransparencyGrid(), yaze::gui::EndThemedTabBar(), yaze::gfx::Arena::Get(), HandleCanvasInput(), yaze::editor::PixelSelection::height, yaze::editor::PixelSelection::is_active, is_drawing_, yaze::editor::kBrush, yaze::editor::kEraser, yaze::editor::kLine, yaze::editor::kRectangle, yaze::editor::GraphicsEditorState::modified_sheets, yaze::gfx::Arena::mutable_gfx_sheets(), yaze::editor::GraphicsEditorState::open_sheets, PixelToScreen(), preview_end_, yaze::editor::GraphicsEditorState::selection, yaze::editor::GraphicsEditorState::show_brush_preview, yaze::editor::GraphicsEditorState::show_cursor_crosshair, yaze::editor::GraphicsEditorState::show_grid, yaze::editor::GraphicsEditorState::show_pixel_info_tooltip, show_tool_preview_, yaze::editor::GraphicsEditorState::show_transparency_grid, state_, tool_start_pixel_, yaze::editor::PixelSelection::width, yaze::editor::PixelSelection::x, yaze::editor::PixelSelection::y, yaze::gui::Canvas::zero_point(), and yaze::editor::GraphicsEditorState::zoom_level.

Referenced by Update().

◆ DrawColorPicker()

◆ DrawStatusBar()

◆ DrawMiniMap()

void yaze::editor::PixelEditorView::DrawMiniMap ( )
private

Draw the mini navigation map.

Todo
Calculate actual viewport bounds based on scroll position

Definition at line 524 of file pixel_editor_view.cc.

References yaze::editor::GraphicsEditorState::current_sheet_id, yaze::gfx::Arena::Get(), yaze::gfx::Arena::mutable_gfx_sheets(), yaze::editor::GraphicsEditorState::open_sheets, and state_.

Referenced by Update().

Here is the call graph for this function:

◆ HandleCanvasInput()

◆ ApplyPencil()

void yaze::editor::PixelEditorView::ApplyPencil ( int x,
int y )
private

◆ ApplyBrush()

◆ ApplyEraser()

void yaze::editor::PixelEditorView::ApplyEraser ( int x,
int y )
private

◆ ApplyFill()

void yaze::editor::PixelEditorView::ApplyFill ( int x,
int y )
private

◆ ApplyEyedropper()

void yaze::editor::PixelEditorView::ApplyEyedropper ( int x,
int y )
private

◆ DrawLine()

void yaze::editor::PixelEditorView::DrawLine ( int x1,
int y1,
int x2,
int y2 )
private

◆ DrawRectangle()

void yaze::editor::PixelEditorView::DrawRectangle ( int x1,
int y1,
int x2,
int y2,
bool filled )
private

◆ BeginSelection()

◆ UpdateSelection()

void yaze::editor::PixelEditorView::UpdateSelection ( int x,
int y )
private

◆ EndSelection()

◆ CopySelection()

void yaze::editor::PixelEditorView::CopySelection ( )
private

Copy selection to clipboard.

Definition at line 943 of file pixel_editor_view.cc.

◆ PasteSelection()

◆ FlipSelectionHorizontal()

void yaze::editor::PixelEditorView::FlipSelectionHorizontal ( )
private

◆ FlipSelectionVertical()

void yaze::editor::PixelEditorView::FlipSelectionVertical ( )
private

◆ SaveUndoState()

void yaze::editor::PixelEditorView::SaveUndoState ( )
private

Save current state for undo (captures before-snapshot)

Definition at line 1006 of file pixel_editor_view.cc.

References yaze::editor::GraphicsEditorState::current_sheet_id, yaze::gfx::Arena::Get(), yaze::gfx::Arena::gfx_sheets(), has_pending_undo_, pending_undo_before_data_, pending_undo_sheet_id_, state_, and undo_manager_.

Referenced by HandleCanvasInput(), and PasteSelection().

Here is the call graph for this function:

◆ FinalizeUndoAction()

void yaze::editor::PixelEditorView::FinalizeUndoAction ( )
private

Finalize the current undo action by capturing the after-snapshot and pushing a GraphicsPixelEditAction to the UndoManager.

Definition at line 1015 of file pixel_editor_view.cc.

References yaze::gfx::Arena::Get(), yaze::gfx::Arena::gfx_sheets(), has_pending_undo_, pending_undo_before_data_, pending_undo_sheet_id_, yaze::editor::UndoManager::Push(), and undo_manager_.

Referenced by HandleCanvasInput(), and PasteSelection().

Here is the call graph for this function:

◆ ScreenToPixel()

ImVec2 yaze::editor::PixelEditorView::ScreenToPixel ( ImVec2 screen_pos)
private

Convert screen coordinates to pixel coordinates.

Definition at line 1037 of file pixel_editor_view.cc.

References canvas_, state_, yaze::gui::Canvas::zero_point(), and yaze::editor::GraphicsEditorState::zoom_level.

Referenced by HandleCanvasInput().

Here is the call graph for this function:

◆ PixelToScreen()

ImVec2 yaze::editor::PixelEditorView::PixelToScreen ( int x,
int y )
private

Convert pixel coordinates to screen coordinates.

Definition at line 1043 of file pixel_editor_view.cc.

References canvas_, state_, yaze::gui::Canvas::zero_point(), and yaze::editor::GraphicsEditorState::zoom_level.

Referenced by DrawBrushPreview(), DrawCanvas(), DrawCursorCrosshair(), and DrawTileHighlight().

Here is the call graph for this function:

◆ DrawTransparencyGrid()

void yaze::editor::PixelEditorView::DrawTransparencyGrid ( float canvas_width,
float canvas_height )
private

Draw checkerboard pattern for transparent pixels.

Definition at line 303 of file pixel_editor_view.cc.

References canvas_, yaze::gui::Canvas::draw_list(), and yaze::gui::Canvas::zero_point().

Referenced by DrawCanvas().

Here is the call graph for this function:

◆ DrawCursorCrosshair()

void yaze::editor::PixelEditorView::DrawCursorCrosshair ( )
private

Draw crosshair at cursor position.

Definition at line 325 of file pixel_editor_view.cc.

References canvas_, yaze::gui::Canvas::canvas_size(), cursor_x_, cursor_y_, yaze::gui::Canvas::draw_list(), PixelToScreen(), state_, yaze::gui::Canvas::zero_point(), and yaze::editor::GraphicsEditorState::zoom_level.

Referenced by DrawCanvas().

Here is the call graph for this function:

◆ DrawBrushPreview()

void yaze::editor::PixelEditorView::DrawBrushPreview ( )
private

◆ DrawPixelInfoTooltip()

void yaze::editor::PixelEditorView::DrawPixelInfoTooltip ( const gfx::Bitmap & sheet)
private

Draw tooltip with pixel information.

Definition at line 376 of file pixel_editor_view.cc.

References cursor_x_, cursor_y_, yaze::gfx::Bitmap::GetPixel(), yaze::gfx::Bitmap::height(), yaze::gfx::Bitmap::palette(), and yaze::gfx::Bitmap::width().

Referenced by DrawCanvas().

Here is the call graph for this function:

◆ DrawTileHighlight()

Member Data Documentation

◆ state_

◆ rom_

Rom* yaze::editor::PixelEditorView::rom_
private

Definition at line 217 of file pixel_editor_view.h.

◆ undo_manager_

UndoManager* yaze::editor::PixelEditorView::undo_manager_ = nullptr
private

Definition at line 218 of file pixel_editor_view.h.

Referenced by DrawToolbar(), FinalizeUndoAction(), and SaveUndoState().

◆ canvas_

gui::Canvas yaze::editor::PixelEditorView::canvas_
private

◆ has_pending_undo_

bool yaze::editor::PixelEditorView::has_pending_undo_ = false
private

Definition at line 224 of file pixel_editor_view.h.

Referenced by FinalizeUndoAction(), and SaveUndoState().

◆ pending_undo_sheet_id_

uint16_t yaze::editor::PixelEditorView::pending_undo_sheet_id_ = 0
private

Definition at line 225 of file pixel_editor_view.h.

Referenced by FinalizeUndoAction(), and SaveUndoState().

◆ pending_undo_before_data_

std::vector<uint8_t> yaze::editor::PixelEditorView::pending_undo_before_data_
private

Definition at line 226 of file pixel_editor_view.h.

Referenced by FinalizeUndoAction(), and SaveUndoState().

◆ is_drawing_

bool yaze::editor::PixelEditorView::is_drawing_ = false
private

Definition at line 229 of file pixel_editor_view.h.

Referenced by DrawCanvas(), and HandleCanvasInput().

◆ last_mouse_pixel_

ImVec2 yaze::editor::PixelEditorView::last_mouse_pixel_ = {-1, -1}
private

Definition at line 230 of file pixel_editor_view.h.

Referenced by HandleCanvasInput().

◆ tool_start_pixel_

ImVec2 yaze::editor::PixelEditorView::tool_start_pixel_ = {-1, -1}
private

Definition at line 231 of file pixel_editor_view.h.

Referenced by DrawCanvas(), HandleCanvasInput(), and UpdateSelection().

◆ show_tool_preview_

bool yaze::editor::PixelEditorView::show_tool_preview_ = false
private

Definition at line 234 of file pixel_editor_view.h.

Referenced by DrawCanvas(), and HandleCanvasInput().

◆ preview_end_

ImVec2 yaze::editor::PixelEditorView::preview_end_ = {0, 0}
private

Definition at line 235 of file pixel_editor_view.h.

Referenced by DrawCanvas(), and HandleCanvasInput().

◆ cursor_x_

int yaze::editor::PixelEditorView::cursor_x_ = 0
private

◆ cursor_y_

int yaze::editor::PixelEditorView::cursor_y_ = 0
private

◆ cursor_in_canvas_

bool yaze::editor::PixelEditorView::cursor_in_canvas_ = false
private

Definition at line 240 of file pixel_editor_view.h.

Referenced by DrawCanvas(), DrawStatusBar(), and HandleCanvasInput().


The documentation for this class was generated from the following files: