Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Fixes to drawing tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed Oct 30, 2020
1 parent bef35f9 commit c5361bf
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 145 deletions.
4 changes: 2 additions & 2 deletions Content/PixelVisionOS/Tools/BootTool/boot-text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ message = " " .. SystemName() ..
"Pixel Vision 8 was created by Jesse Freeman and Christina-Antoinette Neofotistou in collaboration with Pedro Medeiros, Christer Kaitila, Shawn Rakowski and Drake Williams." ..
"\n\n" ..
"With additional coding contributions by Matt Hughson and Dean Ellis." ..
"\n\n\n" ..
"\n\n" ..
"The " .. SystemName() .. " is built on top of the open source Pixel Vision SDK thanks to the following sponsors: " ..
"Jan Rochat and Ethan Shaughnessy" ..
"\n\n" ..
"\n\n\n" ..
"Learn more at pixelvision8.com"
4 changes: 2 additions & 2 deletions Content/PixelVisionOS/Tools/BootTool/code.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ function Draw()
RedrawDisplay()

-- Draw top border
DrawSprites(topborder.spriteIDs, 0, 0, topborder.width, false, false, DrawMode.Sprite, 0, false, false)
DrawSprites(topborder.spriteIDs, 0, 0, topborder.width)

-- Draw bottom border
DrawSprites(bottomborder.spriteIDs, 0, 232, bottomborder.width, false, false, DrawMode.Sprite, 0, false, false)
DrawSprites(bottomborder.spriteIDs, 0, 232, bottomborder.width)

-- Mask off the bottom of the screen so you can see the scrolling
DrawRect(0, 240, 256, 8, 0, DrawMode.UI)
Expand Down
32 changes: 9 additions & 23 deletions Disks/PixelVisionOS/System/Libs/pixel-vision-os-canvas-v3.lua
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ function PixelVisionOS:DrawOnCanvas(data, mousePos, toolID)
data.tmpPaintCanvas:Clear()

self:ResetCanvasStroke(data)

data.tmpPaintCanvas:DrawLine(data.startPos.x, data.startPos.y, mousePos.x, mousePos.y, data.fill)

-- force the paint canvas to redraw
Expand All @@ -400,18 +400,11 @@ function PixelVisionOS:DrawOnCanvas(data, mousePos, toolID)

self:ResetCanvasStroke(data)

local w = math.abs(mousePos.x - data.startPos.x)
local h = math.abs(mousePos.y - data.startPos.y)

if(w <= 0 or h <= 0) then
return
end

data.tmpPaintCanvas:DrawRectangle(
math.min(data.startPos.x, mousePos.x),
math.min(data.startPos.y, mousePos.y),
w,
h,
math.min(data.startPos.y, mousePos.y),
math.abs(mousePos.x - data.startPos.x)+ 1,
math.abs(mousePos.y - data.startPos.y) + 1,
data.fill
)

Expand All @@ -426,19 +419,12 @@ function PixelVisionOS:DrawOnCanvas(data, mousePos, toolID)

self:ResetCanvasStroke(data)

local w = math.abs(mousePos.x - data.startPos.x)
local h = math.abs(mousePos.y - data.startPos.y)

if(w <= 0 or h <= 0) then
return
end

data.tmpPaintCanvas:DrawEllipse(
math.min(data.startPos.x, mousePos.x),
math.min(data.startPos.y, mousePos.y),
w,
h,
data.fill
math.min(data.startPos.x, mousePos.x),
math.min(data.startPos.y, mousePos.y),
math.abs(mousePos.x - data.startPos.x)+ 1,
math.abs(mousePos.y - data.startPos.y) + 1,
data.fill
)

-- force the paint canvas to redraw
Expand Down
8 changes: 2 additions & 6 deletions SDK/Engine/Chips/Game/GameChip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,7 @@ public SpriteCollection MetaSprite(int id, SpriteCollection spriteCollection = n


public void DrawMetaSprite(int id, int x, int y, bool flipH = false, bool flipV = false,
DrawMode drawMode = DrawMode.Sprite, int colorOffset = 0, bool onScreen = true, bool useScrollPos = true,
Rectangle? bounds = null)
DrawMode drawMode = DrawMode.Sprite, int colorOffset = 0)
{
// This draw method doesn't support background or tile draw modes
if (drawMode == DrawMode.TilemapCache || drawMode == DrawMode.Tile) return;
Expand Down Expand Up @@ -634,10 +633,7 @@ public SpriteCollection MetaSprite(int id, SpriteCollection spriteCollection = n
_tmpFlipH,
_tmpFlipV,
drawMode,
_currentSpriteData.ColorOffset + colorOffset,
onScreen,
useScrollPos,
bounds
_currentSpriteData.ColorOffset + colorOffset
);
}
}
Expand Down
136 changes: 46 additions & 90 deletions SDK/Engine/Chips/Game/GameChipLite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ public void ReplaceColor(int index, int id)

