选框大小可调
Browse files- src/WeChatOcrCpp/ocr_aliyun.js +15 -7
- src/WpfEditor/MainWindow.xaml +164 -1
- src/WpfEditor/MainWindow.xaml.cs +206 -2
- src/WpfEditor/ViewModel.cs +3 -0
src/WeChatOcrCpp/ocr_aliyun.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
(async () => {
|
| 2 |
|
| 3 |
// New-NetFirewallRule -DisplayName "Allow Port 7788" -Direction Inbound -Protocol TCP -LocalPort 7788 -Action Allow
|
|
@@ -10,11 +12,17 @@
|
|
| 10 |
|
| 11 |
|
| 12 |
async function ocr(imgData) {
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
//const api = 'http://127.0.0.1:7788/wechatocr';
|
| 15 |
-
const api = 'http://127.0.0.1:8889/ppocr';
|
| 16 |
-
const appCode =
|
| 17 |
-
const appSecret =
|
| 18 |
|
| 19 |
let request = require('request')
|
| 20 |
|
|
@@ -80,17 +88,17 @@
|
|
| 80 |
|
| 81 |
|
| 82 |
let fs = require('fs')
|
| 83 |
-
let md5 = require('md5')
|
| 84 |
|
| 85 |
let bytes = fs.readFileSync("0170.jpg")
|
| 86 |
let buf = Buffer.from(bytes)
|
| 87 |
-
let m5 = md5(buf)
|
| 88 |
let b64 = buf.toString('base64')
|
| 89 |
|
| 90 |
|
| 91 |
for (let i = 0; i < 5000; i++) {
|
| 92 |
console.log(`Send ${i}`)
|
| 93 |
-
ocr(b64);
|
| 94 |
await sleep(300);
|
| 95 |
}
|
| 96 |
|
|
|
|
| 1 |
+
const { json } = require('stream/consumers');
|
| 2 |
+
|
| 3 |
(async () => {
|
| 4 |
|
| 5 |
// New-NetFirewallRule -DisplayName "Allow Port 7788" -Direction Inbound -Protocol TCP -LocalPort 7788 -Action Allow
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
async function ocr(imgData) {
|
| 15 |
+
|
| 16 |
+
let fs = require('fs')
|
| 17 |
+
|
| 18 |
+
let config = fs.readFileSync("../WpfEditor/config.json", {encoding: "utf-8"})
|
| 19 |
+
config = JSON.parse(config)
|
| 20 |
+
|
| 21 |
+
const api = config.aliOCR.api // 'https://gjbsb.market.alicloudapi.com/ocrservice/advanced';
|
| 22 |
//const api = 'http://127.0.0.1:7788/wechatocr';
|
| 23 |
+
//const api = 'http://127.0.0.1:8889/ppocr';
|
| 24 |
+
const appCode = config.aliOCR.appCode;
|
| 25 |
+
const appSecret = config.aliOCR.appSecret;
|
| 26 |
|
| 27 |
let request = require('request')
|
| 28 |
|
|
|
|
| 88 |
|
| 89 |
|
| 90 |
let fs = require('fs')
|
| 91 |
+
// let md5 = require('md5')
|
| 92 |
|
| 93 |
let bytes = fs.readFileSync("0170.jpg")
|
| 94 |
let buf = Buffer.from(bytes)
|
| 95 |
+
// let m5 = md5(buf)
|
| 96 |
let b64 = buf.toString('base64')
|
| 97 |
|
| 98 |
|
| 99 |
for (let i = 0; i < 5000; i++) {
|
| 100 |
console.log(`Send ${i}`)
|
| 101 |
+
await ocr(b64);
|
| 102 |
await sleep(300);
|
| 103 |
}
|
| 104 |
|
src/WpfEditor/MainWindow.xaml
CHANGED
|
@@ -224,7 +224,9 @@
|
|
| 224 |
</ItemsControl.ItemContainerStyle>
|
| 225 |
<ItemsControl.ItemTemplate>
|
| 226 |
<DataTemplate>
|
| 227 |
-
<Grid
|
|
|
|
|
|
|
| 228 |
<!-- 矩形框 -->
|
| 229 |
<Rectangle Width="{Binding Width}"
|
| 230 |
Height="{Binding Height}"
|
|
@@ -246,6 +248,167 @@
|
|
| 246 |
FontSize="12"
|
| 247 |
FontWeight="Bold"/>
|
| 248 |
</Border>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
</Grid>
|
| 250 |
</DataTemplate>
|
| 251 |
</ItemsControl.ItemTemplate>
|
|
|
|
| 224 |
</ItemsControl.ItemContainerStyle>
|
| 225 |
<ItemsControl.ItemTemplate>
|
| 226 |
<DataTemplate>
|
| 227 |
+
<Grid Width="{Binding Width}" Height="{Binding Height}"
|
| 228 |
+
MouseEnter="RectangleGrid_MouseEnter"
|
| 229 |
+
MouseLeave="RectangleGrid_MouseLeave">
|
| 230 |
<!-- 矩形框 -->
|
| 231 |
<Rectangle Width="{Binding Width}"
|
| 232 |
Height="{Binding Height}"
|
|
|
|
| 248 |
FontSize="12"
|
| 249 |
FontWeight="Bold"/>
|
| 250 |
</Border>
|
| 251 |
+
|
| 252 |
+
<!-- 调整大小的控制点 -->
|
| 253 |
+
<!-- 右下角调整点 -->
|
| 254 |
+
<Thumb x:Name="ResizeThumb"
|
| 255 |
+
Width="8"
|
| 256 |
+
Height="8"
|
| 257 |
+
Background="Lime"
|
| 258 |
+
BorderBrush="DarkGreen"
|
| 259 |
+
BorderThickness="1"
|
| 260 |
+
HorizontalAlignment="Right"
|
| 261 |
+
VerticalAlignment="Bottom"
|
| 262 |
+
Margin="0,0,-4,-4"
|
| 263 |
+
Cursor="SizeNWSE"
|
| 264 |
+
DragDelta="ResizeThumb_DragDelta">
|
| 265 |
+
<Thumb.Visibility>
|
| 266 |
+
<MultiBinding Converter="{x:Static local:VisibilityAndHoverConverter.Instance}">
|
| 267 |
+
<Binding Path="IsVisible"/>
|
| 268 |
+
<Binding Path="IsHovered"/>
|
| 269 |
+
</MultiBinding>
|
| 270 |
+
</Thumb.Visibility>
|
| 271 |
+
</Thumb>
|
| 272 |
+
|
| 273 |
+
<!-- 右边中间调整点 -->
|
| 274 |
+
<Thumb x:Name="ResizeRightThumb"
|
| 275 |
+
Width="8"
|
| 276 |
+
Height="8"
|
| 277 |
+
Background="Lime"
|
| 278 |
+
BorderBrush="DarkGreen"
|
| 279 |
+
BorderThickness="1"
|
| 280 |
+
HorizontalAlignment="Right"
|
| 281 |
+
VerticalAlignment="Center"
|
| 282 |
+
Margin="0,0,-4,0"
|
| 283 |
+
Cursor="SizeWE"
|
| 284 |
+
DragDelta="ResizeRightThumb_DragDelta">
|
| 285 |
+
<Thumb.Visibility>
|
| 286 |
+
<MultiBinding Converter="{x:Static local:VisibilityAndHoverConverter.Instance}">
|
| 287 |
+
<Binding Path="IsVisible"/>
|
| 288 |
+
<Binding Path="IsHovered"/>
|
| 289 |
+
</MultiBinding>
|
| 290 |
+
</Thumb.Visibility>
|
| 291 |
+
</Thumb>
|
| 292 |
+
|
| 293 |
+
<!-- 下边中间调整点 -->
|
| 294 |
+
<Thumb x:Name="ResizeBottomThumb"
|
| 295 |
+
Width="8"
|
| 296 |
+
Height="8"
|
| 297 |
+
Background="Lime"
|
| 298 |
+
BorderBrush="DarkGreen"
|
| 299 |
+
BorderThickness="1"
|
| 300 |
+
HorizontalAlignment="Center"
|
| 301 |
+
VerticalAlignment="Bottom"
|
| 302 |
+
Margin="0,0,0,-4"
|
| 303 |
+
Cursor="SizeNS"
|
| 304 |
+
DragDelta="ResizeBottomThumb_DragDelta">
|
| 305 |
+
<Thumb.Visibility>
|
| 306 |
+
<MultiBinding Converter="{x:Static local:VisibilityAndHoverConverter.Instance}">
|
| 307 |
+
<Binding Path="IsVisible"/>
|
| 308 |
+
<Binding Path="IsHovered"/>
|
| 309 |
+
</MultiBinding>
|
| 310 |
+
</Thumb.Visibility>
|
| 311 |
+
</Thumb>
|
| 312 |
+
|
| 313 |
+
<!-- 左边中间调整点 -->
|
| 314 |
+
<Thumb x:Name="ResizeLeftThumb"
|
| 315 |
+
Width="8"
|
| 316 |
+
Height="8"
|
| 317 |
+
Background="Lime"
|
| 318 |
+
BorderBrush="DarkGreen"
|
| 319 |
+
BorderThickness="1"
|
| 320 |
+
HorizontalAlignment="Left"
|
| 321 |
+
VerticalAlignment="Center"
|
| 322 |
+
Margin="-4,0,0,0"
|
| 323 |
+
Cursor="SizeWE"
|
| 324 |
+
DragDelta="ResizeLeftThumb_DragDelta">
|
| 325 |
+
<Thumb.Visibility>
|
| 326 |
+
<MultiBinding Converter="{x:Static local:VisibilityAndHoverConverter.Instance}">
|
| 327 |
+
<Binding Path="IsVisible"/>
|
| 328 |
+
<Binding Path="IsHovered"/>
|
| 329 |
+
</MultiBinding>
|
| 330 |
+
</Thumb.Visibility>
|
| 331 |
+
</Thumb>
|
| 332 |
+
|
| 333 |
+
<!-- 上边中间调整点 -->
|
| 334 |
+
<Thumb x:Name="ResizeTopThumb"
|
| 335 |
+
Width="8"
|
| 336 |
+
Height="8"
|
| 337 |
+
Background="Lime"
|
| 338 |
+
BorderBrush="DarkGreen"
|
| 339 |
+
BorderThickness="1"
|
| 340 |
+
HorizontalAlignment="Center"
|
| 341 |
+
VerticalAlignment="Top"
|
| 342 |
+
Margin="0,-4,0,0"
|
| 343 |
+
Cursor="SizeNS"
|
| 344 |
+
DragDelta="ResizeTopThumb_DragDelta">
|
| 345 |
+
<Thumb.Visibility>
|
| 346 |
+
<MultiBinding Converter="{x:Static local:VisibilityAndHoverConverter.Instance}">
|
| 347 |
+
<Binding Path="IsVisible"/>
|
| 348 |
+
<Binding Path="IsHovered"/>
|
| 349 |
+
</MultiBinding>
|
| 350 |
+
</Thumb.Visibility>
|
| 351 |
+
</Thumb>
|
| 352 |
+
|
| 353 |
+
<!-- 左上角调整点 -->
|
| 354 |
+
<Thumb x:Name="ResizeTopLeftThumb"
|
| 355 |
+
Width="8"
|
| 356 |
+
Height="8"
|
| 357 |
+
Background="Lime"
|
| 358 |
+
BorderBrush="DarkGreen"
|
| 359 |
+
BorderThickness="1"
|
| 360 |
+
HorizontalAlignment="Left"
|
| 361 |
+
VerticalAlignment="Top"
|
| 362 |
+
Margin="-4,-4,0,0"
|
| 363 |
+
Cursor="SizeNWSE"
|
| 364 |
+
DragDelta="ResizeTopLeftThumb_DragDelta">
|
| 365 |
+
<Thumb.Visibility>
|
| 366 |
+
<MultiBinding Converter="{x:Static local:VisibilityAndHoverConverter.Instance}">
|
| 367 |
+
<Binding Path="IsVisible"/>
|
| 368 |
+
<Binding Path="IsHovered"/>
|
| 369 |
+
</MultiBinding>
|
| 370 |
+
</Thumb.Visibility>
|
| 371 |
+
</Thumb>
|
| 372 |
+
|
| 373 |
+
<!-- 右上角调整点 -->
|
| 374 |
+
<Thumb x:Name="ResizeTopRightThumb"
|
| 375 |
+
Width="8"
|
| 376 |
+
Height="8"
|
| 377 |
+
Background="Lime"
|
| 378 |
+
BorderBrush="DarkGreen"
|
| 379 |
+
BorderThickness="1"
|
| 380 |
+
HorizontalAlignment="Right"
|
| 381 |
+
VerticalAlignment="Top"
|
| 382 |
+
Margin="0,-4,-4,0"
|
| 383 |
+
Cursor="SizeNESW"
|
| 384 |
+
DragDelta="ResizeTopRightThumb_DragDelta">
|
| 385 |
+
<Thumb.Visibility>
|
| 386 |
+
<MultiBinding Converter="{x:Static local:VisibilityAndHoverConverter.Instance}">
|
| 387 |
+
<Binding Path="IsVisible"/>
|
| 388 |
+
<Binding Path="IsHovered"/>
|
| 389 |
+
</MultiBinding>
|
| 390 |
+
</Thumb.Visibility>
|
| 391 |
+
</Thumb>
|
| 392 |
+
|
| 393 |
+
<!-- 左下角调整点 -->
|
| 394 |
+
<Thumb x:Name="ResizeBottomLeftThumb"
|
| 395 |
+
Width="8"
|
| 396 |
+
Height="8"
|
| 397 |
+
Background="Lime"
|
| 398 |
+
BorderBrush="DarkGreen"
|
| 399 |
+
BorderThickness="1"
|
| 400 |
+
HorizontalAlignment="Left"
|
| 401 |
+
VerticalAlignment="Bottom"
|
| 402 |
+
Margin="-4,0,0,-4"
|
| 403 |
+
Cursor="SizeNESW"
|
| 404 |
+
DragDelta="ResizeBottomLeftThumb_DragDelta">
|
| 405 |
+
<Thumb.Visibility>
|
| 406 |
+
<MultiBinding Converter="{x:Static local:VisibilityAndHoverConverter.Instance}">
|
| 407 |
+
<Binding Path="IsVisible"/>
|
| 408 |
+
<Binding Path="IsHovered"/>
|
| 409 |
+
</MultiBinding>
|
| 410 |
+
</Thumb.Visibility>
|
| 411 |
+
</Thumb>
|
| 412 |
</Grid>
|
| 413 |
</DataTemplate>
|
| 414 |
</ItemsControl.ItemTemplate>
|
src/WpfEditor/MainWindow.xaml.cs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
using Microsoft.Win32;
|
| 3 |
using Newtonsoft.Json;
|
| 4 |
using Newtonsoft.Json.Linq;
|
|
@@ -1860,7 +1860,191 @@ namespace WpfEditor
|
|
| 1860 |
_previousImageWidth = newWidth;
|
| 1861 |
_previousImageHeight = newHeight;
|
| 1862 |
}
|
| 1863 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1864 |
|
| 1865 |
|
| 1866 |
// 添加布尔值到可见性转换器
|
|
@@ -1879,6 +2063,26 @@ namespace WpfEditor
|
|
| 1879 |
}
|
| 1880 |
}
|
| 1881 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1882 |
}
|
| 1883 |
|
| 1884 |
|
|
|
|
| 1 |
+
using CommunityToolkit.Mvvm.DependencyInjection;
|
| 2 |
using Microsoft.Win32;
|
| 3 |
using Newtonsoft.Json;
|
| 4 |
using Newtonsoft.Json.Linq;
|
|
|
|
| 1860 |
_previousImageWidth = newWidth;
|
| 1861 |
_previousImageHeight = newHeight;
|
| 1862 |
}
|
| 1863 |
+
|
| 1864 |
+
// 右下角调整大小事件处理
|
| 1865 |
+
private void ResizeThumb_DragDelta(object sender, DragDeltaEventArgs e)
|
| 1866 |
+
{
|
| 1867 |
+
var thumb = sender as Thumb;
|
| 1868 |
+
if (thumb?.DataContext is RectangleItem rectangle)
|
| 1869 |
+
{
|
| 1870 |
+
// 调整宽度和高度
|
| 1871 |
+
double newWidth = Math.Max(10, rectangle.Width + e.HorizontalChange);
|
| 1872 |
+
double newHeight = Math.Max(10, rectangle.Height + e.VerticalChange);
|
| 1873 |
+
|
| 1874 |
+
rectangle.Width = newWidth;
|
| 1875 |
+
rectangle.Height = newHeight;
|
| 1876 |
+
|
| 1877 |
+
// 标记文本已更改
|
| 1878 |
+
_textChanged = true;
|
| 1879 |
+
}
|
| 1880 |
+
}
|
| 1881 |
+
|
| 1882 |
+
// 右边中间调整大小事件处理
|
| 1883 |
+
private void ResizeRightThumb_DragDelta(object sender, DragDeltaEventArgs e)
|
| 1884 |
+
{
|
| 1885 |
+
var thumb = sender as Thumb;
|
| 1886 |
+
if (thumb?.DataContext is RectangleItem rectangle)
|
| 1887 |
+
{
|
| 1888 |
+
// 只调整宽度
|
| 1889 |
+
double newWidth = Math.Max(10, rectangle.Width + e.HorizontalChange);
|
| 1890 |
+
rectangle.Width = newWidth;
|
| 1891 |
+
|
| 1892 |
+
// 标记文本已更改
|
| 1893 |
+
_textChanged = true;
|
| 1894 |
+
}
|
| 1895 |
+
}
|
| 1896 |
+
|
| 1897 |
+
// 下边中间调整大小事件处理
|
| 1898 |
+
private void ResizeBottomThumb_DragDelta(object sender, DragDeltaEventArgs e)
|
| 1899 |
+
{
|
| 1900 |
+
var thumb = sender as Thumb;
|
| 1901 |
+
if (thumb?.DataContext is RectangleItem rectangle)
|
| 1902 |
+
{
|
| 1903 |
+
// 只调整高度
|
| 1904 |
+
double newHeight = Math.Max(10, rectangle.Height + e.VerticalChange);
|
| 1905 |
+
rectangle.Height = newHeight;
|
| 1906 |
+
|
| 1907 |
+
// 标记文本已更改
|
| 1908 |
+
_textChanged = true;
|
| 1909 |
+
}
|
| 1910 |
+
}
|
| 1911 |
+
|
| 1912 |
+
// 左边中间调整大小事件处理
|
| 1913 |
+
private void ResizeLeftThumb_DragDelta(object sender, DragDeltaEventArgs e)
|
| 1914 |
+
{
|
| 1915 |
+
var thumb = sender as Thumb;
|
| 1916 |
+
if (thumb?.DataContext is RectangleItem rectangle)
|
| 1917 |
+
{
|
| 1918 |
+
// 调整左边位置和宽度
|
| 1919 |
+
double newLeft = rectangle.Left + e.HorizontalChange;
|
| 1920 |
+
double newWidth = rectangle.Width - e.HorizontalChange;
|
| 1921 |
+
|
| 1922 |
+
// 确保最小宽度
|
| 1923 |
+
if (newWidth >= 10)
|
| 1924 |
+
{
|
| 1925 |
+
rectangle.Left = newLeft;
|
| 1926 |
+
rectangle.Width = newWidth;
|
| 1927 |
+
}
|
| 1928 |
+
|
| 1929 |
+
// 标记文本已更改
|
| 1930 |
+
_textChanged = true;
|
| 1931 |
+
}
|
| 1932 |
+
}
|
| 1933 |
+
|
| 1934 |
+
// 上边中间调整大小事件处理
|
| 1935 |
+
private void ResizeTopThumb_DragDelta(object sender, DragDeltaEventArgs e)
|
| 1936 |
+
{
|
| 1937 |
+
var thumb = sender as Thumb;
|
| 1938 |
+
if (thumb?.DataContext is RectangleItem rectangle)
|
| 1939 |
+
{
|
| 1940 |
+
// 调整上边位置和高度
|
| 1941 |
+
double newTop = rectangle.Top + e.VerticalChange;
|
| 1942 |
+
double newHeight = rectangle.Height - e.VerticalChange;
|
| 1943 |
+
|
| 1944 |
+
// 确保最小高度
|
| 1945 |
+
if (newHeight >= 10)
|
| 1946 |
+
{
|
| 1947 |
+
rectangle.Top = newTop;
|
| 1948 |
+
rectangle.Height = newHeight;
|
| 1949 |
+
}
|
| 1950 |
+
|
| 1951 |
+
// 标记文本已更改
|
| 1952 |
+
_textChanged = true;
|
| 1953 |
+
}
|
| 1954 |
+
}
|
| 1955 |
+
|
| 1956 |
+
// 左上角调整大小事件处理
|
| 1957 |
+
private void ResizeTopLeftThumb_DragDelta(object sender, DragDeltaEventArgs e)
|
| 1958 |
+
{
|
| 1959 |
+
var thumb = sender as Thumb;
|
| 1960 |
+
if (thumb?.DataContext is RectangleItem rectangle)
|
| 1961 |
+
{
|
| 1962 |
+
// 调整左上角位置和尺寸
|
| 1963 |
+
double newLeft = rectangle.Left + e.HorizontalChange;
|
| 1964 |
+
double newTop = rectangle.Top + e.VerticalChange;
|
| 1965 |
+
double newWidth = rectangle.Width - e.HorizontalChange;
|
| 1966 |
+
double newHeight = rectangle.Height - e.VerticalChange;
|
| 1967 |
+
|
| 1968 |
+
// 确保最小尺寸
|
| 1969 |
+
if (newWidth >= 10 && newHeight >= 10)
|
| 1970 |
+
{
|
| 1971 |
+
rectangle.Left = newLeft;
|
| 1972 |
+
rectangle.Top = newTop;
|
| 1973 |
+
rectangle.Width = newWidth;
|
| 1974 |
+
rectangle.Height = newHeight;
|
| 1975 |
+
}
|
| 1976 |
+
|
| 1977 |
+
// 标记文本已更改
|
| 1978 |
+
_textChanged = true;
|
| 1979 |
+
}
|
| 1980 |
+
}
|
| 1981 |
+
|
| 1982 |
+
// 右上角调整大小事件处理
|
| 1983 |
+
private void ResizeTopRightThumb_DragDelta(object sender, DragDeltaEventArgs e)
|
| 1984 |
+
{
|
| 1985 |
+
var thumb = sender as Thumb;
|
| 1986 |
+
if (thumb?.DataContext is RectangleItem rectangle)
|
| 1987 |
+
{
|
| 1988 |
+
// 调整右上角位置和尺寸
|
| 1989 |
+
double newTop = rectangle.Top + e.VerticalChange;
|
| 1990 |
+
double newWidth = rectangle.Width + e.HorizontalChange;
|
| 1991 |
+
double newHeight = rectangle.Height - e.VerticalChange;
|
| 1992 |
+
|
| 1993 |
+
// 确保最小尺寸
|
| 1994 |
+
if (newWidth >= 10 && newHeight >= 10)
|
| 1995 |
+
{
|
| 1996 |
+
rectangle.Top = newTop;
|
| 1997 |
+
rectangle.Width = newWidth;
|
| 1998 |
+
rectangle.Height = newHeight;
|
| 1999 |
+
}
|
| 2000 |
+
|
| 2001 |
+
// 标记文本已更改
|
| 2002 |
+
_textChanged = true;
|
| 2003 |
+
}
|
| 2004 |
+
}
|
| 2005 |
+
|
| 2006 |
+
// 左下角调整大小事件处理
|
| 2007 |
+
private void ResizeBottomLeftThumb_DragDelta(object sender, DragDeltaEventArgs e)
|
| 2008 |
+
{
|
| 2009 |
+
var thumb = sender as Thumb;
|
| 2010 |
+
if (thumb?.DataContext is RectangleItem rectangle)
|
| 2011 |
+
{
|
| 2012 |
+
// 调整左下角位置和尺寸
|
| 2013 |
+
double newLeft = rectangle.Left + e.HorizontalChange;
|
| 2014 |
+
double newWidth = rectangle.Width - e.HorizontalChange;
|
| 2015 |
+
double newHeight = rectangle.Height + e.VerticalChange;
|
| 2016 |
+
|
| 2017 |
+
// 确保最小尺寸
|
| 2018 |
+
if (newWidth >= 10 && newHeight >= 10)
|
| 2019 |
+
{
|
| 2020 |
+
rectangle.Left = newLeft;
|
| 2021 |
+
rectangle.Width = newWidth;
|
| 2022 |
+
rectangle.Height = newHeight;
|
| 2023 |
+
}
|
| 2024 |
+
|
| 2025 |
+
// 标记文本已更改
|
| 2026 |
+
_textChanged = true;
|
| 2027 |
+
}
|
| 2028 |
+
}
|
| 2029 |
+
|
| 2030 |
+
// 鼠标进入矩形区域事件处理器
|
| 2031 |
+
private void RectangleGrid_MouseEnter(object sender, MouseEventArgs e)
|
| 2032 |
+
{
|
| 2033 |
+
if (sender is Grid grid && grid.DataContext is RectangleItem rectangle)
|
| 2034 |
+
{
|
| 2035 |
+
rectangle.IsHovered = true;
|
| 2036 |
+
}
|
| 2037 |
+
}
|
| 2038 |
+
|
| 2039 |
+
// 鼠标离开矩形区域事件处理器
|
| 2040 |
+
private void RectangleGrid_MouseLeave(object sender, MouseEventArgs e)
|
| 2041 |
+
{
|
| 2042 |
+
if (sender is Grid grid && grid.DataContext is RectangleItem rectangle)
|
| 2043 |
+
{
|
| 2044 |
+
rectangle.IsHovered = false;
|
| 2045 |
+
}
|
| 2046 |
+
}
|
| 2047 |
+
}
|
| 2048 |
|
| 2049 |
|
| 2050 |
// 添加布尔值到可见性转换器
|
|
|
|
| 2063 |
}
|
| 2064 |
}
|
| 2065 |
|
| 2066 |
+
// 多值转换器:同时检查IsVisible和IsHovered属性
|
| 2067 |
+
public class VisibilityAndHoverConverter : IMultiValueConverter
|
| 2068 |
+
{
|
| 2069 |
+
public static readonly VisibilityAndHoverConverter Instance = new VisibilityAndHoverConverter();
|
| 2070 |
+
|
| 2071 |
+
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
| 2072 |
+
{
|
| 2073 |
+
if (values.Length >= 2 && values[0] is bool isVisible && values[1] is bool isHovered)
|
| 2074 |
+
{
|
| 2075 |
+
return (isVisible && isHovered) ? Visibility.Visible : Visibility.Collapsed;
|
| 2076 |
+
}
|
| 2077 |
+
return Visibility.Collapsed;
|
| 2078 |
+
}
|
| 2079 |
+
|
| 2080 |
+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
|
| 2081 |
+
{
|
| 2082 |
+
throw new NotImplementedException();
|
| 2083 |
+
}
|
| 2084 |
+
}
|
| 2085 |
+
|
| 2086 |
}
|
| 2087 |
|
| 2088 |
|
src/WpfEditor/ViewModel.cs
CHANGED
|
@@ -26,6 +26,9 @@ namespace WpfEditor
|
|
| 26 |
[ObservableProperty]
|
| 27 |
private bool isVisible = true;
|
| 28 |
|
|
|
|
|
|
|
|
|
|
| 29 |
public RectangleItem(int id, double left, double top, double width, double height)
|
| 30 |
{
|
| 31 |
Id = id;
|
|
|
|
| 26 |
[ObservableProperty]
|
| 27 |
private bool isVisible = true;
|
| 28 |
|
| 29 |
+
[ObservableProperty]
|
| 30 |
+
private bool isHovered = false;
|
| 31 |
+
|
| 32 |
public RectangleItem(int id, double left, double top, double width, double height)
|
| 33 |
{
|
| 34 |
Id = id;
|