From 45bf8c122a483957596c89516f900bebf3222d2f Mon Sep 17 00:00:00 2001 From: Seungkeun Lee Date: Mon, 19 Dec 2016 09:48:45 +0900 Subject: [PATCH] Add ScreenDpi API in Window class - To get Screen DPI Change-Id: Ic183809290901654330427d9dc8c7f67630cb918 --- src/ElmSharp/ElmSharp/Window.cs | 11 ++- src/ElmSharp/Interop/Interop.Elementary.Win.cs | 3 + test/ElmSharp.Test/ElmSharp.Test.csproj | 3 +- test/ElmSharp.Test/TC/ScreenInformationTest.cs | 111 +++++++++++++++++++++++++ test/ElmSharp.Test/TestRunner.cs | 1 + 5 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 test/ElmSharp.Test/TC/ScreenInformationTest.cs diff --git a/src/ElmSharp/ElmSharp/Window.cs b/src/ElmSharp/ElmSharp/Window.cs index 1b4d54d..3409b2d 100644 --- a/src/ElmSharp/ElmSharp/Window.cs +++ b/src/ElmSharp/ElmSharp/Window.cs @@ -90,6 +90,16 @@ namespace ElmSharp } } + public Point ScreenDpi + { + get + { + Point point = default(Point); + Interop.Elementary.elm_win_screen_dpi_get(Handle, out point.X, out point.Y); + return point; + } + } + public int Rotation { get @@ -151,7 +161,6 @@ namespace ElmSharp } } - public void Active() { Interop.Elementary.elm_win_activate(Handle); diff --git a/src/ElmSharp/Interop/Interop.Elementary.Win.cs b/src/ElmSharp/Interop/Interop.Elementary.Win.cs index bc7c0b9..aadc2de 100644 --- a/src/ElmSharp/Interop/Interop.Elementary.Win.cs +++ b/src/ElmSharp/Interop/Interop.Elementary.Win.cs @@ -115,5 +115,8 @@ internal static partial class Interop rotations = null; return false; } + + [DllImport(Libraries.Elementary)] + internal static extern void elm_win_screen_dpi_get(IntPtr obj, out int xdpi, out int ydpi); } } diff --git a/test/ElmSharp.Test/ElmSharp.Test.csproj b/test/ElmSharp.Test/ElmSharp.Test.csproj index ac91e1b..4eeca22 100644 --- a/test/ElmSharp.Test/ElmSharp.Test.csproj +++ b/test/ElmSharp.Test/ElmSharp.Test.csproj @@ -43,6 +43,7 @@ + @@ -188,4 +189,4 @@ - \ No newline at end of file + diff --git a/test/ElmSharp.Test/TC/ScreenInformationTest.cs b/test/ElmSharp.Test/TC/ScreenInformationTest.cs new file mode 100644 index 0000000..92a5d4a --- /dev/null +++ b/test/ElmSharp.Test/TC/ScreenInformationTest.cs @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Linq; + +namespace ElmSharp.Test +{ + public class ScreenInformationTest : TestCaseBase + { + public override string TestName => "ScreenInformationTest"; + public override string TestDescription => "To get screen information"; + + Naviframe _navi; + int _sequence = 0; + + public override void Run(Window window) + { + Conformant conformant = new Conformant(window); + conformant.Show(); + Box box = new Box(window); + box.Show(); + conformant.SetContent(box); + Label label = new Label(window); + label.SetAlignment(-1, 0); + label.SetWeight(1, 0); + label.Text = string.Format("ScreenSize : {0}x{1}", window.ScreenSize.Width, window.ScreenSize.Height); + label.Show(); + box.PackEnd(label); + Label label2 = new Label(window); + label2.SetAlignment(-1, 0); + label2.SetWeight(1, 0); + label2.Text = string.Format("ScreenDPI : xdpi : {0} ydpi : {1}", window.ScreenDpi.X, window.ScreenDpi.Y); + label2.Show(); + box.PackEnd(label2); + } + + EvasObject CreatePage(Window parent) + { + Box box = new Box(parent); + box.Show(); + + Label label = new Label(parent) + { + Text = string.Format("{0} Page", _sequence++), + WeightX = 1, + AlignmentX = -1, + }; + Button push = new Button(parent) + { + Text = "Push", + WeightX = 1, + AlignmentX = -1, + }; + Button pop = new Button(parent) + { + Text = "pop", + WeightX = 1, + AlignmentX = -1, + }; + + label.Show(); + push.Show(); + pop.Show(); + + push.Clicked += (s, e) => + { + _navi.Push(CreatePage(parent), string.Format("{0} Page", _sequence - 1)); + }; + + pop.Clicked += (s, e) => + { + var item = _navi.NavigationStack.LastOrDefault(); + int nativePointer = (int)(IntPtr)(item.Content); + Console.WriteLine("----- Before Call _navi.Pop() {0:x} ", nativePointer); + _navi.Pop(); + Console.WriteLine("----- After Call _navi.Pop() {0:x} ", nativePointer); + }; + + push.Resize(500, 100); + pop.Resize(500, 100); + label.Resize(500, 100); + box.SetLayoutCallback(() => + { + Console.WriteLine("Layout callback with : {0}", box.Geometry); + var rect = box.Geometry; + label.Move(rect.X, rect.Y); + push.Move(rect.X, rect.Y + 100); + pop.Move(rect.X, rect.Y + 200); + }); + + box.PackEnd(label); + box.PackEnd(push); + box.PackEnd(pop); + return box; + } + } +} diff --git a/test/ElmSharp.Test/TestRunner.cs b/test/ElmSharp.Test/TestRunner.cs index 0d7afa2..b359d20 100644 --- a/test/ElmSharp.Test/TestRunner.cs +++ b/test/ElmSharp.Test/TestRunner.cs @@ -128,6 +128,7 @@ namespace ElmSharp.Test private void CreateFirstPage(IEnumerable testCases) { _firstPageWindow = CreateWindow(); + Console.WriteLine("Screen DPI : {0}", _firstPageWindow.ScreenDpi.X); Conformant conformant = new Conformant(_firstPageWindow); conformant.Show(); Box box = new Box(_firstPageWindow) -- 2.7.4