From 0de61c3dc12ec9def5a53628e6461bd5e35f377a Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 26 Mar 2013 22:26:44 +0100 Subject: [PATCH] [DEV] add the management of the screen display size --- sources/android/PROJECT_NAME.java | 5 ++ .../android/src/org/ewol/interfaceJNI.java | 2 + sources/ewol/DisplayConv.cpp | 64 ++++++++++++++++ sources/ewol/DisplayConv.h | 73 +++++++++++++++++++ sources/ewol/ewol.cpp | 4 +- sources/ewol/renderer/os/gui.Android.base.cpp | 8 +- sources/ewol/renderer/os/gui.X11.cpp | 4 + sources/file.mk | 3 +- 8 files changed, 160 insertions(+), 3 deletions(-) create mode 100644 sources/ewol/DisplayConv.cpp create mode 100644 sources/ewol/DisplayConv.h diff --git a/sources/android/PROJECT_NAME.java b/sources/android/PROJECT_NAME.java index 4cbdca6a..5cb676e1 100644 --- a/sources/android/PROJECT_NAME.java +++ b/sources/android/PROJECT_NAME.java @@ -52,6 +52,7 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.AssetFileDescriptor; import android.content.res.AssetManager; +import android.util.DisplayMetrics; // inport the ewol package : import org.ewol.interfaceJNI; @@ -106,6 +107,10 @@ public class __PROJECT_NAME__ extends Activity { ActivityParamSetArchiveDir(0, apkFilePath); + DisplayMetrics metrics = new DisplayMetrics(); + getWindowManager().getDefaultDisplay().getMetrics(metrics); + interfaceJNI.DisplayPropertyMetrics(metrics.xdpi, metrics.ydpi); + // call C init ... interfaceJNI.ActivityOnCreate(); diff --git a/sources/android/src/org/ewol/interfaceJNI.java b/sources/android/src/org/ewol/interfaceJNI.java index 2ae90a60..00830f27 100644 --- a/sources/android/src/org/ewol/interfaceJNI.java +++ b/sources/android/src/org/ewol/interfaceJNI.java @@ -34,6 +34,8 @@ public class interfaceJNI { public static native void ActivityOnPause(); public static native void ActivityOnStop(); public static native void ActivityOnDestroy(); + // set display properties : + public static native void DisplayPropertyMetrics(float ratioX, float ratioY); // IO native function : // Specific for the type of input : TOOL_TYPE_FINGER and TOOL_TYPE_STYLUS (work as the same) public static native void IOInputEventMotion(int pointerID, float x, float y); diff --git a/sources/ewol/DisplayConv.cpp b/sources/ewol/DisplayConv.cpp new file mode 100644 index 00000000..5273db9a --- /dev/null +++ b/sources/ewol/DisplayConv.cpp @@ -0,0 +1,64 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#include +#include + +static vec2 ratioInch(65475,75654); +static vec2 ratioMillimeter(76545,46547445); + +static const float numberOfMillimeterInOneInch = 25.4f; + + +void ewol::DC_Init(void) +{ + ratioInch.setValue(96,96); + ratioMillimeter = ratioInch/numberOfMillimeterInOneInch; +} + + +vec2 ewol::InchToPixel(const vec2& inch) +{ + return vec2(inch.x()*ratioInch.x(), inch.y()*ratioInch.y()); +} + + +vec2 ewol::MillemeterToPixel(const vec2& millimeter) +{ + return vec2(millimeter.x()*ratioMillimeter.x(), millimeter.y()*ratioMillimeter.y()); +} + + +vec2 ewol::PixelToInch(const vec2& pixel) +{ + return vec2(pixel.x()/ratioInch.x(), pixel.y()/ratioInch.y()); +} + + +vec2 ewol::PixelToMillemeter(const vec2& pixel) +{ + return vec2(pixel.x()/ratioMillimeter.x(), pixel.y()/ratioMillimeter.y()); +} + + +void ewol::SetPixelPerInch(const vec2& ratio) +{ + ratioInch = ratio; + ratioMillimeter = ratioInch/numberOfMillimeterInOneInch; + EWOL_INFO("Set a new Inch/milimeter Ratio for the screen : ratioInch=" << ratioInch << " ratioMm=" << ratioMillimeter); +} + + +void ewol::SetPixelPerMillimeter(const vec2& ratio) +{ + ratioMillimeter = ratio; + ratioInch = ratioMillimeter*numberOfMillimeterInOneInch; + EWOL_INFO("Set a new Inch/milimeter Ratio for the screen : ratioInch=" << ratioInch << " ratioMm=" << ratioMillimeter); +} + + diff --git a/sources/ewol/DisplayConv.h b/sources/ewol/DisplayConv.h new file mode 100644 index 00000000..ea42117c --- /dev/null +++ b/sources/ewol/DisplayConv.h @@ -0,0 +1,73 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#ifndef __DISPLAY_CONV_H__ +#define __DISPLAY_CONV_H__ + +#include +#include +#include + +namespace ewol +{ + /** + * @brief basic init + */ + void DC_Init(void); + /** + * @brief convert a dimention in Inch to a pixel dimension + * @param[in] inch Dimention in Inch + * @return dimention in Pixel + */ + vec2 InchToPixel(const vec2& inch); + /** + * @brief convert a dimention in millimeter to a pixel dimension + * @param[in] millimeter Dimention in millimeter + * @return dimention in Pixel + */ + vec2 MillemeterToPixel(const vec2& millimeter); + /** + * @brief convert a dimention in pourcent to a pixel dimension + * @param[in] pourcent Dimention in pourcent + * @return dimention in Pixel + */ + //vec2 PourcentToPixel(const vec2& pourcent); + /** + * @brief convert a dimention in Pixel to a inch dimension + * @param[in] pixel Dimention in pixel + * @return dimention in Inch + */ + vec2 PixelToInch(const vec2& pixel); + /** + * @brief convert a dimention in Pixel to a Millemeter dimension + * @param[in] pixel Dimention in pixel + * @return dimention in Millemeter + */ + vec2 PixelToMillemeter(const vec2& pixel); + /** + * @brief convert a dimention in Pixel to a pourcent dimension + * @param[in] pixel Dimention in pixel + * @return dimention in pourcent + */ + //vec2 PixelToPourcent(const vec2& pixel); + /** + * @brief Set the Inch ratio for calculation + * @param[in] Ratio Inch ration for the screen calculation interpolation + * @note: same as @ref SetPixelPerMillimeter (internal manage convertion) + */ + void SetPixelPerInch(const vec2& ratio); + /** + * @brief Set the Milimeter ratio for calculation + * @param[in] Ratio Milimeter ration for the screen calculation interpolation + * @note: same as @ref SetPixelPerInch (internal manage convertion) + */ + void SetPixelPerMillimeter(const vec2& ratio); +}; + +#endif + diff --git a/sources/ewol/ewol.cpp b/sources/ewol/ewol.cpp index 0bc1fcbc..32bdc908 100644 --- a/sources/ewol/ewol.cpp +++ b/sources/ewol/ewol.cpp @@ -13,13 +13,15 @@ #include #include #include - +#include #undef __class__ #define __class__ "ewol" int32_t ewol::Run(int32_t argc, const char* argv[]) { + // init display convertions: + ewol::DC_Init(); EWOL_DEBUG("Store commangLine in the specific system"); ewol::commandLine::Clean(); diff --git a/sources/ewol/renderer/os/gui.Android.base.cpp b/sources/ewol/renderer/os/gui.Android.base.cpp index c47c5ca1..6e2706b1 100644 --- a/sources/ewol/renderer/os/gui.Android.base.cpp +++ b/sources/ewol/renderer/os/gui.Android.base.cpp @@ -15,6 +15,7 @@ #include #include #include +#include // get a resources from the java environement : static JNIEnv* JavaVirtualMachinePointer = NULL; // the JVM @@ -413,6 +414,12 @@ extern "C" eSystem::SetKeyboard(guiKeyBoardSpecialKeyMode, uniChar, isdown); } + void Java_org_ewol_interfaceJNI_DisplayPropertyMetrics( JNIEnv* env, jobject thiz, jfloat ratioX, jfloat ratioY) + { + // set the internal system ratio properties ... + ewol::SetPixelPerInch(vec2(ratioX,ratioY)); + } + enum { SYSTEM_KEY__VOLUME_UP = 1, SYSTEM_KEY__VOLUME_DOWN, @@ -486,7 +493,6 @@ extern "C" //} } - }; diff --git a/sources/ewol/renderer/os/gui.X11.cpp b/sources/ewol/renderer/os/gui.X11.cpp index e5d2abda..88274ba2 100644 --- a/sources/ewol/renderer/os/gui.X11.cpp +++ b/sources/ewol/renderer/os/gui.X11.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -168,6 +169,9 @@ bool CreateX11Context(void) EWOL_INFO("Display opened."); } int Xscreen = DefaultScreen(m_display); + // set the DPI for the current screen : + ewol::SetPixelPerMillimeter(vec2((float)DisplayWidth(m_display, Xscreen)/(float)DisplayWidthMM(m_display, Xscreen), + (float)DisplayHeight(m_display, Xscreen)/(float)DisplayHeightMM(m_display, Xscreen))); // get an appropriate visual m_visual = glXChooseVisual(m_display, Xscreen, attrListDbl); if (NULL == m_visual) { diff --git a/sources/file.mk b/sources/file.mk index 7cf02176..75d4f8c2 100644 --- a/sources/file.mk +++ b/sources/file.mk @@ -6,7 +6,8 @@ FILE_LIST:= ewol/ewol.cpp \ ewol/config.cpp \ ewol/commandLine.cpp \ ewol/key.cpp \ - ewol/cursor.cpp + ewol/cursor.cpp \ + ewol/DisplayConv.cpp # Basic Eobject of EWOL FILE_LIST+= ewol/eObject/EObject.cpp \