diff --git a/3D/Chart3D.h b/3D/Chart3D.h index a0bf9f9f7..86175fd55 100644 --- a/3D/Chart3D.h +++ b/3D/Chart3D.h @@ -79,9 +79,9 @@ class Chart3D : public Dynamic { // Shaders. Ref shader_vs; Ref shader_ps; - + Chart3DType* current_renderer; - + Instances instances; public: @@ -96,21 +96,21 @@ class Chart3D : public Dynamic { initialized = false; Interface::AddListener(chart3d_interface_listener, &this); } - + void OnInterfaceEvent(InterfaceEvent& _event) { if (GetCurrentRenderer() == NULL) { return; } - + Device* _gfx = GetCurrentRenderer().GetDevice(); - + _gfx.DrawText(10, 10, "Event!"); } - + Shader* GetShaderVS() { return shader_vs.Ptr(); } Shader* GetShaderPS() { return shader_ps.Ptr(); } - + Chart3DType* GetCurrentRenderer() { return current_renderer; } @@ -139,7 +139,7 @@ class Chart3D : public Dynamic { return NULL; } } - + current_renderer = renderers[type].Ptr(); return renderers[type].Ptr(); @@ -209,4 +209,4 @@ class Chart3D : public Dynamic { _type_renderer.Render(_device); } -}; \ No newline at end of file +}; diff --git a/3D/Chart3DCandles.h b/3D/Chart3DCandles.h index fbab65553..8598dec5b 100644 --- a/3D/Chart3DCandles.h +++ b/3D/Chart3DCandles.h @@ -65,9 +65,9 @@ class Chart3DCandles : public Chart3DType { cube1.Ptr().GetTSR().translation.x = chart3d.GetBarPositionX(_shift); cube1.Ptr().GetTSR().translation.y = chart3d.GetPriceScale(_ohlc.GetMinOC()) + _height / 2; cube1.Ptr().GetTSR().scale.y = _height; - + //Print(cube1.Ptr().GetTSR().translation.y); - + cube1.Ptr().GetMaterial().SetColor(higher ? 0x22FF11 : 0xFF1122); _device.Render(cube1.Ptr()); @@ -78,25 +78,25 @@ class Chart3DCandles : public Chart3DType { cube2.Ptr().GetMaterial().SetColor(higher ? 0x22FF11 : 0xFF1122); _device.Render(cube2.Ptr()); } - + int _digits = (int)MarketInfo(Symbol(), MODE_DIGITS); float _pip_pow = (float)MathPow(10, _digits); float _pip_size = 1.0f / (float)MathPow(10, _digits); float _pip_size_m1 = 1.0f / (float)MathPow(10, _digits - 1); float _start = float(int(chart3d.GetMinBarsPrice() * _pip_pow) * _pip_size); float _end = float(int(chart3d.GetMaxBarsPrice() * _pip_pow) * _pip_size); - + // Rendering price lines. for (double _s = _start; _s < _end + _pip_size_m1; _s += _pip_size * 10) { float _y = chart3d.GetPriceScale((float)_s); cube3.Ptr().GetTSR().translation.y = _y; cube3.Ptr().GetTSR().scale.x = 200.0f; - + _device.DrawText(5, _y, StringFormat("%." + IntegerToString(_digits) + "f", _s), 0x90FFFFFF, TA_LEFT | TA_VCENTER, GFX_DRAW_TEXT_FLAG_2D_COORD_X); - + cube3.Ptr().GetMaterial().SetColor(0x333333); _device.Render(cube3.Ptr()); } } -}; \ No newline at end of file +}; diff --git a/3D/Chart3DType.h b/3D/Chart3DType.h index 122444dbd..66e458212 100644 --- a/3D/Chart3DType.h +++ b/3D/Chart3DType.h @@ -44,7 +44,7 @@ class Chart3DType : public Dynamic { * Constructor. */ Chart3DType(Chart3D* _chart3d, Device* _device) : chart3d(_chart3d), device(_device) {} - + Device* GetDevice() { return device; } @@ -53,4 +53,4 @@ class Chart3DType : public Dynamic { * Renders chart. */ virtual void Render(Device* _device) {} -}; \ No newline at end of file +}; diff --git a/3D/Cube.h b/3D/Cube.h index 5d0c69d45..b4070b7f3 100644 --- a/3D/Cube.h +++ b/3D/Cube.h @@ -77,4 +77,4 @@ class Cube : public Mesh { SetShaderVS(_device.VertexShader(ShaderCubeSourceVS, T::Layout)); SetShaderPS(_device.PixelShader(ShaderCubeSourcePS)); } -}; \ No newline at end of file +}; diff --git a/3D/Device.h b/3D/Device.h index d449565a5..eb54420a2 100644 --- a/3D/Device.h +++ b/3D/Device.h @@ -272,11 +272,11 @@ class Device : public Dynamic { _viewport.height = frontend.Ptr().Height(); _viewport.minz = -10000.0f; _viewport.maxz = 10000.0f; - + DXVector3 _vec3_in(_x, _y, 0.0f); DXVector3 _vec3_out; DXVec3Project(_vec3_out, _vec3_in, _viewport, GetProjectionMatrix(), GetViewMatrix(), GetWorldMatrix()); - + if ((_flags & GFX_DRAW_TEXT_FLAG_2D_COORD_X) == GFX_DRAW_TEXT_FLAG_2D_COORD_X) { _vec3_out.x = _x; } @@ -284,7 +284,7 @@ class Device : public Dynamic { if ((_flags & GFX_DRAW_TEXT_FLAG_2D_COORD_Y) == GFX_DRAW_TEXT_FLAG_2D_COORD_Y) { _vec3_out.y = _y; } - + frontend.Ptr().DrawText(_vec3_out.x, _vec3_out.y, _text, _color, _align); } diff --git a/3D/Devices/MTDX/MTDXDevice.h b/3D/Devices/MTDX/MTDXDevice.h index 6200f1b36..7bb1c93b8 100644 --- a/3D/Devices/MTDX/MTDXDevice.h +++ b/3D/Devices/MTDX/MTDXDevice.h @@ -154,4 +154,4 @@ class MTDXDevice : public Device { #endif } } -}; \ No newline at end of file +}; diff --git a/3D/Devices/MTDX/MTDXIndexBuffer.h b/3D/Devices/MTDX/MTDXIndexBuffer.h index 60b33124f..6662aacab 100644 --- a/3D/Devices/MTDX/MTDXIndexBuffer.h +++ b/3D/Devices/MTDX/MTDXIndexBuffer.h @@ -66,4 +66,4 @@ class MTDXIndexBuffer : public IndexBuffer { Print("Select: LastError: ", GetLastError()); #endif } -}; \ No newline at end of file +}; diff --git a/3D/Devices/MTDX/MTDXShader.h b/3D/Devices/MTDX/MTDXShader.h index 6a5b951c4..dbde130ad 100644 --- a/3D/Devices/MTDX/MTDXShader.h +++ b/3D/Devices/MTDX/MTDXShader.h @@ -196,4 +196,4 @@ class MTDXShader : public Shader { DXInputSet(cbuffer_mvp_handle, mvp_buffer); DXShaderSet(GetDevice().Context(), handle); } -}; \ No newline at end of file +}; diff --git a/3D/Devices/MTDX/MTDXVertexBuffer.h b/3D/Devices/MTDX/MTDXVertexBuffer.h index 915d60979..e96b9c7b7 100644 --- a/3D/Devices/MTDX/MTDXVertexBuffer.h +++ b/3D/Devices/MTDX/MTDXVertexBuffer.h @@ -60,4 +60,4 @@ class MTDXVertexBuffer : public VertexBuffer { Print("Select: LastError: ", GetLastError()); #endif } -}; \ No newline at end of file +}; diff --git a/3D/Face.h b/3D/Face.h index 76b87e26b..558c0bc4e 100644 --- a/3D/Face.h +++ b/3D/Face.h @@ -93,4 +93,4 @@ struct Face { points[i].Normal = _normal; } } -}; \ No newline at end of file +}; diff --git a/3D/Frontend.h b/3D/Frontend.h index 5757e7893..1870fb9bd 100644 --- a/3D/Frontend.h +++ b/3D/Frontend.h @@ -40,7 +40,7 @@ struct DrawTextQueueItem { */ class Frontend : public Dynamic { protected: - + DrawTextQueueItem draw_text_queue[]; public: @@ -96,7 +96,7 @@ class Frontend : public Dynamic { _item.align = _align; Util::ArrayPush(draw_text_queue, _item); } - + void ProcessDrawText() { for (int i = 0; i < ArraySize(draw_text_queue); ++i) { DrawTextQueueItem _item = draw_text_queue[i]; @@ -111,4 +111,4 @@ class Frontend : public Dynamic { * Draws text directly into the pixel buffer. Should be executed after all 3d drawing. */ virtual void DrawTextNow(int _x, int _y, string _text, unsigned int _color = 0xFFFFFFFF, unsigned int _align = 0) {} -}; \ No newline at end of file +}; diff --git a/3D/Frontends/MT5Frontend.h b/3D/Frontends/MT5Frontend.h index f57b70a9d..723e2c2be 100644 --- a/3D/Frontends/MT5Frontend.h +++ b/3D/Frontends/MT5Frontend.h @@ -155,7 +155,7 @@ class MT5Frontend : public Frontend { * Returns canvas' height. */ virtual int Height() { return (int)ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS); } - + /** * Draws text directly into the pixel buffer. Should be executed after all 3d drawing. */ @@ -164,10 +164,10 @@ class MT5Frontend : public Frontend { #ifdef __debug__ Print("TextSetFont: LastError = ", GetLastError()); #endif - + TextOut(_text, _x, _y, _align, image, Width(), Height(), _color, COLOR_FORMAT_ARGB_NORMALIZE); #ifdef __debug__ Print("TextOut: LastError = ", GetLastError()); #endif } -}; \ No newline at end of file +}; diff --git a/3D/IndexBuffer.h b/3D/IndexBuffer.h index fef406675..fdd83d91e 100644 --- a/3D/IndexBuffer.h +++ b/3D/IndexBuffer.h @@ -60,4 +60,4 @@ class IndexBuffer : public Dynamic { * Activates index buffer for rendering. */ virtual void Select() = NULL; -}; \ No newline at end of file +}; diff --git a/3D/Interface.h b/3D/Interface.h index 5bacb1d8b..6ea02fba6 100644 --- a/3D/Interface.h +++ b/3D/Interface.h @@ -26,14 +26,14 @@ */ #include "../Util.h" - + enum ENUM_INTERFACE_EVENT { INTERFACE_EVENT_NONE, INTERFACE_EVENT_MOUSE_MOVE, INTERFACE_EVENT_MOUSE_DOWN, INTERFACE_EVENT_MOUSE_UP }; - + struct InterfaceEvent { ENUM_INTERFACE_EVENT type; struct EventMouse { @@ -41,20 +41,20 @@ struct InterfaceEvent { int y; datetime dt; }; - + union EventData { EventMouse mouse; } data; }; - + void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam) { datetime _dt; double _mp; int _window = 0; InterfaceEvent _event; - - + + if (id == CHART_EVENT_MOUSE_MOVE) { Interface::mouse_pos_x = (int)lparam; Interface::mouse_pos_y = (int)dparam; @@ -63,7 +63,7 @@ void OnChartEvent(const int id, const long& lparam, const double& dparam, const _event.data.mouse.x = Interface::mouse_pos_x; _event.data.mouse.y = Interface::mouse_pos_y; Interface::FireEvent(_event); - } + } } typedef void (*InterfaceListener)(InterfaceEvent&, void*); @@ -71,7 +71,7 @@ typedef void (*InterfaceListener)(InterfaceEvent&, void*); class Interface { public: - + struct Installation { InterfaceListener listener; @@ -79,40 +79,40 @@ class Interface }; static Installation installations[]; - + static bool mouse_was_down; static int mouse_pos_x; static int mouse_pos_y; static bool initialized; - + static void AddListener(InterfaceListener _listener, void* _target) { if (!initialized) { ChartSetInteger(0, CHART_EVENT_MOUSE_MOVE, true); ChartRedraw(); initialized = true; } - + for (int i = 0; i < ArraySize(installations); ++i) { if (installations[i].listener == _listener) { // Listener already added. return; } } - + Installation _installation; _installation.listener = _listener; _installation.target = _target; - + Util::ArrayPush(installations, _installation); } - + static void FireEvent(InterfaceEvent& _event) { for (int i = 0; i < ArraySize(installations); ++i) { Installation _installation = installations[i]; _installation.listener(_event, _installation.target); } } - + static int GetMouseX() { return mouse_pos_x; } diff --git a/3D/Mesh.h b/3D/Mesh.h index 94b8e9f0a..0ee82c0dc 100644 --- a/3D/Mesh.h +++ b/3D/Mesh.h @@ -253,4 +253,4 @@ class Mesh : public Dynamic { ibuff = _ibuff = _device.IndexBuffer(_indices); return true; } -}; \ No newline at end of file +}; diff --git a/3D/Shader.h b/3D/Shader.h index c586092de..51ae50504 100644 --- a/3D/Shader.h +++ b/3D/Shader.h @@ -105,4 +105,4 @@ class Shader : public Dynamic { * Selectes shader to be used by graphics device for rendering. */ virtual void Select() = NULL; -}; \ No newline at end of file +}; diff --git a/3D/Shaders/cube_vs.hlsl b/3D/Shaders/cube_vs.hlsl index c28c1b513..d9c651d7d 100644 --- a/3D/Shaders/cube_vs.hlsl +++ b/3D/Shaders/cube_vs.hlsl @@ -30,4 +30,4 @@ OUTPUT main(INPUT input) { output.color = input.color * mat_color; return output; -} \ No newline at end of file +} diff --git a/3D/TSR.h b/3D/TSR.h index 88b586693..ee015a01f 100644 --- a/3D/TSR.h +++ b/3D/TSR.h @@ -59,4 +59,4 @@ class TSR { return _mtx_result; } -}; \ No newline at end of file +}; diff --git a/3D/VertexBuffer.h b/3D/VertexBuffer.h index 8c979b384..822c33fb2 100644 --- a/3D/VertexBuffer.h +++ b/3D/VertexBuffer.h @@ -43,4 +43,4 @@ class VertexBuffer : public Dynamic { Device* GetDevice() { return device.Ptr(); } virtual void Select() = NULL; -}; \ No newline at end of file +}; diff --git a/Instances.h b/Instances.h index ed1c264d8..fee38cb80 100644 --- a/Instances.h +++ b/Instances.h @@ -48,4 +48,4 @@ class Instances { }; template -T* Instances::instances[]; \ No newline at end of file +T* Instances::instances[]; diff --git a/Util.h b/Util.h index e03176268..243b80752 100644 --- a/Util.h +++ b/Util.h @@ -53,7 +53,7 @@ class Util { ::ArrayResize(_array, ArraySize(_array) - 1); return _result; } - + template static T Print(T& _array[]) { string _result; @@ -73,7 +73,7 @@ class Util { return true; } } - + return false; } -}; \ No newline at end of file +}; diff --git a/tests/3D/Shaders/vertex.hlsl b/tests/3D/Shaders/vertex.hlsl index ab4715043..7df27058a 100644 --- a/tests/3D/Shaders/vertex.hlsl +++ b/tests/3D/Shaders/vertex.hlsl @@ -24,16 +24,16 @@ struct OUTPUT OUTPUT main(INPUT input) { OUTPUT output; - + input.position.w = 1.0f; - + matrix mvp = mul(mul(projection, view), world); - + output.position = mul(mvp, input.position); - + output.normal = normalize(mul(world, input.normal)); output.lightdir = lightdir; output.color = input.color; return output; -} \ No newline at end of file +} diff --git a/tests/3DTest.mq5 b/tests/3DTest.mq5 index 5ba1014e7..63390f3da 100644 --- a/tests/3DTest.mq5 +++ b/tests/3DTest.mq5 @@ -32,13 +32,7 @@ #resource "3D/Shaders/vertex.hlsl" as string ShaderSourceVS; #resource "3D/Shaders/pixel.hlsl" as string ShaderSourcePS; -//#define Print if (false) Print - // Includes. -#include "../Serializer.mqh" -#include "../Test.mqh" -#include "../BufferStruct.mqh" -#include "../Chart.mqh" #include "../3D/Chart3D.h" #include "../3D/Cube.h" #include "../3D/Devices/MTDX/MTDXDevice.h" @@ -46,9 +40,10 @@ #include "../3D/Devices/MTDX/MTDXShader.h" #include "../3D/Devices/MTDX/MTDXVertexBuffer.h" #include "../3D/Frontends/MT5Frontend.h" - -// int OnStart() { return OnInit(); } - +#include "../BufferStruct.mqh" +#include "../Chart.mqh" +#include "../Serializer.mqh" +#include "../Test.mqh" BarOHLC ChartPriceFeeder(ENUM_TIMEFRAMES _tf, int _shift) { static Chart _chart(); @@ -68,16 +63,15 @@ BarOHLC ChartPriceFeeder(ENUM_TIMEFRAMES _tf, int _shift) { _entry.SetFlag(INDI_ENTRY_FLAG_IS_VALID, true); idata.Add(_entry, _bar_time); } - - return BarOHLC(_entry.GetValue(0), _entry.GetValue(1), _entry.GetValue(2), _entry.GetValue(3)); -} -int OnInit() { return OnStart(); } + return BarOHLC(_entry.GetValue(0), _entry.GetValue(1), _entry.GetValue(2), + _entry.GetValue(3)); +} /** - * Implements OnStart(). + * Implements OnInit(). */ -int OnStart() { +int OnInit() { Ref gfx_ptr = new MTDXDevice(); // Making a scope to ensure graphics device will be destructed as last. @@ -111,9 +105,9 @@ int OnStart() { x += 0.025f; TSR tsr; - //tsr.rotation.y = (float)sin(x) / 4.0f; + // tsr.rotation.y = (float)sin(x) / 4.0f; tsr.rotation.x = (float)sin(x / 2); - + gfx.PushTransform(tsr); _chart.Ptr().Render(gfx); gfx.PopTransform(); @@ -128,12 +122,12 @@ int OnStart() { return (INIT_SUCCEEDED); } - #else - +/** + * Implements OnInit(). + */ int OnInit() { // Nothing to test in non-MT5 environment. return (INIT_SUCCEEDED); } - -#endif \ No newline at end of file +#endif