2018-08-05 19:54:57 +00:00
|
|
|
package doodle
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-10-20 22:42:49 +00:00
|
|
|
"path/filepath"
|
2018-08-05 19:54:57 +00:00
|
|
|
|
2019-04-10 00:35:44 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/balance"
|
2019-06-24 00:52:48 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/branding"
|
2021-10-05 05:02:00 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/doodads"
|
2019-07-04 00:19:25 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/drawtool"
|
2019-04-10 00:35:44 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/enum"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/level"
|
2021-06-17 04:55:45 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/license"
|
2019-04-10 00:35:44 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/log"
|
2021-10-05 05:02:00 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/shmem"
|
2019-04-10 00:35:44 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/uix"
|
2021-06-20 05:14:41 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/usercfg"
|
2019-12-28 03:16:34 +00:00
|
|
|
"git.kirsle.net/go/render"
|
|
|
|
"git.kirsle.net/go/render/event"
|
|
|
|
"git.kirsle.net/go/ui"
|
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
|
2020-06-05 04:55:54 +00:00
|
|
|
screen *ui.Frame // full-window parent frame for layout
|
2018-08-05 19:54:57 +00:00
|
|
|
Supervisor *ui.Supervisor
|
2018-10-08 17:38:49 +00:00
|
|
|
Canvas *uix.Canvas
|
|
|
|
Workspace *ui.Frame
|
2020-06-05 04:55:54 +00:00
|
|
|
MenuBar *ui.MenuBar
|
2018-08-05 19:54:57 +00:00
|
|
|
StatusBar *ui.Frame
|
2019-07-04 03:24:04 +00:00
|
|
|
ToolBar *ui.Frame
|
2019-06-26 01:36:53 +00:00
|
|
|
PlayButton *ui.Button
|
2018-10-08 20:06:42 +00:00
|
|
|
|
2020-04-07 06:21:17 +00:00
|
|
|
// Popup windows.
|
2021-09-03 04:26:55 +00:00
|
|
|
levelSettingsWindow *ui.Window
|
|
|
|
doodadPropertiesWindow *ui.Window
|
|
|
|
aboutWindow *ui.Window
|
|
|
|
doodadWindow *ui.Window
|
|
|
|
paletteEditor *ui.Window
|
|
|
|
layersWindow *ui.Window
|
2022-03-05 23:31:09 +00:00
|
|
|
textToolWindow *ui.Window
|
2021-09-03 04:26:55 +00:00
|
|
|
publishWindow *ui.Window
|
|
|
|
filesystemWindow *ui.Window
|
|
|
|
licenseWindow *ui.Window
|
|
|
|
settingsWindow *ui.Window // lazy loaded
|
2020-04-07 06:21:17 +00:00
|
|
|
|
2018-10-08 20:06:42 +00:00
|
|
|
// Palette window.
|
|
|
|
Palette *ui.Window
|
|
|
|
PaletteTab *ui.Frame
|
|
|
|
DoodadTab *ui.Frame
|
|
|
|
|
2019-07-04 03:24:04 +00:00
|
|
|
// ToolBar window.
|
2019-07-04 04:55:15 +00:00
|
|
|
activeTool string
|
2019-07-04 03:24:04 +00:00
|
|
|
|
2018-10-20 22:42:49 +00:00
|
|
|
// Draggable Doodad canvas.
|
|
|
|
DraggableActor *DraggableActor
|
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",
|
|
|
|
}
|
|
|
|
|
2020-06-05 04:55:54 +00:00
|
|
|
// The screen is a full-window-sized frame for laying out the UI.
|
|
|
|
u.screen = ui.NewFrame("screen")
|
|
|
|
u.screen.Resize(render.NewRect(d.width, d.height))
|
|
|
|
u.screen.Compute(d.Engine)
|
|
|
|
|
2019-07-04 03:24:04 +00:00
|
|
|
// Default tool in the toolbox.
|
2019-07-04 04:55:15 +00:00
|
|
|
u.activeTool = drawtool.PencilTool.String()
|
2019-07-04 03:24:04 +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
|
|
|
// 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)
|
2019-07-04 03:24:04 +00:00
|
|
|
u.ToolBar = u.SetupToolbar(d)
|
2018-10-08 17:38:49 +00:00
|
|
|
u.Workspace = u.SetupWorkspace(d) // important that this is last!
|
|
|
|
|
2020-07-10 02:38:37 +00:00
|
|
|
// Preload pop-up windows before they're needed.
|
|
|
|
u.SetupPopups(d)
|
|
|
|
|
2020-06-05 04:55:54 +00:00
|
|
|
u.screen.Pack(u.MenuBar, ui.Pack{
|
|
|
|
Side: ui.N,
|
|
|
|
FillX: true,
|
|
|
|
})
|
|
|
|
|
2021-07-19 03:04:24 +00:00
|
|
|
// Play Button, for levels only.
|
|
|
|
if s.DrawingType == enum.LevelDrawing {
|
|
|
|
u.PlayButton = ui.NewButton("Play", ui.NewLabel(ui.Label{
|
|
|
|
Text: "Play (P)",
|
|
|
|
Font: balance.PlayButtonFont,
|
|
|
|
}))
|
2021-10-05 05:02:00 +00:00
|
|
|
u.PlayButton.Handle(ui.MouseDown, func(ed ui.EventData) error {
|
|
|
|
// Ugly hack: reuse the doodad dropper drag/drop function,
|
|
|
|
// smuggle state by the special filename >.<
|
|
|
|
doodad, _ := doodads.LoadFile(balance.PlayerCharacterDoodad)
|
|
|
|
u.startDragActor(doodad, &level.Actor{
|
|
|
|
Filename: "__play_from_here__",
|
|
|
|
})
|
|
|
|
return nil
|
|
|
|
})
|
2021-07-19 03:04:24 +00:00
|
|
|
u.PlayButton.Handle(ui.Click, func(ed ui.EventData) error {
|
|
|
|
u.Scene.Playtest()
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
u.Supervisor.Add(u.PlayButton)
|
|
|
|
}
|
2019-06-26 01:36:53 +00:00
|
|
|
|
2018-10-08 17:38:49 +00:00
|
|
|
// Position the Canvas inside the frame.
|
|
|
|
u.Workspace.Pack(u.Canvas, ui.Pack{
|
2019-12-29 05:48:49 +00:00
|
|
|
Side: ui.N,
|
2018-10-08 17:38:49 +00:00
|
|
|
})
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-04-09 21:41:24 +00:00
|
|
|
// Teardown the UI manager and free all the SDL2 textures under its control.
|
|
|
|
func (u *EditorUI) Teardown() {
|
|
|
|
log.Debug("EditorUI.Teardown()")
|
|
|
|
u.Canvas.Destroy()
|
|
|
|
}
|
|
|
|
|
2019-06-26 00:43:23 +00:00
|
|
|
// FinishSetup runs the Setup tasks that must be postponed til the end, such
|
|
|
|
// as rendering the Palette window so that it can accurately show the palette
|
|
|
|
// loaded from a level.
|
|
|
|
func (u *EditorUI) FinishSetup(d *Doodle) {
|
|
|
|
u.Palette = u.SetupPalette(d)
|
|
|
|
u.Resized(d)
|
|
|
|
}
|
|
|
|
|
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) {
|
2020-06-05 04:55:54 +00:00
|
|
|
// Resize the screen frame to fill the window.
|
|
|
|
u.screen.Resize(render.NewRect(d.width, d.height))
|
|
|
|
u.screen.Compute(d.Engine)
|
|
|
|
menuHeight := 20 // TODO: ideally the MenuBar should know its own height and we can ask
|
2018-10-19 20:31:58 +00:00
|
|
|
|
|
|
|
// Status Bar.
|
|
|
|
{
|
|
|
|
u.StatusBar.Configure(ui.Config{
|
2019-12-28 03:16:34 +00:00
|
|
|
Width: d.width,
|
2018-10-19 20:31:58 +00:00
|
|
|
})
|
|
|
|
u.StatusBar.MoveTo(render.Point{
|
|
|
|
X: 0,
|
2019-12-28 03:16:34 +00:00
|
|
|
Y: d.height - u.StatusBar.Size().H,
|
2018-10-19 20:31:58 +00:00
|
|
|
})
|
|
|
|
u.StatusBar.Compute(d.Engine)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Palette panel.
|
|
|
|
{
|
2021-06-20 05:14:41 +00:00
|
|
|
if usercfg.Current.HorizontalToolbars {
|
2021-06-14 04:23:26 +00:00
|
|
|
u.Palette.Configure(ui.Config{
|
|
|
|
Width: u.d.width,
|
|
|
|
Height: paletteWidth,
|
|
|
|
})
|
|
|
|
u.Palette.MoveTo(render.NewPoint(
|
|
|
|
0,
|
|
|
|
u.d.height-u.Palette.BoxSize().H-u.StatusBar.Size().H,
|
|
|
|
))
|
|
|
|
} else {
|
|
|
|
u.Palette.Configure(ui.Config{
|
|
|
|
Width: paletteWidth,
|
|
|
|
Height: u.d.height - u.StatusBar.Size().H,
|
|
|
|
})
|
|
|
|
u.Palette.MoveTo(render.NewPoint(
|
|
|
|
u.d.width-u.Palette.BoxSize().W,
|
|
|
|
menuHeight,
|
|
|
|
))
|
|
|
|
}
|
2018-10-19 20:31:58 +00:00
|
|
|
u.Palette.Compute(d.Engine)
|
|
|
|
}
|
|
|
|
|
2021-06-14 04:23:26 +00:00
|
|
|
var (
|
|
|
|
innerHeight = u.d.height - menuHeight - u.StatusBar.Size().H
|
|
|
|
innerWidth = u.d.width
|
|
|
|
)
|
2019-07-04 03:24:04 +00:00
|
|
|
|
|
|
|
// Tool Bar.
|
|
|
|
{
|
2021-06-14 04:23:26 +00:00
|
|
|
tbSize := ui.Config{
|
2019-07-04 03:24:04 +00:00
|
|
|
Width: toolbarWidth,
|
|
|
|
Height: innerHeight,
|
2021-06-14 04:23:26 +00:00
|
|
|
}
|
2021-06-20 05:14:41 +00:00
|
|
|
if usercfg.Current.HorizontalToolbars {
|
2021-06-14 04:23:26 +00:00
|
|
|
tbSize.Width = innerWidth
|
|
|
|
tbSize.Height = toolbarWidth
|
|
|
|
}
|
|
|
|
u.ToolBar.Configure(tbSize)
|
2019-07-04 03:24:04 +00:00
|
|
|
u.ToolBar.MoveTo(render.NewPoint(
|
|
|
|
0,
|
2020-06-05 04:55:54 +00:00
|
|
|
menuHeight,
|
2019-07-04 03:24:04 +00:00
|
|
|
))
|
|
|
|
u.ToolBar.Compute(d.Engine)
|
|
|
|
}
|
|
|
|
|
2018-10-19 20:31:58 +00:00
|
|
|
// Position the workspace around with the other widgets.
|
|
|
|
{
|
2019-07-02 22:24:46 +00:00
|
|
|
|
2018-10-19 20:31:58 +00:00
|
|
|
frame := u.Workspace
|
2021-06-20 05:14:41 +00:00
|
|
|
if usercfg.Current.HorizontalToolbars {
|
2021-06-14 04:23:26 +00:00
|
|
|
frame.MoveTo(render.NewPoint(
|
|
|
|
0,
|
|
|
|
menuHeight+u.ToolBar.Size().H,
|
|
|
|
))
|
|
|
|
frame.Resize(render.NewRect(
|
|
|
|
d.width,
|
|
|
|
d.height-menuHeight-u.StatusBar.Size().H-u.ToolBar.Size().H-u.Palette.Size().H,
|
|
|
|
))
|
|
|
|
} else {
|
|
|
|
frame.MoveTo(render.NewPoint(
|
|
|
|
u.ToolBar.Size().W,
|
|
|
|
menuHeight,
|
|
|
|
))
|
|
|
|
frame.Resize(render.NewRect(
|
|
|
|
d.width-u.Palette.Size().W-u.ToolBar.Size().W,
|
|
|
|
d.height-menuHeight-u.StatusBar.Size().H,
|
|
|
|
))
|
|
|
|
}
|
2018-10-19 20:31:58 +00:00
|
|
|
frame.Compute(d.Engine)
|
|
|
|
|
|
|
|
u.ExpandCanvas(d.Engine)
|
|
|
|
}
|
2019-06-26 01:36:53 +00:00
|
|
|
|
|
|
|
// Position the Play button over the workspace.
|
2021-07-19 03:04:24 +00:00
|
|
|
if u.PlayButton != nil {
|
2019-06-26 01:36:53 +00:00
|
|
|
btn := u.PlayButton
|
|
|
|
btn.Compute(d.Engine)
|
|
|
|
|
|
|
|
var (
|
2019-12-28 03:16:34 +00:00
|
|
|
wsP = u.Workspace.Point()
|
|
|
|
wsSize = u.Workspace.Size()
|
|
|
|
btnSize = btn.Size()
|
|
|
|
padding = 8
|
2019-06-26 01:36:53 +00:00
|
|
|
)
|
|
|
|
btn.MoveTo(render.NewPoint(
|
|
|
|
wsP.X+wsSize.W-btnSize.W-padding,
|
|
|
|
wsP.Y+wsSize.H-btnSize.H-padding,
|
|
|
|
))
|
|
|
|
}
|
2018-10-19 20:31:58 +00:00
|
|
|
}
|
|
|
|
|
2018-08-05 19:54:57 +00:00
|
|
|
// Loop to process events and update the UI.
|
2019-12-22 22:11:01 +00:00
|
|
|
func (u *EditorUI) Loop(ev *event.State) error {
|
2019-12-28 03:16:34 +00:00
|
|
|
u.cursor = render.NewPoint(ev.CursorX, ev.CursorY)
|
2018-10-20 22:42:49 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
{
|
2022-01-09 21:16:29 +00:00
|
|
|
u.StatusMouseText = fmt.Sprintf("Rel:(%s) Abs:(%d,%d)",
|
|
|
|
*u.Scene.debWorldIndex,
|
2019-12-22 22:11:01 +00:00
|
|
|
ev.CursorX,
|
|
|
|
ev.CursorY,
|
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.
|
2019-07-07 06:28:11 +00:00
|
|
|
filename := "untitled.level"
|
2018-10-20 22:42:49 +00:00
|
|
|
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.
|
2019-07-04 03:24:04 +00:00
|
|
|
// Explanation: if I don't, the UI packing algorithm somehow causes widgets
|
|
|
|
// to creep away every frame and fly right off the screen. For example the
|
|
|
|
// ToolBar's buttons would start packed at the top of the bar but then just
|
|
|
|
// move themselves every frame downward and away.
|
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)
|
2019-07-04 03:24:04 +00:00
|
|
|
u.ToolBar.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.
|
2020-04-09 01:21:29 +00:00
|
|
|
// Also ignore events if a managed ui.Window is overlapping the canvas.
|
2020-06-05 04:55:54 +00:00
|
|
|
// Also ignore if an active modal (popup menu) is on screen.
|
|
|
|
if !(stopPropagation || u.Supervisor.IsPointInWindow(u.cursor) || u.Supervisor.GetModal() != nil) {
|
2018-10-20 22:42:49 +00:00
|
|
|
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) {
|
2020-03-10 05:22:22 +00:00
|
|
|
// Draw the workspace canvas first. Rationale: we want it to have the lowest
|
|
|
|
// Z-index so Tooltips can pop on top of the workspace.
|
|
|
|
u.Workspace.Present(e, u.Workspace.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
|
|
|
// 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())
|
2019-07-04 03:24:04 +00:00
|
|
|
u.ToolBar.Present(e, u.ToolBar.Point())
|
2021-07-19 03:04:24 +00:00
|
|
|
if u.PlayButton != nil {
|
|
|
|
u.PlayButton.Present(e, u.PlayButton.Point())
|
|
|
|
}
|
2018-10-20 22:42:49 +00:00
|
|
|
|
2020-06-05 04:55:54 +00:00
|
|
|
u.screen.Present(e, render.Origin)
|
|
|
|
|
2021-10-11 22:57:33 +00:00
|
|
|
// Draw the crosshair over the level canvas, but not over UI popups.
|
|
|
|
uix.DrawCrosshair(e, u.Canvas, usercfg.Current.CrosshairColor, usercfg.Current.CrosshairSize)
|
|
|
|
|
2020-07-10 02:38:37 +00:00
|
|
|
// Draw any windows being managed by Supervisor.
|
|
|
|
u.Supervisor.Present(e)
|
|
|
|
|
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()
|
2021-09-12 04:18:22 +00:00
|
|
|
|
|
|
|
// Scale the actor up or down by the zoom level of the Editor Canvas.
|
|
|
|
// TODO: didn't seem to make a difference
|
|
|
|
// size.W = u.Canvas.ZoomMultiply(size.W)
|
|
|
|
// size.H = u.Canvas.ZoomMultiply(size.H)
|
|
|
|
// actor.canvas.Zoom = u.Canvas.Zoom
|
|
|
|
|
2018-10-20 22:42:49 +00:00
|
|
|
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.
|
2022-04-09 21:41:24 +00:00
|
|
|
drawing.OnDeleteActors = func(actors []*uix.Actor) {
|
2018-10-21 00:08:20 +00:00
|
|
|
if u.Scene.Level != nil {
|
|
|
|
for _, actor := range actors {
|
2022-04-09 21:41:24 +00:00
|
|
|
u.Scene.Level.Actors.Remove(actor.Actor)
|
2018-10-21 00:08:20 +00:00
|
|
|
}
|
2021-08-12 03:40:31 +00:00
|
|
|
u.Scene.Level.PruneLinks()
|
2018-10-21 00:08:20 +00:00
|
|
|
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.
|
2019-07-05 23:04:36 +00:00
|
|
|
drawing.OnDragStart = func(actor *level.Actor) {
|
2020-07-10 02:38:37 +00:00
|
|
|
log.Warn("drawing.OnDragStart: grab actor %s", actor)
|
2019-07-05 23:04:36 +00:00
|
|
|
u.startDragActor(nil, actor)
|
2018-10-21 00:08:20 +00:00
|
|
|
}
|
|
|
|
|
2019-06-23 23:15:09 +00:00
|
|
|
// A link event to connect two actors together.
|
2019-06-28 05:54:46 +00:00
|
|
|
drawing.OnLinkActors = func(a, b *uix.Actor) {
|
|
|
|
// The actors are a uix.Actor which houses a level.Actor which we
|
|
|
|
// want to update to map each other's IDs.
|
|
|
|
idA, idB := a.Actor.ID(), b.Actor.ID()
|
2021-08-12 03:40:31 +00:00
|
|
|
|
|
|
|
// Are they already linked?
|
|
|
|
if a.Actor.IsLinked(idB) || b.Actor.IsLinked(idA) {
|
|
|
|
a.Actor.Unlink(idB)
|
|
|
|
b.Actor.Unlink(idA)
|
|
|
|
} else {
|
|
|
|
a.Actor.AddLink(idB)
|
|
|
|
b.Actor.AddLink(idA)
|
|
|
|
}
|
2019-06-23 23:15:09 +00:00
|
|
|
|
|
|
|
// Reset the Link tool.
|
2020-04-05 04:00:32 +00:00
|
|
|
d.Flash("Linked '%s' and '%s' together", a.Doodad().Title, b.Doodad().Title)
|
2019-06-23 23:15:09 +00:00
|
|
|
}
|
|
|
|
|
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.
|
2020-04-07 06:21:17 +00:00
|
|
|
drawing.Handle(ui.Drop, func(ed ui.EventData) error {
|
2021-09-12 04:18:22 +00:00
|
|
|
// Editor Canvas's position relative to the window.
|
2018-10-20 22:42:49 +00:00
|
|
|
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)
|
2020-07-10 02:38:37 +00:00
|
|
|
|
|
|
|
// The actor has been dropped so null it out.
|
|
|
|
defer func() {
|
2022-04-09 21:41:24 +00:00
|
|
|
u.DraggableActor.Teardown()
|
2020-07-10 02:38:37 +00:00
|
|
|
u.DraggableActor = nil
|
|
|
|
}()
|
|
|
|
|
2018-10-20 22:42:49 +00:00
|
|
|
if u.Scene.Level == nil {
|
|
|
|
u.d.Flash("Can't drop doodads onto doodad drawings!")
|
2020-04-07 06:21:17 +00:00
|
|
|
return nil
|
2018-10-20 22:42:49 +00:00
|
|
|
}
|
|
|
|
|
2020-07-10 02:38:37 +00:00
|
|
|
// If they dropped it onto a UI window, ignore it.
|
|
|
|
if u.Supervisor.IsPointInWindow(ed.Point) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-07-05 23:04:36 +00:00
|
|
|
var (
|
2018-10-20 22:42:49 +00:00
|
|
|
// Uncenter the drawing from the cursor.
|
2019-07-05 23:04:36 +00:00
|
|
|
size = actor.canvas.Size()
|
|
|
|
position = render.Point{
|
2018-10-20 22:42:49 +00:00
|
|
|
X: (u.cursor.X - drawing.Scroll.X - (size.W / 2)) - P.X,
|
|
|
|
Y: (u.cursor.Y - drawing.Scroll.Y - (size.H / 2)) - P.Y,
|
2019-07-05 23:04:36 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-09-12 04:18:22 +00:00
|
|
|
// Adjust the level position per the zoom factor.
|
|
|
|
position.X = drawing.ZoomDivide(position.X)
|
|
|
|
position.Y = drawing.ZoomDivide(position.Y)
|
|
|
|
|
2019-07-05 23:04:36 +00:00
|
|
|
// Was it an already existing actor to re-add to the map?
|
|
|
|
if actor.actor != nil {
|
2021-10-05 05:02:00 +00:00
|
|
|
// Was this doodad drop, the Play Level button?
|
|
|
|
if actor.actor.Filename == "__play_from_here__" {
|
|
|
|
if shmem.Cursor.Inside(u.PlayButton.Rect()) {
|
|
|
|
u.Scene.Playtest()
|
|
|
|
} else {
|
|
|
|
u.Scene.PlaytestFrom(position)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2021-10-08 03:50:24 +00:00
|
|
|
|
|
|
|
actor.actor.Point = position
|
|
|
|
u.Scene.Level.Actors.Add(actor.actor)
|
2019-07-05 23:04:36 +00:00
|
|
|
} else {
|
|
|
|
u.Scene.Level.Actors.Add(&level.Actor{
|
|
|
|
Point: position,
|
|
|
|
Filename: actor.doodad.Filename,
|
|
|
|
})
|
|
|
|
}
|
2018-10-20 22:42:49 +00:00
|
|
|
|
2019-05-05 22:12:15 +00:00
|
|
|
err := drawing.InstallActors(u.Scene.Level.Actors)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Error installing actor onDrop to canvas: %s", err)
|
|
|
|
}
|
2018-10-20 22:42:49 +00:00
|
|
|
}
|
2020-04-07 06:21:17 +00:00
|
|
|
|
|
|
|
return nil
|
2018-10-20 22:42:49 +00:00
|
|
|
})
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2019-12-28 03:16:34 +00:00
|
|
|
var labelHeight int
|
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
|
|
|
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{
|
2019-12-29 05:48:49 +00:00
|
|
|
Side: ui.W,
|
2019-12-31 02:13:28 +00:00
|
|
|
PadX: 1,
|
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
|
|
|
})
|
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
|
|
|
|
2019-06-09 00:02:28 +00:00
|
|
|
var shareware string
|
2021-06-17 04:55:45 +00:00
|
|
|
if !license.IsRegistered() {
|
2019-06-09 00:02:28 +00:00
|
|
|
shareware = " (shareware)"
|
|
|
|
}
|
2018-10-08 17:38:49 +00:00
|
|
|
extraLabel := ui.NewLabel(ui.Label{
|
2019-06-24 00:52:48 +00:00
|
|
|
Text: fmt.Sprintf("%s v%s%s", branding.AppName, branding.Version, shareware),
|
2018-10-08 17:38:49 +00:00
|
|
|
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{
|
2019-12-29 05:48:49 +00:00
|
|
|
Side: ui.E,
|
2018-10-08 17:38:49 +00:00
|
|
|
})
|
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{
|
2019-12-28 03:16:34 +00:00
|
|
|
W: 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
|
|
|
|
}
|