#region Display


/// <summary>
/// Clearing the display removed all of the existing pixel data, replacing it with the default background
/// color. The Clear() method allows you specify what region of the display to clear. By simply calling
Expand All @@ -326,29 +325,7 @@ public void ReplaceColor(int index, int id)
/// useful for drawing a HUD but clearing the display below for a scrolling map and sprites. Clear can only
/// be used once during the draw phase.
/// </summary>
/// <param name="x">
/// This is an optional value that defaults to 0 and defines where the clear's X position should begin.
/// When X is 0, clear starts on the far left-hand side of the display. Values less than 0 or greater than
/// the width of the display are ignored.
/// </param>
/// <param name="y">
/// This is an optional value that defaults to 0 and defines where the clear's Y position should begin. When Y
/// is 0, clear starts at the top of the display. Values less than 0 or greater than the height of the display
/// are ignored.
/// </param>
/// <param name="width">
/// This is an optional value that defaults to the width of the display and defines how many horizontal pixels
/// to clear. When the width is 0, clear starts at the x position and ends at the far right-hand side of the
/// display. Values less than 0 or greater than the width are adjusted to stay within the boundaries of the
/// screen's visible pixels.
/// </param>
/// <param name="height">
/// This is an optional value that defaults to the height of the display and defines how many vertical pixels
/// to clear. When the height is 0, clear starts at the Y position and ends at the bottom of the display.
/// Values less than 0 or greater than the height are adjusted to stay within the boundaries of the screen's
/// visible pixels.
/// </param>
public void Clear(int x = 0, int y = 0, int? width = null, int? height = null)
public void Clear()
{
// DisplayChip.Clear();
//
Expand Down Expand Up @@ -483,18 +460,19 @@ public Point Display(bool visible = true)
/// This is an optional argument which accepts a bool. The default value is set to false but passing in true flips
/// the pixel data vertically.
/// </param>
/// <param name="drawMode"></param>
/// <param name="colorOffset">
/// This optional argument accepts an int that offsets all the color IDs in the pixel data array. This value is added
/// to each int, in the pixel data array, allowing you to simulate palette shifting.
/// </param>
/// <param name="srcChip"></param>
/// <param name="aboveBG">
/// An optional bool that defines if the sprite is above or below the tilemap. Sprites are set to render above the
/// tilemap by default. When rendering below the tilemap, the sprite is visible in the transparent area of the tile
/// above the background color.
/// </param>
/// <param name="colorOffset">
/// This optional argument accepts an int that offsets all the color IDs in the pixel data array. This value is added
/// to each int, in the pixel data array, allowing you to simulate palette shifting.
/// </param>
public virtual void DrawSprite(int id, int x, int y, bool flipH = false, bool flipV = false,
DrawMode drawMode = DrawMode.Sprite, int colorOffset = 0, bool onScreen = true, bool useScrollPos = true,
Rectangle? bounds = null, SpriteChip srcChip = null)
DrawMode drawMode = DrawMode.Sprite, int colorOffset = 0, SpriteChip srcChip = null)
{
// Only apply the max sprite count to sprite draw modes

Expand All @@ -506,8 +484,8 @@ public Point Display(bool visible = true)
}
else
{
x -=(useScrollPos ? _scrollPos.X : 0);
y -=(useScrollPos ? _scrollPos.Y : 0);
// x -=(useScrollPos ? _scrollPos.X : 0);
// y -=(useScrollPos ? _scrollPos.Y : 0);

if (drawMode == DrawMode.TilemapCache)
{
Expand All @@ -522,23 +500,23 @@ public Point Display(bool visible = true)
if (SpriteChip.maxSpriteCount > 0 && CurrentSprites >= SpriteChip.maxSpriteCount) return;

// Check to see if we need to test the bounds
if (onScreen)
{
// _tmpBounds = bounds ?? DisplayChip.VisibleBounds;

// This can set the render flag to true or false based on it's location
//TODO need to take into account the current bounds of the screen
render = x >= 0 && x <= display.X && y >= 0 && y <= display.Y;
}
else
{
// If we are not testing to see if the sprite is onscreen it will always render and wrap based on its position
render = true;
}

// If the sprite should be rendered, call DrawSprite()
if (render)
{
// if (onScreen)
// {
// // _tmpBounds = bounds ?? DisplayChip.VisibleBounds;
//
// // This can set the render flag to true or false based on it's location
// //TODO need to take into account the current bounds of the screen
// render = x >= 0 && x <= display.X && y >= 0 && y <= display.Y;
// }
// else
// {
// // If we are not testing to see if the sprite is onscreen it will always render and wrap based on its position
// render = true;
// }
//
// // If the sprite should be rendered, call DrawSprite()
// if (render)
// {

var pos = MathUtil.CalculatePosition(id, srcChip.Columns);
pos.X *= SpriteChip.width;
Expand All @@ -547,7 +525,7 @@ public Point Display(bool visible = true)
DisplayChip.NewDrawCall(srcChip, x, y, SpriteChip.width, SpriteChip.height, (byte)drawMode, flipH, flipV, colorOffset, pos.X, pos.Y);

CurrentSprites++;
}
// }
}

}
Expand Down Expand Up @@ -591,16 +569,8 @@ public Point Display(bool visible = true)
/// This optional argument accepts an int that offsets all the color IDs in the pixel data array. This value is added
/// to each int, in the pixel data array, allowing you to simulate palette shifting.
/// </param>
/// <param name="onScreen">
/// This flag defines if the sprites should not render when they are off the screen. Use this in conjunction with
/// overscan border control what happens to sprites at the edge of the display. If this value is false, the sprites
/// wrap around the screen when they reach the edges of the screen.
/// </param>
/// <param name="useScrollPos">This will automatically offset the sprite's x and y position based on the scroll value.</param>
/// <param name="bounds"></param>
public void DrawSprites(int[] ids, int x, int y, int width, bool flipH = false, bool flipV = false,
DrawMode drawMode = DrawMode.Sprite, int colorOffset = 0, bool onScreen = true, bool useScrollPos = true,
Rectangle? bounds = null)
DrawMode drawMode = DrawMode.Sprite, int colorOffset = 0)
{
total = ids.Length;

Expand Down Expand Up @@ -648,10 +618,7 @@ public Point Display(bool visible = true)
flipH,
flipV,
drawMode,
colorOffset,
onScreen,
useScrollPos,
bounds);
colorOffset);
}
}
}
Expand All @@ -670,11 +637,8 @@ public Point Display(bool visible = true)
/// An int value representing the Y position to place sprite on the display. If set to 0, it renders on the top
/// of the screen.
/// </param>
/// <param name="width">
/// The width, in sprites, of the grid. A value of 2 renders 2 sprites wide. The DrawSprites method continues to
/// run through all of the sprites in the ID array until reaching the end. Sprite groups do not have to be perfect
/// squares since the width value is only used to wrap sprites to the next row.
/// </param>
/// <param name="columns"></param>
/// <param name="rows"></param>
/// <param name="flipH">
/// This is an optional argument which accepts a bool. The default value is set to false but passing in true flips
/// the pixel data horizontally.
Expand All @@ -688,17 +652,10 @@ public Point Display(bool visible = true)
/// This optional argument accepts an int that offsets all the color IDs in the pixel data array. This value is added
/// to each int, in the pixel data array, allowing you to simulate palette shifting.
/// </param>
/// <param name="onScreen">
/// This flag defines if the sprites should not render when they are off the screen. Use this in conjunction with
/// overscan border control what happens to sprites at the edge of the display. If this value is false, the sprites
/// wrap around the screen when they reach the edges of the screen.
/// </param>
/// <param name="useScrollPos">This will automatically offset the sprite's x and y position based on the scroll value.</param>
public void DrawSpriteBlock(int id, int x, int y, int width = 1, int height = 1, bool flipH = false,
bool flipV = false, DrawMode drawMode = DrawMode.Sprite, int colorOffset = 0, bool onScreen = true,
bool useScrollPos = true, Rectangle? bounds = null)
public void DrawSpriteBlock(int id, int x, int y, int columns = 1, int rows = 1, bool flipH = false,
bool flipV = false, DrawMode drawMode = DrawMode.Sprite, int colorOffset = 0)
{
total = width * height;
total = columns * rows;

var sprites = new int[total];

Expand All @@ -708,7 +665,7 @@ public Point Display(bool visible = true)
var tmpC = id % sW;
var tmpR = (int) Math.Floor(id / (double) sW);

var tmpCols = tmpC + width;
var tmpCols = tmpC + columns;

for (var i = 0; i < total; i++)
{
Expand All @@ -723,7 +680,7 @@ public Point Display(bool visible = true)
}
}

