pelcanvas

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package pelcanvas provides mouse event handling for the pixel canvas.

Package pelcanvas provides canvas operations for zooming and panning.

Package pelcanvas provides the pixel canvas widget for the Pel pixel art editor.

Package pelcanvas provides rendering functionality for the pixel canvas widget.

Index

Constants

View Source
const (
	MinPixelSize     = 2   // Minimum size for a pixel in screen pixels
	MaxPixelSize     = 100 // Maximum size for a pixel in screen pixels
	DefaultPixelSize = 10  // Default pixel size when reset
	ScaleStep        = 1   // Amount to change pixel size per scroll event
)

Canvas operation constants

View Source
const (
	BorderStrokeWidth = 2
	DefaultGrayValue  = 128
)

Canvas rendering constants

View Source
const (
	BorderLeft   = 0
	BorderTop    = 1
	BorderRight  = 2
	BorderBottom = 3
	BorderCount  = 4
)

Border position indices

View Source
const (
	ScrollSensitivity = 1 // Multiplier for scroll events
)

Mouse interaction constants

Variables

View Source
var (
	BorderColor       = color.NRGBA{R: 100, G: 100, B: 100, A: 255}
	DefaultCanvasGray = color.NRGBA{R: DefaultGrayValue, G: DefaultGrayValue, B: DefaultGrayValue, A: 255}
)

Default colors

Functions

func NewBlankImage

func NewBlankImage(cols, rows int, c color.Color) (image.Image, error)

NewBlankImage creates a new image filled with the specified color

Types

type PelCanvas

type PelCanvas struct {
	widget.BaseWidget
	apptype.PelCanvasConfig

	PixelData image.Image
	// contains filtered or unexported fields
}

PelCanvas is the main canvas widget for drawing pixel art

func NewPelCanvas

func NewPelCanvas(state *apptype.State, config apptype.PelCanvasConfig) *PelCanvas

NewPelCanvas creates a new pixel canvas with the given configuration

func (*PelCanvas) Bounds

func (pelCanvas *PelCanvas) Bounds() image.Rectangle

Bounds returns the current bounds of the canvas in screen coordinates

func (*PelCanvas) Clear

func (pelCanvas *PelCanvas) Clear(c color.Color) error

Clear fills the entire canvas with the specified color

func (*PelCanvas) CreateRenderer

func (pelCanvas *PelCanvas) CreateRenderer() fyne.WidgetRenderer

CreateRenderer creates the renderer for the canvas widget

func (*PelCanvas) GetPixelColor

func (pelCanvas *PelCanvas) GetPixelColor(x, y int) (color.Color, error)

GetPixelColor returns the color at the specified pixel coordinates

func (*PelCanvas) GetZoomLevel

func (pelCanvas *PelCanvas) GetZoomLevel() int

GetZoomLevel returns the current zoom level as a percentage 100% = DefaultPixelSize

func (*PelCanvas) InBounds

func (pelCanvas *PelCanvas) InBounds(pos fyne.Position) bool

InBounds checks if a position is within the given bounds

func (*PelCanvas) LoadImage

func (pelCanvas *PelCanvas) LoadImage(img image.Image) error

LoadImage loads an image into the canvas The canvas dimensions will be adjusted to match the image

func (*PelCanvas) MouseDown

func (pelCanvas *PelCanvas) MouseDown(ev *desktop.MouseEvent)

MouseDown handles mouse button press events

func (*PelCanvas) MouseIn

func (pelCanvas *PelCanvas) MouseIn(ev *desktop.MouseEvent)

MouseIn handles mouse entering the canvas area

func (*PelCanvas) MouseMoved

func (pelCanvas *PelCanvas) MouseMoved(ev *desktop.MouseEvent)

MouseMoved handles mouse movement events for drawing and cursor updates

func (*PelCanvas) MouseOut

func (pelCanvas *PelCanvas) MouseOut()

MouseOut handles mouse leaving the canvas area

func (*PelCanvas) MouseToCanvasXY

func (pelCanvas *PelCanvas) MouseToCanvasXY(ev *desktop.MouseEvent) (*int, *int)

MouseToCanvasXY converts mouse event coordinates to canvas pixel coordinates Returns nil pointers if the coordinates are outside the canvas

func (*PelCanvas) MouseUp

func (pelCanvas *PelCanvas) MouseUp(ev *desktop.MouseEvent)

MouseUp handles mouse button release events

func (*PelCanvas) NewDrawing

func (pelCanvas *PelCanvas) NewDrawing(cols, rows int) error

NewDrawing creates a new blank drawing with the specified dimensions

func (*PelCanvas) Pan

func (pelCanvas *PelCanvas) Pan(previousCoord, currentCoord fyne.PointEvent)

Pan shifts the canvas offset based on mouse movement This allows the user to move the canvas around the viewport

func (*PelCanvas) ResetView

func (pelCanvas *PelCanvas) ResetView()

ResetView resets the canvas to default zoom and position

func (*PelCanvas) Scrolled

func (pelCanvas *PelCanvas) Scrolled(ev *fyne.ScrollEvent)

Scrolled handles mouse scroll events for zooming the canvas

func (*PelCanvas) SetColor

func (pelCanvas *PelCanvas) SetColor(c color.Color, x, y int) error

SetColor sets the color of a pixel at the specified coordinates Returns an error if the coordinates are out of bounds or if the operation fails

func (*PelCanvas) TryPan

func (pelCanvas *PelCanvas) TryPan(previousCoord *fyne.PointEvent, ev *desktop.MouseEvent)

TryPan attempts to pan the canvas if the middle mouse button is pressed

func (*PelCanvas) ZoomIn

func (pelCanvas *PelCanvas) ZoomIn()

ZoomIn increases the pixel size by one step

func (*PelCanvas) ZoomOut

func (pelCanvas *PelCanvas) ZoomOut()

ZoomOut decreases the pixel size by one step

func (*PelCanvas) ZoomToFit

func (pelCanvas *PelCanvas) ZoomToFit(windowSize fyne.Size)

ZoomToFit adjusts the canvas to fit the window size

type PelCanvasMouseState

type PelCanvasMouseState struct {
	// contains filtered or unexported fields
}

PelCanvasMouseState tracks the mouse state for pan/drag operations

type PelCanvasRenderer

type PelCanvasRenderer struct {
	// contains filtered or unexported fields
}

PelCanvasRenderer handles the rendering of the pixel canvas widget

func (*PelCanvasRenderer) Destroy

func (renderer *PelCanvasRenderer) Destroy()

Destroy cleans up any resources used by the renderer

func (*PelCanvasRenderer) Layout

func (renderer *PelCanvasRenderer) Layout(size fyne.Size)

Layout positions and sizes all canvas objects

func (*PelCanvasRenderer) MinSize

func (renderer *PelCanvasRenderer) MinSize() fyne.Size

MinSize returns the minimum size required to display the canvas

func (*PelCanvasRenderer) Objects

func (renderer *PelCanvasRenderer) Objects() []fyne.CanvasObject

Objects returns all canvas objects that need to be rendered

func (*PelCanvasRenderer) Refresh

func (renderer *PelCanvasRenderer) Refresh()

Refresh updates the renderer with the latest canvas state

func (*PelCanvasRenderer) SetCursor

func (renderer *PelCanvasRenderer) SetCursor(objects []fyne.CanvasObject)

SetCursor updates the cursor objects to be displayed

Directories

Path Synopsis
Package brush provides brush tools and cursor rendering for the Pel pixel art editor.
Package brush provides brush tools and cursor rendering for the Pel pixel art editor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL