diff --git a/sprites/icons/Cut.png b/sprites/icons/Cut.png new file mode 100644 index 0000000..6b14230 Binary files /dev/null and b/sprites/icons/Cut.png differ diff --git a/sprites/icons/Paste.png b/sprites/icons/Paste.png new file mode 100644 index 0000000..972b4fc Binary files /dev/null and b/sprites/icons/Paste.png differ diff --git a/src/main/resources/ocelot/desktop/images/spritesheet/spritesheet.png b/src/main/resources/ocelot/desktop/images/spritesheet/spritesheet.png index 0a6028c..214e7a1 100644 Binary files a/src/main/resources/ocelot/desktop/images/spritesheet/spritesheet.png and b/src/main/resources/ocelot/desktop/images/spritesheet/spritesheet.png differ diff --git a/src/main/resources/ocelot/desktop/images/spritesheet/spritesheet.txt b/src/main/resources/ocelot/desktop/images/spritesheet/spritesheet.txt index caa3018..71e1df4 100644 --- a/src/main/resources/ocelot/desktop/images/spritesheet/spritesheet.txt +++ b/src/main/resources/ocelot/desktop/images/spritesheet/spritesheet.txt @@ -47,46 +47,48 @@ icons/Code 321 632 16 16 icons/ComponentBus 338 632 16 16 icons/Copy 355 632 16 16 icons/Cross 372 632 16 16 -icons/Delete 389 632 16 16 +icons/Cut 389 632 16 16 +icons/Delete 406 632 16 16 icons/DragLMB 509 567 21 14 icons/DragRMB 531 567 21 14 -icons/EEPROM 406 632 16 16 -icons/Edit 423 632 16 16 -icons/Eject 440 632 16 16 -icons/File 457 632 16 16 -icons/Floppy 474 632 16 16 -icons/Folder 491 632 16 16 -icons/FolderSlash 508 632 16 16 +icons/EEPROM 423 632 16 16 +icons/Edit 440 632 16 16 +icons/Eject 457 632 16 16 +icons/File 474 632 16 16 +icons/Floppy 491 632 16 16 +icons/Folder 508 632 16 16 +icons/FolderSlash 525 632 16 16 icons/Grid 177 567 22 22 icons/GridOff 200 567 22 22 -icons/Guitar 525 632 16 16 -icons/HDD 542 632 16 16 -icons/Help 559 632 16 16 +icons/Guitar 542 632 16 16 +icons/HDD 559 632 16 16 +icons/Help 576 632 16 16 icons/Home 223 567 22 22 -icons/Keyboard 576 632 16 16 -icons/KeyboardOff 593 632 16 16 +icons/Keyboard 593 632 16 16 +icons/KeyboardOff 610 632 16 16 icons/LMB 453 434 11 14 -icons/Label 610 632 16 16 -icons/LinesHorizontal 627 632 16 16 -icons/Link 644 632 16 16 -icons/LinkSlash 661 632 16 16 -icons/Memory 678 632 16 16 -icons/Microchip 695 632 16 16 -icons/NA 712 632 16 16 +icons/Label 627 632 16 16 +icons/LinesHorizontal 644 632 16 16 +icons/Link 661 632 16 16 +icons/LinkSlash 678 632 16 16 +icons/Memory 695 632 16 16 +icons/Microchip 712 632 16 16 +icons/NA 729 632 16 16 icons/NotificationError 477 434 11 11 icons/NotificationInfo 489 434 11 11 icons/NotificationWarning 501 434 11 11 -icons/Ocelot 729 632 16 16 -icons/Pause 746 632 16 16 +icons/Ocelot 746 632 16 16 +icons/Paste 763 632 16 16 +icons/Pause 780 632 16 16 icons/Pin 408 434 14 14 -icons/Play 763 632 16 16 -icons/Plus 780 632 16 16 -icons/Power 797 632 16 16 +icons/Play 797 632 16 16 +icons/Plus 814 632 16 16 +icons/Power 831 632 16 16 icons/RMB 465 434 11 14 -icons/Restart 814 632 16 16 -icons/Save 831 632 16 16 -icons/SaveAs 848 632 16 16 -icons/Server 865 632 16 16 +icons/Restart 848 632 16 16 +icons/Save 865 632 16 16 +icons/SaveAs 882 632 16 16 +icons/Server 899 632 16 16 icons/SettingsKeymap 356 434 12 17 icons/SettingsSound 369 434 12 17 icons/SettingsSystem 382 434 12 17 @@ -100,90 +102,90 @@ icons/SideSouth 573 434 11 11 icons/SideUndefined 585 434 11 11 icons/SideUp 597 434 11 11 icons/SideWest 609 434 11 11 -icons/Tier0 882 632 16 16 -icons/Tier1 899 632 16 16 -icons/Tier2 916 632 16 16 -icons/Tiers 933 632 16 16 +icons/Tier0 916 632 16 16 +icons/Tier1 933 632 16 16 +icons/Tier2 950 632 16 16 +icons/Tiers 967 632 16 16 icons/Unpin 423 434 14 14 -icons/WaveLFSR 254 540 24 10 -icons/WaveNoise 279 540 24 10 -icons/WaveSawtooth 304 540 24 10 -icons/WaveSine 329 540 24 10 -icons/WaveSquare 354 540 24 10 -icons/WaveTriangle 379 540 24 10 -icons/Window 950 632 16 16 +icons/WaveLFSR 288 540 24 10 +icons/WaveNoise 313 540 24 10 +icons/WaveSawtooth 338 540 24 10 +icons/WaveSine 363 540 24 10 +icons/WaveSquare 388 540 24 10 +icons/WaveTriangle 413 540 24 10 +icons/Window 984 632 16 16 icons/WireArrowLeft 281 344 4 8 icons/WireArrowRight 286 344 4 8 items/APU0 49 655 16 96 items/APU1 66 655 16 96 items/APU2 83 655 16 96 -items/CPU0 967 632 16 16 -items/CPU1 984 632 16 16 -items/CPU2 1001 632 16 16 -items/CardBase 358 674 16 16 -items/CircuitBoard 375 674 16 16 -items/ComponentBus0 392 674 16 16 -items/ComponentBus1 409 674 16 16 -items/ComponentBus2 426 674 16 16 -items/ComponentBus3 443 674 16 16 +items/CPU0 1001 632 16 16 +items/CPU1 358 674 16 16 +items/CPU2 375 674 16 16 +items/CardBase 392 674 16 16 +items/CircuitBoard 409 674 16 16 +items/ComponentBus0 426 674 16 16 +items/ComponentBus1 443 674 16 16 +items/ComponentBus2 460 674 16 16 +items/ComponentBus3 477 674 16 16 items/DataCard0 49 526 16 128 items/DataCard1 66 526 16 128 items/DataCard2 83 526 16 128 -items/DebugCard 460 674 16 16 -items/DiskDriveMountable 477 674 16 16 -items/EEPROM 494 674 16 16 -items/FloppyDisk_dyeBlack 511 674 16 16 -items/FloppyDisk_dyeBlue 528 674 16 16 -items/FloppyDisk_dyeBrown 545 674 16 16 -items/FloppyDisk_dyeCyan 562 674 16 16 -items/FloppyDisk_dyeGray 579 674 16 16 -items/FloppyDisk_dyeGreen 596 674 16 16 -items/FloppyDisk_dyeLightBlue 613 674 16 16 -items/FloppyDisk_dyeLightGray 630 674 16 16 -items/FloppyDisk_dyeLime 647 674 16 16 -items/FloppyDisk_dyeMagenta 664 674 16 16 -items/FloppyDisk_dyeOrange 681 674 16 16 -items/FloppyDisk_dyePink 698 674 16 16 -items/FloppyDisk_dyePurple 715 674 16 16 -items/FloppyDisk_dyeRed 732 674 16 16 -items/FloppyDisk_dyeWhite 749 674 16 16 -items/FloppyDisk_dyeYellow 766 674 16 16 -items/GraphicsCard0 783 674 16 16 -items/GraphicsCard1 800 674 16 16 -items/GraphicsCard2 817 674 16 16 -items/HardDiskDrive0 834 674 16 16 -items/HardDiskDrive1 851 674 16 16 -items/HardDiskDrive2 868 674 16 16 +items/DebugCard 494 674 16 16 +items/DiskDriveMountable 511 674 16 16 +items/EEPROM 528 674 16 16 +items/FloppyDisk_dyeBlack 545 674 16 16 +items/FloppyDisk_dyeBlue 562 674 16 16 +items/FloppyDisk_dyeBrown 579 674 16 16 +items/FloppyDisk_dyeCyan 596 674 16 16 +items/FloppyDisk_dyeGray 613 674 16 16 +items/FloppyDisk_dyeGreen 630 674 16 16 +items/FloppyDisk_dyeLightBlue 647 674 16 16 +items/FloppyDisk_dyeLightGray 664 674 16 16 +items/FloppyDisk_dyeLime 681 674 16 16 +items/FloppyDisk_dyeMagenta 698 674 16 16 +items/FloppyDisk_dyeOrange 715 674 16 16 +items/FloppyDisk_dyePink 732 674 16 16 +items/FloppyDisk_dyePurple 749 674 16 16 +items/FloppyDisk_dyeRed 766 674 16 16 +items/FloppyDisk_dyeWhite 783 674 16 16 +items/FloppyDisk_dyeYellow 800 674 16 16 +items/GraphicsCard0 817 674 16 16 +items/GraphicsCard1 834 674 16 16 +items/GraphicsCard2 851 674 16 16 +items/HardDiskDrive0 868 674 16 16 +items/HardDiskDrive1 885 674 16 16 +items/HardDiskDrive2 902 674 16 16 items/InternetCard 143 567 16 32 items/LinkedCard 100 655 16 96 -items/Memory0 885 674 16 16 -items/Memory1 902 674 16 16 -items/Memory2 919 674 16 16 -items/Memory3 936 674 16 16 -items/Memory4 953 674 16 16 -items/Memory5 970 674 16 16 -items/Memory6 987 674 16 16 -items/NetworkCard 1004 674 16 16 +items/Memory0 919 674 16 16 +items/Memory1 936 674 16 16 +items/Memory2 953 674 16 16 +items/Memory3 970 674 16 16 +items/Memory4 987 674 16 16 +items/Memory5 1004 674 16 16 +items/Memory6 134 707 16 16 +items/NetworkCard 151 707 16 16 items/OcelotCard 100 526 16 128 -items/RedstoneCard0 134 707 16 16 -items/RedstoneCard1 151 707 16 16 +items/RedstoneCard0 168 707 16 16 +items/RedstoneCard1 185 707 16 16 items/SelfDestructingCard 160 567 16 32 -items/Server0 168 707 16 16 -items/Server1 185 707 16 16 -items/Server2 202 707 16 16 -items/Server3 219 707 16 16 +items/Server0 202 707 16 16 +items/Server1 219 707 16 16 +items/Server2 236 707 16 16 +items/Server3 253 707 16 16 items/SoundCard 117 526 16 128 -items/TapeCopper 236 707 16 16 -items/TapeDiamond 253 707 16 16 -items/TapeGold 270 707 16 16 -items/TapeGreg 287 707 16 16 -items/TapeIg 304 707 16 16 -items/TapeIron 321 707 16 16 -items/TapeNetherStar 338 707 16 16 -items/TapeSteel 355 707 16 16 -items/WirelessNetworkCard0 372 707 16 16 -items/WirelessNetworkCard1 389 707 16 16 -light-panel/BookmarkLeft 235 540 18 14 +items/TapeCopper 270 707 16 16 +items/TapeDiamond 287 707 16 16 +items/TapeGold 304 707 16 16 +items/TapeGreg 321 707 16 16 +items/TapeIg 338 707 16 16 +items/TapeIron 355 707 16 16 +items/TapeNetherStar 372 707 16 16 +items/TapeSteel 389 707 16 16 +items/WirelessNetworkCard0 406 707 16 16 +items/WirelessNetworkCard1 423 707 16 16 +light-panel/BookmarkLeft 269 540 18 14 light-panel/BookmarkRight 197 600 20 14 light-panel/BorderB 296 344 4 4 light-panel/BorderL 284 353 4 2 @@ -196,94 +198,94 @@ light-panel/CornerTR 326 344 4 4 light-panel/Fill 410 344 2 2 light-panel/Vent 279 305 2 38 nodes/Cable 300 316 8 8 -nodes/Camera 406 707 16 16 +nodes/Camera 440 707 16 16 nodes/Chest 438 434 14 14 -nodes/HologramProjector0 423 707 16 16 -nodes/HologramProjector1 440 707 16 16 -nodes/IronNoteBlock 457 707 16 16 -nodes/Lamp 474 707 16 16 -nodes/LampFrame 491 707 16 16 +nodes/HologramProjector0 457 707 16 16 +nodes/HologramProjector1 474 707 16 16 +nodes/IronNoteBlock 491 707 16 16 +nodes/Lamp 508 707 16 16 +nodes/LampFrame 525 707 16 16 nodes/LampGlow 49 305 128 128 -nodes/NewNode 508 707 16 16 -nodes/NoteBlock 525 707 16 16 -nodes/OpenFMRadio 542 707 16 16 -nodes/Relay 559 707 16 16 -nodes/TapeDrive 576 707 16 16 -nodes/computer/Default 593 707 16 16 -nodes/computer/DiskActivity 610 707 16 16 -nodes/computer/Error 627 707 16 16 -nodes/computer/On 644 707 16 16 -nodes/disk-drive/Default 661 707 16 16 -nodes/disk-drive/DiskActivity 678 707 16 16 -nodes/disk-drive/Floppy 695 707 16 16 +nodes/NewNode 542 707 16 16 +nodes/NoteBlock 559 707 16 16 +nodes/OpenFMRadio 576 707 16 16 +nodes/Relay 593 707 16 16 +nodes/TapeDrive 610 707 16 16 +nodes/computer/Default 627 707 16 16 +nodes/computer/DiskActivity 644 707 16 16 +nodes/computer/Error 661 707 16 16 +nodes/computer/On 678 707 16 16 +nodes/disk-drive/Default 695 707 16 16 +nodes/disk-drive/DiskActivity 712 707 16 16 +nodes/disk-drive/Floppy 729 707 16 16 nodes/holidays/Christmas 134 674 32 32 nodes/holidays/Halloween 167 674 32 32 nodes/holidays/Valentines 200 674 32 32 -nodes/microcontroller/Default 712 707 16 16 -nodes/microcontroller/Error 729 707 16 16 -nodes/microcontroller/On 746 707 16 16 +nodes/microcontroller/Default 746 707 16 16 +nodes/microcontroller/Error 763 707 16 16 +nodes/microcontroller/On 780 707 16 16 nodes/ocelot-block/Default 117 655 16 80 -nodes/ocelot-block/Rx 763 707 16 16 -nodes/ocelot-block/Tx 780 707 16 16 -nodes/rack/Default 797 707 16 16 -nodes/rack/Empty 814 707 16 16 -nodes/rack/drive/0/Default 831 707 16 16 -nodes/rack/drive/0/DiskActivity 848 707 16 16 -nodes/rack/drive/0/Floppy 865 707 16 16 -nodes/rack/drive/1/Default 882 707 16 16 -nodes/rack/drive/1/DiskActivity 899 707 16 16 -nodes/rack/drive/1/Floppy 916 707 16 16 -nodes/rack/drive/2/Default 933 707 16 16 -nodes/rack/drive/2/DiskActivity 950 707 16 16 -nodes/rack/drive/2/Floppy 967 707 16 16 -nodes/rack/drive/3/Default 984 707 16 16 -nodes/rack/drive/3/DiskActivity 1001 707 16 16 -nodes/rack/drive/3/Floppy 266 655 16 16 -nodes/rack/drive/Floppy 283 655 16 16 -nodes/rack/server/0/Default 300 655 16 16 -nodes/rack/server/0/DiskActivity 317 655 16 16 -nodes/rack/server/0/Error 334 655 16 16 -nodes/rack/server/0/NetworkActivity 351 655 16 16 -nodes/rack/server/0/On 368 655 16 16 -nodes/rack/server/1/Default 385 655 16 16 -nodes/rack/server/1/DiskActivity 402 655 16 16 -nodes/rack/server/1/Error 419 655 16 16 -nodes/rack/server/1/NetworkActivity 436 655 16 16 -nodes/rack/server/1/On 453 655 16 16 -nodes/rack/server/2/Default 470 655 16 16 -nodes/rack/server/2/DiskActivity 487 655 16 16 -nodes/rack/server/2/Error 504 655 16 16 -nodes/rack/server/2/NetworkActivity 521 655 16 16 -nodes/rack/server/2/On 538 655 16 16 -nodes/rack/server/3/Default 555 655 16 16 -nodes/rack/server/3/DiskActivity 572 655 16 16 -nodes/rack/server/3/Error 589 655 16 16 -nodes/rack/server/3/NetworkActivity 606 655 16 16 -nodes/rack/server/3/On 623 655 16 16 -nodes/raid/0/DiskActivity 640 655 16 16 -nodes/raid/0/Error 657 655 16 16 -nodes/raid/1/DiskActivity 674 655 16 16 -nodes/raid/1/Error 691 655 16 16 -nodes/raid/2/DiskActivity 708 655 16 16 -nodes/raid/2/Error 725 655 16 16 -nodes/raid/Default 742 655 16 16 -nodes/screen/BottomLeft 759 655 16 16 -nodes/screen/BottomMiddle 776 655 16 16 -nodes/screen/BottomRight 793 655 16 16 -nodes/screen/ColumnBottom 810 655 16 16 -nodes/screen/ColumnMiddle 827 655 16 16 -nodes/screen/ColumnTop 844 655 16 16 -nodes/screen/Middle 861 655 16 16 -nodes/screen/MiddleLeft 878 655 16 16 -nodes/screen/MiddleRight 895 655 16 16 -nodes/screen/PowerOnOverlay 912 655 16 16 -nodes/screen/RowLeft 929 655 16 16 -nodes/screen/RowMiddle 946 655 16 16 -nodes/screen/RowRight 963 655 16 16 -nodes/screen/Standalone 980 655 16 16 -nodes/screen/TopLeft 997 655 16 16 -nodes/screen/TopMiddle 201 540 16 16 -nodes/screen/TopRight 218 540 16 16 +nodes/ocelot-block/Rx 797 707 16 16 +nodes/ocelot-block/Tx 814 707 16 16 +nodes/rack/Default 831 707 16 16 +nodes/rack/Empty 848 707 16 16 +nodes/rack/drive/0/Default 865 707 16 16 +nodes/rack/drive/0/DiskActivity 882 707 16 16 +nodes/rack/drive/0/Floppy 899 707 16 16 +nodes/rack/drive/1/Default 916 707 16 16 +nodes/rack/drive/1/DiskActivity 933 707 16 16 +nodes/rack/drive/1/Floppy 950 707 16 16 +nodes/rack/drive/2/Default 967 707 16 16 +nodes/rack/drive/2/DiskActivity 984 707 16 16 +nodes/rack/drive/2/Floppy 1001 707 16 16 +nodes/rack/drive/3/Default 266 655 16 16 +nodes/rack/drive/3/DiskActivity 283 655 16 16 +nodes/rack/drive/3/Floppy 300 655 16 16 +nodes/rack/drive/Floppy 317 655 16 16 +nodes/rack/server/0/Default 334 655 16 16 +nodes/rack/server/0/DiskActivity 351 655 16 16 +nodes/rack/server/0/Error 368 655 16 16 +nodes/rack/server/0/NetworkActivity 385 655 16 16 +nodes/rack/server/0/On 402 655 16 16 +nodes/rack/server/1/Default 419 655 16 16 +nodes/rack/server/1/DiskActivity 436 655 16 16 +nodes/rack/server/1/Error 453 655 16 16 +nodes/rack/server/1/NetworkActivity 470 655 16 16 +nodes/rack/server/1/On 487 655 16 16 +nodes/rack/server/2/Default 504 655 16 16 +nodes/rack/server/2/DiskActivity 521 655 16 16 +nodes/rack/server/2/Error 538 655 16 16 +nodes/rack/server/2/NetworkActivity 555 655 16 16 +nodes/rack/server/2/On 572 655 16 16 +nodes/rack/server/3/Default 589 655 16 16 +nodes/rack/server/3/DiskActivity 606 655 16 16 +nodes/rack/server/3/Error 623 655 16 16 +nodes/rack/server/3/NetworkActivity 640 655 16 16 +nodes/rack/server/3/On 657 655 16 16 +nodes/raid/0/DiskActivity 674 655 16 16 +nodes/raid/0/Error 691 655 16 16 +nodes/raid/1/DiskActivity 708 655 16 16 +nodes/raid/1/Error 725 655 16 16 +nodes/raid/2/DiskActivity 742 655 16 16 +nodes/raid/2/Error 759 655 16 16 +nodes/raid/Default 776 655 16 16 +nodes/screen/BottomLeft 793 655 16 16 +nodes/screen/BottomMiddle 810 655 16 16 +nodes/screen/BottomRight 827 655 16 16 +nodes/screen/ColumnBottom 844 655 16 16 +nodes/screen/ColumnMiddle 861 655 16 16 +nodes/screen/ColumnTop 878 655 16 16 +nodes/screen/Middle 895 655 16 16 +nodes/screen/MiddleLeft 912 655 16 16 +nodes/screen/MiddleRight 929 655 16 16 +nodes/screen/PowerOnOverlay 946 655 16 16 +nodes/screen/RowLeft 963 655 16 16 +nodes/screen/RowMiddle 980 655 16 16 +nodes/screen/RowRight 997 655 16 16 +nodes/screen/Standalone 201 540 16 16 +nodes/screen/TopLeft 218 540 16 16 +nodes/screen/TopMiddle 235 540 16 16 +nodes/screen/TopRight 252 540 16 16 panel/BorderB 331 344 4 4 panel/BorderL 289 353 4 2 panel/BorderR 336 344 4 4 diff --git a/src/main/scala/ocelot/desktop/graphics/IconSource.scala b/src/main/scala/ocelot/desktop/graphics/IconSource.scala index b14d19f..8457566 100644 --- a/src/main/scala/ocelot/desktop/graphics/IconSource.scala +++ b/src/main/scala/ocelot/desktop/graphics/IconSource.scala @@ -205,6 +205,8 @@ object IconSource { val Delete: IconSource = get("Delete") val Label: IconSource = get("Label") val Copy: IconSource = get("Copy") + val Cut: IconSource = get("Cut") + val Paste: IconSource = get("Paste") val AspectRatio: IconSource = get("AspectRatio") val Eject: IconSource = get("Eject") val Restart: IconSource = get("Restart") diff --git a/src/main/scala/ocelot/desktop/ui/widget/TextInput.scala b/src/main/scala/ocelot/desktop/ui/widget/TextInput.scala index f5361f5..97e0e92 100644 --- a/src/main/scala/ocelot/desktop/ui/widget/TextInput.scala +++ b/src/main/scala/ocelot/desktop/ui/widget/TextInput.scala @@ -3,12 +3,13 @@ package ocelot.desktop.ui.widget import ocelot.desktop.ColorScheme import ocelot.desktop.color.Color import ocelot.desktop.geometry.Size2D -import ocelot.desktop.graphics.{Font, Graphics} +import ocelot.desktop.graphics.{Font, Graphics, IconSource} import ocelot.desktop.ui.UiHandler import ocelot.desktop.ui.event.handlers.MouseHandler import ocelot.desktop.ui.event.sources.KeyEvents import ocelot.desktop.ui.event.{DragEvent, KeyEvent, MouseEvent} import ocelot.desktop.ui.widget.TextInput.{Cursor, Selector, Text} +import ocelot.desktop.ui.widget.contextmenu.{ContextMenu, ContextMenuEntry} import ocelot.desktop.ui.widget.traits.HoverAnimation import ocelot.desktop.util.{DrawUtils, Register, Watcher} import ocelot.desktop.util.animation.ColorAnimation @@ -130,6 +131,24 @@ class TextInput(val initialText: String = "") extends Widget with MouseHandler w selector.active = false } + case MouseEvent(MouseEvent.State.Pressed, MouseEvent.Button.Right) if isFocused => + val inBounds = clippedBounds.contains(UiHandler.mousePosition) + if (inBounds) { + val menu = new ContextMenu + if (selector.active) { + menu.addEntry(ContextMenuEntry("Cut", IconSource.Icons.Cut) { cutSelection() }) + menu.addEntry(ContextMenuEntry("Copy", IconSource.Icons.Copy) { copySelection() }) + } + if (UiHandler.clipboard.nonEmpty) { + menu.addEntry(ContextMenuEntry("Paste", IconSource.Icons.Paste) { pasteSelection() }) + } + if (menu.children.nonEmpty) { + menu.addSeparator() + } + menu.addEntry(ContextMenuEntry("Select all") { selectAll() }) + root.get.contextMenus.open(menu) + } + case event @ DragEvent(DragEvent.State.Start, MouseEvent.Button.Left, mouse) if isFocused => val pos = pixelToCursorPosition(mouse.x - bounds.x) selector.active = true @@ -221,24 +240,21 @@ class TextInput(val initialText: String = "") extends Widget with MouseHandler w case event @ KeyEvent(KeyEvent.State.Press | KeyEvent.State.Repeat, Keyboard.KEY_C, _) if isFocused && KeyEvents.isControlDown && selector.active => - UiHandler.clipboard = selectedText + copySelection() event.consume() case event @ KeyEvent(KeyEvent.State.Press | KeyEvent.State.Repeat, Keyboard.KEY_X, _) if isFocused && KeyEvents.isControlDown && selector.active => - UiHandler.clipboard = selectedText - deleteSelection() + cutSelection() event.consume() case event @ KeyEvent(KeyEvent.State.Press | KeyEvent.State.Repeat, Keyboard.KEY_INSERT, _) if isFocused => - if (selector.active) deleteSelection() - writeString(UiHandler.clipboard) + pasteSelection() event.consume() case event @ KeyEvent(KeyEvent.State.Press | KeyEvent.State.Repeat, Keyboard.KEY_V, _) if isFocused && KeyEvents.isControlDown => - if (selector.active) deleteSelection() - writeString(UiHandler.clipboard) + pasteSelection() event.consume() case event @ KeyEvent(KeyEvent.State.Press, Keyboard.KEY_RETURN, _) if isFocused => @@ -272,6 +288,20 @@ class TextInput(val initialText: String = "") extends Widget with MouseHandler w selector.to = _text.chars.length } + private def copySelection(): Unit = { + UiHandler.clipboard = selectedText + } + + private def cutSelection(): Unit = { + UiHandler.clipboard = selectedText + deleteSelection() + } + + private def pasteSelection(): Unit = { + if (selector.active) deleteSelection() + writeString(UiHandler.clipboard) + } + private def deleteSelection(): Unit = { selector.active = false _text.chars = _text.chars.take(selector.start) ++ _text.chars.drop(selector.end) diff --git a/src/main/scala/ocelot/desktop/ui/widget/contextmenu/ContextMenuEntry.scala b/src/main/scala/ocelot/desktop/ui/widget/contextmenu/ContextMenuEntry.scala index a371ac3..966870b 100644 --- a/src/main/scala/ocelot/desktop/ui/widget/contextmenu/ContextMenuEntry.scala +++ b/src/main/scala/ocelot/desktop/ui/widget/contextmenu/ContextMenuEntry.scala @@ -69,9 +69,12 @@ class ContextMenuEntry( override protected def receiveClickEvents: Boolean = true eventHandlers += { - case MouseEvent(MouseEvent.State.Pressed, MouseEvent.Button.Left) if !contextMenu.isOpening => + case event @ MouseEvent(MouseEvent.State.Pressed, MouseEvent.Button.Left) if !contextMenu.isOpening => clickSoundSource.press.play() - case ClickEvent(MouseEvent.Button.Left, _) if !contextMenu.isOpening => clicked() + event.consume() + case event @ ClickEvent(MouseEvent.Button.Left, _) if !contextMenu.isOpening => + clicked() + event.consume() case HoverEvent(HoverEvent.State.Enter) => enter() case HoverEvent(HoverEvent.State.Leave) if !isGhost => leave() }