1 /* 2 * Copyright (C) 2015-2019, by Laszlo Szeremi under the Boost license. 3 * 4 * Pixel Perfect Engine, concrete.interfaces module 5 */ 6 7 module PixelPerfectEngine.concrete.interfaces; 8 9 public import PixelPerfectEngine.graphics.fontsets; 10 public import PixelPerfectEngine.graphics.bitmap; 11 public import PixelPerfectEngine.graphics.common; 12 public import PixelPerfectEngine.graphics.text; 13 14 public import PixelPerfectEngine.concrete.elements.base; 15 public import PixelPerfectEngine.concrete.popup.base; 16 17 public import PixelPerfectEngine.system.input.types; 18 19 /+/** 20 * Checkbox interface. 21 */ 22 public interface ICheckBox { 23 ///Returns whether the object is checked. 24 public @property bool isChecked() @safe pure @nogc nothrow const; 25 ///Sets the object to checked position and returns the new state. 26 public bool check() @trusted; 27 ///Sets the object to unchecked position and returns the new state. 28 public bool unCheck() @trusted; 29 }+/ 30 /** 31 * Radio button interface. Can be used to implement radio button style behavior on almost any component that implements this interface. 32 */ 33 public interface IRadioButton { 34 /** 35 * If the radio button is pressed, then it sets to unpressed. Does nothing otherwise. 36 */ 37 public void latchOff() @trusted; 38 /** 39 * Sets the radio button into its pressed state. 40 */ 41 public void latchOn() @trusted; 42 /** 43 * Sets the group of the radio button. 44 */ 45 public void setGroup(IRadioButtonGroup group) @safe @property; 46 /** 47 * Workaround the stupid issue of object.opEquals having to be `@system inpure throw`. 48 * The @gc would be fine still. 49 * 50 * Hey DLang foundation! Don't be cowards and commit to some meaningful changes! 51 */ 52 public bool equals(IRadioButton rhs) @safe pure @nogc nothrow const; 53 /** 54 * Returns the assigned value of the radio button. 55 */ 56 public string value() @property @safe @nogc pure nothrow const; 57 } 58 /** 59 * Implements the basis of a radio button group. 60 */ 61 public interface IRadioButtonGroup { 62 /** 63 * Adds a radio button to the group. 64 */ 65 public void add(IRadioButton rg) @safe; 66 /** 67 * Removes a radio button from the group. 68 */ 69 public void remove(IRadioButton rg) @safe; 70 /** 71 * Groups receive latch signals here. 72 */ 73 public void latch(IRadioButton sender) @safe; 74 } 75 /** 76 * Implements the frontend of a drawable canvas, primarily for GUI elements. 77 * Used to avoid using individual bitmaps for each elements. 78 * Colors are mostly limited to 256 by the `ubyte` type. However certain window types will enable more. 79 */ 80 public interface Canvas { 81 ///Draws a line. 82 public void drawLine(Point from, Point to, ubyte color) @trusted; 83 ///Draws a line pattern. 84 public void drawLinePattern(Point from, Point to, ubyte[] pattern) @trusted; 85 ///Draws an empty rectangle. 86 public void drawBox(Box target, ubyte color) @trusted; 87 ///Draws an empty rectangle with line patterns. 88 public void drawBoxPattern(Box target, ubyte[] pattern) @trusted; 89 ///Draws a filled rectangle with a specified color. 90 public void drawFilledBox(Box target, ubyte color) @trusted; 91 ///Pastes a bitmap to the given point using blitter, which threats color #0 as transparency. 92 public void bitBLT(Point target, ABitmap source) @trusted; 93 ///Pastes a slice of a bitmap to the given point using blitter, which threats color #0 as transparency. 94 public void bitBLT(Point target, ABitmap source, Box slice) @trusted; 95 ///Pastes a repeated bitmap pattern over the specified area. 96 public void bitBLTPattern(Box target, ABitmap pattern) @trusted; 97 ///XOR blits a repeated bitmap pattern over the specified area. 98 public void xorBitBLT(Box target, ABitmap pattern) @trusted; 99 ///XOR blits a color index over a specified area. 100 public void xorBitBLT(Box target, ubyte color) @trusted; 101 ///Fills an area with the specified color. 102 public void fill(Point target, ubyte color, ubyte background = 0) @trusted; 103 ///Draws a single line text within the given prelimiter. 104 public void drawTextSL(Box target, Text text, Point offset) @trusted; 105 ///Draws a multi line text within the given prelimiter. 106 public void drawTextML(Box target, Text text, Point offset) @trusted; 107 ///Clears the area within the target 108 public void clearArea(Box target) @trusted; 109 } 110 /** 111 * TODO: Use this for implement tabbing and etc. 112 */ 113 public interface Focusable { 114 ///Called when an object receives focus. 115 public void focusGiven(); 116 ///Called when an object loses focus. 117 public void focusTaken(); 118 ///Cycles the focus on a single element. 119 ///Returns -1 if end is reached, or the number of remaining elements that 120 ///are cycleable in the direction. 121 public int cycleFocus(int direction); 122 ///Passes key events to the focused element when not in text editing mode. 123 public void passKey(uint keyCode, ubyte mod); 124 } 125 /** 126 * Implements the 127 */ 128 public interface ElementContainer : PopUpHandler, Canvas { 129 /** 130 * Returns the absolute position of the element. 131 */ 132 public Box getAbsolutePosition(WindowElement sender); 133 /** 134 * Gives focus to the element if applicable 135 */ 136 public void requestFocus(WindowElement sender); 137 /** 138 * Sets the cursor to the given type on request. 139 */ 140 public void requestCursor(CursorType type); 141 } 142 /** 143 * Implemented by any object that can store stylesheets. 144 */ 145 public interface StyleSheetContainer { 146 /** 147 * Returns the stylesheet stored by the object. 148 */ 149 public StyleSheet getStyleSheet(); 150 } 151 /** 152 * Implements mouse event passing. 153 */ 154 public interface MouseEventReceptor { 155 ///Passes mouse click event 156 public void passMCE(MouseEventCommons mec, MouseClickEvent mce); 157 ///Passes mouse move event 158 public void passMME(MouseEventCommons mec, MouseMotionEvent mme); 159 ///Passes mouse scroll event 160 public void passMWE(MouseEventCommons mec, MouseWheelEvent mwe); 161 } 162 /** 163 * Implements identification of small buttons. 164 */ 165 public interface ISmallButton { 166 ///Returns true if element is in small button capable and is the supplied height. 167 public bool isSmallButtonHeight(int height); 168 ///Returns true if left side justified, false otherwise. 169 public bool isLeftSide() @nogc @safe pure nothrow const; 170 ///Sets the small button to the left side if true. 171 public bool isLeftSide(bool val) @nogc @safe pure nothrow; 172 } 173 /** 174 * Defines functions for pop up handling. 175 */ 176 public interface PopUpHandler : StyleSheetContainer { 177 /** 178 * Puts a PopUpElement on the GUI. 179 */ 180 public void addPopUpElement(PopUpElement p); 181 /** 182 * Puts a PopUpElement on the GUI at the given position. 183 */ 184 public void addPopUpElement(PopUpElement p, int x, int y); 185 /** 186 * Ends the popup session and closes all popups. 187 */ 188 public void endPopUpSession(PopUpElement p); 189 /** 190 * Closes a single popup element. 191 */ 192 public void closePopUp(PopUpElement p); 193 //public Coordinate getAbsolutePosition(PopUpElement sender); 194 //public void drawUpdate(PopUpElement sender); 195 //public StyleSheet getDefaultStyleSheet(); 196 197 }