Skip to content

Commit

Permalink
Merge pull request #39 from drug007/sdl_app
Browse files Browse the repository at this point in the history
Sdl app
  • Loading branch information
drug007 authored Sep 22, 2022
2 parents ef12aca + bbc04e1 commit e0c1bd6
Show file tree
Hide file tree
Showing 11 changed files with 687 additions and 393 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
matrix:
# Latest stable version, update at will
os: [ ubuntu-18.04, windows-2019 ]
dc: [ dmd-latest, ldc-master, ldc-latest ]
dc: [ dmd-latest, ldc-latest ]

runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description "Port of nanogui to dlang."
license "BSD-like"
authors "drug007"
copyright "Copyright © 2018-2022, drug007"
dependency "arsd-official:nanovega" version="~>10.8.2"
dependency "arsd-official:nanovega" version="~>10.9.2"
dependency "gfm:math" version="~>8.0.6"
dependency "gfm7:opengl" version="~>1.1.2"
dependency "gfm7:sdl2" version="~>1.1.2"
Expand Down
2 changes: 1 addition & 1 deletion examples/renderer/dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ copyright "Copyright © 2019-2022, drug007"
license "BSL"

dependency "nanogui" path="../.."
dependency "arsd-official:nanovega" version="10.8.2"
dependency "arsd-official:nanovega" version="10.9.2"
dependency "taggedalgebraic" version="~>0.11.22"
dependency "printed" version="~>0.0.12"
2 changes: 1 addition & 1 deletion examples/renderer/dub.selections.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"fileVersion": 1,
"versions": {
"arsd-official": "10.8.2",
"arsd-official": "10.9.2",
"automem": "0.6.7",
"auxil": {"path":"../../auxil"},
"bindbc-loader": "0.3.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/sdl/dub.selections.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"fileVersion": 1,
"versions": {
"arsd-official": "10.8.2",
"arsd-official": "10.9.2",
"automem": "0.6.7",
"auxil": {"path":"../../auxil"},
"bindbc-loader": "0.3.2",
Expand Down
Binary file added examples/sdl/resources/fonts/Amiri-Regular.ttf
Binary file not shown.
Binary file not shown.
38 changes: 38 additions & 0 deletions examples/sdl/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,44 @@ class MyGui : SdlBackend
tb = new TextBox(window, "中国");
tb.theme = asian_theme;
tb.editable = true;

version(none)
{

// Added two arabic themes after https://forum.dlang.org/thread/sbymyafmdrsfgemlgsld@forum.dlang.org
// currently don't work as expected

auto arabic_theme1 = new Theme(ctx);
{
// sorta hack because loading font in nvg results in
// conflicting font id
auto nvg2 = nvgCreateContext(NVGContextFlag.Debug);
scope(exit) nvg2.kill;
nvg2.createFont("arabic1", "./resources/fonts/Amiri-Regular.ttf");
ctx.nvg.addFontsFrom(nvg2);
arabic_theme1.mFontNormal = ctx.nvg.findFont("arabic1");
}

auto arabic_theme2 = new Theme(ctx);
{
// sorta hack because loading font in nvg results in
// conflicting font id
auto nvg2 = nvgCreateContext(NVGContextFlag.Debug);
scope(exit) nvg2.kill;
nvg2.createFont("arabic2", "./resources/fonts/ElMessiri-VariableFont_wght.ttf");
ctx.nvg.addFontsFrom(nvg2);
arabic_theme2.mFontNormal = ctx.nvg.findFont("arabic2");
}

tb = new TextBox(window, "حالكم");
tb.theme = arabic_theme1;
tb.editable = true;

tb = new TextBox(window, "حالكم");
tb.theme = arabic_theme2;
tb.editable = true;

} // version(none)
}

{
Expand Down
17 changes: 11 additions & 6 deletions source/nanogui/screen.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Screen : Widget
mLastInteraction = mTimestamp = timestamp;
mCursor = Cursor.Arrow;
mPixelRatio = 1.0;
mClearEnabled = true;
}

auto currTime() const { return mTimestamp; }
Expand Down Expand Up @@ -69,9 +70,12 @@ class Screen : Widget
}

// draw the rest
glViewport(0, 0, size.x, size.y);
glClearColor(0., 0., 0., 0);
glClear(glNVGClearFlags); // use NanoVega API to get flags for OpenGL call
if (mClearEnabled)
{
glViewport(0, 0, size.x, size.y);
glClearColor(0., 0., 0., 0);
glClear(glNVGClearFlags); // use NanoVega API to get flags for OpenGL call
}
ctx.beginFrame(size.x, size.y); // begin rendering
scope(exit)
{
Expand Down Expand Up @@ -395,9 +399,9 @@ class Screen : Widget
/// Return the ratio between pixel and device coordinates (e.g. >= 2 on Mac Retina displays)
float pixelRatio() const { return mPixelRatio; }

package bool needToDraw() const pure @safe nothrow { return mNeedToDraw; }
// TODO add package qualifier at least but better to remove it completely
void needToDraw(bool value) pure @safe nothrow { if (value) mNeedToDraw = value; }
bool clearEnabled() @safe const { return mClearEnabled; }
void clearEnabled(bool value) @safe { mClearEnabled = value; }

package bool needToPerfomLayout() const pure @safe nothrow { return mNeedToPerfomLayout; }
package void needToPerfomLayout(bool value) pure @safe nothrow { if (value) mNeedToPerfomLayout = value; }
package bool blinkingCursorIsVisibleNow() const pure @safe nothrow { return mBlinkingCursorVisible; }
Expand Down Expand Up @@ -445,4 +449,5 @@ protected:
float mPixelRatio;
void delegate(Vector2i) mResizeCallback;
Array!GLCanvas mGLCanvases;
bool mClearEnabled;
}
Loading

0 comments on commit e0c1bd6

Please sign in to comment.