DrawSprites(sprites, x, y, width, flipH, flipV, drawMode, colorOffset, onScreen, useScrollPos, bounds);
DrawSprites(sprites, x, y, columns, flipH, flipV, drawMode, colorOffset);
}

/// <summary>
Expand Down Expand Up @@ -766,8 +723,7 @@ public Point Display(bool visible = true)
/// </param>
/// <returns></returns>
public void DrawText(string text, int x, int y, DrawMode drawMode = DrawMode.Sprite, string font = "Default",
int colorOffset = 0, int spacing = 0, bool onScreen = true, bool useScrollPos = true,
Rectangle? bounds = null)
int colorOffset = 0, int spacing = 0)
{
// TODO this should use DrawSprites() API
spriteSize = SpriteSize();
Expand Down Expand Up @@ -801,12 +757,12 @@ public Point Display(bool visible = true)

for (var j = 0; j < total; j++)
{
var visible = true;

if (bounds.HasValue) visible = bounds.Value.Contains(nextX, nextY);

if (visible)
{
// var visible = true;
//
// if (bounds.HasValue) visible = bounds.Value.Contains(nextX, nextY);
//
// if (visible)
// {
// var tmpFontData = new int[64];

// Clear the background when in tile mode
Expand All @@ -822,9 +778,9 @@ public Point Display(bool visible = true)
CurrentSprites++;
}

DrawSprite(spriteIDs[j], nextX, nextY, false, false, drawMode, colorOffset, onScreen, useScrollPos, null, FontChip);
DrawSprite(spriteIDs[j], nextX, nextY, false, false, drawMode, colorOffset, FontChip);

}
// }

nextX += offset;
}
Expand Down
19 changes: 6 additions & 13 deletions SDK/Engine/Data/Canvas/Canvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ public void DrawLine(int x0, int y0, int x1, int y1)
newRequest.Bounds.Y = y0;

