1 module PixelPerfectEngine.concrete.types.event; 2 3 import PixelPerfectEngine.concrete.elements.base; 4 import PixelPerfectEngine.concrete.popup.base; 5 public import PixelPerfectEngine.system.input.types; 6 7 import PixelPerfectEngine.concrete.elements.listview : ListViewItem; 8 9 /** 10 * Defines an event in the GUI. 11 */ 12 public class Event { 13 ///The origin of the event 14 public Object sender; 15 ///Auxilliary event data (secondary sender, selection, etc) 16 ///Type can be checked with classinfo. 17 public Object aux; 18 ///The type of this event 19 public EventType type; 20 ///The type of the sender 21 public SourceType srcType; 22 ///Default CTOR 23 this (Object sender, EventType type, SourceType srcType) @nogc @safe pure nothrow { 24 this.sender = sender; 25 this.type = type; 26 this.srcType = srcType; 27 } 28 ///Ditto 29 this (Object sender, Object aux, EventType type, SourceType srcType) @nogc @safe pure nothrow { 30 this.sender = sender; 31 this.aux = aux; 32 this.type = type; 33 this.srcType = srcType; 34 } 35 } 36 /** 37 * Defines a cell editing event. 38 */ 39 public class CellEditEvent : Event { 40 ///The number of row that was edited 41 public int row; 42 ///The number of column that was edited 43 public int column; 44 ///Default CTOR 45 this (Object sender, Object aux, int row, int column) @nogc @safe pure nothrow { 46 super(sender, aux, EventType.CellEdit, SourceType.WindowElement); 47 this.row = row; 48 this.column = column; 49 } 50 ///Returns the edited text of the cell 51 public Text text() @trusted @nogc pure nothrow { 52 ListViewItem getListViewItem() @system @nogc pure nothrow { 53 return cast(ListViewItem)aux; 54 } 55 return getListViewItem()[column].text; 56 } 57 } 58 /** 59 * Defines a mouse event in the GUI. 60 */ 61 public class MouseEvent : Event { 62 ///Stores mouseclick event data 63 MouseClickEvent mce; 64 ///Stores mousewheel event data (direction, etc) 65 MouseWheelEvent mwe; 66 ///Mouse motion event values 67 ///Mouse scroll event position is stored here 68 MouseMotionEvent mme; 69 ///Common values for mouse events 70 MouseEventCommons mec; 71 ///Default CTOR 72 ///Any other fields should be set after construction 73 this (Object sender, EventType type, SourceType srcType) @nogc @safe pure nothrow { 74 super(sender, type, srcType); 75 } 76 } 77 /** 78 * Defines a file event (save, open, etc.) 79 */ 80 public class FileEvent : Event { 81 string path; ///The path where the file is found or being written to. 82 string filename; ///The name of the target file. 83 string extension; ///The selected file extension. 84 ///Default CTOR 85 this (Object sender, SourceType srcType, string path, string filename, string extension) @nogc @safe pure nothrow { 86 super(sender, EventType.File, srcType); 87 this.path = path; 88 this.filename = filename; 89 this.extension = extension; 90 } 91 /** 92 * Returns the full path. 93 */ 94 public string getFullPath() @safe pure nothrow const { 95 import std.path : extension; 96 if (extension(filename).length) 97 return path ~ filename; 98 else 99 return path ~ filename ~ this.extension; 100 } 101 } 102 /** 103 * Defines a menu event. 104 */ 105 public class MenuEvent : Event { 106 Text text; ///Text of the selected menu item. 107 size_t itemNum; ///Number of the selected item. 108 string itemSource; ///Source ID of the menu item. 109 ///Default CTOR 110 this (Object sender, SourceType srcType, Text text, size_t itemNum, string itemSource) { 111 super(sender, EventType.Menu, srcType); 112 this.text = text; 113 this.itemNum = itemNum; 114 this.itemSource = itemSource; 115 } 116 } 117 /** 118 * Defines event types. 119 * Mouse events and file events have data that can be accessed via extra fields in an inherited class. 120 * Selection uses the aux field. 121 * Text input and other value change events should be checked on the source for value changes. 122 */ 123 public enum EventType { 124 MouseMotion, 125 MouseClick, 126 MouseScroll, 127 Menu, 128 TextInput, 129 File, 130 Selection, 131 Toggle, 132 CellEdit, 133 } 134 /** 135 * Defines source types. 136 */ 137 public enum SourceType { 138 WindowElement, 139 RadioButtonGroup, 140 DialogWindow, 141 PopUpElement, 142 }