[DEV] new Dimension management
This commit is contained in:
parent
100fbd43e2
commit
36dbd60e19
181
sources/ewol/Dimension.cpp
Normal file
181
sources/ewol/Dimension.cpp
Normal file
@ -0,0 +1,181 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#include <ewol/Dimension.h>
|
||||
#include <ewol/debug.h>
|
||||
|
||||
// ratio in milimeter :
|
||||
static vec2 ratio(9999999,888888);
|
||||
static vec2 invRatio(1,1);
|
||||
static ewol::Dimension windowsSize(vec2(9999999,888888), ewol::Dimension::Pixel);
|
||||
|
||||
static const float inchToMillimeter = 1.0f/25.4f;
|
||||
static const float footToMillimeter = 1.0f/304.8f;
|
||||
static const float meterToMillimeter = 1.0f/1000.0f;
|
||||
static const float centimeterToMillimeter = 1.0f/10.0f;
|
||||
static const float kilometerToMillimeter = 1.0f/1000000.0f;
|
||||
static const float millimeterToInch = 25.4f;
|
||||
static const float millimeterToFoot = 304.8f;
|
||||
static const float millimeterToMeter = 1000.0f;
|
||||
static const float millimeterToCentimeter = 10.0f;
|
||||
static const float millimeterToKilometer = 1000000.0f;
|
||||
|
||||
|
||||
void ewol::dimension::Init(void)
|
||||
{
|
||||
ratio = vec2(96,96)*inchToMillimeter;
|
||||
invRatio.setValue(1.0f/ratio.x(),1.0f/ratio.y());
|
||||
windowsSize.Set(vec2(200,200), ewol::Dimension::Pixel);
|
||||
}
|
||||
|
||||
void ewol::dimension::UnInit(void)
|
||||
{
|
||||
ratio.setValue(9999999,888888);
|
||||
invRatio.setValue(1.0f/ratio.x(),1.0f/ratio.y());
|
||||
windowsSize.Set(vec2(9999999,88888), ewol::Dimension::Pixel);
|
||||
}
|
||||
|
||||
void ewol::dimension::SetPixelRatio(const vec2& ratio, ewol::Dimension::distance_te type)
|
||||
{
|
||||
ewol::Dimension conversion(ratio, type);
|
||||
ratio = conversion.GetMillimeter();
|
||||
invRatio.setValue(1.0f/ratio.x(),1.0f/ratio.y());
|
||||
EWOL_INFO("Set a new screen ratio for the screen : ratioMm=" << ratio);
|
||||
}
|
||||
|
||||
void ewol::dimension::SetPixelWindowsSize(const vec2& size)
|
||||
{
|
||||
windowsSize = size;
|
||||
EWOL_VERBOSE("Set a new Windows property size " << windowsSize << "px");
|
||||
}
|
||||
|
||||
vec2 ewol::dimension::GetWindowsSize(ewol::Dimension::distance_te type)
|
||||
{
|
||||
return windowsSize.Get(type);
|
||||
}
|
||||
|
||||
float ewol::dimension::GetWindowsDiag(ewol::Dimension::distance_te type)
|
||||
{
|
||||
vec2 size = ewol::dimension::GetWindowsSize(type);
|
||||
return size.length();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ewol::Dimension::Dimension(const vec2& size, ewol::Dimension::distance_te type)
|
||||
{
|
||||
Set(size, type);
|
||||
}
|
||||
|
||||
ewol::Dimension::~Dimension(void)
|
||||
{
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
vec2 ewol::Dimension::Get(ewol::Dimension::distance_te type)
|
||||
{
|
||||
switch(m_type) {
|
||||
case ewol::Dimension::Pourcent:
|
||||
return GetPourcent();
|
||||
case ewol::Dimension::Pixel:
|
||||
return GetPixel();
|
||||
case ewol::Dimension::Meter:
|
||||
return GetMeter();
|
||||
case ewol::Dimension::Centimeter:
|
||||
return GetCentimeter();
|
||||
case ewol::Dimension::Millimeter:
|
||||
return GetMillimeter();
|
||||
case ewol::Dimension::Kilometer:
|
||||
return GetKilometer();
|
||||
case ewol::Dimension::Inch:
|
||||
return GetInch();
|
||||
case ewol::Dimension::foot:
|
||||
return GetFoot();
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::Dimension::Set(const vec2& size, ewol::Dimension::distance_te type)
|
||||
{
|
||||
switch(type) {
|
||||
case ewol::Dimension::Pourcent:
|
||||
m_data = size*0.01f;
|
||||
break;
|
||||
case ewol::Dimension::Pixel:
|
||||
m_data = size;
|
||||
break;
|
||||
case ewol::Dimension::Meter:
|
||||
m_data = (size*meterToMillimeter)*ratio;
|
||||
break;
|
||||
case ewol::Dimension::Centimeter:
|
||||
m_data = (size*centimeterToMillimeter)*ratio;
|
||||
break;
|
||||
case ewol::Dimension::Millimeter:
|
||||
m_data = size*ratio;
|
||||
break;
|
||||
case ewol::Dimension::Kilometer:
|
||||
m_data = (size*kilometerToMillimeter)*ratio;
|
||||
break;
|
||||
case ewol::Dimension::Inch:
|
||||
m_data = (size*inchToMillimeter)*ratio;
|
||||
break;
|
||||
case ewol::Dimension::foot:
|
||||
m_data = (size*footToMillimeter)*ratio;
|
||||
break;
|
||||
}
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
vec2 ewol::Dimension::GetPixel(void)
|
||||
{
|
||||
if (type!=ewol::Dimension::Pourcent) {
|
||||
return m_data;
|
||||
}
|
||||
return windowsSize*m_data;
|
||||
}
|
||||
|
||||
vec2 ewol::Dimension::GetPourcent(void)
|
||||
{
|
||||
if (type!=ewol::Dimension::Pourcent) {
|
||||
return m_data/windowsSize*100.0f;
|
||||
}
|
||||
return m_data*100.0f;
|
||||
}
|
||||
|
||||
vec2 ewol::Dimension::GetMeter(void)
|
||||
{
|
||||
return ewol::Dimension::GetMillimeter()*millimeterToMeter;
|
||||
}
|
||||
|
||||
vec2 ewol::Dimension::GetCentimeter(void)
|
||||
{
|
||||
return ewol::Dimension::GetMillimeter()*millimeterToMeter;
|
||||
}
|
||||
|
||||
vec2 ewol::Dimension::GetMillimeter(void)
|
||||
{
|
||||
return ewol::Dimension::GetPixel()*invRatio;
|
||||
}
|
||||
|
||||
vec2 ewol::Dimension::GetKilometer(void)
|
||||
{
|
||||
return ewol::Dimension::GetMillimeter()*millimeterToKilometer;
|
||||
}
|
||||
|
||||
vec2 ewol::Dimension::GetInch(void)
|
||||
{
|
||||
return ewol::Dimension::GetMillimeter()*millimeterToInch;
|
||||
}
|
||||
|
||||
vec2 ewol::Dimension::GetFoot(void)
|
||||
{
|
||||
return ewol::Dimension::GetMillimeter()*millimeterToFoot;
|
||||
}
|
||||
|
||||
|
135
sources/ewol/Dimension.h
Normal file
135
sources/ewol/Dimension.h
Normal file
@ -0,0 +1,135 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __DIMENSION_H__
|
||||
#define __DIMENSION_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <etk/UString.h>
|
||||
#include <etk/math/Vector2D.h>
|
||||
|
||||
namespace ewol
|
||||
{
|
||||
/**
|
||||
* @brief in the dimention class we store the data as the more usefull unit (pixel)
|
||||
* but one case need to be dynamic the %, then when requested in % the register the % value
|
||||
*/
|
||||
class Dimension
|
||||
{
|
||||
public:
|
||||
typedef enum {
|
||||
Pourcent=0,
|
||||
Pixel,
|
||||
Meter,
|
||||
Centimeter,
|
||||
Millimeter,
|
||||
Kilometer,
|
||||
Inch,
|
||||
foot,
|
||||
} distance_te;
|
||||
private:
|
||||
vec2 m_data;
|
||||
distance_te m_type;
|
||||
public:
|
||||
Dimension(const vec2& size, ewol::Dimension::distance_te type=ewol::Dimension::Pixel);
|
||||
~Dimension(void);
|
||||
/**
|
||||
* @brief Get the current dimention in requested type
|
||||
* @param[in] type Type of unit requested.
|
||||
* @return dimention requested.
|
||||
*/
|
||||
vec2 Get(ewol::Dimension::distance_te type);
|
||||
/**
|
||||
* @brief Set the current dimention in requested type
|
||||
* @param[in] size Dimention to set
|
||||
* @param[in] type Type of unit requested.
|
||||
*/
|
||||
void Set(const vec2& size, ewol::Dimension::distance_te type);
|
||||
/**
|
||||
* @brief Get the current dimention in pixel
|
||||
* @return dimention in Pixel
|
||||
*/
|
||||
vec2 GetPixel(void);
|
||||
/**
|
||||
* @brief Get the current dimention in Pourcent
|
||||
* @return dimention in Pourcent
|
||||
*/
|
||||
vec2 GetPourcent(void);
|
||||
/**
|
||||
* @brief Get the current dimention in Meter
|
||||
* @return dimention in Meter
|
||||
*/
|
||||
vec2 GetMeter(void);
|
||||
/**
|
||||
* @brief Get the current dimention in Centimeter
|
||||
* @return dimention in Centimeter
|
||||
*/
|
||||
vec2 GetCentimeter(void);
|
||||
/**
|
||||
* @brief Get the current dimention in Millimeter
|
||||
* @return dimention in Millimeter
|
||||
*/
|
||||
vec2 GetMillimeter(void);
|
||||
/**
|
||||
* @brief Get the current dimention in Kilometer
|
||||
* @return dimention in Kilometer
|
||||
*/
|
||||
vec2 GetKilometer(void);
|
||||
/**
|
||||
* @brief Get the current dimention in Inch
|
||||
* @return dimention in Inch
|
||||
*/
|
||||
vec2 GetInch(void);
|
||||
/**
|
||||
* @brief Get the current dimention in Foot
|
||||
* @return dimention in Foot
|
||||
*/
|
||||
vec2 GetFoot(void);
|
||||
|
||||
};
|
||||
|
||||
namespace dimension
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief basic init
|
||||
*/
|
||||
void Init(void);
|
||||
/**
|
||||
* @brief basic un-init
|
||||
*/
|
||||
void UnInit(void);
|
||||
/**
|
||||
* @brief Set the Milimeter ratio for calculation
|
||||
* @param[in] Ratio Milimeter ration for the screen calculation interpolation
|
||||
* @param[in] type Unit type requested.
|
||||
* @note: same as @ref SetPixelPerInch (internal manage convertion)
|
||||
*/
|
||||
void SetPixelRatio(const vec2& ratio, ewol::Dimension::distance_te type);
|
||||
/**
|
||||
* @brief Set the current Windows Size
|
||||
* @param[in] size Size of the current windows in pixel.
|
||||
*/
|
||||
void SetPixelWindowsSize(const vec2& size);
|
||||
/**
|
||||
* @brief Get the Windows Size in the request unit
|
||||
* @param[in] type Unit type requested.
|
||||
* @return the requested size
|
||||
*/
|
||||
vec2 GetWindowsSize(ewol::Dimension::distance_te type);
|
||||
/**
|
||||
* @brief Get the Windows diagonal size in the request unit
|
||||
* @param[in] type Unit type requested.
|
||||
* @return the requested size
|
||||
*/
|
||||
float GetWindowsDiag(ewol::Dimension::distance_te type);
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,99 +0,0 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#include <ewol/DisplayConv.h>
|
||||
#include <ewol/debug.h>
|
||||
|
||||
static vec2 ratioInch(9999999,888888);
|
||||
static vec2 ratioMillimeter(9999999,888888);
|
||||
static vec2 windowsSize(9999999,888888);
|
||||
|
||||
static const float numberOfMillimeterInOneInch = 25.4f;
|
||||
|
||||
|
||||
void ewol::DC_Init(void)
|
||||
{
|
||||
ratioInch.setValue(96,96);
|
||||
ratioMillimeter = ratioInch/numberOfMillimeterInOneInch;
|
||||
windowsSize.setValue(200,200);
|
||||
}
|
||||
|
||||
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::PourcentToPixel(const vec2& pourcent)
|
||||
{
|
||||
return vec2(pourcent.x()*windowsSize.x()/100.0f, pourcent.y()*windowsSize.y()/100.0f);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
vec2 ewol::PixelToPourcent(const vec2& pixel)
|
||||
{
|
||||
return vec2(pixel.x()*100.0f/windowsSize.x(), pixel.y()*100.0f/windowsSize.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);
|
||||
}
|
||||
|
||||
void ewol::SetPixelWindowsSize(const vec2& size)
|
||||
{
|
||||
windowsSize = size;
|
||||
EWOL_VERBOSE("Set a new Windows property size " << windowsSize << "px");
|
||||
}
|
||||
|
||||
vec2 ewol::GetWindowsSizeMilimeter(void)
|
||||
{
|
||||
return vec2(windowsSize.x()/ratioMillimeter.x(), windowsSize.y()/ratioMillimeter.y());
|
||||
}
|
||||
|
||||
vec2 ewol::GetWindowsSizeInch(void)
|
||||
{
|
||||
return vec2(windowsSize.x()/ratioInch.x(), windowsSize.y()/ratioInch.y());
|
||||
}
|
||||
|
||||
float ewol::GetWindowsDiagSizeMilimeter(void)
|
||||
{
|
||||
vec2 tmpSize = ewol::GetWindowsSizeMilimeter();
|
||||
return sqrtf(tmpSize.x()*tmpSize.x()+tmpSize.y()*tmpSize.y());
|
||||
}
|
||||
|
||||
float ewol::GetWindowsDiagSizeInch(void)
|
||||
{
|
||||
vec2 tmpSize = ewol::GetWindowsSizeInch();
|
||||
return sqrtf(tmpSize.x()*tmpSize.x()+tmpSize.y()*tmpSize.y());
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,98 +0,0 @@
|
||||
/**
|
||||
* @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 <etk/types.h>
|
||||
#include <etk/UString.h>
|
||||
#include <etk/math/Vector2D.h>
|
||||
|
||||
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);
|
||||
/**
|
||||
* @brief Set the current Windows Size
|
||||
* @param[in] size Size of the current windows in pixel.
|
||||
*/
|
||||
void SetPixelWindowsSize(const vec2& size);
|
||||
/**
|
||||
* @brief Get the Windows Size in the request unit
|
||||
* @return the requested size
|
||||
*/
|
||||
vec2 GetWindowsSizeMilimeter(void);
|
||||
/**
|
||||
* @brief Get the Windows Size in the request unit
|
||||
* @return the requested size
|
||||
*/
|
||||
vec2 GetWindowsSizeInch(void);
|
||||
/**
|
||||
* @brief Get the Windows diagonal size in the request unit
|
||||
* @return the requested size
|
||||
*/
|
||||
float GetWindowsDiagSizeMilimeter(void);
|
||||
/**
|
||||
* @brief Get the Windows diagonal size in the request unit
|
||||
* @return the requested size
|
||||
*/
|
||||
float GetWindowsDiagSizeInch(void);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <ewol/renderer/os/gui.h>
|
||||
#include <ewol/commandLine.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
#include <ewol/DisplayConv.h>
|
||||
#include <ewol/Dimension.h>
|
||||
#undef __class__
|
||||
#define __class__ "ewol"
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
int32_t ewol::Run(int32_t argc, const char* argv[])
|
||||
{
|
||||
// init display convertions:
|
||||
ewol::DC_Init();
|
||||
ewol::dimension::Init();
|
||||
|
||||
EWOL_DEBUG("Store commangLine in the specific system");
|
||||
ewol::commandLine::Clean();
|
||||
|
@ -7,7 +7,7 @@ FILE_LIST:= ewol/ewol.cpp \
|
||||
ewol/commandLine.cpp \
|
||||
ewol/key.cpp \
|
||||
ewol/cursor.cpp \
|
||||
ewol/DisplayConv.cpp
|
||||
ewol/Dimension.cpp
|
||||
|
||||
# Basic Eobject of EWOL
|
||||
FILE_LIST+= ewol/eObject/EObject.cpp \
|
||||
|
Loading…
x
Reference in New Issue
Block a user