Skip to content

Commit

Permalink
chore: 2.0 beta
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz committed Jan 28, 2024
1 parent 7ade325 commit 5a05f08
Show file tree
Hide file tree
Showing 46 changed files with 4,457 additions and 392 deletions.
2 changes: 1 addition & 1 deletion packages/canvas-babylon/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nativescript/canvas-babylon",
"version": "2.0.0-alpha.50",
"version": "2.0.0-beta.0",
"description": "",
"main": "index",
"typings": "index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas-chartjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nativescript/canvas-chartjs",
"version": "2.0.0-alpha.50",
"version": "2.0.0-beta.0",
"description": "ChartJS",
"main": "index",
"typings": "index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas-media/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nativescript/canvas-media",
"version": "2.0.0-alpha.50",
"version": "2.0.0-beta.0",
"description": "Canvas media",
"main": "index",
"typings": "index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas-phaser-ce/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nativescript/canvas-phaser-ce",
"version": "2.0.0-alpha.50",
"version": "2.0.0-beta.0",
"description": "Tools for using Phaser-ce to build native 2D games in NativeScript 👾",
"main": "index",
"typings": "index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas-phaser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nativescript/canvas-phaser",
"version": "2.0.0-alpha.50",
"version": "2.0.0-beta.0",
"description": "Build awesome 2D games with Phaser.js and NativeScript",
"main": "index",
"typings": "index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas-pixi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nativescript/canvas-pixi",
"version": "2.0.0-alpha.50",
"version": "2.0.0-beta.0",
"description": "Plugin for using pixi.js in NativeScript",
"main": "index",
"typings": "index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas-polyfill/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nativescript/canvas-polyfill",
"version": "2.0.0-alpha.50",
"version": "2.0.0-beta.0",
"description": "Polyfill for making NativeScript compatible with web libs like pixi.js, three.js, phaser.js, babylon.js, etc....",
"main": "index",
"typings": "index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas-three/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nativescript/canvas-three",
"version": "2.0.0-alpha.50",
"version": "2.0.0-beta.0",
"description": "Utilities for using THREE.js on NativeScript",
"main": "index",
"typings": "index.d.ts",
Expand Down
60 changes: 47 additions & 13 deletions packages/canvas/Canvas2D/CanvasRenderingContext2D/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,44 @@ function ruleToEnum(rule: string): number {
}
}

function toBaseLine(value: string): number {
switch (value) {
case 'top':
return 0;
case 'hanging':
return 1;
case 'middle':
return 2;
case 'alphabetic':
return 3;
case 'ideographic':
return 4;
case 'bottom':
return 5;
default:
return -1;
}
}

function fromBaseLine(value: number): string {
switch (value) {
case 0:
return 'top';
case 1:
return 'hanging';
case 2:
return 'middle';
case 3:
return 'alphabetic';
case 4:
return 'ideographic';
case 5:
return 'bottom';
default:
return null;
}
}

