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) == this.extension) 97 return path ~ filename; 98 else 99 return path ~ filename ~ this.extension; 100 } 101 } 102 alias EventDeleg = void delegate(Event ev); 103 /** 104 * Defines a menu event. 105 */ 106 public class MenuEvent : Event { 107 Text text; ///Text of the selected menu item. 108 size_t itemNum; ///Number of the selected item. 109 string itemSource; ///Source ID of the menu item. 110 ///Default CTOR 111 this (Object sender, SourceType srcType, Text text, size_t itemNum, string itemSource) { 112 super(sender, EventType.Menu, srcType); 113 this.text = text; 114 this.itemNum = itemNum; 115 this.itemSource = itemSource; 116 } 117 } 118 /** 119 * Defines event types. 120 * Mouse events and file events have data that can be accessed via extra fields in an inherited class. 121 * Selection uses the aux field. 122 * Text input and other value change events should be checked on the source for value changes. 123 */ 124 public enum EventType { 125 MouseMotion, 126 MouseClick, 127 MouseScroll, 128 Menu, 129 TextInput, 130 File, 131 Selection, 132 Toggle, 133 CellEdit, 134 } 135 /** 136 * Defines source types. 137 */ 138 public enum SourceType { 139 WindowElement, 140 RadioButtonGroup, 141 DialogWindow, 142 PopUpElement, 143 }