2018-08-05 19:54:57 +00:00
|
|
|
package doodle
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-10-20 22:42:49 +00:00
|
|
|
"path/filepath"
|
2018-09-26 17:04:46 +00:00
|
|
|
"strconv"
|
2018-08-05 19:54:57 +00:00
|
|
|
|
2019-04-10 00:35:44 +00:00
|
|
|
"git.kirsle.net/apps/doodle/lib/events"
|
|
|
|
"git.kirsle.net/apps/doodle/lib/render"
|
|
|
|
"git.kirsle.net/apps/doodle/lib/ui"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/doodads"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/enum"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/level"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/log"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/uix"
|
2018-10-21 00:08:20 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/userdir"
|
2018-08-05 19:54:57 +00:00
|
|
|
)
|
|
|
|
|
2018-10-19 20:31:58 +00:00
|
|
|
// Width of the panel frame.
|
|
|
|
var paletteWidth int32 = 150
|
|
|
|
|
2018-08-05 19:54:57 +00:00
|
|
|
// EditorUI manages the user interface for the Editor Scene.
|
|
|
|
type EditorUI struct {
|
2018-08-11 00:19:47 +00:00
|
|
|
d *Doodle
|
|
|
|
Scene *EditorScene
|
2018-08-05 19:54:57 +00:00
|
|
|
|
|
|
|
// Variables
|
WIP Texture Caching
NOTICE: Chunk size set to 100 for visual testing!
NOTICE: guitest references a bmp file that isn't checked in!
BUGS REMAINING:
- When scrolling the level in Edit Mode, some of the chunks will pop
out of existence randomly.
- When clicking-dragging to draw in Edit Mode, if the scroll position
is not at 0,0 then the pixels drawn will be offset from the cursor.
- These are to do with the Scroll position and chunk coordinate calc
functions probably.
Implements a texture caching interface to stop redrawing everything
pixel by pixel on every frame.
The texture caching workflow is briefly:
- The uix.Canvas widget's Present() function iterates over the list of
Chunk Coordinates that are visible inside of the current viewport
(i.e. viewable on screen)
- For each Chunk:
- Make it render and/or return its cached Texture object.
- Work out how much of the Chunk will be visible and how to crop the
boxes for the Copy()
- Copy the cached Texture instead of drawing all the pixels every
time like we were doing before.
- The Chunk.Texture() function that returns said Texture:
- It calls Chunk.ToBitmap() to save a bitmap on disk.
- It calls Engine.NewBitmap() to get a Texture it can hang onto.
- It hangs onto the Texture and returns it on future calls.
- Any call to Set() or Delete() a pixel will invalidate the cache
(mark the Chunk "dirty") and Texture() will rebuild next call.
The interface `render.Texturer` provides a way for rendering backends
(SDL2, OpenGL) to transport a "texture" of their own kind without
exposing the type details to the user.
The interface `render.Engine` adds two new methods:
* NewBitmap(filename string) (Texturer, error)
* Copy(t Texturer, src, dst Rect)
NewBitmap should open a bitmap image on disk and return it wrapped in a
Texturer (really it's an SDL2 Texture). This is for caching purposes.
Next the Copy() function blits the texture onto the screen renderer
using the source and destination rectangles.
The uix.Canvas widget orchestrates the caching for the drawing it's
responsible for. It queries which chunks are viewable in the Canvas
viewport (scroll and bounding boxes), has each chunk render out their
entire bitmap image to then cache them as SDL textures and then only
_those_ need to be copied out to the renderer each frame.
The frame rate now sits at a decent 60 FPS even when the drawing gets
messy and full of lines. Each unique version of each chunk needs to
render only one time and then it's a fast copy operation for future
ticks.
Other changes:
- Chunker now assigns each Chunk what their coordinate and size are, so
that the chunk can self reference that information. This info is
considered read-only but that isn't really enforced.
- Add Chunker.IterViewportChunks() that returns a channel of Chunk
Coordinates that are visible in your viewport, rather than iterating
over all of the pixels in all of those chunks.
- Add Chunk.ToBitmap(filename) that causes a Chunk to render its pixels
to a bitmap image on disk. SDL2 can natively speak Bitmaps for texture
caching. Currently these go to files in /tmp but will soon go into your
$XDG_CACHE_FOLDER instead.
- Add Chunk.Texture() that causes a Chunk to render and then return a
cached bitmap texture of the pixels it's responsible for. The texture
is cached until the Chunk is next modified with Set() or Delete().
- UI: add an Image widget that currently just shows a bitmap image. It
was the first test for caching bitmap images for efficiency. Can show
any *.bmp file on disk!
- Editor UI: make the StatusBar boxes dynamically build from an array
of string pointers to make it SUPER EASY to add/remove labels.
2018-10-18 03:52:14 +00:00
|
|
|
StatusBoxes []*string
|
2018-08-11 00:19:47 +00:00
|
|
|
StatusMouseText string
|
|
|
|
StatusPaletteText string
|
|
|
|
StatusFilenameText string
|
WIP Texture Caching
NOTICE: Chunk size set to 100 for visual testing!
NOTICE: guitest references a bmp file that isn't checked in!
BUGS REMAINING:
- When scrolling the level in Edit Mode, some of the chunks will pop
out of existence randomly.
- When clicking-dragging to draw in Edit Mode, if the scroll position
is not at 0,0 then the pixels drawn will be offset from the cursor.
- These are to do with the Scroll position and chunk coordinate calc
functions probably.
Implements a texture caching interface to stop redrawing everything
pixel by pixel on every frame.
The texture caching workflow is briefly:
- The uix.Canvas widget's Present() function iterates over the list of
Chunk Coordinates that are visible inside of the current viewport
(i.e. viewable on screen)
- For each Chunk:
- Make it render and/or return its cached Texture object.
- Work out how much of the Chunk will be visible and how to crop the
boxes for the Copy()
- Copy the cached Texture instead of drawing all the pixels every
time like we were doing before.
- The Chunk.Texture() function that returns said Texture:
- It calls Chunk.ToBitmap() to save a bitmap on disk.
- It calls Engine.NewBitmap() to get a Texture it can hang onto.
- It hangs onto the Texture and returns it on future calls.
- Any call to Set() or Delete() a pixel will invalidate the cache
(mark the Chunk "dirty") and Texture() will rebuild next call.
The interface `render.Texturer` provides a way for rendering backends
(SDL2, OpenGL) to transport a "texture" of their own kind without
exposing the type details to the user.
The interface `render.Engine` adds two new methods:
* NewBitmap(filename string) (Texturer, error)
* Copy(t Texturer, src, dst Rect)
NewBitmap should open a bitmap image on disk and return it wrapped in a
Texturer (really it's an SDL2 Texture). This is for caching purposes.
Next the Copy() function blits the texture onto the screen renderer
using the source and destination rectangles.
The uix.Canvas widget orchestrates the caching for the drawing it's
responsible for. It queries which chunks are viewable in the Canvas
viewport (scroll and bounding boxes), has each chunk render out their
entire bitmap image to then cache them as SDL textures and then only
_those_ need to be copied out to the renderer each frame.
The frame rate now sits at a decent 60 FPS even when the drawing gets
messy and full of lines. Each unique version of each chunk needs to
render only one time and then it's a fast copy operation for future
ticks.
Other changes:
- Chunker now assigns each Chunk what their coordinate and size are, so
that the chunk can self reference that information. This info is
considered read-only but that isn't really enforced.
- Add Chunker.IterViewportChunks() that returns a channel of Chunk
Coordinates that are visible in your viewport, rather than iterating
over all of the pixels in all of those chunks.
- Add Chunk.ToBitmap(filename) that causes a Chunk to render its pixels
to a bitmap image on disk. SDL2 can natively speak Bitmaps for texture
caching. Currently these go to files in /tmp but will soon go into your
$XDG_CACHE_FOLDER instead.
- Add Chunk.Texture() that causes a Chunk to render and then return a
cached bitmap texture of the pixels it's responsible for. The texture
is cached until the Chunk is next modified with Set() or Delete().
- UI: add an Image widget that currently just shows a bitmap image. It
was the first test for caching bitmap images for efficiency. Can show
any *.bmp file on disk!
- Editor UI: make the StatusBar boxes dynamically build from an array
of string pointers to make it SUPER EASY to add/remove labels.
2018-10-18 03:52:14 +00:00
|
|
|
StatusScrollText string
|
2018-10-20 22:42:49 +00:00
|
|
|
selectedSwatch string // name of selected swatch in palette
|
|
|
|
cursor render.Point // remember the cursor position in Loop
|
2018-08-05 19:54:57 +00:00
|
|
|
|
|
|
|
// Widgets
|
|
|
|
Supervisor *ui.Supervisor
|
2018-10-08 17:38:49 +00:00
|
|
|
Canvas *uix.Canvas
|
|
|
|
Workspace *ui.Frame
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
MenuBar *ui.Frame
|
2018-08-05 19:54:57 +00:00
|
|
|
StatusBar *ui.Frame
|
2018-10-08 20:06:42 +00:00
|
|
|
|
|
|
|
// Palette window.
|
|
|
|
Palette *ui.Window
|
|
|
|
PaletteTab *ui.Frame
|
|
|
|
DoodadTab *ui.Frame
|
|
|
|
|
2018-10-20 22:42:49 +00:00
|
|
|
// Draggable Doodad canvas.
|
|
|
|
DraggableActor *DraggableActor
|
|
|
|
|
2018-10-08 20:06:42 +00:00
|
|
|
// Palette variables.
|
|
|
|
paletteTab string // selected tab, Palette or Doodads
|
2018-08-05 19:54:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewEditorUI initializes the Editor UI.
|
2018-08-11 00:19:47 +00:00
|
|
|
func NewEditorUI(d *Doodle, s *EditorScene) *EditorUI {
|
2018-08-05 19:54:57 +00:00
|
|
|
u := &EditorUI{
|
2018-08-11 00:19:47 +00:00
|
|
|
d: d,
|
|
|
|
Scene: s,
|
|
|
|
Supervisor: ui.NewSupervisor(),
|
|
|
|
StatusMouseText: "Cursor: (waiting)",
|
|
|
|
StatusPaletteText: "Swatch: <none>",
|
|
|
|
StatusFilenameText: "Filename: <none>",
|
WIP Texture Caching
NOTICE: Chunk size set to 100 for visual testing!
NOTICE: guitest references a bmp file that isn't checked in!
BUGS REMAINING:
- When scrolling the level in Edit Mode, some of the chunks will pop
out of existence randomly.
- When clicking-dragging to draw in Edit Mode, if the scroll position
is not at 0,0 then the pixels drawn will be offset from the cursor.
- These are to do with the Scroll position and chunk coordinate calc
functions probably.
Implements a texture caching interface to stop redrawing everything
pixel by pixel on every frame.
The texture caching workflow is briefly:
- The uix.Canvas widget's Present() function iterates over the list of
Chunk Coordinates that are visible inside of the current viewport
(i.e. viewable on screen)
- For each Chunk:
- Make it render and/or return its cached Texture object.
- Work out how much of the Chunk will be visible and how to crop the
boxes for the Copy()
- Copy the cached Texture instead of drawing all the pixels every
time like we were doing before.
- The Chunk.Texture() function that returns said Texture:
- It calls Chunk.ToBitmap() to save a bitmap on disk.
- It calls Engine.NewBitmap() to get a Texture it can hang onto.
- It hangs onto the Texture and returns it on future calls.
- Any call to Set() or Delete() a pixel will invalidate the cache
(mark the Chunk "dirty") and Texture() will rebuild next call.
The interface `render.Texturer` provides a way for rendering backends
(SDL2, OpenGL) to transport a "texture" of their own kind without
exposing the type details to the user.
The interface `render.Engine` adds two new methods:
* NewBitmap(filename string) (Texturer, error)
* Copy(t Texturer, src, dst Rect)
NewBitmap should open a bitmap image on disk and return it wrapped in a
Texturer (really it's an SDL2 Texture). This is for caching purposes.
Next the Copy() function blits the texture onto the screen renderer
using the source and destination rectangles.
The uix.Canvas widget orchestrates the caching for the drawing it's
responsible for. It queries which chunks are viewable in the Canvas
viewport (scroll and bounding boxes), has each chunk render out their
entire bitmap image to then cache them as SDL textures and then only
_those_ need to be copied out to the renderer each frame.
The frame rate now sits at a decent 60 FPS even when the drawing gets
messy and full of lines. Each unique version of each chunk needs to
render only one time and then it's a fast copy operation for future
ticks.
Other changes:
- Chunker now assigns each Chunk what their coordinate and size are, so
that the chunk can self reference that information. This info is
considered read-only but that isn't really enforced.
- Add Chunker.IterViewportChunks() that returns a channel of Chunk
Coordinates that are visible in your viewport, rather than iterating
over all of the pixels in all of those chunks.
- Add Chunk.ToBitmap(filename) that causes a Chunk to render its pixels
to a bitmap image on disk. SDL2 can natively speak Bitmaps for texture
caching. Currently these go to files in /tmp but will soon go into your
$XDG_CACHE_FOLDER instead.
- Add Chunk.Texture() that causes a Chunk to render and then return a
cached bitmap texture of the pixels it's responsible for. The texture
is cached until the Chunk is next modified with Set() or Delete().
- UI: add an Image widget that currently just shows a bitmap image. It
was the first test for caching bitmap images for efficiency. Can show
any *.bmp file on disk!
- Editor UI: make the StatusBar boxes dynamically build from an array
of string pointers to make it SUPER EASY to add/remove labels.
2018-10-18 03:52:14 +00:00
|
|
|
StatusScrollText: "Hello world",
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bind the StatusBoxes arrays to the text variables.
|
|
|
|
u.StatusBoxes = []*string{
|
|
|
|
&u.StatusMouseText,
|
|
|
|
&u.StatusPaletteText,
|
|
|
|
&u.StatusFilenameText,
|
|
|
|
&u.StatusScrollText,
|
2018-08-05 19:54:57 +00:00
|
|
|
}
|
2018-08-17 03:37:19 +00:00
|
|
|
|
2018-10-08 17:38:49 +00:00
|
|
|
u.Canvas = u.SetupCanvas(d)
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
u.MenuBar = u.SetupMenuBar(d)
|
2018-08-05 19:54:57 +00:00
|
|
|
u.StatusBar = u.SetupStatusBar(d)
|
2018-08-11 00:19:47 +00:00
|
|
|
u.Palette = u.SetupPalette(d)
|
2018-10-08 17:38:49 +00:00
|
|
|
u.Workspace = u.SetupWorkspace(d) // important that this is last!
|
|
|
|
|
2018-10-19 20:31:58 +00:00
|
|
|
u.Resized(d)
|
|
|
|
|
2018-10-08 17:38:49 +00:00
|
|
|
// Position the Canvas inside the frame.
|
|
|
|
u.Workspace.Pack(u.Canvas, ui.Pack{
|
|
|
|
Anchor: ui.N,
|
|
|
|
})
|
|
|
|
u.Workspace.Compute(d.Engine)
|
|
|
|
u.ExpandCanvas(d.Engine)
|
|
|
|
|
|
|
|
// Select the first swatch of the palette.
|
|
|
|
if u.Canvas.Palette != nil && u.Canvas.Palette.ActiveSwatch != nil {
|
|
|
|
u.selectedSwatch = u.Canvas.Palette.ActiveSwatch.Name
|
|
|
|
}
|
2018-08-05 19:54:57 +00:00
|
|
|
return u
|
|
|
|
}
|
|
|
|
|
2018-10-19 20:31:58 +00:00
|
|
|
// Resized handles the window being resized so we can recompute the widgets.
|
|
|
|
func (u *EditorUI) Resized(d *Doodle) {
|
|
|
|
// Menu Bar frame.
|
|
|
|
{
|
|
|
|
u.MenuBar.Configure(ui.Config{
|
|
|
|
Width: int32(d.width),
|
|
|
|
Background: render.Black,
|
|
|
|
})
|
|
|
|
u.MenuBar.Compute(d.Engine)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Status Bar.
|
|
|
|
{
|
|
|
|
u.StatusBar.Configure(ui.Config{
|
|
|
|
Width: int32(d.width),
|
|
|
|
})
|
|
|
|
u.StatusBar.MoveTo(render.Point{
|
|
|
|
X: 0,
|
|
|
|
Y: int32(d.height) - u.StatusBar.Size().H,
|
|
|
|
})
|
|
|
|
u.StatusBar.Compute(d.Engine)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Palette panel.
|
|
|
|
{
|
|
|
|
u.Palette.Configure(ui.Config{
|
|
|
|
Width: paletteWidth,
|
|
|
|
Height: int32(u.d.height) - u.StatusBar.Size().H,
|
|
|
|
})
|
|
|
|
u.Palette.MoveTo(render.NewPoint(
|
|
|
|
int32(u.d.width)-u.Palette.BoxSize().W,
|
|
|
|
u.MenuBar.BoxSize().H,
|
|
|
|
))
|
|
|
|
u.Palette.Compute(d.Engine)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Position the workspace around with the other widgets.
|
|
|
|
{
|
|
|
|
frame := u.Workspace
|
|
|
|
frame.MoveTo(render.NewPoint(
|
|
|
|
0,
|
|
|
|
u.MenuBar.Size().H,
|
|
|
|
))
|
|
|
|
frame.Resize(render.NewRect(
|
|
|
|
int32(d.width)-u.Palette.Size().W,
|
|
|
|
int32(d.height)-u.MenuBar.Size().H-u.StatusBar.Size().H,
|
|
|
|
))
|
|
|
|
frame.Compute(d.Engine)
|
|
|
|
|
|
|
|
u.ExpandCanvas(d.Engine)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-05 19:54:57 +00:00
|
|
|
// Loop to process events and update the UI.
|
2018-10-20 22:42:49 +00:00
|
|
|
func (u *EditorUI) Loop(ev *events.State) error {
|
|
|
|
u.cursor = render.NewPoint(ev.CursorX.Now, ev.CursorY.Now)
|
|
|
|
|
|
|
|
// Loop the UI and see whether we're told to stop event propagation.
|
|
|
|
var stopPropagation bool
|
|
|
|
if err := u.Supervisor.Loop(ev); err != nil {
|
|
|
|
if err == ui.ErrStopPropagation {
|
|
|
|
stopPropagation = true
|
|
|
|
} else {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2018-08-11 00:19:47 +00:00
|
|
|
|
2018-10-20 22:42:49 +00:00
|
|
|
// Update status bar labels.
|
2018-10-19 20:31:58 +00:00
|
|
|
{
|
2018-10-20 22:42:49 +00:00
|
|
|
u.StatusMouseText = fmt.Sprintf("Rel:(%d,%d) Abs:(%s)",
|
2018-10-19 20:31:58 +00:00
|
|
|
ev.CursorX.Now,
|
|
|
|
ev.CursorY.Now,
|
2019-04-10 01:28:08 +00:00
|
|
|
*u.Scene.debWorldIndex,
|
2018-10-19 20:31:58 +00:00
|
|
|
)
|
2018-10-21 00:08:20 +00:00
|
|
|
u.StatusPaletteText = fmt.Sprintf("%s Tool",
|
|
|
|
u.Canvas.Tool,
|
2018-10-20 22:42:49 +00:00
|
|
|
)
|
|
|
|
u.StatusScrollText = fmt.Sprintf("Scroll: %s Viewport: %s",
|
|
|
|
u.Canvas.Scroll,
|
|
|
|
u.Canvas.Viewport(),
|
|
|
|
)
|
|
|
|
|
|
|
|
// Statusbar filename label.
|
|
|
|
filename := "untitled.map"
|
|
|
|
fileType := "Level"
|
|
|
|
if u.Scene.filename != "" {
|
|
|
|
filename = u.Scene.filename
|
|
|
|
}
|
|
|
|
if u.Scene.DrawingType == enum.DoodadDrawing {
|
|
|
|
fileType = "Doodad"
|
|
|
|
}
|
|
|
|
u.StatusFilenameText = fmt.Sprintf("Filename: %s (%s)",
|
|
|
|
filepath.Base(filename),
|
|
|
|
fileType,
|
|
|
|
)
|
2018-10-19 20:31:58 +00:00
|
|
|
}
|
2018-08-11 00:19:47 +00:00
|
|
|
|
2018-10-20 22:42:49 +00:00
|
|
|
// Recompute widgets.
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
u.MenuBar.Compute(u.d.Engine)
|
2018-08-05 19:54:57 +00:00
|
|
|
u.StatusBar.Compute(u.d.Engine)
|
2018-08-11 00:19:47 +00:00
|
|
|
u.Palette.Compute(u.d.Engine)
|
2018-10-20 22:42:49 +00:00
|
|
|
|
|
|
|
// Only forward events to the Canvas if the UI hasn't stopped them.
|
|
|
|
if !stopPropagation {
|
|
|
|
u.Canvas.Loop(ev)
|
|
|
|
}
|
|
|
|
return nil
|
2018-08-05 19:54:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Present the UI to the screen.
|
|
|
|
func (u *EditorUI) Present(e render.Engine) {
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
// TODO: if I don't Compute() the palette window, then, whenever the dev console
|
|
|
|
// is open the window will blank out its contents leaving only the outermost Frame.
|
|
|
|
// The title bar and borders are gone. But other UI widgets don't do this.
|
|
|
|
// FIXME: Scene interface should have a separate ComputeUI() from Loop()?
|
|
|
|
u.Palette.Compute(u.d.Engine)
|
|
|
|
|
2018-08-11 00:19:47 +00:00
|
|
|
u.Palette.Present(e, u.Palette.Point())
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
u.MenuBar.Present(e, u.MenuBar.Point())
|
2018-08-05 19:54:57 +00:00
|
|
|
u.StatusBar.Present(e, u.StatusBar.Point())
|
2018-10-08 17:38:49 +00:00
|
|
|
u.Workspace.Present(e, u.Workspace.Point())
|
2018-10-20 22:42:49 +00:00
|
|
|
|
|
|
|
// Are we dragging a Doodad canvas?
|
|
|
|
if u.Supervisor.IsDragging() {
|
|
|
|
if actor := u.DraggableActor; actor != nil {
|
|
|
|
var size = actor.canvas.Size()
|
|
|
|
actor.canvas.Present(u.d.Engine, render.NewPoint(
|
|
|
|
u.cursor.X-(size.W/2),
|
|
|
|
u.cursor.Y-(size.H/2),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
2018-10-08 17:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetupWorkspace configures the main Workspace frame that takes up the full
|
|
|
|
// window apart from toolbars. The Workspace has a single child element, the
|
|
|
|
// Canvas, so it can easily full-screen it or center it for Doodad editing.
|
|
|
|
func (u *EditorUI) SetupWorkspace(d *Doodle) *ui.Frame {
|
|
|
|
frame := ui.NewFrame("Workspace")
|
|
|
|
return frame
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetupCanvas configures the main drawing canvas in the editor.
|
|
|
|
func (u *EditorUI) SetupCanvas(d *Doodle) *uix.Canvas {
|
|
|
|
drawing := uix.NewCanvas(balance.ChunkSize, true)
|
WIP Texture Caching
NOTICE: Chunk size set to 100 for visual testing!
NOTICE: guitest references a bmp file that isn't checked in!
BUGS REMAINING:
- When scrolling the level in Edit Mode, some of the chunks will pop
out of existence randomly.
- When clicking-dragging to draw in Edit Mode, if the scroll position
is not at 0,0 then the pixels drawn will be offset from the cursor.
- These are to do with the Scroll position and chunk coordinate calc
functions probably.
Implements a texture caching interface to stop redrawing everything
pixel by pixel on every frame.
The texture caching workflow is briefly:
- The uix.Canvas widget's Present() function iterates over the list of
Chunk Coordinates that are visible inside of the current viewport
(i.e. viewable on screen)
- For each Chunk:
- Make it render and/or return its cached Texture object.
- Work out how much of the Chunk will be visible and how to crop the
boxes for the Copy()
- Copy the cached Texture instead of drawing all the pixels every
time like we were doing before.
- The Chunk.Texture() function that returns said Texture:
- It calls Chunk.ToBitmap() to save a bitmap on disk.
- It calls Engine.NewBitmap() to get a Texture it can hang onto.
- It hangs onto the Texture and returns it on future calls.
- Any call to Set() or Delete() a pixel will invalidate the cache
(mark the Chunk "dirty") and Texture() will rebuild next call.
The interface `render.Texturer` provides a way for rendering backends
(SDL2, OpenGL) to transport a "texture" of their own kind without
exposing the type details to the user.
The interface `render.Engine` adds two new methods:
* NewBitmap(filename string) (Texturer, error)
* Copy(t Texturer, src, dst Rect)
NewBitmap should open a bitmap image on disk and return it wrapped in a
Texturer (really it's an SDL2 Texture). This is for caching purposes.
Next the Copy() function blits the texture onto the screen renderer
using the source and destination rectangles.
The uix.Canvas widget orchestrates the caching for the drawing it's
responsible for. It queries which chunks are viewable in the Canvas
viewport (scroll and bounding boxes), has each chunk render out their
entire bitmap image to then cache them as SDL textures and then only
_those_ need to be copied out to the renderer each frame.
The frame rate now sits at a decent 60 FPS even when the drawing gets
messy and full of lines. Each unique version of each chunk needs to
render only one time and then it's a fast copy operation for future
ticks.
Other changes:
- Chunker now assigns each Chunk what their coordinate and size are, so
that the chunk can self reference that information. This info is
considered read-only but that isn't really enforced.
- Add Chunker.IterViewportChunks() that returns a channel of Chunk
Coordinates that are visible in your viewport, rather than iterating
over all of the pixels in all of those chunks.
- Add Chunk.ToBitmap(filename) that causes a Chunk to render its pixels
to a bitmap image on disk. SDL2 can natively speak Bitmaps for texture
caching. Currently these go to files in /tmp but will soon go into your
$XDG_CACHE_FOLDER instead.
- Add Chunk.Texture() that causes a Chunk to render and then return a
cached bitmap texture of the pixels it's responsible for. The texture
is cached until the Chunk is next modified with Set() or Delete().
- UI: add an Image widget that currently just shows a bitmap image. It
was the first test for caching bitmap images for efficiency. Can show
any *.bmp file on disk!
- Editor UI: make the StatusBar boxes dynamically build from an array
of string pointers to make it SUPER EASY to add/remove labels.
2018-10-18 03:52:14 +00:00
|
|
|
drawing.Name = "edit-canvas"
|
2018-10-08 17:38:49 +00:00
|
|
|
drawing.Palette = level.DefaultPalette()
|
2018-10-20 22:42:49 +00:00
|
|
|
drawing.SetBackground(render.White)
|
2018-10-08 17:38:49 +00:00
|
|
|
if len(drawing.Palette.Swatches) > 0 {
|
|
|
|
drawing.SetSwatch(drawing.Palette.Swatches[0])
|
|
|
|
}
|
2018-10-20 22:42:49 +00:00
|
|
|
|
2018-10-21 00:08:20 +00:00
|
|
|
// Handle the Canvas deleting our actors in edit mode.
|
|
|
|
drawing.OnDeleteActors = func(actors []*level.Actor) {
|
|
|
|
if u.Scene.Level != nil {
|
|
|
|
for _, actor := range actors {
|
|
|
|
u.Scene.Level.Actors.Remove(actor)
|
|
|
|
}
|
|
|
|
drawing.InstallActors(u.Scene.Level.Actors)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A drag event initiated inside the Canvas. This happens in the ActorTool
|
|
|
|
// mode when you click an existing Doodad and it "pops" out of the canvas
|
|
|
|
// and onto the cursor to be repositioned.
|
|
|
|
drawing.OnDragStart = func(filename string) {
|
|
|
|
doodad, err := doodads.LoadJSON(userdir.DoodadPath(filename))
|
|
|
|
if err != nil {
|
|
|
|
log.Error("drawing.OnDragStart: %s", err.Error())
|
|
|
|
}
|
|
|
|
u.startDragActor(doodad)
|
|
|
|
}
|
|
|
|
|
2018-10-20 22:42:49 +00:00
|
|
|
// Set up the drop handler for draggable doodads.
|
|
|
|
// NOTE: The drag event begins at editor_ui_doodad.go when configuring the
|
|
|
|
// Doodad Palette buttons.
|
|
|
|
drawing.Handle(ui.Drop, func(e render.Point) {
|
|
|
|
log.Info("Drawing canvas has received a drop!")
|
|
|
|
var P = ui.AbsolutePosition(drawing)
|
|
|
|
|
|
|
|
// Was it an actor from the Doodad Palette?
|
|
|
|
if actor := u.DraggableActor; actor != nil {
|
|
|
|
log.Info("Actor is a %s", actor.doodad.Filename)
|
|
|
|
if u.Scene.Level == nil {
|
|
|
|
u.d.Flash("Can't drop doodads onto doodad drawings!")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
size := actor.canvas.Size()
|
|
|
|
u.Scene.Level.Actors.Add(&level.Actor{
|
|
|
|
// Uncenter the drawing from the cursor.
|
|
|
|
Point: render.Point{
|
|
|
|
X: (u.cursor.X - drawing.Scroll.X - (size.W / 2)) - P.X,
|
|
|
|
Y: (u.cursor.Y - drawing.Scroll.Y - (size.H / 2)) - P.Y,
|
|
|
|
},
|
|
|
|
Filename: actor.doodad.Filename,
|
|
|
|
})
|
|
|
|
|
|
|
|
drawing.InstallActors(u.Scene.Level.Actors)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
u.Supervisor.Add(drawing)
|
2018-10-08 17:38:49 +00:00
|
|
|
return drawing
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExpandCanvas manually expands the Canvas to fill the frame, to work around
|
|
|
|
// UI packing bugs. Ideally I would use `Expand: true` when packing the Canvas
|
|
|
|
// in its frame, but that would artificially expand the Canvas also when it
|
|
|
|
// _wanted_ to be smaller, as in Doodad Editing Mode.
|
|
|
|
func (u *EditorUI) ExpandCanvas(e render.Engine) {
|
2018-10-19 20:31:58 +00:00
|
|
|
if u.Scene.DrawingType == enum.LevelDrawing {
|
|
|
|
u.Canvas.Resize(u.Workspace.Size())
|
|
|
|
} else {
|
|
|
|
// Size is managed externally.
|
|
|
|
}
|
2018-10-08 17:38:49 +00:00
|
|
|
u.Workspace.Compute(e)
|
2018-08-05 19:54:57 +00:00
|
|
|
}
|
|
|
|
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
// SetupMenuBar sets up the menu bar.
|
|
|
|
func (u *EditorUI) SetupMenuBar(d *Doodle) *ui.Frame {
|
|
|
|
frame := ui.NewFrame("MenuBar")
|
|
|
|
|
2019-04-16 06:22:38 +00:00
|
|
|
// Save and Save As common menu handler
|
|
|
|
var saveFunc func(filename string)
|
|
|
|
|
|
|
|
switch u.Scene.DrawingType {
|
|
|
|
case enum.LevelDrawing:
|
|
|
|
saveFunc = func(filename string) {
|
|
|
|
if err := u.Scene.SaveLevel(filename); err != nil {
|
|
|
|
d.Flash("Error: %s", err)
|
|
|
|
} else {
|
|
|
|
d.Flash("Saved level: %s", filename)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case enum.DoodadDrawing:
|
|
|
|
saveFunc = func(filename string) {
|
|
|
|
if err := u.Scene.SaveDoodad(filename); err != nil {
|
|
|
|
d.Flash("Error: %s", err)
|
|
|
|
} else {
|
|
|
|
d.Flash("Saved doodad: %s", filename)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
d.Flash("Error: Scene.DrawingType is not a valid type")
|
|
|
|
}
|
|
|
|
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
type menuButton struct {
|
|
|
|
Text string
|
|
|
|
Click func(render.Point)
|
|
|
|
}
|
|
|
|
buttons := []menuButton{
|
|
|
|
menuButton{
|
|
|
|
Text: "New Level",
|
|
|
|
Click: func(render.Point) {
|
|
|
|
d.NewMap()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
menuButton{
|
|
|
|
Text: "New Doodad",
|
|
|
|
Click: func(render.Point) {
|
2018-09-26 17:04:46 +00:00
|
|
|
d.Prompt("Doodad size [100]>", func(answer string) {
|
|
|
|
size := balance.DoodadSize
|
|
|
|
if answer != "" {
|
|
|
|
i, err := strconv.Atoi(answer)
|
|
|
|
if err != nil {
|
|
|
|
d.Flash("Error: Doodad size must be a number.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
size = i
|
|
|
|
}
|
|
|
|
d.NewDoodad(size)
|
|
|
|
})
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
menuButton{
|
|
|
|
Text: "Save",
|
|
|
|
Click: func(render.Point) {
|
|
|
|
if u.Scene.filename != "" {
|
2018-09-26 17:04:46 +00:00
|
|
|
saveFunc(u.Scene.filename)
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
} else {
|
|
|
|
d.Prompt("Save filename>", func(answer string) {
|
|
|
|
if answer != "" {
|
2018-09-26 17:04:46 +00:00
|
|
|
saveFunc(answer)
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
menuButton{
|
|
|
|
Text: "Save as...",
|
|
|
|
Click: func(render.Point) {
|
|
|
|
d.Prompt("Save as filename>", func(answer string) {
|
|
|
|
if answer != "" {
|
2019-04-16 06:22:38 +00:00
|
|
|
saveFunc(answer)
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
menuButton{
|
|
|
|
Text: "Load",
|
|
|
|
Click: func(render.Point) {
|
|
|
|
d.Prompt("Open filename>", func(answer string) {
|
|
|
|
if answer != "" {
|
2019-04-16 06:22:38 +00:00
|
|
|
if err := d.EditFile(answer); err != nil {
|
2019-04-20 00:23:37 +00:00
|
|
|
d.Flash(err.Error())
|
2019-04-16 06:22:38 +00:00
|
|
|
}
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, btn := range buttons {
|
2019-04-20 00:23:37 +00:00
|
|
|
if balance.FreeVersion {
|
|
|
|
if btn.Text == "New Doodad" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
w := ui.NewButton(btn.Text, ui.NewLabel(ui.Label{
|
|
|
|
Text: btn.Text,
|
|
|
|
Font: balance.MenuFont,
|
|
|
|
}))
|
|
|
|
w.Configure(ui.Config{
|
|
|
|
BorderSize: 1,
|
|
|
|
OutlineSize: 0,
|
|
|
|
})
|
2018-08-17 03:37:19 +00:00
|
|
|
w.Handle(ui.MouseUp, btn.Click)
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
u.Supervisor.Add(w)
|
|
|
|
frame.Pack(w, ui.Pack{
|
|
|
|
Anchor: ui.W,
|
|
|
|
PadX: 1,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
frame.Compute(d.Engine)
|
|
|
|
return frame
|
|
|
|
}
|
|
|
|
|
2018-08-11 00:19:47 +00:00
|
|
|
// SetupPalette sets up the palette panel.
|
|
|
|
func (u *EditorUI) SetupPalette(d *Doodle) *ui.Window {
|
|
|
|
window := ui.NewWindow("Palette")
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
window.ConfigureTitle(balance.TitleConfig)
|
|
|
|
window.TitleBar().Font = balance.TitleFont
|
2018-08-11 00:19:47 +00:00
|
|
|
window.Configure(ui.Config{
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
Background: balance.WindowBackground,
|
|
|
|
BorderColor: balance.WindowBorder,
|
2018-08-11 00:19:47 +00:00
|
|
|
})
|
|
|
|
|
2018-10-08 20:06:42 +00:00
|
|
|
// Frame that holds the tab buttons in Level Edit mode.
|
|
|
|
tabFrame := ui.NewFrame("Palette Tabs")
|
|
|
|
for _, name := range []string{"Palette", "Doodads"} {
|
|
|
|
if u.paletteTab == "" {
|
|
|
|
u.paletteTab = name
|
2018-08-11 00:19:47 +00:00
|
|
|
}
|
2018-10-08 20:06:42 +00:00
|
|
|
|
|
|
|
tab := ui.NewRadioButton("Palette Tab", &u.paletteTab, name, ui.NewLabel(ui.Label{
|
|
|
|
Text: name,
|
|
|
|
}))
|
|
|
|
tab.Handle(ui.Click, func(p render.Point) {
|
|
|
|
if u.paletteTab == "Palette" {
|
2018-10-21 00:08:20 +00:00
|
|
|
u.Canvas.Tool = uix.PencilTool
|
2018-10-08 20:06:42 +00:00
|
|
|
u.PaletteTab.Show()
|
|
|
|
u.DoodadTab.Hide()
|
|
|
|
} else {
|
2018-10-21 00:08:20 +00:00
|
|
|
u.Canvas.Tool = uix.ActorTool
|
2018-10-08 20:06:42 +00:00
|
|
|
u.PaletteTab.Hide()
|
|
|
|
u.DoodadTab.Show()
|
|
|
|
}
|
|
|
|
window.Compute(d.Engine)
|
|
|
|
})
|
|
|
|
u.Supervisor.Add(tab)
|
|
|
|
tabFrame.Pack(tab, ui.Pack{
|
|
|
|
Anchor: ui.W,
|
|
|
|
Fill: true,
|
|
|
|
Expand: true,
|
|
|
|
})
|
2018-08-11 00:19:47 +00:00
|
|
|
}
|
2018-10-08 20:06:42 +00:00
|
|
|
window.Pack(tabFrame, ui.Pack{
|
|
|
|
Anchor: ui.N,
|
|
|
|
Fill: true,
|
|
|
|
PadY: 4,
|
|
|
|
})
|
2018-08-11 00:19:47 +00:00
|
|
|
|
2018-10-21 00:08:20 +00:00
|
|
|
// Only show the tab frame in Level drawing mode!
|
|
|
|
if u.Scene.DrawingType != enum.LevelDrawing {
|
|
|
|
tabFrame.Hide()
|
|
|
|
}
|
|
|
|
|
2018-10-08 20:06:42 +00:00
|
|
|
// Doodad frame.
|
|
|
|
{
|
2018-10-20 22:42:49 +00:00
|
|
|
frame, err := u.setupDoodadFrame(d.Engine, window)
|
|
|
|
if err != nil {
|
|
|
|
d.Flash(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Even if there was an error (userdir.ListDoodads couldn't read the
|
|
|
|
// config folder on disk or whatever) the Frame is still valid but
|
|
|
|
// empty, which is still the intended behavior.
|
|
|
|
u.DoodadTab = frame
|
2018-10-08 20:06:42 +00:00
|
|
|
u.DoodadTab.Hide()
|
|
|
|
window.Pack(u.DoodadTab, ui.Pack{
|
|
|
|
Anchor: ui.N,
|
|
|
|
Fill: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Color Palette Frame.
|
2018-10-20 22:42:49 +00:00
|
|
|
u.PaletteTab = u.setupPaletteFrame(window)
|
|
|
|
window.Pack(u.PaletteTab, ui.Pack{
|
|
|
|
Anchor: ui.N,
|
|
|
|
Fill: true,
|
|
|
|
})
|
2018-08-11 00:19:47 +00:00
|
|
|
|
|
|
|
return window
|
|
|
|
}
|
|
|
|
|
2018-08-05 19:54:57 +00:00
|
|
|
// SetupStatusBar sets up the status bar widget along the bottom of the window.
|
|
|
|
func (u *EditorUI) SetupStatusBar(d *Doodle) *ui.Frame {
|
|
|
|
frame := ui.NewFrame("Status Bar")
|
|
|
|
frame.Configure(ui.Config{
|
|
|
|
BorderStyle: ui.BorderRaised,
|
|
|
|
Background: render.Grey,
|
|
|
|
BorderSize: 2,
|
|
|
|
})
|
|
|
|
|
2018-08-11 00:19:47 +00:00
|
|
|
style := ui.Config{
|
2018-08-05 19:54:57 +00:00
|
|
|
Background: render.Grey,
|
|
|
|
BorderStyle: ui.BorderSunken,
|
|
|
|
BorderColor: render.Grey,
|
|
|
|
BorderSize: 1,
|
2018-08-11 00:19:47 +00:00
|
|
|
}
|
|
|
|
|
WIP Texture Caching
NOTICE: Chunk size set to 100 for visual testing!
NOTICE: guitest references a bmp file that isn't checked in!
BUGS REMAINING:
- When scrolling the level in Edit Mode, some of the chunks will pop
out of existence randomly.
- When clicking-dragging to draw in Edit Mode, if the scroll position
is not at 0,0 then the pixels drawn will be offset from the cursor.
- These are to do with the Scroll position and chunk coordinate calc
functions probably.
Implements a texture caching interface to stop redrawing everything
pixel by pixel on every frame.
The texture caching workflow is briefly:
- The uix.Canvas widget's Present() function iterates over the list of
Chunk Coordinates that are visible inside of the current viewport
(i.e. viewable on screen)
- For each Chunk:
- Make it render and/or return its cached Texture object.
- Work out how much of the Chunk will be visible and how to crop the
boxes for the Copy()
- Copy the cached Texture instead of drawing all the pixels every
time like we were doing before.
- The Chunk.Texture() function that returns said Texture:
- It calls Chunk.ToBitmap() to save a bitmap on disk.
- It calls Engine.NewBitmap() to get a Texture it can hang onto.
- It hangs onto the Texture and returns it on future calls.
- Any call to Set() or Delete() a pixel will invalidate the cache
(mark the Chunk "dirty") and Texture() will rebuild next call.
The interface `render.Texturer` provides a way for rendering backends
(SDL2, OpenGL) to transport a "texture" of their own kind without
exposing the type details to the user.
The interface `render.Engine` adds two new methods:
* NewBitmap(filename string) (Texturer, error)
* Copy(t Texturer, src, dst Rect)
NewBitmap should open a bitmap image on disk and return it wrapped in a
Texturer (really it's an SDL2 Texture). This is for caching purposes.
Next the Copy() function blits the texture onto the screen renderer
using the source and destination rectangles.
The uix.Canvas widget orchestrates the caching for the drawing it's
responsible for. It queries which chunks are viewable in the Canvas
viewport (scroll and bounding boxes), has each chunk render out their
entire bitmap image to then cache them as SDL textures and then only
_those_ need to be copied out to the renderer each frame.
The frame rate now sits at a decent 60 FPS even when the drawing gets
messy and full of lines. Each unique version of each chunk needs to
render only one time and then it's a fast copy operation for future
ticks.
Other changes:
- Chunker now assigns each Chunk what their coordinate and size are, so
that the chunk can self reference that information. This info is
considered read-only but that isn't really enforced.
- Add Chunker.IterViewportChunks() that returns a channel of Chunk
Coordinates that are visible in your viewport, rather than iterating
over all of the pixels in all of those chunks.
- Add Chunk.ToBitmap(filename) that causes a Chunk to render its pixels
to a bitmap image on disk. SDL2 can natively speak Bitmaps for texture
caching. Currently these go to files in /tmp but will soon go into your
$XDG_CACHE_FOLDER instead.
- Add Chunk.Texture() that causes a Chunk to render and then return a
cached bitmap texture of the pixels it's responsible for. The texture
is cached until the Chunk is next modified with Set() or Delete().
- UI: add an Image widget that currently just shows a bitmap image. It
was the first test for caching bitmap images for efficiency. Can show
any *.bmp file on disk!
- Editor UI: make the StatusBar boxes dynamically build from an array
of string pointers to make it SUPER EASY to add/remove labels.
2018-10-18 03:52:14 +00:00
|
|
|
var labelHeight int32
|
|
|
|
for _, variable := range u.StatusBoxes {
|
|
|
|
label := ui.NewLabel(ui.Label{
|
|
|
|
TextVariable: variable,
|
|
|
|
Font: balance.StatusFont,
|
|
|
|
})
|
|
|
|
label.Configure(style)
|
|
|
|
label.Compute(d.Engine)
|
|
|
|
frame.Pack(label, ui.Pack{
|
|
|
|
Anchor: ui.W,
|
|
|
|
PadX: 1,
|
|
|
|
})
|
2018-08-11 00:19:47 +00:00
|
|
|
|
WIP Texture Caching
NOTICE: Chunk size set to 100 for visual testing!
NOTICE: guitest references a bmp file that isn't checked in!
BUGS REMAINING:
- When scrolling the level in Edit Mode, some of the chunks will pop
out of existence randomly.
- When clicking-dragging to draw in Edit Mode, if the scroll position
is not at 0,0 then the pixels drawn will be offset from the cursor.
- These are to do with the Scroll position and chunk coordinate calc
functions probably.
Implements a texture caching interface to stop redrawing everything
pixel by pixel on every frame.
The texture caching workflow is briefly:
- The uix.Canvas widget's Present() function iterates over the list of
Chunk Coordinates that are visible inside of the current viewport
(i.e. viewable on screen)
- For each Chunk:
- Make it render and/or return its cached Texture object.
- Work out how much of the Chunk will be visible and how to crop the
boxes for the Copy()
- Copy the cached Texture instead of drawing all the pixels every
time like we were doing before.
- The Chunk.Texture() function that returns said Texture:
- It calls Chunk.ToBitmap() to save a bitmap on disk.
- It calls Engine.NewBitmap() to get a Texture it can hang onto.
- It hangs onto the Texture and returns it on future calls.
- Any call to Set() or Delete() a pixel will invalidate the cache
(mark the Chunk "dirty") and Texture() will rebuild next call.
The interface `render.Texturer` provides a way for rendering backends
(SDL2, OpenGL) to transport a "texture" of their own kind without
exposing the type details to the user.
The interface `render.Engine` adds two new methods:
* NewBitmap(filename string) (Texturer, error)
* Copy(t Texturer, src, dst Rect)
NewBitmap should open a bitmap image on disk and return it wrapped in a
Texturer (really it's an SDL2 Texture). This is for caching purposes.
Next the Copy() function blits the texture onto the screen renderer
using the source and destination rectangles.
The uix.Canvas widget orchestrates the caching for the drawing it's
responsible for. It queries which chunks are viewable in the Canvas
viewport (scroll and bounding boxes), has each chunk render out their
entire bitmap image to then cache them as SDL textures and then only
_those_ need to be copied out to the renderer each frame.
The frame rate now sits at a decent 60 FPS even when the drawing gets
messy and full of lines. Each unique version of each chunk needs to
render only one time and then it's a fast copy operation for future
ticks.
Other changes:
- Chunker now assigns each Chunk what their coordinate and size are, so
that the chunk can self reference that information. This info is
considered read-only but that isn't really enforced.
- Add Chunker.IterViewportChunks() that returns a channel of Chunk
Coordinates that are visible in your viewport, rather than iterating
over all of the pixels in all of those chunks.
- Add Chunk.ToBitmap(filename) that causes a Chunk to render its pixels
to a bitmap image on disk. SDL2 can natively speak Bitmaps for texture
caching. Currently these go to files in /tmp but will soon go into your
$XDG_CACHE_FOLDER instead.
- Add Chunk.Texture() that causes a Chunk to render and then return a
cached bitmap texture of the pixels it's responsible for. The texture
is cached until the Chunk is next modified with Set() or Delete().
- UI: add an Image widget that currently just shows a bitmap image. It
was the first test for caching bitmap images for efficiency. Can show
any *.bmp file on disk!
- Editor UI: make the StatusBar boxes dynamically build from an array
of string pointers to make it SUPER EASY to add/remove labels.
2018-10-18 03:52:14 +00:00
|
|
|
if labelHeight == 0 {
|
|
|
|
labelHeight = label.BoxSize().H
|
|
|
|
}
|
|
|
|
}
|
2018-08-05 19:54:57 +00:00
|
|
|
|
2018-08-11 00:19:47 +00:00
|
|
|
// TODO: right-aligned labels clip out of bounds
|
2018-10-08 17:38:49 +00:00
|
|
|
extraLabel := ui.NewLabel(ui.Label{
|
|
|
|
Text: "blah",
|
|
|
|
Font: balance.StatusFont,
|
|
|
|
})
|
|
|
|
extraLabel.Configure(ui.Config{
|
|
|
|
Background: render.Grey,
|
|
|
|
BorderStyle: ui.BorderSunken,
|
|
|
|
BorderColor: render.Grey,
|
|
|
|
BorderSize: 1,
|
|
|
|
})
|
|
|
|
extraLabel.Compute(d.Engine)
|
|
|
|
frame.Pack(extraLabel, ui.Pack{
|
|
|
|
Anchor: ui.E,
|
|
|
|
})
|
2018-08-05 19:54:57 +00:00
|
|
|
|
2018-10-19 20:31:58 +00:00
|
|
|
// Set the initial good frame size to have the height secured,
|
|
|
|
// so when resizing the application window we can just adjust for width.
|
2018-08-05 19:54:57 +00:00
|
|
|
frame.Resize(render.Rect{
|
2018-10-19 20:31:58 +00:00
|
|
|
W: int32(d.width),
|
WIP Texture Caching
NOTICE: Chunk size set to 100 for visual testing!
NOTICE: guitest references a bmp file that isn't checked in!
BUGS REMAINING:
- When scrolling the level in Edit Mode, some of the chunks will pop
out of existence randomly.
- When clicking-dragging to draw in Edit Mode, if the scroll position
is not at 0,0 then the pixels drawn will be offset from the cursor.
- These are to do with the Scroll position and chunk coordinate calc
functions probably.
Implements a texture caching interface to stop redrawing everything
pixel by pixel on every frame.
The texture caching workflow is briefly:
- The uix.Canvas widget's Present() function iterates over the list of
Chunk Coordinates that are visible inside of the current viewport
(i.e. viewable on screen)
- For each Chunk:
- Make it render and/or return its cached Texture object.
- Work out how much of the Chunk will be visible and how to crop the
boxes for the Copy()
- Copy the cached Texture instead of drawing all the pixels every
time like we were doing before.
- The Chunk.Texture() function that returns said Texture:
- It calls Chunk.ToBitmap() to save a bitmap on disk.
- It calls Engine.NewBitmap() to get a Texture it can hang onto.
- It hangs onto the Texture and returns it on future calls.
- Any call to Set() or Delete() a pixel will invalidate the cache
(mark the Chunk "dirty") and Texture() will rebuild next call.
The interface `render.Texturer` provides a way for rendering backends
(SDL2, OpenGL) to transport a "texture" of their own kind without
exposing the type details to the user.
The interface `render.Engine` adds two new methods:
* NewBitmap(filename string) (Texturer, error)
* Copy(t Texturer, src, dst Rect)
NewBitmap should open a bitmap image on disk and return it wrapped in a
Texturer (really it's an SDL2 Texture). This is for caching purposes.
Next the Copy() function blits the texture onto the screen renderer
using the source and destination rectangles.
The uix.Canvas widget orchestrates the caching for the drawing it's
responsible for. It queries which chunks are viewable in the Canvas
viewport (scroll and bounding boxes), has each chunk render out their
entire bitmap image to then cache them as SDL textures and then only
_those_ need to be copied out to the renderer each frame.
The frame rate now sits at a decent 60 FPS even when the drawing gets
messy and full of lines. Each unique version of each chunk needs to
render only one time and then it's a fast copy operation for future
ticks.
Other changes:
- Chunker now assigns each Chunk what their coordinate and size are, so
that the chunk can self reference that information. This info is
considered read-only but that isn't really enforced.
- Add Chunker.IterViewportChunks() that returns a channel of Chunk
Coordinates that are visible in your viewport, rather than iterating
over all of the pixels in all of those chunks.
- Add Chunk.ToBitmap(filename) that causes a Chunk to render its pixels
to a bitmap image on disk. SDL2 can natively speak Bitmaps for texture
caching. Currently these go to files in /tmp but will soon go into your
$XDG_CACHE_FOLDER instead.
- Add Chunk.Texture() that causes a Chunk to render and then return a
cached bitmap texture of the pixels it's responsible for. The texture
is cached until the Chunk is next modified with Set() or Delete().
- UI: add an Image widget that currently just shows a bitmap image. It
was the first test for caching bitmap images for efficiency. Can show
any *.bmp file on disk!
- Editor UI: make the StatusBar boxes dynamically build from an array
of string pointers to make it SUPER EASY to add/remove labels.
2018-10-18 03:52:14 +00:00
|
|
|
H: labelHeight + frame.BoxThickness(1),
|
2018-08-05 19:54:57 +00:00
|
|
|
})
|
|
|
|
frame.Compute(d.Engine)
|
|
|
|
|
|
|
|
return frame
|
|
|
|
}
|