export class CanvasRenderingContext2D {
public static isDebug = true;
private context;
Expand Down Expand Up @@ -183,11 +221,15 @@ export class CanvasRenderingContext2D {
}

get textBaseline() {
return this.context.textBaseline;
return fromBaseLine(this.context.textBaseline);
}

set textBaseline(baseline: string) {
this.context.textBaseline = baseline;
const value = toBaseLine(baseline);
if (value === -1) {
return;
}
this.context.textBaseline = value;
}

get globalCompositeOperation() {
Expand All @@ -202,15 +244,11 @@ export class CanvasRenderingContext2D {
return this.context.fillStyle;
}

set fillStyle(color: string | CanvasGradient | CanvasPattern) {
set fillStyle(color: CanvasGradient | CanvasPattern | string) {
if (color === undefined || color === null) {
return;
}
if (color instanceof CanvasGradient || color instanceof CanvasPattern) {
this.context.fillStyle = color.native;
} else {
this.context.fillStyle = color;
}
this.context.fillStyle = typeof color === 'object' ? color.native : color;
}

get filter(): string {
Expand All @@ -229,11 +267,7 @@ export class CanvasRenderingContext2D {
if (color === undefined || color === null) {
return;
}
if (color instanceof CanvasGradient || color instanceof CanvasPattern) {
this.context.strokeStyle = color.native;
} else {
this.context.strokeStyle = color;
}
this.context.strokeStyle = typeof color === 'object' ? color.native : color;
}

get lineWidth() {
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nativescript/canvas",
"version": "2.0.0-alpha.50",
"version": "2.0.0-beta.0",
"description": "DOM Canvas API for NativeScript",
"main": "index",
"typings": "index.d.ts",
Expand Down
Binary file modified packages/canvas/platforms/android/canvas-release.aar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@
<key>DebugSymbolsPath</key>
<string>dSYMs</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>CanvasNative.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>DebugSymbolsPath</key>
<string>dSYMs</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>CanvasNative.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ typedef enum PaintStyleType {
PaintStyleTypePattern,
} PaintStyleType;

typedef enum TextBaseLine {
TOP = 0,
HANGING = 1,
MIDDLE = 2,
ALPHABETIC = 3,
IDEOGRAPHIC = 4,
BOTTOM = 5,
} TextBaseLine;

typedef enum WebGLExtensionType {
WebGLExtensionTypeEXT_blend_minmax,
WebGLExtensionTypeEXT_color_buffer_half_float,
Expand Down Expand Up @@ -364,10 +373,15 @@ const char *canvas_native_context_get_text_align(const struct CanvasRenderingCon
void canvas_native_context_set_text_align(struct CanvasRenderingContext2D *context,
const char *alignment);

const char *canvas_native_context_get_text_baseline(const struct CanvasRenderingContext2D *context);
const char *canvas_native_context_get_text_baseline_str(const struct CanvasRenderingContext2D *context);

void canvas_native_context_set_text_baseline_str(struct CanvasRenderingContext2D *context,
const char *baseline);

void canvas_native_context_set_text_baseline(struct CanvasRenderingContext2D *context,
const char *baseline);
enum TextBaseLine baseline);

enum TextBaseLine canvas_native_context_get_text_baseline(const struct CanvasRenderingContext2D *context);

const char *canvas_native_context_get_global_composition(const struct CanvasRenderingContext2D *context);

Expand Down Expand Up @@ -482,11 +496,18 @@ void canvas_native_context_clear_rect(struct CanvasRenderingContext2D *context,
float width,
float height);

void canvas_native_context_clip_str(struct CanvasRenderingContext2D *context,
struct Path *path,
const char *rule);

void canvas_native_context_clip_rule_str(struct CanvasRenderingContext2D *context,
const char *rule);

void canvas_native_context_clip(struct CanvasRenderingContext2D *context,
struct Path *path,
const char *rule);
uint32_t rule);

void canvas_native_context_clip_rule(struct CanvasRenderingContext2D *context, const char *rule);
void canvas_native_context_clip_rule(struct CanvasRenderingContext2D *context, uint32_t rule);

void canvas_native_context_close_path(struct CanvasRenderingContext2D *context);

Expand Down Expand Up @@ -659,11 +680,17 @@ void canvas_native_context_ellipse(struct CanvasRenderingContext2D *context,
float end_angle,
bool anticlockwise);

void canvas_native_context_fill(struct CanvasRenderingContext2D *context, const char *rule);
void canvas_native_context_fill_str(struct CanvasRenderingContext2D *context, const char *rule);

void canvas_native_context_fill_with_path_str(struct CanvasRenderingContext2D *context,
struct Path *path,
const char *rule);

void canvas_native_context_fill(struct CanvasRenderingContext2D *context, uint32_t rule);

void canvas_native_context_fill_with_path(struct CanvasRenderingContext2D *context,
struct Path *path,
const char *rule);
uint32_t rule);

void canvas_native_context_fill_rect(struct CanvasRenderingContext2D *context,
float x,
Expand All @@ -690,16 +717,27 @@ struct ImageData *canvas_native_context_get_image_data(struct CanvasRenderingCon

struct Matrix *canvas_native_context_get_transform(struct CanvasRenderingContext2D *context);

bool canvas_native_context_is_point_in_path_str(struct CanvasRenderingContext2D *context,
float x,
float y,
const char *rule);

bool canvas_native_context_is_point_in_path_with_path_str(struct CanvasRenderingContext2D *context,
struct Path *path,
float x,
float y,
const char *rule);

bool canvas_native_context_is_point_in_path(struct CanvasRenderingContext2D *context,
float x,
float y,
const char *rule);
uint32_t rule);

bool canvas_native_context_is_point_in_path_with_path(struct CanvasRenderingContext2D *context,
struct Path *path,
float x,
float y,
const char *rule);
uint32_t rule);

bool canvas_native_context_is_point_in_stroke(struct CanvasRenderingContext2D *context,
float x,
Expand Down
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 5a05f08

Please sign in to comment.