Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: transparent oval outline #763

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions runtimes/native/src/framebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ void w4_framebufferOval (int x, int y, int width, int height) {
uint8_t dc0 = dc01 & 0xf;
uint8_t dc1 = (dc01 >> 4) & 0xf;

if (dc1 == 0xf) {
return;
if (dc1 == 0) {
dc1 = dc0;
}

uint8_t strokeColor = (dc1 - 1) & 0x3;
Expand Down Expand Up @@ -426,10 +426,12 @@ void w4_framebufferOval (int x, int y, int width, int height) {
b1 = 8 * b2;

do {
drawPointUnclipped(strokeColor, east, north); /* I. Quadrant */
drawPointUnclipped(strokeColor, west, north); /* II. Quadrant */
drawPointUnclipped(strokeColor, west, south); /* III. Quadrant */
drawPointUnclipped(strokeColor, east, south); /* IV. Quadrant */
if (dc1 != 0) {
drawPointUnclipped(strokeColor, east, north); /* I. Quadrant */
drawPointUnclipped(strokeColor, west, north); /* II. Quadrant */
drawPointUnclipped(strokeColor, west, south); /* III. Quadrant */
drawPointUnclipped(strokeColor, east, south); /* IV. Quadrant */
}

const int start = west + 1;
const int len = east - start;
Expand Down Expand Up @@ -458,14 +460,16 @@ void w4_framebufferOval (int x, int y, int width, int height) {
}
} while (west <= east);

// Make sure north and south have moved the entire way so top/bottom aren't missing
while (north - south < height) {
drawPointUnclipped(strokeColor, west - 1, north); /* II. Quadrant */
drawPointUnclipped(strokeColor, east + 1, north); /* I. Quadrant */
north += 1;
drawPointUnclipped(strokeColor, west - 1, south); /* III. Quadrant */
drawPointUnclipped(strokeColor, east + 1, south); /* IV. Quadrant */
south -= 1;
if (dc1 != 0) {
// Make sure north and south have moved the entire way so top/bottom aren't missing
while (north - south < height) {
drawPointUnclipped(strokeColor, west - 1, north); /* II. Quadrant */
drawPointUnclipped(strokeColor, east + 1, north); /* I. Quadrant */
north += 1;
drawPointUnclipped(strokeColor, west - 1, south); /* III. Quadrant */
drawPointUnclipped(strokeColor, east + 1, south); /* IV. Quadrant */
south -= 1;
}
}
}

Expand Down
35 changes: 20 additions & 15 deletions runtimes/web/src/framebuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ export class Framebuffer {
drawOval (x: number, y: number, width: number, height: number) {
const drawColors = this.drawColors[0];
const dc0 = drawColors & 0xf;
const dc1 = (drawColors >>> 4) & 0xf;
let dc1 = (drawColors >>> 4) & 0xf;

if (dc1 === 0xf) {
return;
if (dc1 == 0) {
dc1 = dc0;
}

const strokeColor = (dc1 - 1) & 0x3;
Expand Down Expand Up @@ -193,10 +193,13 @@ export class Framebuffer {
b1 = 8 * b2;

do {
this.drawPointUnclipped(strokeColor, east, north); /* I. Quadrant */
this.drawPointUnclipped(strokeColor, west, north); /* II. Quadrant */
this.drawPointUnclipped(strokeColor, west, south); /* III. Quadrant */
this.drawPointUnclipped(strokeColor, east, south); /* IV. Quadrant */
if (dc1 !== 0) {
this.drawPointUnclipped(strokeColor, east, north); /* I. Quadrant */
this.drawPointUnclipped(strokeColor, west, north); /* II. Quadrant */
this.drawPointUnclipped(strokeColor, west, south); /* III. Quadrant */
this.drawPointUnclipped(strokeColor, east, south); /* IV. Quadrant */
}


const start = west + 1;
const len = east - start;
Expand Down Expand Up @@ -225,14 +228,16 @@ export class Framebuffer {
}
} while (west <= east);

// Make sure north and south have moved the entire way so top/bottom aren't missing
while (north - south < height) {
this.drawPointUnclipped(strokeColor, west - 1, north); /* II. Quadrant */
this.drawPointUnclipped(strokeColor, east + 1, north); /* I. Quadrant */
north += 1;
this.drawPointUnclipped(strokeColor, west - 1, south); /* III. Quadrant */
this.drawPointUnclipped(strokeColor, east + 1, south); /* IV. Quadrant */
south -= 1;
if (dc1 !== 0) {
// Make sure north and south have moved the entire way so top/bottom aren't missing
while (north - south < height) {
this.drawPointUnclipped(strokeColor, west - 1, north); /* II. Quadrant */
this.drawPointUnclipped(strokeColor, east + 1, north); /* I. Quadrant */
north += 1;
this.drawPointUnclipped(strokeColor, west - 1, south); /* III. Quadrant */
this.drawPointUnclipped(strokeColor, east + 1, south); /* IV. Quadrant */
south -= 1;
}
}
}

Expand Down