Add the Label widget
This commit is contained in:
parent
2e50ce7690
commit
9e5e81f690
@ -105,6 +105,7 @@ etk::String etk::File::GetCompleateName(void) const
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
const etk::File& etk::File::operator= (const etk::File &etkF )
|
||||
{
|
||||
if( this != &etkF ) // avoid copy to itself
|
||||
|
@ -8,7 +8,7 @@ LOCAL_STATIC_LIBRARIES := etk tinyxml libzip libpng
|
||||
LOCAL_C_INCLUDES := -I$(LOCAL_PATH) -I$(LOCAL_PATH)/../libzip/ -I$(LOCAL_PATH)/../libpng/ -I$(LOCAL_PATH)/../libtinyxml/ -I$(LOCAL_PATH)/../libetk/
|
||||
|
||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
|
||||
LOCAL_EXPORT_LDLIBS := -lGL -lGLU -lz -lX11 -lXxf86vm
|
||||
LOCAL_EXPORT_LDLIBS := -lGL -lGLU -lz -lX11 -lXxf86vm `pkg-config --libs freetype2`
|
||||
|
||||
LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
||||
-Wno-write-strings \
|
||||
@ -16,7 +16,9 @@ LOCAL_CFLAGS := -D__PLATFORM__Linux \
|
||||
-DEWOL_DEBUG_LEVEL=3 \
|
||||
-DEWOL_VERSION_TAG_NAME="\"UNKNOW-debug\"" \
|
||||
-DVERSION_BUILD_TIME="\"pasd_heure\"" \
|
||||
-DEWOL_X11_MODE__XF86V
|
||||
-DEWOL_X11_MODE__XF86V \
|
||||
-DEWOL_USE_FREE_TYPE \
|
||||
`pkg-config --cflags freetype2`
|
||||
|
||||
# load the common sources file of the platform
|
||||
include $(LOCAL_PATH)/file.mk
|
||||
|
@ -22,6 +22,7 @@
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef EWOL_USE_FREE_TYPE
|
||||
|
||||
#include <ewol/Font.h>
|
||||
#include <ewol/Texture.h>
|
||||
@ -540,4 +541,4 @@ int32_t ewol::GetHeight(int32_t fontID)
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -21,7 +21,7 @@
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef EWOL_USE_FREE_TYPE
|
||||
|
||||
#include <ewol/Font.h>
|
||||
#include <ewol/Texture.h>
|
||||
@ -36,7 +36,7 @@
|
||||
# include <X11/extensions/Xrender.h>
|
||||
#endif
|
||||
*/
|
||||
#include <importgl.h>
|
||||
#include <ewol/importgl.h>
|
||||
#if defined(__PLATFORM__Linux)
|
||||
# include <ft2build.h>
|
||||
#else
|
||||
@ -188,7 +188,37 @@ class FTFontInternal
|
||||
{
|
||||
m_fontName = fontName;
|
||||
m_fileName = fontFileName;
|
||||
int32_t error = FT_New_Face( library, m_fileName.GetCompleateName().c_str(), 0, &m_fftFace );
|
||||
m_FileBuffer = NULL;
|
||||
m_FileSize = 0;
|
||||
#if 0
|
||||
int32_t error = FT_New_Face( library, m_fileName.GetCompleateName().c_str(), 0, &m_fftFace );
|
||||
#else
|
||||
if (false == m_fileName.Exist()) {
|
||||
EWOL_ERROR("File Does not exist : " << m_fileName);
|
||||
return;
|
||||
}
|
||||
m_FileSize = m_fileName.Size();
|
||||
if (0==m_FileSize) {
|
||||
EWOL_ERROR("This file is empty : " << m_fileName);
|
||||
return;
|
||||
}
|
||||
if (false == m_fileName.fOpenRead()) {
|
||||
EWOL_ERROR("Can not open the file : " << m_fileName);
|
||||
return;
|
||||
}
|
||||
// allocate data
|
||||
m_FileBuffer = new FT_Byte[m_FileSize];
|
||||
if (NULL == m_FileBuffer) {
|
||||
EWOL_ERROR("Error Memory allocation size=" << m_FileSize);
|
||||
return;
|
||||
}
|
||||
// load data from the file :
|
||||
m_fileName.fRead(m_FileBuffer, 1, m_FileSize);
|
||||
// close the file:
|
||||
m_fileName.fClose();
|
||||
// load Face ...
|
||||
int32_t error = FT_New_Memory_Face( library, m_FileBuffer, m_FileSize, 0, &m_fftFace );
|
||||
#endif
|
||||
if( FT_Err_Unknown_File_Format == error) {
|
||||
EWOL_ERROR("... the font file could be opened and read, but it appears ... that its font format is unsupported");
|
||||
} else if (0 != error) {
|
||||
@ -201,7 +231,11 @@ class FTFontInternal
|
||||
}
|
||||
~FTFontInternal(void)
|
||||
{
|
||||
|
||||
// clean the tmp memory
|
||||
if (NULL != m_FileBuffer) {
|
||||
delete[] m_FileBuffer;
|
||||
m_FileBuffer = NULL;
|
||||
}
|
||||
}
|
||||
public:
|
||||
etk::String GetFontName(void) {return m_fontName;};
|
||||
@ -322,6 +356,8 @@ class FTFontInternal
|
||||
private:
|
||||
etk::String m_fontName;
|
||||
etk::File m_fileName;
|
||||
FT_Byte * m_FileBuffer;
|
||||
int32_t m_FileSize;
|
||||
FT_Face m_fftFace;
|
||||
};
|
||||
|
||||
@ -661,4 +697,8 @@ int32_t ewol::GetHeight(int32_t fontID)
|
||||
return 10;
|
||||
}
|
||||
return m_listLoadedFont[fontID]->GetHeight();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
129
Sources/libewol/ewol/widget/Label.cpp
Normal file
129
Sources/libewol/ewol/widget/Label.cpp
Normal file
@ -0,0 +1,129 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file ewol/widget/Label.cpp
|
||||
* @brief ewol Label widget system (Sources)
|
||||
* @author Edouard DUPIN
|
||||
* @date 22/12/2011
|
||||
* @par Project
|
||||
* ewol
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#include <ewol/widget/Label.h>
|
||||
|
||||
#include <ewol/OObject.h>
|
||||
#include <ewol/WidgetManager.h>
|
||||
|
||||
|
||||
const char * const ewolEventLabelPressed = "ewol Label Pressed";
|
||||
|
||||
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "ewol::Label"
|
||||
|
||||
|
||||
void ewol::Label::Init(void)
|
||||
{
|
||||
m_textColorFg.red = 0.0;
|
||||
m_textColorFg.green = 0.0;
|
||||
m_textColorFg.blue = 0.0;
|
||||
m_textColorFg.alpha = 1.0;
|
||||
SetCanHaveFocus(true);
|
||||
}
|
||||
|
||||
ewol::Label::Label(void)
|
||||
{
|
||||
m_label = "---";
|
||||
Init();
|
||||
}
|
||||
|
||||
ewol::Label::Label(etk::String newLabel)
|
||||
{
|
||||
m_label = newLabel;
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
ewol::Label::~Label(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool ewol::Label::CalculateMinSize(void)
|
||||
{
|
||||
int32_t fontId = GetDefaultFontId();
|
||||
int32_t minWidth = ewol::GetWidth(fontId, m_label.c_str());
|
||||
int32_t minHeight = ewol::GetHeight(fontId);
|
||||
m_minSize.x = 3+minWidth;
|
||||
m_minSize.y = 3+minHeight;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ewol::Label::SetLabel(etk::String newLabel)
|
||||
{
|
||||
m_label = newLabel;
|
||||
}
|
||||
|
||||
|
||||
void ewol::Label::OnRegenerateDisplay(void)
|
||||
{
|
||||
// clean the object list ...
|
||||
ClearOObjectList();
|
||||
|
||||
int32_t paddingSize = 3;
|
||||
|
||||
int32_t tmpOriginX = 0;
|
||||
int32_t tmpOriginY = 0;
|
||||
|
||||
if (true==m_userFillX) {
|
||||
tmpOriginX = (m_size.x - m_minSize.x) / 2;
|
||||
}
|
||||
if (true==m_userFillY) {
|
||||
tmpOriginY = (m_size.y - m_minSize.y) / 2;
|
||||
}
|
||||
tmpOriginX += paddingSize;
|
||||
tmpOriginY += paddingSize;
|
||||
|
||||
ewol::OObject2DText * tmpText = new ewol::OObject2DText("", -1, m_textColorFg);
|
||||
tmpText->Text(tmpOriginX, tmpOriginY, m_label.c_str());
|
||||
|
||||
AddOObject(tmpText, "LabelText");
|
||||
|
||||
// Regenerate the event Area:
|
||||
EventAreaRemoveAll();
|
||||
coord origin;
|
||||
coord size;
|
||||
origin.x = tmpOriginX;
|
||||
origin.y = tmpOriginY;
|
||||
size.x = m_minSize.x;
|
||||
size.y = m_minSize.y;
|
||||
AddEventArea(origin, size, FLAG_EVENT_INPUT_1 | FLAG_EVENT_INPUT_CLICKED_ALL, ewolEventLabelPressed);
|
||||
}
|
||||
|
||||
bool ewol::Label::OnEventArea(const char * generateEventId, etkFloat_t x, etkFloat_t y)
|
||||
{
|
||||
bool eventIsOK = false;
|
||||
//EWOL_DEBUG("Receive event : \"" << generateEventId << "\"");
|
||||
if(ewolEventLabelPressed == generateEventId) {
|
||||
EWOL_INFO("LBL pressed ... " << m_label);
|
||||
//ewol::widgetManager::FocusKeep(this);
|
||||
}
|
||||
return eventIsOK;
|
||||
}
|
||||
|
||||
|
53
Sources/libewol/ewol/widget/Label.h
Normal file
53
Sources/libewol/ewol/widget/Label.h
Normal file
@ -0,0 +1,53 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file ewol/widget/Label.h
|
||||
* @brief ewol Label widget system (header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 22/12/2011
|
||||
* @par Project
|
||||
* ewol
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __EWOL_LABEL_H__
|
||||
#define __EWOL_LABEL_H__
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <ewol/Debug.h>
|
||||
#include <ewol/Widget.h>
|
||||
|
||||
namespace ewol {
|
||||
class Label :public ewol::Widget
|
||||
{
|
||||
public:
|
||||
Label(void);
|
||||
Label(etk::String newLabel);
|
||||
void Init(void);
|
||||
virtual ~Label(void);
|
||||
virtual bool CalculateMinSize(void);
|
||||
void SetLabel(etk::String newLabel);
|
||||
private:
|
||||
etk::String m_label;
|
||||
color_ts m_textColorFg; //!< Text color
|
||||
public:
|
||||
virtual void OnRegenerateDisplay(void);
|
||||
public:
|
||||
//virtual bool OnEventInput(int32_t IdInput, eventInputType_te typeEvent, etkFloat_t x, etkFloat_t y);
|
||||
virtual bool OnEventArea(const char * generateEventId, etkFloat_t x, etkFloat_t y);
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
@ -9,10 +9,12 @@ FILE_LIST = \
|
||||
ewol/OObject/2DTextured.cpp \
|
||||
ewol/Texture.cpp \
|
||||
ewol/FontBitmap.cpp \
|
||||
ewol/FontFreeType.cpp \
|
||||
ewol/Widget.cpp \
|
||||
ewol/WidgetManager.cpp \
|
||||
ewol/Windows.cpp \
|
||||
ewol/widget/Button.cpp \
|
||||
ewol/widget/Label.cpp \
|
||||
ewol/widget/CheckBox.cpp \
|
||||
ewol/widget/Entry.cpp \
|
||||
ewol/widget/List.cpp \
|
||||
|
Loading…
x
Reference in New Issue
Block a user