// Well be using the wid as the second point
newRequest.Bounds.Width = x1;// - stroke.Width;
newRequest.Bounds.Height = y1;// - stroke.Height;
newRequest.Bounds.Width = x1;
newRequest.Bounds.Height = y1;

// Save the changes to the request
requestPool[currentRequest] = newRequest;
Expand All @@ -254,15 +254,8 @@ private void DrawLineAction(CanvasDrawRequest drawRequest)
{
_x0 = drawRequest.Bounds.X;
_y0 = drawRequest.Bounds.Y;
_x1 = drawRequest.Bounds.Width - stroke.Width;

if (_x1 < _x0)
_x1 = _x0;

_y1 = drawRequest.Bounds.Height - stroke.Width;

if (_y1 < _y0)
_y1 = _y0;
_x1 = drawRequest.Bounds.Width;// - stroke.Width;
_y1 = drawRequest.Bounds.Height;// - stroke.Width;

_counter = 0;

Expand Down Expand Up @@ -397,14 +390,14 @@ public void DrawRectangleAction(CanvasDrawRequest request)
request.Bounds.Y = _tmpRect.Bottom;

// Well be using the wid as the second point
request.Bounds.Width = _tmpRect.Right + stroke.Width;
request.Bounds.Width = _tmpRect.Right;
request.Bounds.Height = _tmpRect.Bottom;

DrawLineAction(request);

// Left
request.Bounds.X = _tmpRect.Left;
request.Bounds.Y = _tmpRect.Top + stroke.Height;
request.Bounds.Y = _tmpRect.Top;

// Well be using the wid as the second point
request.Bounds.Width = _tmpRect.Left;
Expand Down

0 comments on commit c5361bf

Please sign in to comment.