Highlight line brush line in 2D editor

Fix pressing keys API when using multiple keys
Fix UV editor UV size text not clickable
This commit is contained in:
JannisX11 2023-11-15 01:22:03 +01:00
parent 57124f258e
commit 19d1f36a10
4 changed files with 51 additions and 9 deletions

View File

@ -1875,12 +1875,12 @@ span.controller_state_section_info {
.UVEditor > .toolbar {
margin-top: 3px;
}
#project_resolution_status {
#uv_resolution_status {
margin: 2px;
padding: 0px 5px;
pointer-events: auto;
}
#project_resolution_status:hover {
#uv_resolution_status:hover {
color: var(--color-light);
}
@ -1988,6 +1988,14 @@ span.controller_state_section_info {
color: white;
width: 16px;
}
div#uv_brush_line_preview {
margin: calc(var(--radius) * 1px);
position: relative;
height: 2px;
transform-origin: left;
background-color: #cccccc;
pointer-events: none;
}
canvas.move_texture_with_uv {
position: absolute;
pointer-events: none;

View File

@ -886,9 +886,9 @@ $(document).keyup(function(e) {
}
let changed = Pressing.shift || Pressing.alt || Pressing.ctrl;
let before = changed && {shift: Pressing.shift, alt: Pressing.alt, ctrl: Pressing.ctrl};
Pressing.shift = false;
Pressing.alt = false;
Pressing.ctrl = false;
Pressing.shift = e.shiftKey;
Pressing.alt = e.altKey;
Pressing.ctrl = e.ctrlKey;
if (changed) {
Blockbench.dispatchEvent('update_pressed_modifier_keys', {before, now: Pressing});
}

View File

@ -337,8 +337,9 @@ const Painter = {
},
useBrushlike(texture, x, y, event, uvTag, no_update, is_opposite) {
if (Painter.currentPixel[0] === x && Painter.currentPixel[1] === y) return;
Painter.currentPixel = [x, y]
Painter.currentPixel = [x, y];
Painter.brushChanges = true;
UVEditor.vue.last_brush_position.V2_set(x, y);
let uvFactorX = texture.width / texture.getUVWidth();
let uvFactorY = texture.display_height / texture.getUVHeight();

View File

@ -1975,7 +1975,8 @@ Interface.definePanels(function() {
uv_overlay: false,
texture: 0,
layer: null,
mouse_coords: {x: -1, y: -1, active: false},
mouse_coords: {x: -1, y: -1, active: false, line_preview: false},
last_brush_position: [0, 0],
copy_brush_source: null,
helper_lines: {x: -1, y: -1},
brush_type: BarItems.brush_shape.value,
@ -3510,6 +3511,30 @@ Interface.definePanels(function() {
}
return false;
},
getLinePreviewAngle() {
let angle = Math.atan2(this.last_brush_position[1] - this.mouse_coords.y, this.last_brush_position[0] - this.mouse_coords.x);
return Math.radToDeg(angle);
},
getLinePreviewStyle() {
let tex = this.texture;
let pixel_size = this.inner_width / (tex ? tex.width : Project.texture_width);
let width = Math.sqrt(Math.pow(this.mouse_coords.x - this.last_brush_position[0], 2) + Math.pow(this.mouse_coords.y - this.last_brush_position[1], 2));
let angle = this.getLinePreviewAngle();
return {
width: width * pixel_size + 'px',
rotate: angle + 'deg'
};
},
getBrushPositionText() {
if (!this.mouse_coords.active) return '';
let string = trimFloatNumber(this.mouse_coords.x, 1) + ', ' + trimFloatNumber(this.mouse_coords.y, 1);
if (this.mouse_coords.line_preview) {
let angle = this.getLinePreviewAngle();
angle = (angle + 180) % 90;
string += `, ${trimFloatNumber(Math.roundTo(angle, 1))}°`;
}
return string;
},
checkFormat(values) {
for (let key in values) {
@ -3813,7 +3838,9 @@ Interface.definePanels(function() {
<div v-if="helper_lines.x >= 0" class="uv_helper_line_x" :style="{left: toPixels(helper_lines.x)}"></div>
<div v-if="helper_lines.y >= 0" class="uv_helper_line_y" :style="{top: toPixels(helper_lines.y)}"></div>
<div id="uv_brush_outline" v-if="mode == 'paint' && mouse_coords.active" :class="brush_type" :style="getBrushOutlineStyle()"></div>
<div id="uv_brush_outline" v-if="mode == 'paint' && mouse_coords.active" :class="brush_type" :style="getBrushOutlineStyle()">
<div v-if="mouse_coords.line_preview" id="uv_brush_line_preview" :style="getLinePreviewStyle()"></div>
</div>
<div id="uv_copy_brush_outline" v-if="copy_brush_source && texture && texture.uuid == copy_brush_source.texture" :style="getCopyBrushOutlineStyle()"></div>
@ -3881,7 +3908,7 @@ Interface.definePanels(function() {
</div>
<template v-else>
<span style="color: var(--color-subtle_text);">{{ mouse_coords.active ? (trimFloatNumber(mouse_coords.x, 1) + ', ' + trimFloatNumber(mouse_coords.y, 1)) : '-' }}</span>
<span style="color: var(--color-subtle_text);">{{ getBrushPositionText() }}</span>
<span v-if="texture" class="uv_panel_texture_name" @click="selectTextureMenu($event)">{{ texture.name }}</span>
<span style="color: var(--color-subtle_text);">{{ Math.round(this.zoom*100).toString() + '%' }}</span>
</template>
@ -3908,6 +3935,12 @@ Interface.definePanels(function() {
})
})
Blockbench.on('update_pressed_modifier_keys', ({before, now}) => {
if (before.shift != now.shift && document.querySelector('#uv_viewport:hover')) {
UVEditor.vue.mouse_coords.line_preview = now.shift;
}
});
Toolbars.uv_editor.toPlace()
BarItems.paint_mode_uv_overlay.toElement('#toggle_uv_overlay_anchor');