@@ -3,6 +3,12 @@ import { CTRL_KEYS, TCtrlKey } from '../types';
33import { createEl , getCvsRatio , getRectCtrls } from '../utils' ;
44import { ESpriteManagerEvt , SpriteManager } from './sprite-manager' ;
55
6+ const CloseSvg = `
7+ <svg t="1756779136804" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1456" width="16" height="16">
8+ <path d="M1022.793875 170.063604L852.730271 0 511.396938 341.333333 170.063604 0 0 170.063604l341.333333 341.333334L0 852.730271l170.063604 170.063604 341.333334-340.127208 341.333333 340.127208 170.063604-170.063604-340.127208-341.333333 340.127208-341.333334z" fill="#bfbfbf" p-id="1457"></path>
9+ </svg>
10+ ` ;
11+
612export function renderCtrls (
713 container : HTMLElement ,
814 cvsEl : HTMLCanvasElement ,
@@ -75,7 +81,8 @@ function createRectAndCtrlEl(container: HTMLElement): {
7581 d . style . cssText = `
7682 display: none;
7783 position: absolute;
78- border: 1px solid #3ee; border-radius: 50%;
84+ border: 1px solid #3ee;
85+ border-radius: 50%;
7986 box-sizing: border-box;
8087 background-color: #fff;
8188 pointer-events: auto;
@@ -111,15 +118,44 @@ function syncCtrlElPos(
111118 } ) ;
112119 Object . entries ( getRectCtrls ( cvsEl , s . rect ) ) . forEach ( ( [ k , { x, y, w, h } ] ) => {
113120 // ctrl 是相对中心点定位的
114- Object . assign ( ctrlsEl [ k as TCtrlKey ] . style , {
115- display : s . interactable === 'interactive' ? 'block' : 'none' ,
121+ const baseStyle = {
116122 left : '50%' ,
117123 top : '50%' ,
118124 width : `${ w * cvsRatio . w } px` ,
119125 height : `${ h * cvsRatio . h } px` ,
120- // border 1px, 所以要 -1
121126 transform : `translate(${ x * cvsRatio . w } px, ${ y * cvsRatio . h } px)` ,
122- } ) ;
127+ } ;
128+ ctrlsEl [ k as TCtrlKey ] . innerHTML = '' ;
129+ if ( k === 'rotate' ) {
130+ Object . assign ( ctrlsEl [ k as TCtrlKey ] . style , {
131+ display : s . interactable === 'interactive' ? 'block' : 'none' ,
132+ ...baseStyle ,
133+ } ) ;
134+ } else {
135+ if ( s . interactable === 'interactive' ) {
136+ Object . assign ( ctrlsEl [ k as TCtrlKey ] . style , {
137+ display : 'block' ,
138+ backgroundColor : '#fff' ,
139+ border : '1px solid #3ee' ,
140+ ...baseStyle ,
141+ } ) ;
142+ } else if ( s . interactable === 'selectable' ) {
143+ Object . assign ( ctrlsEl [ k as TCtrlKey ] . style , {
144+ display : 'flex' ,
145+ justifyContent : 'center' ,
146+ alignItems : 'center' ,
147+ backgroundColor : 'transparent' ,
148+ border : 'none' ,
149+ ...baseStyle ,
150+ } ) ;
151+ ctrlsEl [ k as TCtrlKey ] . innerHTML = CloseSvg ;
152+ } else {
153+ Object . assign ( ctrlsEl [ k as TCtrlKey ] . style , {
154+ display : 'none' ,
155+ ...baseStyle ,
156+ } ) ;
157+ }
158+ }
123159 } ) ;
124160 if ( s . interactable === 'disabled' ) {
125161 rectEl . style . display = 'none' ;
0 commit comments