x4js 1.6.5 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -14
- package/lib/README.txt +3 -14
- package/lib/src/assets/house-light.svg +1 -0
- package/lib/src/assets/radio.svg +4 -0
- package/lib/src/components/base.scss +26 -0
- package/lib/src/components/boxes/boxes.module.scss +37 -0
- package/lib/src/components/boxes/boxes.ts +125 -0
- package/lib/src/components/btngroup/btngroup.module.scss +29 -0
- package/lib/src/components/btngroup/btngroup.ts +106 -0
- package/lib/src/components/button/button.module.scss +154 -0
- package/lib/src/components/button/button.ts +117 -0
- package/lib/src/components/calendar/calendar-check-sharp-light.svg +1 -0
- package/lib/src/components/calendar/calendar.module.scss +163 -0
- package/lib/src/{calendar.ts → components/calendar/calendar.ts} +81 -83
- package/lib/src/components/calendar/chevron-left-sharp-light.svg +1 -0
- package/lib/src/components/calendar/chevron-right-sharp-light.svg +1 -0
- package/lib/src/components/checkbox/check.svg +4 -0
- package/lib/src/components/checkbox/checkbox.module.scss +142 -0
- package/lib/src/components/checkbox/checkbox.ts +125 -0
- package/lib/src/components/colorinput/colorinput.module.scss +65 -0
- package/lib/src/components/colorinput/colorinput.ts +88 -0
- package/lib/src/components/colorinput/crosshairs-simple-sharp-light.svg +1 -0
- package/lib/src/components/colorpicker/colorpicker.module.scss +133 -0
- package/lib/src/components/colorpicker/colorpicker.ts +477 -0
- package/lib/src/components/combobox/combobox.module.scss +121 -0
- package/lib/src/components/combobox/combobox.ts +190 -0
- package/lib/src/components/combobox/updown.svg +4 -0
- package/lib/src/components/dialog/dialog.module.scss +71 -0
- package/lib/src/components/dialog/dialog.ts +91 -0
- package/lib/src/components/dialog/xmark-sharp-light.svg +1 -0
- package/lib/src/components/form/form.module.scss +34 -0
- package/lib/src/components/form/form.ts +36 -0
- package/lib/src/components/header/header.module.scss +40 -0
- package/lib/src/components/header/header.ts +124 -0
- package/lib/src/components/icon/icon.module.scss +30 -0
- package/lib/src/components/icon/icon.ts +134 -0
- package/lib/src/components/image/image.module.scss +21 -0
- package/lib/src/components/image/image.ts +67 -0
- package/lib/src/components/input/input.module.scss +69 -0
- package/lib/src/components/input/input.ts +274 -0
- package/lib/src/components/label/label.module.scss +52 -0
- package/lib/src/components/label/label.ts +55 -0
- package/lib/src/components/listbox/listbox.module.scss +103 -0
- package/lib/src/components/listbox/listbox.ts +427 -0
- package/lib/src/components/menu/caret-right-solid.svg +1 -0
- package/lib/src/components/menu/menu.module.scss +108 -0
- package/lib/src/components/menu/menu.ts +168 -0
- package/lib/src/components/messages/circle-exclamation.svg +1 -0
- package/lib/src/components/messages/messages.module.scss +47 -0
- package/lib/src/components/messages/messages.ts +64 -0
- package/lib/src/components/normalize.scss +386 -0
- package/lib/src/components/notification/circle-check-solid.svg +1 -0
- package/lib/src/components/notification/circle-exclamation-solid.svg +1 -0
- package/lib/src/components/notification/circle-notch-light.svg +1 -0
- package/lib/src/components/notification/notification.module.scss +82 -0
- package/lib/src/components/notification/notification.ts +108 -0
- package/lib/src/components/notification/xmark-sharp-light.svg +1 -0
- package/lib/src/components/panel/panel.module.scss +48 -0
- package/lib/src/components/panel/panel.ts +57 -0
- package/lib/src/components/popup/popup.module.scss +43 -0
- package/lib/src/components/popup/popup.ts +395 -0
- package/lib/src/components/progress/progress.module.scss +57 -0
- package/lib/src/components/progress/progress.ts +43 -0
- package/lib/src/components/rating/rating.module.scss +23 -0
- package/lib/src/components/rating/rating.ts +125 -0
- package/lib/src/components/rating/star-sharp-light.svg +1 -0
- package/lib/src/components/rating/star-sharp-solid.svg +1 -0
- package/lib/src/components/shared.scss +76 -0
- package/lib/src/components/sizers/sizer.module.scss +90 -0
- package/lib/src/components/sizers/sizer.ts +120 -0
- package/lib/src/components/slider/slider.module.scss +71 -0
- package/lib/src/components/slider/slider.ts +143 -0
- package/lib/src/components/switch/switch.module.scss +127 -0
- package/lib/src/components/switch/switch.ts +56 -0
- package/lib/src/components/tabs/tabs.module.scss +46 -0
- package/lib/src/components/tabs/tabs.ts +157 -0
- package/lib/src/components/textarea/textarea.module.scss +59 -0
- package/lib/src/components/textarea/textarea.ts +54 -0
- package/lib/src/components/textedit/textedit.module.scss +114 -0
- package/lib/src/components/textedit/textedit.ts +82 -0
- package/lib/src/components/themes.scss +77 -0
- package/lib/src/components/tooltips/circle-info-sharp-light.svg +1 -0
- package/lib/src/components/tooltips/tooltips.scss +51 -0
- package/lib/src/components/tooltips/tooltips.ts +103 -0
- package/lib/src/components/treeview/chevron-down-light.svg +1 -0
- package/lib/src/components/treeview/treeview.module.scss +116 -0
- package/lib/src/components/treeview/treeview.ts +403 -0
- package/lib/src/components/viewport/viewport.module.scss +25 -0
- package/lib/src/components/viewport/viewport.ts +38 -0
- package/lib/src/core/component.ts +979 -0
- package/lib/src/core/core_colors.ts +250 -0
- package/lib/src/{dom_events.ts → core/core_dom.ts} +195 -39
- package/lib/src/{drag_manager.ts → core/core_dragdrop.ts} +29 -44
- package/lib/src/core/core_element.ts +98 -0
- package/lib/src/core/core_events.ts +149 -0
- package/lib/src/{i18n.ts → core/core_i18n.ts} +43 -42
- package/lib/src/{router.ts → core/core_router.ts} +27 -40
- package/lib/src/core/core_styles.ts +215 -0
- package/lib/src/core/core_svg.ts +550 -0
- package/lib/src/core/core_tools.ts +673 -0
- package/lib/src/main.scss +21 -0
- package/lib/src/main.tsx +323 -0
- package/lib/src/x4.scss +19 -0
- package/lib/types/x4.d.ts +2624 -0
- package/package.json +67 -59
- package/scripts/build.mjs +351 -0
- package/scripts/prepack.mjs +15 -0
- package/src/assets/house-light.svg +1 -0
- package/src/assets/radio.svg +4 -0
- package/src/components/base.scss +26 -0
- package/src/components/boxes/boxes.module.scss +37 -0
- package/src/components/boxes/boxes.ts +125 -0
- package/src/components/btngroup/btngroup.module.scss +29 -0
- package/src/components/btngroup/btngroup.ts +106 -0
- package/src/components/button/button.module.scss +154 -0
- package/src/components/button/button.ts +117 -0
- package/src/components/calendar/calendar-check-sharp-light.svg +1 -0
- package/src/components/calendar/calendar.module.scss +163 -0
- package/src/components/calendar/calendar.ts +326 -0
- package/src/components/calendar/chevron-left-sharp-light.svg +1 -0
- package/src/components/calendar/chevron-right-sharp-light.svg +1 -0
- package/src/components/checkbox/check.svg +4 -0
- package/src/components/checkbox/checkbox.module.scss +142 -0
- package/src/components/checkbox/checkbox.ts +125 -0
- package/src/components/colorinput/colorinput.module.scss +65 -0
- package/src/components/colorinput/colorinput.ts +88 -0
- package/src/components/colorinput/crosshairs-simple-sharp-light.svg +1 -0
- package/src/components/colorpicker/colorpicker.module.scss +133 -0
- package/src/components/colorpicker/colorpicker.ts +477 -0
- package/src/components/combobox/combobox.module.scss +121 -0
- package/src/components/combobox/combobox.ts +190 -0
- package/src/components/combobox/updown.svg +4 -0
- package/src/components/dialog/dialog.module.scss +71 -0
- package/src/components/dialog/dialog.ts +91 -0
- package/src/components/dialog/xmark-sharp-light.svg +1 -0
- package/src/components/form/form.module.scss +34 -0
- package/src/components/form/form.ts +36 -0
- package/src/components/header/header.module.scss +40 -0
- package/src/components/header/header.ts +124 -0
- package/src/components/icon/icon.module.scss +30 -0
- package/src/components/icon/icon.ts +134 -0
- package/src/components/image/image.module.scss +21 -0
- package/src/components/image/image.ts +67 -0
- package/src/components/input/input.module.scss +69 -0
- package/src/components/input/input.ts +274 -0
- package/src/components/label/label.module.scss +52 -0
- package/src/components/label/label.ts +55 -0
- package/src/components/listbox/listbox.module.scss +103 -0
- package/src/components/listbox/listbox.ts +427 -0
- package/src/components/menu/caret-right-solid.svg +1 -0
- package/src/components/menu/menu.module.scss +108 -0
- package/src/components/menu/menu.ts +168 -0
- package/src/components/messages/circle-exclamation.svg +1 -0
- package/src/components/messages/messages.module.scss +47 -0
- package/src/components/messages/messages.ts +64 -0
- package/src/components/normalize.scss +386 -0
- package/src/components/notification/circle-check-solid.svg +1 -0
- package/src/components/notification/circle-exclamation-solid.svg +1 -0
- package/src/components/notification/circle-notch-light.svg +1 -0
- package/src/components/notification/notification.module.scss +82 -0
- package/src/components/notification/notification.ts +108 -0
- package/src/components/notification/xmark-sharp-light.svg +1 -0
- package/src/components/panel/panel.module.scss +48 -0
- package/src/components/panel/panel.ts +57 -0
- package/src/components/popup/popup.module.scss +43 -0
- package/src/components/popup/popup.ts +395 -0
- package/src/components/progress/progress.module.scss +57 -0
- package/src/components/progress/progress.ts +43 -0
- package/src/components/rating/rating.module.scss +23 -0
- package/src/components/rating/rating.ts +125 -0
- package/src/components/rating/star-sharp-light.svg +1 -0
- package/src/components/rating/star-sharp-solid.svg +1 -0
- package/src/components/shared.scss +76 -0
- package/src/components/sizers/sizer.module.scss +90 -0
- package/src/components/sizers/sizer.ts +120 -0
- package/src/components/slider/slider.module.scss +71 -0
- package/src/components/slider/slider.ts +143 -0
- package/src/components/switch/switch.module.scss +127 -0
- package/src/components/switch/switch.ts +56 -0
- package/src/components/tabs/tabs.module.scss +46 -0
- package/src/components/tabs/tabs.ts +157 -0
- package/src/components/textarea/textarea.module.scss +59 -0
- package/src/components/textarea/textarea.ts +54 -0
- package/src/components/textedit/textedit.module.scss +114 -0
- package/src/components/textedit/textedit.ts +82 -0
- package/src/components/themes.scss +77 -0
- package/src/components/tooltips/circle-info-sharp-light.svg +1 -0
- package/src/components/tooltips/tooltips.scss +51 -0
- package/src/components/tooltips/tooltips.ts +103 -0
- package/src/components/treeview/chevron-down-light.svg +1 -0
- package/src/components/treeview/treeview.module.scss +116 -0
- package/src/components/treeview/treeview.ts +403 -0
- package/src/components/viewport/viewport.module.scss +25 -0
- package/src/components/viewport/viewport.ts +38 -0
- package/src/core/component.ts +979 -0
- package/src/core/core_colors.ts +250 -0
- package/src/core/core_dom.ts +471 -0
- package/src/core/core_dragdrop.ts +201 -0
- package/src/core/core_element.ts +98 -0
- package/src/core/core_events.ts +149 -0
- package/src/core/core_i18n.ts +377 -0
- package/src/core/core_router.ts +221 -0
- package/src/core/core_styles.ts +215 -0
- package/src/core/core_svg.ts +550 -0
- package/src/core/core_tools.ts +673 -0
- package/src/main.scss +21 -0
- package/src/main.tsx +323 -0
- package/src/x4.scss +19 -0
- package/tsconfig.json +14 -0
- package/types/scss.d.ts +4 -0
- package/types/svg.d.ts +4 -0
- package/types/x4react.d.ts +9 -0
- package/lib/changelog.txt +0 -23
- package/lib/cjs/x4js.js +0 -39
- package/lib/cjs/x4js.js.map +0 -7
- package/lib/esm/x4js.mjs +0 -15972
- package/lib/esm/x4js.mjs.map +0 -7
- package/lib/licence.md +0 -21
- package/lib/src/MIT-license.md +0 -14
- package/lib/src/action.ts +0 -88
- package/lib/src/alpha.jpg +0 -0
- package/lib/src/app_sockets.ts +0 -81
- package/lib/src/application.ts +0 -262
- package/lib/src/autocomplete.ts +0 -232
- package/lib/src/base64.ts +0 -166
- package/lib/src/base_component.ts +0 -152
- package/lib/src/button.ts +0 -355
- package/lib/src/canvas.ts +0 -510
- package/lib/src/cardview.ts +0 -228
- package/lib/src/checkbox.ts +0 -188
- package/lib/src/color.ts +0 -752
- package/lib/src/colorpicker.ts +0 -1649
- package/lib/src/combobox.ts +0 -512
- package/lib/src/component.ts +0 -2367
- package/lib/src/copyright.txt +0 -27
- package/lib/src/datastore.ts +0 -1302
- package/lib/src/dialog.ts +0 -656
- package/lib/src/drawtext.ts +0 -355
- package/lib/src/fileupload.ts +0 -213
- package/lib/src/form.ts +0 -413
- package/lib/src/formatters.ts +0 -105
- package/lib/src/gridview.ts +0 -1185
- package/lib/src/icon.ts +0 -362
- package/lib/src/image.ts +0 -225
- package/lib/src/index.ts +0 -89
- package/lib/src/input.ts +0 -297
- package/lib/src/label.ts +0 -153
- package/lib/src/layout.ts +0 -442
- package/lib/src/link.ts +0 -86
- package/lib/src/listview.ts +0 -765
- package/lib/src/md5.ts +0 -438
- package/lib/src/menu.ts +0 -425
- package/lib/src/messagebox.ts +0 -224
- package/lib/src/panel.ts +0 -86
- package/lib/src/popup.ts +0 -494
- package/lib/src/property_editor.ts +0 -337
- package/lib/src/radiobtn.ts +0 -197
- package/lib/src/rating.ts +0 -135
- package/lib/src/request.ts +0 -300
- package/lib/src/settings.ts +0 -77
- package/lib/src/sidebarview.ts +0 -108
- package/lib/src/spreadsheet.ts +0 -1449
- package/lib/src/styles.ts +0 -343
- package/lib/src/svgcomponent.ts +0 -592
- package/lib/src/tabbar.ts +0 -151
- package/lib/src/tabview.ts +0 -110
- package/lib/src/textarea.ts +0 -235
- package/lib/src/textedit.ts +0 -533
- package/lib/src/toaster.ts +0 -80
- package/lib/src/tools.ts +0 -1473
- package/lib/src/tooltips.ts +0 -191
- package/lib/src/treeview.ts +0 -716
- package/lib/src/version.ts +0 -30
- package/lib/src/x4.less +0 -2242
- package/lib/src/x4dom.ts +0 -57
- package/lib/src/x4events.ts +0 -585
- package/lib/src/x4js.ts +0 -89
- package/lib/src/x4react.ts +0 -90
- package/lib/styles/x4.css +0 -1785
- package/lib/styles/x4.less +0 -2242
- package/lib/types/x4js.d.ts +0 -6728
- package/license.md +0 -21
package/lib/src/canvas.ts
DELETED
|
@@ -1,510 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / \____ _|
|
|
6
|
-
* /__/\__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file canvas.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
*
|
|
11
|
-
* Copyright (c) 2019-2023 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
-
* in the Software without restriction, including without limitation the rights
|
|
16
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
17
|
-
* of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
18
|
-
* subject to the following conditions:
|
|
19
|
-
* The above copyright notice and this permission notice shall be included in all copies
|
|
20
|
-
* or substantial portions of the Software.
|
|
21
|
-
*
|
|
22
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
23
|
-
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
24
|
-
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
25
|
-
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
26
|
-
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
27
|
-
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
28
|
-
**/
|
|
29
|
-
|
|
30
|
-
import { Component, CProps, CEventMap, html } from './component'
|
|
31
|
-
import { BasicEvent, EventCallback } from './x4events'
|
|
32
|
-
|
|
33
|
-
interface IPoint {
|
|
34
|
-
x: number;
|
|
35
|
-
y: number;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
interface EvPaint extends BasicEvent {
|
|
39
|
-
ctx: CanvasPainter;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function EvPaint(ctx: CanvasPainter) {
|
|
43
|
-
return BasicEvent<EvPaint>({ ctx });
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface CanvasEventMap extends CEventMap {
|
|
47
|
-
paint: EvPaint;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
interface CanvasProps extends CProps<CanvasEventMap> {
|
|
51
|
-
autoClear?: boolean;
|
|
52
|
-
painter?: PaintHandler;
|
|
53
|
-
paint: EventCallback<EvPaint>
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// ============================================================================
|
|
58
|
-
// [CANVAS]
|
|
59
|
-
// ============================================================================
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
export interface CanvasPainter extends CanvasRenderingContext2D {
|
|
65
|
-
width: number;
|
|
66
|
-
height: number;
|
|
67
|
-
|
|
68
|
-
smoothLine(points: any[], path: CanvasPath, move: boolean): void;
|
|
69
|
-
smoothLineEx(_points: any[], tension: number, numOfSeg: number, path: CanvasPath, move?: boolean, close?: boolean): void;
|
|
70
|
-
line(x1: number, y1: number, x2: number, y2: number, color: string, lineWidth: number): void;
|
|
71
|
-
roundRect(x: number, y: number, width: number, height: number, radius: number): void;
|
|
72
|
-
calcTextSize(text: string, rounded: boolean): { width: number, height: number };
|
|
73
|
-
setFontSize(fs: number): void;
|
|
74
|
-
circle(x: number, y: number, radius: number): void;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function mkPainter(c2d: CanvasRenderingContext2D, w: number, h: number): CanvasPainter {
|
|
78
|
-
|
|
79
|
-
let cp = c2d as CanvasPainter;
|
|
80
|
-
|
|
81
|
-
cp.width = w;
|
|
82
|
-
cp.height = h;
|
|
83
|
-
|
|
84
|
-
cp.smoothLine = smoothLine;
|
|
85
|
-
cp.smoothLineEx = smoothLineEx;
|
|
86
|
-
cp.line = line;
|
|
87
|
-
cp.roundRect = roundRect;
|
|
88
|
-
cp.calcTextSize = calcTextSize;
|
|
89
|
-
cp.setFontSize = setFontSize;
|
|
90
|
-
cp.circle = circle;
|
|
91
|
-
|
|
92
|
-
return cp;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function smoothLine( this: CanvasRenderingContext2D, points: any[], path: CanvasPath = null, move = true) {
|
|
96
|
-
if (points.length < 2) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (!path) {
|
|
101
|
-
path = this;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (points.length == 2) {
|
|
105
|
-
if (move !== false) {
|
|
106
|
-
path.moveTo(points[0].x, points[0].y);
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
path.lineTo(points[0].x, points[0].y);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
path.lineTo(points[1].x, points[1].y);
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function midPointBtw(p1: IPoint, p2: IPoint ) {
|
|
117
|
-
return {
|
|
118
|
-
x: p1.x + (p2.x - p1.x) / 2,
|
|
119
|
-
y: p1.y + (p2.y - p1.y) / 2
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function getQuadraticXY(t: number, sx: number, sy: number, cp1x: number, cp1y: number, ex: number, ey: number) : IPoint {
|
|
124
|
-
return {
|
|
125
|
-
x: (1 - t) * (1 - t) * sx + 2 * (1 - t) * t * cp1x + t * t * ex,
|
|
126
|
-
y: (1 - t) * (1 - t) * sy + 2 * (1 - t) * t * cp1y + t * t * ey
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
let p1 = points[0],
|
|
131
|
-
p2 = points[1],
|
|
132
|
-
p3 = p1;
|
|
133
|
-
|
|
134
|
-
path.moveTo(p1.x, p1.y);
|
|
135
|
-
|
|
136
|
-
for (let i = 1, len = points.length; i < len; i++) {
|
|
137
|
-
// we pick the point between pi+1 & pi+2 as the
|
|
138
|
-
// end point and p1 as our control point
|
|
139
|
-
let midPoint = midPointBtw(p1, p2);
|
|
140
|
-
//this.quadraticCurveTo(p1.x, p1.y, midPoint.x, midPoint.y);
|
|
141
|
-
for (let i = 0; i < 8; i++) {
|
|
142
|
-
let { x, y } = getQuadraticXY(i / 8, p3.x, p3.y, p1.x, p1.y, midPoint.x, midPoint.y);
|
|
143
|
-
path.lineTo(x, y);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
p1 = points[i];
|
|
147
|
-
p2 = points[i + 1];
|
|
148
|
-
p3 = midPoint;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Draw last line as a straight line while
|
|
152
|
-
// we wait for the next point to be able to calculate
|
|
153
|
-
// the bezier control point
|
|
154
|
-
|
|
155
|
-
path.lineTo(p1.x, p1.y);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function smoothLineEx(this: CanvasRenderingContext2D, _points: any[], tension: number = 0.5, numOfSeg: number = 10, path: CanvasPath = null, move = true, close = false) {
|
|
159
|
-
|
|
160
|
-
let points = [];
|
|
161
|
-
|
|
162
|
-
//pts = points.slice(0);
|
|
163
|
-
for (let p = 0, pc = _points.length; p < pc; p++) {
|
|
164
|
-
points.push(_points[p].x);
|
|
165
|
-
points.push(_points[p].y);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
let pts,
|
|
169
|
-
i = 1,
|
|
170
|
-
l = points.length,
|
|
171
|
-
rPos = 0,
|
|
172
|
-
rLen = (l - 2) * numOfSeg + 2 + (close ? 2 * numOfSeg : 0),
|
|
173
|
-
res = new Float32Array(rLen),
|
|
174
|
-
cache = new Float32Array((numOfSeg + 2) * 4),
|
|
175
|
-
cachePtr = 4;
|
|
176
|
-
|
|
177
|
-
pts = points.slice(0);
|
|
178
|
-
|
|
179
|
-
if (close) {
|
|
180
|
-
pts.unshift(points[l - 1]); // insert end point as first point
|
|
181
|
-
pts.unshift(points[l - 2]);
|
|
182
|
-
pts.push(points[0], points[1]); // first point as last point
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
pts.unshift(points[1]); // copy 1. point and insert at beginning
|
|
186
|
-
pts.unshift(points[0]);
|
|
187
|
-
pts.push(points[l - 2], points[l - 1]); // duplicate end-points
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// cache inner-loop calculations as they are based on t alone
|
|
191
|
-
cache[0] = 1; // 1,0,0,0
|
|
192
|
-
|
|
193
|
-
for (; i < numOfSeg; i++) {
|
|
194
|
-
|
|
195
|
-
var st = i / numOfSeg,
|
|
196
|
-
st2 = st * st,
|
|
197
|
-
st3 = st2 * st,
|
|
198
|
-
st23 = st3 * 2,
|
|
199
|
-
st32 = st2 * 3;
|
|
200
|
-
|
|
201
|
-
cache[cachePtr++] = st23 - st32 + 1; // c1
|
|
202
|
-
cache[cachePtr++] = st32 - st23; // c2
|
|
203
|
-
cache[cachePtr++] = st3 - 2 * st2 + st; // c3
|
|
204
|
-
cache[cachePtr++] = st3 - st2; // c4
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
cache[cachePtr] = 1; // 0,1,0,0
|
|
208
|
-
|
|
209
|
-
// calc. points
|
|
210
|
-
parse(pts, cache, l);
|
|
211
|
-
|
|
212
|
-
if (close) {
|
|
213
|
-
//l = points.length;
|
|
214
|
-
pts = [];
|
|
215
|
-
pts.push(points[l - 4], points[l - 3], points[l - 2], points[l - 1]); // second last and last
|
|
216
|
-
pts.push(points[0], points[1], points[2], points[3]); // first and second
|
|
217
|
-
parse(pts, cache, 4);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function parse(pts: number[], cache: Float32Array, l: number) {
|
|
221
|
-
|
|
222
|
-
for (var i = 2, t; i < l; i += 2) {
|
|
223
|
-
|
|
224
|
-
var pt1 = pts[i],
|
|
225
|
-
pt2 = pts[i + 1],
|
|
226
|
-
pt3 = pts[i + 2],
|
|
227
|
-
pt4 = pts[i + 3],
|
|
228
|
-
|
|
229
|
-
t1x = (pt3 - pts[i - 2]) * tension,
|
|
230
|
-
t1y = (pt4 - pts[i - 1]) * tension,
|
|
231
|
-
t2x = (pts[i + 4] - pt1) * tension,
|
|
232
|
-
t2y = (pts[i + 5] - pt2) * tension;
|
|
233
|
-
|
|
234
|
-
for (t = 0; t < numOfSeg; t++) {
|
|
235
|
-
|
|
236
|
-
var c = t << 2, //t * 4;
|
|
237
|
-
|
|
238
|
-
c1 = cache[c],
|
|
239
|
-
c2 = cache[c + 1],
|
|
240
|
-
c3 = cache[c + 2],
|
|
241
|
-
c4 = cache[c + 3];
|
|
242
|
-
|
|
243
|
-
res[rPos++] = c1 * pt1 + c2 * pt3 + c3 * t1x + c4 * t2x;
|
|
244
|
-
res[rPos++] = c1 * pt2 + c2 * pt4 + c3 * t1y + c4 * t2y;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// add last point
|
|
250
|
-
l = close ? 0 : points.length - 2;
|
|
251
|
-
res[rPos++] = points[l];
|
|
252
|
-
res[rPos] = points[l + 1];
|
|
253
|
-
|
|
254
|
-
if (!path) {
|
|
255
|
-
path = this;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// add lines to path
|
|
259
|
-
for (let i = 0, l = res.length; i < l; i += 2) {
|
|
260
|
-
if (i == 0 && move !== false) {
|
|
261
|
-
path.moveTo(res[i], res[i + 1]);
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
path.lineTo(res[i], res[i + 1]);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
function line(this: CanvasRenderingContext2D, x1: number, y1: number, x2: number, y2: number, color: string, lineWidth: number = 1) {
|
|
270
|
-
this.save();
|
|
271
|
-
this.beginPath();
|
|
272
|
-
this.moveTo(x1, y1);
|
|
273
|
-
this.lineTo(x2, y2);
|
|
274
|
-
this.lineWidth = lineWidth;
|
|
275
|
-
this.strokeStyle = color;
|
|
276
|
-
this.stroke();
|
|
277
|
-
this.restore();
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
function roundRect(this: CanvasRenderingContext2D, x: number, y: number, width: number, height: number, radius: number) {
|
|
281
|
-
//this.beginPath( );
|
|
282
|
-
this.moveTo(x + radius, y);
|
|
283
|
-
this.lineTo(x + width - radius, y);
|
|
284
|
-
this.quadraticCurveTo(x + width, y, x + width, y + radius);
|
|
285
|
-
this.lineTo(x + width, y + height - radius);
|
|
286
|
-
this.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
|
|
287
|
-
this.lineTo(x + radius, y + height);
|
|
288
|
-
this.quadraticCurveTo(x, y + height, x, y + height - radius);
|
|
289
|
-
this.lineTo(x, y + radius);
|
|
290
|
-
this.quadraticCurveTo(x, y, x + radius, y);
|
|
291
|
-
this.closePath();
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
function calcTextSize( this: CanvasRenderingContext2D, text: string, rounded = false): { width: number, height: number } {
|
|
295
|
-
|
|
296
|
-
let fh = this.measureText(text);
|
|
297
|
-
let lh = fh.fontBoundingBoxAscent + fh.fontBoundingBoxDescent;
|
|
298
|
-
|
|
299
|
-
if (rounded) {
|
|
300
|
-
return { width: Math.round(fh.width), height: Math.round(lh) };
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
return { width: fh.width, height: lh };
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
function setFontSize( this: CanvasRenderingContext2D, fs: number) {
|
|
308
|
-
let fsize = Math.round(fs) + 'px';
|
|
309
|
-
this.font = this.font.replace(/\d+px/, fsize);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
function circle( this: CanvasRenderingContext2D, x: number, y: number, radius: number) {
|
|
313
|
-
this.moveTo(x + radius, y);
|
|
314
|
-
this.arc(x, y, radius, 0, Math.PI * 2);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
type PaintHandler = (ctx: CanvasPainter) => any;
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
*
|
|
321
|
-
*/
|
|
322
|
-
|
|
323
|
-
//export class CanvasProps extends CProps
|
|
324
|
-
//{
|
|
325
|
-
// low level handlers
|
|
326
|
-
//mousedown?: (ev: MouseEvent) => any;
|
|
327
|
-
//mousemove?: (ev: MouseEvent) => any;
|
|
328
|
-
//mouseup?: (ev: MouseEvent) => any;
|
|
329
|
-
//mouseleave?: (ev: MouseEvent) => any;
|
|
330
|
-
//mousewheel?: (ev: WheelEvent) => any;
|
|
331
|
-
//click?: (ev: MouseEvent) => any;
|
|
332
|
-
//dblclick?: (ev: MouseEvent) => any;
|
|
333
|
-
//touchstart?: (ev: TouchEvent) => any;
|
|
334
|
-
//touchmove?: (ev: TouchEvent) => any;
|
|
335
|
-
//touchend?: (ev: TouchEvent) => any;
|
|
336
|
-
//keydown?: (ev: KeyboardEvent) => any;
|
|
337
|
-
//keyup?: (ev: KeyboardEvent) => any;
|
|
338
|
-
//}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Standard Canvas
|
|
343
|
-
*/
|
|
344
|
-
|
|
345
|
-
export class Canvas extends Component<CanvasProps, CanvasEventMap> {
|
|
346
|
-
|
|
347
|
-
private m_iwidth: number = -1;
|
|
348
|
-
private m_iheight: number = -1;
|
|
349
|
-
private m_scale = 1.0;
|
|
350
|
-
private m_canvas: Component;
|
|
351
|
-
|
|
352
|
-
constructor(props: CanvasProps) {
|
|
353
|
-
super(props);
|
|
354
|
-
|
|
355
|
-
//if( props.mousedown ) { this.setDomEvent( 'mousedown', props.mousedown ); }
|
|
356
|
-
//if( props.mousemove ) { this.setDomEvent( 'mousemove', props.mousemove ); }
|
|
357
|
-
//if( props.mouseup ) { this.setDomEvent( 'mouseup', props.mouseup ); }
|
|
358
|
-
//if( props.mousewheel ) { this.setDomEvent( 'wheel', props.mousewheel ); }
|
|
359
|
-
//if( props.mouseleave ) { this.setDomEvent( 'mouseleave', props.mouseleave ); }
|
|
360
|
-
//if( props.click ) { this.setDomEvent( 'click', props.click ); }
|
|
361
|
-
//if( props.dblclick ) { this.setDomEvent( 'dblclick', props.dblclick ); }
|
|
362
|
-
//if( props.touchstart ) { this.setDomEvent( 'touchstart', props.touchstart ); }
|
|
363
|
-
//if( props.touchmove ) { this.setDomEvent( 'touchmove', props.touchmove ); }
|
|
364
|
-
//if( props.touchend ) { this.setDomEvent( 'touchend', props.touchend ); }
|
|
365
|
-
//if( props.keydown ) { this.setDomEvent( 'keydown', props.keydown ); this.setAttribute( 'tabindex', 0 ); }
|
|
366
|
-
//if( props.keyup ) { this.setDomEvent( 'keyup', props.keyup ); this.setAttribute( 'tabindex', 0 ); }
|
|
367
|
-
//if( props.paint ) { this.onPaint( props.paint ); }
|
|
368
|
-
|
|
369
|
-
this.setDomEvent('sizechange', () => { this._paint(); })
|
|
370
|
-
this.mapPropEvents( props, 'paint' );
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/** @ignore */
|
|
374
|
-
render() {
|
|
375
|
-
this.m_iwidth = -1;
|
|
376
|
-
this.m_iheight = -1;
|
|
377
|
-
this.m_canvas = new Component({
|
|
378
|
-
tag: 'canvas'
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
this.setContent( this.m_canvas );
|
|
382
|
-
// this.redraw(10);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
update(delay=0 ) {
|
|
386
|
-
this.m_iheight = this.m_iwidth = -1;
|
|
387
|
-
super.update( delay );
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* scale the whole canvas
|
|
392
|
-
*/
|
|
393
|
-
|
|
394
|
-
scale(scale: number) {
|
|
395
|
-
this.m_scale = scale;
|
|
396
|
-
this.m_iwidth = -1; // force recalc
|
|
397
|
-
this.redraw();
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
/**
|
|
401
|
-
* return the internal canvas
|
|
402
|
-
*/
|
|
403
|
-
get canvas(): Component {
|
|
404
|
-
return this.m_canvas;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* redraw the canvas (force a paint)
|
|
409
|
-
*/
|
|
410
|
-
|
|
411
|
-
private $update_rep = 0;
|
|
412
|
-
public redraw(wait?: number) {
|
|
413
|
-
|
|
414
|
-
if (wait !== undefined) {
|
|
415
|
-
|
|
416
|
-
if( ++this.$update_rep>=20 ) {
|
|
417
|
-
this.stopTimer( 'update' );
|
|
418
|
-
this._paint( );
|
|
419
|
-
}
|
|
420
|
-
else {
|
|
421
|
-
this.startTimer( 'update', wait, false, () => this._paint() );
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
else {
|
|
425
|
-
this.stopTimer( 'update' );
|
|
426
|
-
this._paint();
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
*
|
|
432
|
-
*/
|
|
433
|
-
private _paint() {
|
|
434
|
-
this.$update_rep = 0;
|
|
435
|
-
|
|
436
|
-
let dom = this.dom;
|
|
437
|
-
if (!this.isUserVisible() ) {
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
let canvas = this.m_canvas.dom as HTMLCanvasElement,
|
|
442
|
-
w = dom.clientWidth,
|
|
443
|
-
h = dom.clientHeight;
|
|
444
|
-
|
|
445
|
-
let ctx = <CanvasPainter>canvas.getContext('2d');
|
|
446
|
-
if (w != this.m_iwidth || h != this.m_iheight) {
|
|
447
|
-
// adjustment for HDPI
|
|
448
|
-
let devicePixelRatio = window.devicePixelRatio || 1;
|
|
449
|
-
let backingStoreRatio = (<any>ctx).webkitBackingStorePixelRatio ||
|
|
450
|
-
(<any>ctx).mozBackingStorePixelRatio ||
|
|
451
|
-
(<any>ctx).msBackingStorePixelRatio ||
|
|
452
|
-
(<any>ctx).oBackingStorePixelRatio ||
|
|
453
|
-
(<any>ctx).backingStorePixelRatio || 1;
|
|
454
|
-
|
|
455
|
-
let canvas = this.canvas;
|
|
456
|
-
|
|
457
|
-
if (devicePixelRatio !== backingStoreRatio || this.m_scale != 1.0) {
|
|
458
|
-
let ratio = devicePixelRatio / backingStoreRatio,
|
|
459
|
-
rw = w * ratio,
|
|
460
|
-
rh = h * ratio;
|
|
461
|
-
|
|
462
|
-
canvas.setAttribute('width', '' + rw);
|
|
463
|
-
canvas.setAttribute('height', '' + rh);
|
|
464
|
-
canvas.setStyleValue('width', w);
|
|
465
|
-
canvas.setStyleValue('height', h);
|
|
466
|
-
|
|
467
|
-
ratio *= this.m_scale;
|
|
468
|
-
ctx.scale(ratio, ratio);
|
|
469
|
-
}
|
|
470
|
-
else {
|
|
471
|
-
canvas.setAttribute('width', '' + w);
|
|
472
|
-
canvas.setAttribute('height', '' + h);
|
|
473
|
-
canvas.setStyleValue('width', w);
|
|
474
|
-
canvas.setStyleValue('height', h);
|
|
475
|
-
ctx.scale(1, 1);
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
this.m_iwidth = w;
|
|
479
|
-
this.m_iheight = h;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
if (w && h) {
|
|
483
|
-
|
|
484
|
-
let cc = mkPainter(ctx, w, h);
|
|
485
|
-
|
|
486
|
-
if (this.m_props.autoClear) {
|
|
487
|
-
cc.clearRect(0, 0, w, h);
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
cc.save();
|
|
491
|
-
cc.translate(-0.5, -0.5);
|
|
492
|
-
this.paint(cc);
|
|
493
|
-
cc.restore();
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
protected paint(ctx: CanvasPainter) {
|
|
498
|
-
try {
|
|
499
|
-
if (this.m_props.painter) {
|
|
500
|
-
this.m_props.painter(ctx);
|
|
501
|
-
}
|
|
502
|
-
else {
|
|
503
|
-
this.emit('paint', EvPaint(ctx));
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
catch (x) {
|
|
507
|
-
console.assert(false, x);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|