2018-08-05 19:54:57 +00:00
|
|
|
package doodle
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-06-05 04:55:54 +00:00
|
|
|
"os"
|
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/pkg/balance"
|
2019-06-24 00:52:48 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/branding"
|
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"
|
|
|
|
"git.kirsle.net/apps/doodle/pkg/log"
|
2020-06-05 04:55:54 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/native"
|
2019-04-10 00:35:44 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/uix"
|
2020-04-07 06:21:17 +00:00
|
|
|
"git.kirsle.net/apps/doodle/pkg/windows"
|
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.
|
|
|
|
levelSettingsWindow *ui.Window
|
2020-06-05 04:55:54 +00:00
|
|
|
aboutWindow *ui.Window
|
2020-07-10 02:38:37 +00:00
|
|
|
doodadWindow *ui.Window
|
|
|
|
paletteEditor *ui.Window
|
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 04:55:15 +00:00
|
|
|
// Doodad Palette window variables.
|
|
|
|
doodadSkip int
|
|
|
|
doodadRows []*ui.Frame
|
|
|
|
doodadPager *ui.Frame
|
2019-12-28 03:16:34 +00:00
|
|
|
doodadButtonSize int
|
2019-07-04 04:55:15 +00:00
|
|
|
doodadScroller *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-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",
|
|
|
|
}
|
|
|
|
|
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
|
|
|
log.Error("menu size: %s", u.MenuBar.Rect())
|
|
|
|
u.screen.Pack(u.MenuBar, ui.Pack{
|
|
|
|
Side: ui.N,
|
|
|
|
FillX: true,
|
|
|
|
})
|
|
|
|
|
2019-06-26 01:36:53 +00:00
|
|
|
u.PlayButton = ui.NewButton("Play", ui.NewLabel(ui.Label{
|
|
|
|
Text: "Play (P)",
|
|
|
|
Font: balance.PlayButtonFont,
|
|
|
|
}))
|
2020-04-07 06:21:17 +00:00
|
|
|
u.PlayButton.Handle(ui.Click, func(ed ui.EventData) error {
|
2019-06-26 01:36:53 +00:00
|
|
|
u.Scene.Playtest()
|
2020-04-07 06:21:17 +00:00
|
|
|
return nil
|
2019-06-26 01:36:53 +00:00
|
|
|
})
|
|
|
|
u.Supervisor.Add(u.PlayButton)
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
{
|
|
|
|
u.Palette.Configure(ui.Config{
|
|
|
|
Width: paletteWidth,
|
2019-12-28 03:16:34 +00:00
|
|
|
Height: u.d.height - u.StatusBar.Size().H,
|
2018-10-19 20:31:58 +00:00
|
|
|
})
|
|
|
|
u.Palette.MoveTo(render.NewPoint(
|
2019-12-28 03:16:34 +00:00
|
|
|
u.d.width-u.Palette.BoxSize().W,
|
2020-06-05 04:55:54 +00:00
|
|
|
menuHeight,
|
2018-10-19 20:31:58 +00:00
|
|
|
))
|
|
|
|
u.Palette.Compute(d.Engine)
|
|
|
|
}
|
|
|
|
|
2020-06-05 04:55:54 +00:00
|
|
|
var innerHeight = u.d.height - menuHeight - u.StatusBar.Size().H
|
2019-07-04 03:24:04 +00:00
|
|
|
|
|
|
|
// Tool Bar.
|
|
|
|
{
|
|
|
|
u.ToolBar.Configure(ui.Config{
|
|
|
|
Width: toolbarWidth,
|
|
|
|
Height: innerHeight,
|
|
|
|
})
|
|
|
|
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
|
|
|
|
frame.MoveTo(render.NewPoint(
|
2019-07-04 03:24:04 +00:00
|
|
|
u.ToolBar.Size().W,
|
2020-06-05 04:55:54 +00:00
|
|
|
menuHeight,
|
2018-10-19 20:31:58 +00:00
|
|
|
))
|
|
|
|
frame.Resize(render.NewRect(
|
2019-12-28 03:16:34 +00:00
|
|
|
d.width-u.Palette.Size().W-u.ToolBar.Size().W,
|
2020-06-05 04:55:54 +00:00
|
|
|
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.
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2018-10-20 22:42:49 +00:00
|
|
|
u.StatusMouseText = fmt.Sprintf("Rel:(%d,%d) Abs:(%s)",
|
2019-12-22 22:11:01 +00:00
|
|
|
ev.CursorX,
|
|
|
|
ev.CursorY,
|
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.
|
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())
|
2019-06-26 01:36:53 +00:00
|
|
|
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)
|
|
|
|
|
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()
|
|
|
|
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.
|
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()
|
|
|
|
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 {
|
2018-10-20 22:42:49 +00:00
|
|
|
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)
|
2020-07-10 02:38:37 +00:00
|
|
|
|
|
|
|
// The actor has been dropped so null it out.
|
|
|
|
defer func() {
|
|
|
|
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
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// Was it an already existing actor to re-add to the map?
|
|
|
|
if actor.actor != nil {
|
|
|
|
actor.actor.Point = position
|
|
|
|
u.Scene.Level.Actors.Add(actor.actor)
|
|
|
|
} 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
|
|
|
}
|
|
|
|
|
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.
|
2020-06-05 04:55:54 +00:00
|
|
|
func (u *EditorUI) SetupMenuBar(d *Doodle) *ui.MenuBar {
|
|
|
|
menu := ui.NewMenuBar("Main Menu")
|
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
|
|
|
|
2019-04-16 06:22:38 +00:00
|
|
|
// Save and Save As common menu handler
|
2020-06-05 04:55:54 +00:00
|
|
|
var (
|
|
|
|
drawingType string
|
|
|
|
saveFunc func(filename string)
|
|
|
|
)
|
2019-04-16 06:22:38 +00:00
|
|
|
|
|
|
|
switch u.Scene.DrawingType {
|
|
|
|
case enum.LevelDrawing:
|
2020-06-05 04:55:54 +00:00
|
|
|
drawingType = "level"
|
2019-04-16 06:22:38 +00:00
|
|
|
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:
|
2020-06-05 04:55:54 +00:00
|
|
|
drawingType = "doodad"
|
2019-04-16 06:22:38 +00:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2020-06-05 04:55:54 +00:00
|
|
|
////////
|
|
|
|
// File menu
|
|
|
|
fileMenu := menu.AddMenu("File")
|
|
|
|
fileMenu.AddItemAccel("New level", "Ctrl-N", func() {
|
|
|
|
d.GotoNewMenu()
|
|
|
|
})
|
|
|
|
if !balance.FreeVersion {
|
|
|
|
fileMenu.AddItem("New doodad", func() {
|
|
|
|
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
|
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
|
|
|
}
|
2020-06-05 04:55:54 +00:00
|
|
|
size = i
|
2020-04-07 06:21:17 +00:00
|
|
|
}
|
2020-06-05 04:55:54 +00:00
|
|
|
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
|
|
|
}
|
2020-06-05 04:55:54 +00:00
|
|
|
fileMenu.AddItemAccel("Save", "Ctrl-S", func() {
|
|
|
|
if u.Scene.filename != "" {
|
|
|
|
saveFunc(u.Scene.filename)
|
|
|
|
} else {
|
|
|
|
d.Prompt("Save filename>", func(answer string) {
|
|
|
|
if answer != "" {
|
|
|
|
saveFunc(answer)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
fileMenu.AddItem("Save as...", func() {
|
|
|
|
d.Prompt("Save as filename>", func(answer string) {
|
|
|
|
if answer != "" {
|
|
|
|
saveFunc(answer)
|
2019-04-20 00:23:37 +00:00
|
|
|
}
|
2020-06-05 04:55:54 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
fileMenu.AddItemAccel("Open...", "Ctrl-O", func() {
|
|
|
|
d.GotoLoadMenu()
|
|
|
|
})
|
|
|
|
fileMenu.AddSeparator()
|
|
|
|
fileMenu.AddItem("Close "+drawingType, func() {
|
|
|
|
d.Goto(&MainScene{})
|
|
|
|
})
|
|
|
|
fileMenu.AddItemAccel("Quit", "Ctrl-Q", func() {
|
|
|
|
// TODO graceful shutdown
|
|
|
|
os.Exit(0)
|
|
|
|
})
|
|
|
|
|
|
|
|
////////
|
|
|
|
// Edit menu
|
|
|
|
editMenu := menu.AddMenu("Edit")
|
|
|
|
editMenu.AddItemAccel("Undo", "Ctrl-Z", func() {
|
|
|
|
u.Canvas.UndoStroke()
|
|
|
|
})
|
|
|
|
editMenu.AddItemAccel("Redo", "Shift-Ctrl-Y", func() {
|
|
|
|
u.Canvas.RedoStroke()
|
|
|
|
})
|
|
|
|
editMenu.AddSeparator()
|
|
|
|
editMenu.AddItem("Level options", func() {
|
|
|
|
log.Info("Opening the window")
|
|
|
|
|
|
|
|
// Open the New Level window in edit-settings mode.
|
2020-07-10 02:38:37 +00:00
|
|
|
u.levelSettingsWindow.Hide()
|
|
|
|
u.levelSettingsWindow = nil
|
|
|
|
u.SetupPopups(u.d)
|
|
|
|
u.levelSettingsWindow.Show()
|
2020-06-05 04:55:54 +00:00
|
|
|
})
|
2019-04-20 00:23:37 +00:00
|
|
|
|
2020-06-05 04:55:54 +00:00
|
|
|
////////
|
|
|
|
// Level menu
|
|
|
|
if drawingType == "level" {
|
|
|
|
levelMenu := menu.AddMenu("Level")
|
|
|
|
levelMenu.AddItemAccel("Playtest", "P", func() {
|
|
|
|
u.Scene.Playtest()
|
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
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-06-05 04:55:54 +00:00
|
|
|
////////
|
|
|
|
// Tools menu
|
|
|
|
toolMenu := menu.AddMenu("Tools")
|
|
|
|
toolMenu.AddItemAccel("Debug overlay", "F3", func() {
|
|
|
|
DebugOverlay = !DebugOverlay
|
|
|
|
if DebugOverlay {
|
|
|
|
d.Flash("Debug overlay enabled. Press F3 to turn it off.")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
toolMenu.AddItemAccel("Command shell", "Enter", func() {
|
|
|
|
d.shell.Open = true
|
|
|
|
})
|
2020-07-10 02:38:37 +00:00
|
|
|
toolMenu.AddItemAccel("Doodads", "d", func() {
|
|
|
|
log.Info("Open the DoodadDropper")
|
|
|
|
u.doodadWindow.Show()
|
|
|
|
})
|
2020-06-05 04:55:54 +00:00
|
|
|
|
|
|
|
////////
|
|
|
|
// Help menu
|
|
|
|
helpMenu := menu.AddMenu("Help")
|
|
|
|
helpMenu.AddItemAccel("User Manual", "F1", func() {
|
|
|
|
// TODO: launch the guidebook.
|
|
|
|
native.OpenURL(balance.GuidebookPath)
|
|
|
|
})
|
|
|
|
helpMenu.AddItem("About", func() {
|
|
|
|
if u.aboutWindow == nil {
|
|
|
|
u.aboutWindow = windows.NewAboutWindow(windows.About{
|
|
|
|
Supervisor: u.Supervisor,
|
|
|
|
Engine: d.Engine,
|
|
|
|
})
|
|
|
|
u.aboutWindow.Compute(d.Engine)
|
|
|
|
u.aboutWindow.Supervise(u.Supervisor)
|
|
|
|
|
|
|
|
// Center the window.
|
|
|
|
u.aboutWindow.MoveTo(render.Point{
|
|
|
|
X: (d.width / 2) - (u.aboutWindow.Size().W / 2),
|
|
|
|
Y: 60,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
u.aboutWindow.Show()
|
|
|
|
})
|
|
|
|
|
|
|
|
menu.Supervise(u.Supervisor)
|
|
|
|
menu.Compute(d.Engine)
|
|
|
|
log.Error("Setup MenuBar: %s\n", menu.Size())
|
|
|
|
|
|
|
|
return menu
|
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
|
|
|
}
|
|
|
|
|
2020-07-10 02:38:37 +00:00
|
|
|
// SetupPopups preloads popup windows like the DoodadDropper.
|
|
|
|
func (u *EditorUI) SetupPopups(d *Doodle) {
|
|
|
|
// Common window configure function.
|
|
|
|
var configure = func(window *ui.Window) {
|
|
|
|
var size = window.Size()
|
|
|
|
window.Compute(d.Engine)
|
|
|
|
window.Supervise(u.Supervisor)
|
|
|
|
|
|
|
|
// Center the window.
|
|
|
|
window.MoveTo(render.Point{
|
|
|
|
X: (d.width / 2) - (size.W / 2),
|
|
|
|
Y: (d.height / 2) - (size.H / 2),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Doodad Dropper.
|
|
|
|
if u.doodadWindow == nil {
|
|
|
|
u.doodadWindow = windows.NewDoodadDropper(windows.DoodadDropper{
|
|
|
|
Supervisor: u.Supervisor,
|
|
|
|
Engine: d.Engine,
|
|
|
|
|
|
|
|
OnStartDragActor: u.startDragActor,
|
|
|
|
OnCancel: func() {
|
|
|
|
u.doodadWindow.Hide()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
configure(u.doodadWindow)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Page Settings
|
|
|
|
if u.levelSettingsWindow == nil {
|
|
|
|
scene, _ := d.Scene.(*EditorScene)
|
|
|
|
|
|
|
|
u.levelSettingsWindow = windows.NewAddEditLevel(windows.AddEditLevel{
|
|
|
|
Supervisor: u.Supervisor,
|
|
|
|
Engine: d.Engine,
|
|
|
|
EditLevel: scene.Level,
|
|
|
|
|
|
|
|
OnChangePageTypeAndWallpaper: func(pageType level.PageType, wallpaper string) {
|
|
|
|
log.Info("OnChangePageTypeAndWallpaper called: %+v, %+v", pageType, wallpaper)
|
|
|
|
scene.Level.PageType = pageType
|
|
|
|
scene.Level.Wallpaper = wallpaper
|
|
|
|
u.Canvas.LoadLevel(d.Engine, scene.Level)
|
|
|
|
},
|
|
|
|
OnCancel: func() {
|
|
|
|
u.levelSettingsWindow.Hide()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
configure(u.levelSettingsWindow)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Palette Editor.
|
|
|
|
if u.paletteEditor == nil {
|
|
|
|
scene, _ := d.Scene.(*EditorScene)
|
|
|
|
|
|
|
|
u.paletteEditor = windows.NewPaletteEditor(windows.PaletteEditor{
|
|
|
|
Supervisor: u.Supervisor,
|
|
|
|
Engine: d.Engine,
|
|
|
|
EditLevel: scene.Level,
|
|
|
|
|
|
|
|
OnChange: func() {
|
|
|
|
// Reload the level.
|
|
|
|
log.Warn("RELOAD LEVEL")
|
|
|
|
u.Canvas.LoadLevel(d.Engine, scene.Level)
|
|
|
|
scene.Level.Chunker.Redraw()
|
|
|
|
|
|
|
|
// Reload the palette frame to reflect the changed data.
|
|
|
|
u.Palette.Hide()
|
|
|
|
u.Palette = u.SetupPalette(d)
|
|
|
|
u.Resized(d)
|
|
|
|
},
|
|
|
|
OnAddColor: func() {
|
|
|
|
// Adding a new color to the palette.
|
|
|
|
sw := scene.Level.Palette.AddSwatch()
|
|
|
|
log.Info("Added new palette color: %+v", sw)
|
|
|
|
|
|
|
|
// Awkward but... reload this very same window.
|
|
|
|
u.paletteEditor.Hide()
|
|
|
|
u.paletteEditor = nil
|
|
|
|
u.SetupPopups(d)
|
|
|
|
u.paletteEditor.Show()
|
|
|
|
},
|
|
|
|
OnCancel: func() {
|
|
|
|
u.paletteEditor.Hide()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
configure(u.paletteEditor)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
if balance.FreeVersion {
|
|
|
|
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
|
|
|
|
}
|