1 /** 2 * Copyright: Copyright Auburn Sounds 2015-2017 3 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) 4 * Authors: Guillaume Piolat 5 */ 6 module gui; 7 8 import std.math; 9 10 import gfm.math; 11 import dplug.gui; 12 import dplug.pbrwidgets; 13 import dplug.client; 14 15 import main; 16 17 // Plugin GUI, based on PBRBackgroundGUI. 18 // If you don't want to use PBR, you not inherit from it. 19 class DistortGUI : PBRBackgroundGUI!("basecolor.jpg", "emissive.png", "material.png", 20 "physical.png", "depth.png", "skybox.jpg", 21 22 // Enter here the absolute path to the gfx directory. 23 // This will allow to reload images at debug-time with the press of ENTER. 24 `C:\Users\myuser\Products\distort\gfx\`) 25 { 26 public: 27 nothrow: 28 @nogc: 29 30 DistortClient _client; 31 32 UISlider inputSlider; 33 UIKnob driveKnob; 34 UISlider outputSlider; 35 UIOnOffSwitch onOffSwitch; 36 UIBargraph inputBargraph, outputBargraph; 37 38 Font _font; 39 40 this(DistortClient client) 41 { 42 _client = client; 43 super(620, 330); // size 44 45 46 // Note: PBRCompositor default lighting might change in a future version (increase of light to allow white plastics). 47 // So we keep the value. 48 PBRCompositor comp = cast(PBRCompositor)compositor; 49 comp.light1Color = vec3f(0.26, 0.24, 0.22f) * 0.98f; 50 comp.light2Dir = vec3f(-0.5f, 1.0f, 0.23f).normalized; 51 comp.light2Color = vec3f(0.36, 0.38f, 0.40) * 1.148; 52 comp.light3Dir = vec3f(0.0f, 1.0f, 0.1f).normalized; 53 comp.light3Color = vec3f(0.2f, 0.2f, 0.2f) * 0.84f; 54 comp.ambientLight = 0.042f; 55 comp.skyboxAmount = 0.56f; 56 57 // Optional global color correction. 58 // Very useful at the end of the UI creating process. 59 { 60 mat3x4f colorCorrectionMatrix = mat3x4f(- 0.07f, 1.0f , 1.15f, 0.03f, 61 + 0.01f, 0.93f, 1.16f, 0.08f, 62 + 0.0f , 1.0f , 1.10f, -0.01f); 63 comp.setLiftGammaGainContrastRGB(colorCorrectionMatrix); 64 } 65 66 // Sets the number of pixels recomputed around dirtied controls. 67 // This is a tradeoff between Emissive light accuracy and speed. 68 // A typical value is between 15 and 30 pixels. 69 setUpdateMargin(30); 70 71 // All resources are bundled as a string import. 72 // You can avoid resource compilers that way. 73 // The only cost is that each resource is in each binary, this creates overhead with 74 _font = mallocNew!Font(cast(ubyte[])( import("VeraBd.ttf") )); 75 76 // Builds the UI hierarchy 77 // Note: when Dplug has resizeable UI, all positionning is going 78 // to move into a reflow() override. 79 // Meanwhile, we hardcode each position. 80 81 RGBA litTrailDiffuse = RGBA(151, 119, 255, 100); 82 RGBA unlitTrailDiffuse = RGBA(81, 54, 108, 0); 83 84 // Add knob 85 addChild(driveKnob = mallocNew!UIKnob(context(), cast(FloatParameter) _client.param(paramDrive))); 86 driveKnob.position = box2i.rectangle(250, 140, 120, 120); 87 driveKnob.knobRadius = 0.65f; 88 driveKnob.knobDiffuse = RGBA(255, 255, 238, 0); 89 driveKnob.knobMaterial = RGBA(0, 255, 128, 255); 90 driveKnob.numLEDs = 15; 91 driveKnob.litTrailDiffuse = litTrailDiffuse; 92 driveKnob.unlitTrailDiffuse = unlitTrailDiffuse; 93 driveKnob.LEDDiffuseLit = RGBA(40, 40, 40, 100); 94 driveKnob.LEDDiffuseUnlit = RGBA(40, 40, 40, 0); 95 driveKnob.LEDRadiusMin = 0.06f; 96 driveKnob.LEDRadiusMax = 0.06f; 97 98 // Add sliders 99 addChild(inputSlider = mallocNew!UISlider(context(), cast(FloatParameter) _client.param(paramInput))); 100 inputSlider.position = box2i.rectangle(190, 132, 30, 130); 101 inputSlider.litTrailDiffuse = litTrailDiffuse; 102 inputSlider.unlitTrailDiffuse = unlitTrailDiffuse; 103 104 addChild(outputSlider = mallocNew!UISlider(context(), cast(FloatParameter) _client.param(paramOutput))); 105 outputSlider.position = box2i.rectangle(410, 132, 30, 130); 106 outputSlider.litTrailDiffuse = litTrailDiffuse; 107 outputSlider.unlitTrailDiffuse = unlitTrailDiffuse; 108 109 // Add switch 110 addChild(onOffSwitch = mallocNew!UIOnOffSwitch(context(), cast(BoolParameter) _client.param(paramOnOff))); 111 onOffSwitch.position = box2i.rectangle(90, 177, 30, 40); 112 onOffSwitch.diffuseOn = litTrailDiffuse; 113 onOffSwitch.diffuseOff = unlitTrailDiffuse; 114 115 // Add bargraphs 116 addChild(inputBargraph = mallocNew!UIBargraph(context(), 2, -80.0f, 6.0f)); 117 inputBargraph.position = box2i.rectangle(150, 132, 30, 130); 118 addChild(outputBargraph = mallocNew!UIBargraph(context(), 2, -80.0f, 6.0f)); 119 outputBargraph.position = box2i.rectangle(450, 132, 30, 130); 120 static immutable float[2] startValues = [0.0f, 0.0f]; 121 inputBargraph.setValues(startValues); 122 outputBargraph.setValues(startValues); 123 } 124 125 ~this() 126 { 127 _font.destroyFree(); 128 } 129 }