void ewol::widget::List::setRawVisible(int32_t _id) { EWOL_DEBUG("Set Raw visible : " << _id); if (_id<0) { return; } if (_id == m_displayStartRaw) { // nothing to do ... return; } if (_id < m_displayStartRaw) { m_displayStartRaw = _id-2; } else { if (m_displayStartRaw + m_nbVisibleRaw < _id) { m_displayStartRaw = _id - m_nbVisibleRaw + 2; } } if (m_displayStartRaw > (int32_t)getNuberOfRaw()) { m_displayStartRaw = getNuberOfRaw()-2; } if (m_displayStartRaw<0) { m_displayStartRaw = 0; } EWOL_DEBUG("Set start raw : " << m_displayStartRaw); markToRedraw(); }
void ewol::resource::ColorFile::init(const std::string& _filename) { std::unique_lock<std::recursive_mutex> lock(m_mutex); gale::Resource::init(_filename); EWOL_DEBUG("CF : load \"" << _filename << "\""); reload(); EWOL_DEBUG("List of all color : " << m_list.getKeys()); }
void ewol::resource::DistanceFieldFont::exportOnFile() { std11::unique_lock<std11::recursive_mutex> lock(m_mutex); EWOL_DEBUG("EXPORT: DistanceFieldFont : file : '" << m_fileName << ".json'"); ejson::Document doc; std::shared_ptr<ejson::Array> tmpList = ejson::Array::create(); if (tmpList == nullptr) { EWOL_ERROR("nullptr pointer"); return; } for (size_t iii=0; iii<m_listElement.size(); ++iii) { std::shared_ptr<ejson::Object> tmpObj = ejson::Object::create(); if (tmpObj == nullptr) { continue; } tmpObj->addString("m_UVal", etk::to_string(m_listElement[iii].m_UVal)); tmpObj->addNumber("m_glyphIndex", m_listElement[iii].m_glyphIndex); tmpObj->addString("m_sizeTexture", (std::string)m_listElement[iii].m_sizeTexture); tmpObj->addString("m_bearing", (std::string)m_listElement[iii].m_bearing); tmpObj->addString("m_advance", (std::string)m_listElement[iii].m_advance); tmpObj->addString("m_texturePosStart", (std::string)m_listElement[iii].m_texturePosStart); tmpObj->addString("m_texturePosSize", (std::string)m_listElement[iii].m_texturePosSize); tmpObj->addBoolean("m_exist", m_listElement[iii].m_exist); tmpList->add(tmpObj); } doc.add("m_listElement", tmpList); doc.addNumber("m_sizeRatio", m_sizeRatio); doc.addString("m_lastGlyphPos", (std::string)m_lastGlyphPos); doc.addNumber("m_lastRawHeigh", m_lastRawHeigh); doc.addNumber("m_borderSize", m_borderSize); doc.addString("m_textureBorderSize", (std::string)m_textureBorderSize); doc.store(m_fileName + ".json"); egami::store(m_data, m_fileName + ".bmp"); egami::store(m_data, m_fileName + ".png"); }
void ewol::object::Manager::unInit() { EWOL_DEBUG(" == > Un-Init Object-Manager"); if (m_workerList.size() > 0) { EWOL_DEBUG(" == > Remove all workers"); m_workerList.clear(); } for (auto &it : m_eObjectList) { std::shared_ptr<ewol::Object> element = it.lock(); if (element != nullptr) { //it->removeObject(); } } if (m_eObjectList.size() != 0) { EWOL_ERROR("Have " << m_eObjectList.size() << " active Object"); } m_eObjectList.clear(); }
const std::string& get(const std::string& _instance) { loadTranslation(); auto it = m_translate.find(_instance); if (it == m_translate.end()) { EWOL_DEBUG("Can not find tranlation : '" << _instance << "'"); return _instance; } return it->second; };
bool ewol::resource::DistanceFieldFont::importFromFile() { std11::unique_lock<std11::recursive_mutex> lock(m_mutex); EWOL_DEBUG("IMPORT: DistanceFieldFont : file : '" << m_fileName << ".json'"); // test file existance: etk::FSNode fileJSON(m_fileName + ".json"); etk::FSNode fileBMP(m_fileName + ".bmp"); if ( fileJSON.exist() == false || fileBMP.exist() == false) { EWOL_DEBUG("Does not import file for distance field system"); return false; } ejson::Document doc; doc.load(m_fileName + ".json"); m_sizeRatio = doc.getNumberValue("m_sizeRatio", 0); m_lastGlyphPos = doc.getStringValue("m_lastGlyphPos", "0,0"); m_lastRawHeigh = doc.getNumberValue("m_lastRawHeigh", 0); m_borderSize = doc.getNumberValue("m_borderSize", 2); m_textureBorderSize = doc.addString("m_textureBorderSize", "0,0"); std::shared_ptr<ejson::Array> tmpList = doc.getArray("m_listElement"); if (tmpList == nullptr) { EWOL_ERROR("nullptr pointer array"); return false; } m_listElement.clear(); for (size_t iii=0; iii<tmpList->size(); ++iii) { std::shared_ptr<ejson::Object> tmpObj = tmpList->getObject(iii); if (tmpObj == nullptr) { continue; } GlyphProperty prop; prop.m_UVal = etk::string_to_int32_t(tmpObj->getStringValue("m_UVal", "0")); prop.m_glyphIndex = tmpObj->getNumberValue("m_glyphIndex", 0); prop.m_sizeTexture = tmpObj->getStringValue("m_sizeTexture", "0,0"); prop.m_bearing = tmpObj->getStringValue("m_bearing", "0,0"); prop.m_advance = tmpObj->getStringValue("m_advance", "0,0"); prop.m_texturePosStart = tmpObj->getStringValue("m_texturePosStart", "0,0"); prop.m_texturePosSize = tmpObj->getStringValue("m_texturePosSize", "0,0"); prop.m_exist = tmpObj->getBooleanValue("m_exist", false); m_listElement.push_back(prop); } egami::load(m_data, m_fileName + ".bmp"); return true; }
ewol::object::Manager::Manager(ewol::Context& _context) : m_context(_context), periodicCall(*this, "periodic", "Call every time system render", true), m_applWakeUpTime(0), m_lastPeriodicCallTime(0) { EWOL_DEBUG(" == > init Object-Manager"); // set the basic time properties : m_applWakeUpTime = ewol::getTime(); m_lastPeriodicCallTime = ewol::getTime(); }
void ewol::resource::Shader::init(const std::string& _filename) { ewol::Resource::init(_filename); EWOL_DEBUG("OGL : load SHADER \"" << _filename << "\""); // load data from file "all the time ..." if (etk::end_with(m_name, ".frag") == true) { m_type = GL_FRAGMENT_SHADER; } else if (etk::end_with(m_name, ".vert") == true) { m_type = GL_VERTEX_SHADER; } else { EWOL_ERROR("File does not have extention \".vert\" for Vertex Shader or \".frag\" for Fragment Shader. but : \"" << m_name << "\""); return; } reload(); }
void ewol::resource::TextureFile::init(std::string _genName, const std::string& _tmpFilename, const ivec2& _size) { std::unique_lock<std::recursive_mutex> lock(m_mutex); ewol::resource::Texture::init(_genName); EWOL_DEBUG("create a new resource::Image : _genName=" << _genName << " _tmpFilename=" << _tmpFilename << " size=" << _size); m_data = egami::load(_tmpFilename, _size); if (m_data.exist() == false) { EWOL_ERROR("ERROR when loading the image : " << _tmpFilename); } //egami::store(m_data, "tmpResult.bmp"); ivec2 tmp = m_data.getSize(); m_realImageSize = vec2(tmp.x(), tmp.y()); #ifdef GENERATE_DISTANCE_FIELD_MODE //egami::generateDistanceFieldFile(_tmpFilename, std::string(_tmpFilename, 0, _tmpFilename.size()-4) + ".bmp"); egami::generateDistanceFieldFile(_tmpFilename, std::string(_tmpFilename, 0, _tmpFilename.size()-4) + ".edf"); #endif flush(); }
void ege::widget::Scene::systemDraw(const ewol::DrawProperty& _displayProp) { #ifdef SCENE_BRUT_PERFO_TEST int64_t tmp___startTime0 = ewol::getTime(); #endif gale::openGL::bindBuffer(0); gale::openGL::push(); // here we invert the reference of the standard openGl view because the reference in the common display is Top left and not buttom left gale::openGL::setViewPort(m_origin, m_size); // configure render with the camera... ememory::SharedPtr<ege::Camera> camera = m_env->getCamera(m_cameraName); if (camera != nullptr) { camera->configureOpenGL(); } onDraw(); gale::openGL::pop(); #ifdef SCENE_BRUT_PERFO_TEST float tmp___localTime1 = (float)(ewol::getTime() - tmp___startTime0) / 1000.0f; EWOL_DEBUG(" SCENE render : " << tmp___localTime1 << "ms "); #endif }
void ewol::resource::ColorFile::reload() { std::unique_lock<std::recursive_mutex> lock(m_mutex); // remove all previous set of value : for (int32_t iii = 0; iii < m_list.size() ; ++iii) { m_list[iii] = m_errorColor; } // open and read all json elements: ejson::Document doc; if (doc.load(m_name) == false) { EWOL_ERROR("Can not load file : '" << m_name << "' = " << etk::FSNode(m_name).getFileSystemName()); return; } ejson::Array baseArray = doc["color"].toArray(); if (baseArray.exist() == false) { EWOL_ERROR("Can not get basic array : 'color' in file:" << m_name); doc.display(); return; } bool findError = false; for (const auto it : baseArray) { ejson::Object tmpObj = it.toObject(); if (tmpObj.exist() == false) { EWOL_ERROR(" can not get object in 'color' : " << it); findError = true; continue; } std::string name = tmpObj["name"].toString().get(); std::string color = tmpObj["color"].toString().get(m_errorColor.getHexString()); EWOL_DEBUG("find new color : '" << name << "' color='" << color << "'"); if (name.size() == 0) { EWOL_ERROR("Drop an empty name"); findError = true; continue; } m_list.add(name, etk::Color<float>(color)); } if (findError == true) { EWOL_ERROR("pb in parsing file:" << m_name); doc.display(); } }
bool ewol::widget::Container::loadXML(exml::Element* _node) { if (nullptr == _node) { return false; } // parse generic properties : ewol::Widget::loadXML(_node); // remove previous element : subWidgetRemove(); // parse all the elements : for(size_t iii=0; iii< _node->size(); iii++) { exml::Element* pNode = _node->getElement(iii); if (pNode == nullptr) { // trash here all that is not element continue; } std::string widgetName = pNode->getValue(); if (getWidgetManager().exist(widgetName) == false) { EWOL_ERROR("(l "<<pNode->getPos()<<") Unknown basic node=\"" << widgetName << "\" not in : [" << getWidgetManager().list() << "]" ); continue; } if (nullptr != getSubWidget()) { EWOL_ERROR("(l "<<pNode->getPos()<<") " << __class__ << " Can only have one subWidget ??? node=\"" << widgetName << "\"" ); continue; } EWOL_DEBUG("try to create subwidget : '" << widgetName << "'"); std::shared_ptr<ewol::Widget> tmpWidget = getWidgetManager().create(widgetName); if (tmpWidget == nullptr) { EWOL_ERROR ("(l "<<pNode->getPos()<<") Can not create the widget : \"" << widgetName << "\""); continue; } // add widget : setSubWidget(tmpWidget); if (false == tmpWidget->loadXML(pNode)) { EWOL_ERROR ("(l "<<pNode->getPos()<<") can not load widget properties : \"" << widgetName << "\""); return false; } } return true; }
void ewol::widget::Parameter::menuAdd(std::string _label, std::string _image, std::shared_ptr<ewol::Widget> _associateWidget) { if (nullptr != m_paramList) { m_paramList->menuAdd(_label, m_currentIdList, _image); if (nullptr != m_wSlider) { if (nullptr != _associateWidget) { m_wSlider->subWidgetAdd(_associateWidget); } else { EWOL_DEBUG("Associate an empty widget on it ..."); std::shared_ptr<ewol::widget::Label> myLabel = widget::Label::create(std::string("No widget for : ") + _label); if (nullptr == myLabel) { EWOL_ERROR("Can not allocate widget == > display might be in error"); } else { myLabel->setExpand(bvec2(true,true)); m_wSlider->subWidgetAdd(myLabel); } } if (m_currentIdList == 0) { m_wSlider->subWidgetSelectSet(0); } } m_currentIdList++; } }
void ewol::widget::ParameterList::onLostFocus() { EWOL_DEBUG("Ewol::List Lost focus"); }
void ewol::resource::ConfigFile::init(const std::string& _filename) { ewol::Resource::init(_filename); EWOL_DEBUG("SFP : load \"" << _filename << "\""); reload(); }
void ewol::widget::Parameter::onCallbackMenuSelected(const int32_t& _value) { if (m_wSlider != nullptr) { EWOL_DEBUG("event on the parameter : Menu-select select ID=" << _value << ""); m_wSlider->subWidgetSelectSet(_value); } }
void ewol::context::InputManager::state(enum gale::key::type _type, int _pointerID, bool _isDown, vec2 _pos) { if (_pointerID >= MAX_MANAGE_INPUT) { // reject pointer == > out of IDs... return; } EVENT_DEBUG("event pointerId=" << _pointerID); // convert position in open-GL coordonates ... InputPoperty *eventTable = nullptr; InputLimit localLimit; if (_type == gale::key::type::mouse) { eventTable = m_eventMouseSaved; localLimit = m_eventMouseLimit; } else if (_type == gale::key::type::finger) { eventTable = m_eventInputSaved; localLimit = m_eventInputLimit; } else { EWOL_ERROR("Unknown type of event"); return; } if( _pointerID > MAX_MANAGE_INPUT || _pointerID <= 0) { // not manage input return; } // get the curent time ... echrono::Clock currentTime = echrono::Clock::now(); ewol::widget::WindowsShared tmpWindows = m_context.getWindows(); if (_isDown == true) { EVENT_DEBUG("GUI : Input ID=" << _pointerID << " == >" << eventTable[_pointerID].destinationInputId << " [DOWN] " << _pos); if(eventTable[_pointerID].isUsed == true) { // we have an event previously ... check delay between click and offset position if (currentTime - eventTable[_pointerID].lastTimeEvent > localLimit.sepatateTime) { cleanElement(eventTable, _pointerID); } else if( std::abs(eventTable[_pointerID].downStart.x() - _pos.x()) >= localLimit.DpiOffset || std::abs(eventTable[_pointerID].downStart.y() - _pos.y()) >= localLimit.DpiOffset ){ cleanElement(eventTable, _pointerID); } } if(eventTable[_pointerID].isUsed == true) { // save start time eventTable[_pointerID].lastTimeEvent = currentTime; // generate DOWN Event EVENT_DEBUG("GUI : Input ID=" << _pointerID << " == >" << eventTable[_pointerID].destinationInputId << " [DOWN] " << _pos); eventTable[_pointerID].posEvent = _pos; localEventInput(_type, eventTable[_pointerID].curentWidgetEvent.lock(), eventTable[_pointerID].destinationInputId, gale::key::status::down, _pos); } else { // Mark it used : eventTable[_pointerID].isUsed = true; // Save current position : eventTable[_pointerID].downStart = _pos; // save start time eventTable[_pointerID].lastTimeEvent = currentTime; // set the element inside ... eventTable[_pointerID].isInside = true; ewol::WidgetShared tmpWidget = m_grabWidget.lock(); // get destination widget : if(tmpWindows != nullptr) { if ( tmpWidget != nullptr && _type == gale::key::type::mouse) { eventTable[_pointerID].curentWidgetEvent = tmpWidget; } else { tmpWidget = tmpWindows->getWidgetAtPos(_pos); eventTable[_pointerID].curentWidgetEvent = tmpWidget; if (tmpWidget != nullptr) { EVENT_DEBUG("Get widget at pos=" << _pos << " type: " << tmpWidget->getObjectType()); } else { EVENT_DEBUG("Get widget at pos=" << _pos << " NO WIDGET"); } } } else { eventTable[_pointerID].curentWidgetEvent.reset(); } tmpWidget = eventTable[_pointerID].curentWidgetEvent.lock(); if (tmpWidget != nullptr) { eventTable[_pointerID].origin = tmpWidget->getOrigin(); eventTable[_pointerID].size = tmpWidget->getSize(); eventTable[_pointerID].destinationInputId = localGetDestinationId(_type, tmpWidget, _pointerID); } else { eventTable[_pointerID].destinationInputId = -1; } // generate DOWN Event EVENT_DEBUG("GUI : Input ID=" << _pointerID << " == >" << eventTable[_pointerID].destinationInputId << " [DOWN] " << _pos); eventTable[_pointerID].posEvent = _pos; localEventInput(_type, tmpWidget, eventTable[_pointerID].destinationInputId, gale::key::status::down, _pos); } } else { EVENT_DEBUG("GUI : Input ID=" << _pointerID << " == >" << eventTable[_pointerID].destinationInputId << " [UP] " << _pos); ewol::WidgetShared tmpWidget = eventTable[_pointerID].curentWidgetEvent.lock(); if(eventTable[_pointerID].isUsed == false) { // bad case ... ??? EWOL_DEBUG("Up event without previous down ... "); // Mark it un-used : eventTable[_pointerID].isUsed = false; // revove the widget ... eventTable[_pointerID].curentWidgetEvent.reset(); } else if (tmpWidget == nullptr) { // The widget has been removed: EVENT_DEBUG(" Object Removed ..."); // Mark it un-used : eventTable[_pointerID].isUsed = false; // revove the widget ... eventTable[_pointerID].curentWidgetEvent.reset(); } else { // generate UP Event EVENT_DEBUG("GUI : Input ID=" << _pointerID << " == >" << eventTable[_pointerID].destinationInputId << " [UP] " << _pos); eventTable[_pointerID].posEvent = _pos; // send up event after the single event to prevent multiple widget getting elements localEventInput(_type, tmpWidget, _pointerID, gale::key::status::up, _pos); // generate event (single) if( std::abs(eventTable[_pointerID].downStart.x() - _pos.x()) < localLimit.DpiOffset && std::abs(eventTable[_pointerID].downStart.y() - _pos.y()) < localLimit.DpiOffset ){ // Save current position : eventTable[_pointerID].downStart = _pos; // save start time eventTable[_pointerID].lastTimeEvent = currentTime; int32_t nbClickMax = 0; if(tmpWidget != nullptr) { nbClickMax = tmpWidget->getMouseLimit(); if (nbClickMax>5) { nbClickMax = 5; } } // in grab mode the single to quinte event are not generated .... if( ( m_grabWidget.lock() == nullptr || _type != gale::key::type::mouse ) && eventTable[_pointerID].nbClickEvent < nbClickMax) { // generate event SINGLE : eventTable[_pointerID].nbClickEvent++; EVENT_DEBUG("GUI : Input ID=" << _pointerID << " == >" << eventTable[_pointerID].destinationInputId << " [" << eventTable[_pointerID].nbClickEvent << "] " << _pos); eventTable[_pointerID].posEvent = _pos; localEventInput(_type, tmpWidget, eventTable[_pointerID].destinationInputId, (enum gale::key::status)(uint32_t(gale::key::status::pressSingle) + eventTable[_pointerID].nbClickEvent-1), _pos); if( eventTable[_pointerID].nbClickEvent >= nbClickMax) { eventTable[_pointerID].nbClickEvent = 0; } } else { eventTable[_pointerID].nbClickEvent = 0; } } // send up event after the single event to prevent multiple widget getting elements localEventInput(_type, tmpWidget, _pointerID, gale::key::status::upAfter, _pos); // specific for tuch event if (_type == gale::key::type::finger) { cleanElement(eventTable, _pointerID); } } } }
void ewol::widget::List::onGetFocus() { EWOL_DEBUG("Ewol::List get focus"); }
void ewol::resource::ConfigFile::init(const std::string& _filename) { std11::unique_lock<std11::recursive_mutex> lock(m_mutex); gale::Resource::init(_filename); EWOL_DEBUG("SFP : load \"" << _filename << "\""); reload(); }
void ege::widget::Scene::onDraw() { #ifdef SCENE_DISPLAY_SPEED g_counterNbTimeDisplay++; g_startTime = ewol::getTime(); #endif // draw constant object : { mat4 tmpMatrix; for (auto &it : m_env->getStaticMeshToDraw()) { if (it != nullptr) { it->draw(tmpMatrix); } } } // get camera : ememory::SharedPtr<ege::Camera> camera = m_env->getCamera(m_cameraName); if (camera == nullptr) { EGE_ERROR(" can not get camera named: '" << m_cameraName << "'"); return; } //EGE_DEBUG("Draw (start)"); mat4 tmpMatrix; ememory::SharedPtr<btDynamicsWorld> world = m_env->getPhysicEngine().getDynamicWorld(); if (world != nullptr) { m_env->getOrderedElementForDisplay(m_displayElementOrdered, camera->getEye(), camera->getViewVector()); EGE_VERBOSE("DRAW : " << m_displayElementOrdered.size() << "/" << m_env->getElement().size() << " elements"); // TODO : remove this == > no more needed ==> checked in the generate the list of the element ordered for (size_t iii=0; iii<m_displayElementOrdered.size(); iii++) { m_displayElementOrdered[iii].element->preCalculationDraw(*camera); } // note : the first pass is done at the reverse way to prevent multiple display od the same point in the screen // (and we remember that the first pass is to display all the non transparent elements) for (int32_t iii=m_displayElementOrdered.size()-1; iii >= 0; iii--) { m_displayElementOrdered[iii].element->draw(0); } // for the other pass the user can draw transparent elements ... for (int32_t pass=1; pass <= NUMBER_OF_SUB_PASS+1; pass++) { for (size_t iii=0; iii<m_displayElementOrdered.size(); iii++) { m_displayElementOrdered[iii].element->draw(pass); } } if (propertyDebugPhysic.get() == true) { // Draw debug ... (Object) for (int32_t iii=m_displayElementOrdered.size()-1; iii >= 0; iii--) { m_displayElementOrdered[iii].element->drawDebug(m_debugDrawProperty, camera); } // Draw debug ... (Camera) std::map<std::string, ememory::SharedPtr<ege::Camera>> listCamera = m_env->getCameraList(); for (auto &itCam : listCamera) { if (itCam.second != nullptr) { itCam.second->drawDebug(m_debugDrawProperty, camera); } } } if (propertyDebugApplication.get() == true) { // Draw debug ... (User) signalDisplayDebug.emit(m_debugDrawProperty); } } else { EGE_WARNING("No Dynamic world ..."); } if (camera != nullptr) { m_env->getParticuleEngine().draw(*camera); } #ifdef SCENE_DISPLAY_SPEED float localTime = (float)(ewol::getTime() - g_startTime) / 1000.0f; if (localTime>1) { EWOL_ERROR(" scene : " << localTime << "ms " << g_counterNbTimeDisplay); } else { EWOL_DEBUG(" scene : " << localTime << "ms " << g_counterNbTimeDisplay); } #endif }
ewol::widget::Layer::~Layer() { EWOL_DEBUG("[" << getId() << "] Layer : destroy"); }
void ewol::widget::ButtonColor::onRegenerateDisplay() { if (needRedraw() == false) { return; } EWOL_DEBUG("redraw"); m_text.clear(); m_shaper.clear(); ewol::Padding padding = m_shaper.getPadding(); std::string label = m_textColorFg.getString(); ivec2 localSize = m_minSize; vec3 tmpOrigin((m_size.x() - m_minSize.x()) / 2.0, (m_size.y() - m_minSize.y()) / 2.0, 0); // no change for the text orogin : vec3 tmpTextOrigin((m_size.x() - m_minSize.x()) / 2.0, (m_size.y() - m_minSize.y()) / 2.0, 0); if (true == m_userFill->x()) { localSize.setX(m_size.x()); tmpOrigin.setX(0); tmpTextOrigin.setX(0); } if (true == m_userFill->y()) { localSize.setY(m_size.y()); } tmpOrigin += vec3(padding.xLeft(), padding.yButtom(), 0); tmpTextOrigin += vec3(padding.xLeft(), padding.yButtom(), 0); localSize -= ivec2(padding.x(), padding.y()); // clean the element m_text.reset(); if( m_textColorFg.get().r() < 100 || m_textColorFg.get().g() < 100 || m_textColorFg.get().b() < 100) { m_text.setColor(etk::color::white); } else { m_text.setColor(etk::color::black); } m_text.setPos(tmpTextOrigin); m_text.setColorBg(m_textColorFg.get()); m_text.setTextAlignement(tmpTextOrigin.x(), tmpTextOrigin.x()+localSize.x(), ewol::compositing::alignCenter); m_text.print(label); if (true == m_userFill->y()) { tmpOrigin.setY(padding.yButtom()); } // selection area : m_selectableAreaPos = vec2(tmpOrigin.x()-padding.xLeft(), tmpOrigin.y()-padding.yButtom()); m_selectableAreaSize = localSize + vec2(padding.x(),padding.y()); vec3 tmpp = m_text.calculateSize(label); m_shaper.setShape(m_selectableAreaPos, m_selectableAreaSize, vec2(tmpTextOrigin.x(), tmpTextOrigin.y()), vec2(tmpp.x(), tmpp.y())); }
void ewol::Widget::setCursor(enum gale::context::cursor _newCursor) { EWOL_DEBUG("Change Cursor in " << _newCursor); m_cursorDisplay = _newCursor; getContext().setCursor(m_cursorDisplay); }
void ewol::resource::TexturedFont::init(const std::string& _fontName) { std::unique_lock<std::recursive_mutex> lock(m_mutex); ewol::resource::Texture::init(_fontName); EWOL_DEBUG("Load font : '" << _fontName << "'" ); m_font[0] = nullptr; m_font[1] = nullptr; m_font[2] = nullptr; m_font[3] = nullptr; m_modeWraping[0] = ewol::font::Regular; m_modeWraping[1] = ewol::font::Regular; m_modeWraping[2] = ewol::font::Regular; m_modeWraping[3] = ewol::font::Regular; m_lastGlyphPos[0].setValue(1,1); m_lastGlyphPos[1].setValue(1,1); m_lastGlyphPos[2].setValue(1,1); m_lastGlyphPos[3].setValue(1,1); m_lastRawHeigh[0] = 0; m_lastRawHeigh[1] = 0; m_lastRawHeigh[2] = 0; m_lastRawHeigh[3] = 0; int32_t tmpSize = 0; // extarct name and size : const char * tmpData = _fontName.c_str(); const char * tmpPos = strchr(tmpData, ':'); if (tmpPos == nullptr) { m_size = 1; EWOL_CRITICAL("Can not parse the font name : \"" << _fontName << "\" ??? ':' " ); return; } else { if (sscanf(tmpPos+1, "%d", &tmpSize)!=1) { m_size = 1; EWOL_CRITICAL("Can not parse the font name : \"" << _fontName << "\" == > size ???"); return; } } std::string localName(_fontName, 0, (tmpPos - tmpData)); if (tmpSize>400) { EWOL_ERROR("Font size too big ==> limit at 400 when exxeed ==> error : " << tmpSize << "==>30"); tmpSize = 30; } m_size = tmpSize; std::vector<std::string> folderList; if (true == ewol::getContext().getFontDefault().getUseExternal()) { #if defined(__TARGET_OS__Android) folderList.push_back("ROOT:system/fonts"); #elif defined(__TARGET_OS__Linux) folderList.push_back("ROOT:usr/share/fonts"); #endif } std::string applicationBaseFont = ewol::getContext().getFontDefault().getFolder(); std::vector<std::string> applicationBaseFontList = etk::FSNodeExplodeMultiplePath(applicationBaseFont); for (auto &it : applicationBaseFontList) { folderList.push_back(it); } for (size_t folderID=0; folderID<folderList.size() ; folderID++) { etk::FSNode myFolder(folderList[folderID]); // find the real Font name : std::vector<std::string> output; myFolder.folderGetRecursiveFiles(output); std::vector<std::string> split = etk::split(localName, ';'); EWOL_INFO("try to find font named : " << split << " in: " << myFolder); //EWOL_CRITICAL("parse string : " << split); bool hasFindAFont = false; for (size_t jjj=0; jjj<split.size(); jjj++) { EWOL_INFO(" try with : '" << split[jjj] << "'"); for (size_t iii=0; iii<output.size(); iii++) { //EWOL_DEBUG(" file : " << output[iii]); if( true == etk::end_with(output[iii], split[jjj]+"-"+"bold"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"-"+"b"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"-"+"bd"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"bold"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"bd"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"b"+".ttf", false)) { EWOL_INFO(" find Font [Bold] : " << output[iii]); m_fileName[ewol::font::Bold] = output[iii]; hasFindAFont=true; } else if( true == etk::end_with(output[iii], split[jjj]+"-"+"oblique"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"-"+"italic"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"-"+"Light"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"-"+"i"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"oblique"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"italic"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"light"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"i"+".ttf", false)) { EWOL_INFO(" find Font [Italic] : " << output[iii]); m_fileName[ewol::font::Italic] = output[iii]; hasFindAFont=true; } else if( true == etk::end_with(output[iii], split[jjj]+"-"+"bolditalic"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"-"+"boldoblique"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"-"+"bi"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"-"+"z"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"bolditalic"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"boldoblique"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"bi"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"z"+".ttf", false)) { EWOL_INFO(" find Font [Bold-Italic] : " << output[iii]); m_fileName[ewol::font::BoldItalic] = output[iii]; hasFindAFont=true; } else if( true == etk::end_with(output[iii], split[jjj]+"-"+"regular"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"-"+"r"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"regular"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+"r"+".ttf", false) || true == etk::end_with(output[iii], split[jjj]+".ttf", false)) { EWOL_INFO(" find Font [Regular] : " << output[iii]); m_fileName[ewol::font::Regular] = output[iii]; hasFindAFont=true; } } if (hasFindAFont == true) { EWOL_INFO(" find this font : '" << split[jjj] << "'"); break; } else if (jjj == split.size()-1) { EWOL_ERROR("Find NO font in the LIST ... " << split); } } if (hasFindAFont == true) { EWOL_INFO(" find this font : '" << folderList[folderID] << "'"); break; } else if (folderID == folderList.size()-1) { EWOL_ERROR("Find NO font in the LIST ... " << folderList); } } // try to find the reference mode : enum ewol::font::mode refMode = ewol::font::Regular; for(int32_t iii=3; iii >= 0; iii--) { if (m_fileName[iii].size() != 0) { refMode = (enum ewol::font::mode)iii; } } EWOL_DEBUG(" set reference mode : " << refMode); // generate the wrapping on the preventing error for(int32_t iii=3; iii >= 0; iii--) { if (m_fileName[iii].size() != 0) { m_modeWraping[iii] = (enum ewol::font::mode)iii; } else { m_modeWraping[iii] = refMode; } } for (int32_t iiiFontId=0; iiiFontId<4 ; iiiFontId++) { if (m_fileName[iiiFontId].size() == 0) { EWOL_DEBUG("can not load FONT [" << iiiFontId << "] name : \"" << m_fileName[iiiFontId] << "\" == > size=" << m_size ); m_font[iiiFontId] = nullptr; continue; } EWOL_INFO("Load FONT [" << iiiFontId << "] name : \"" << m_fileName[iiiFontId] << "\" == > size=" << m_size); m_font[iiiFontId] = ewol::resource::FontFreeType::create(m_fileName[iiiFontId]); if (m_font[iiiFontId] == nullptr) { EWOL_DEBUG("error in loading FONT [" << iiiFontId << "] name : \"" << m_fileName[iiiFontId] << "\" == > size=" << m_size ); } } for (int32_t iiiFontId=0; iiiFontId<4 ; iiiFontId++) { // set the bassic charset: m_listElement[iiiFontId].clear(); if (m_font[iiiFontId] == nullptr) { continue; } m_height[iiiFontId] = m_font[iiiFontId]->getHeight(m_size); // TODO : basic font use 512 is better ... == > maybe estimate it with the dpi ??? setImageSize(ivec2(256,32)); // now we can acces directly on the image m_data.clear(etk::Color<>(0x00000000)); } // add error glyph addGlyph(0); // by default we set only the first AINSI char availlable for (int32_t iii=0x20; iii<0x7F; iii++) { EWOL_VERBOSE("Add clyph :" << iii); addGlyph(iii); } flush(); EWOL_DEBUG("Wrapping properties : "); EWOL_DEBUG(" " << ewol::font::Regular << " == >" << getWrappingMode(ewol::font::Regular)); EWOL_DEBUG(" " << ewol::font::Italic << " == >" << getWrappingMode(ewol::font::Italic)); EWOL_DEBUG(" " << ewol::font::Bold << " == >" << getWrappingMode(ewol::font::Bold)); EWOL_DEBUG(" " << ewol::font::BoldItalic << " == >" << getWrappingMode(ewol::font::BoldItalic)); }
/* /--> _displayProp.m_windowsSize *------------------------------------------------------* | | | m_size | | / | | *-----------------------* | | ' ' | | ' _displayProp.m_size ' | | Viewport ' / ' | | o---------'---------o ' | | | ' | ' | | | ' | ' | | | ' | ' | | | ' | ' | | | *-----------------------* | | | / | | | | m_offset | | | | | | | o-------------------o | | / | | _displayProp.m_origin | | | *------------------------------------------------------* / (0,0) */ void ewol::Widget::systemDraw(const ewol::DrawProperty& _displayProp) { if (true == m_hide){ // widget is hidden ... return; } vec2 displayOrigin = m_origin + m_offset; // check if the element is displayable in the windows : if( _displayProp.m_windowsSize.x() < m_origin.x() || _displayProp.m_windowsSize.y() < m_origin.y() ) { // out of the windows == > nothing to display ... return; } ewol::DrawProperty tmpSize = _displayProp; tmpSize.limit(m_origin, m_size); if (tmpSize.m_size.x() <= 0 || tmpSize.m_size.y() <= 0) { return; } glViewport( (int32_t)tmpSize.m_origin.x(), (int32_t)tmpSize.m_origin.y(), (int32_t)tmpSize.m_size.x(), (int32_t)tmpSize.m_size.y()); // special case, when origin < display origin, we need to cut the display : ivec2 downOffset = m_origin - tmpSize.m_origin; downOffset.setMin(ivec2(0,0)); mat4 tmpTranslate = etk::matTranslate(vec3ClipInt32(vec3(-tmpSize.m_size.x()/2+m_offset.x() + downOffset.x(), -tmpSize.m_size.y()/2+m_offset.y() + downOffset.y(), -1.0f))); mat4 tmpScale = etk::matScale(vec3(m_zoom, m_zoom, 1.0f)); mat4 tmpProjection = etk::matOrtho((int32_t)(-tmpSize.m_size.x())>>1, (int32_t)( tmpSize.m_size.x())>>1, (int32_t)(-tmpSize.m_size.y())>>1, (int32_t)( tmpSize.m_size.y())>>1, (int32_t)(-1), (int32_t)( 1)); mat4 tmpMat = tmpProjection * tmpScale * tmpTranslate; gale::openGL::push(); // set internal matrix system : gale::openGL::setMatrix(tmpMat); //int64_t ___startTime = ewol::getTime(); onDraw(); #ifdef old_PLOP if( (_displayProp.m_origin.x() > m_origin.x()) || (_displayProp.m_origin.x() + _displayProp.m_size.x() < m_size.x() + m_origin.x()) ) { // here we invert the reference of the standard openGl view because the reference in the common display is Top left and not buttom left int32_t tmpOriginX = std::max(_displayProp.m_origin.x(), m_origin.x()); int32_t tmppp1 = _displayProp.m_origin.x() + _displayProp.m_size.x(); int32_t tmppp2 = m_origin.x() + m_size.x(); int32_t tmpclipX = std::min(tmppp1, tmppp2) - tmpOriginX; int32_t tmpOriginY = std::max(_displayProp.m_origin.y(), m_origin.y()); tmppp1 = _displayProp.m_origin.y() + _displayProp.m_size.y(); tmppp2 = m_origin.y() + m_size.y(); //int32_t tmpclipY = std::min(tmppp1, tmppp2) - tmpOriginX; glViewport( tmpOriginX, tmpOriginY, tmpclipX, m_size.y()); mat4 tmpTranslate = etk::matTranslate(vec3((float)(-tmpclipX/2 - (tmpOriginX-m_origin.x())), (float)(-m_size.y()/2.0), -1.0f)); mat4 tmpScale = etk::matScale(vec3(m_zoom, m_zoom, 1)); mat4 tmpProjection = etk::matOrtho(-tmpclipX/2, tmpclipX/2, -m_size.y()/2, m_size.y()/2, -1, 1); mat4 tmpMat = tmpProjection * tmpScale * tmpTranslate; // set internal matrix system : gale::openGL::setMatrix(tmpMat); //int64_t ___startTime = ewol::getTime(); onDraw(); //float ___localTime = (float)(ewol::getTime() - ___startTime) / 1000.0f; //EWOL_DEBUG(" Widget1 : " << ___localTime << "ms "); } else { EWOL_DEBUG("rasta.."); glViewport( m_origin.x(), m_origin.y(), m_size.x(), m_size.y()); mat4 tmpTranslate = etk::matTranslate(vec3(-m_size.x()/2, -m_size.y()/2, -1.0f)); mat4 tmpScale = etk::matScale(vec3(m_zoom, m_zoom, 1.0f)); mat4 tmpProjection = etk::matOrtho(-m_size.x()/2, m_size.x()/2, -m_size.y()/2, m_size.y()/2, -1, 1); mat4 tmpMat = tmpProjection * tmpScale * tmpTranslate; // set internal matrix system : gale::openGL::setMatrix(tmpMat); //int64_t ___startTime = ewol::getTime(); onDraw(); //float ___localTime = (float)(ewol::getTime() - ___startTime) / 1000.0f; //EWOL_DEBUG(" Widget2 : " << ___localTime << "ms "); } #endif gale::openGL::pop(); return; }
bool ewol::resource::DistanceFieldFont::addGlyph(const char32_t& _val) { std11::unique_lock<std11::recursive_mutex> lock(m_mutex); bool hasChange = false; if (m_font == nullptr) { return false; } // add the curent "char" GlyphProperty tmpchar; tmpchar.m_UVal = _val; egami::ImageMono imageGlyphRaw; egami::Image imageGlyphDistanceField; EWOL_DEBUG("Generate Glyph : " << _val); if (m_font->getGlyphProperty(SIZE_GENERATION, tmpchar) == true) { //EWOL_DEBUG("load char : '" << _val << "'=" << _val.get()); hasChange = true; // change line if needed ... if (m_lastGlyphPos.x() + tmpchar.m_sizeTexture.x()+m_borderSize*2.0 > m_data.getSize().x()) { m_lastGlyphPos.setX(1); m_lastGlyphPos += ivec2(0, m_lastRawHeigh); m_lastRawHeigh = 0; } while(m_lastGlyphPos.y()+tmpchar.m_sizeTexture.y()+m_borderSize*2.0 > m_data.getSize().y()) { ivec2 size = m_data.getSize(); size.setY(size.y()*2); m_data.resize(size, etk::Color<>(0)); // change the coordonate on the element in the texture for (size_t jjj = 0; jjj < m_listElement.size(); ++jjj) { m_listElement[jjj].m_texturePosStart *= vec2(1.0f, 0.5f); m_listElement[jjj].m_texturePosSize *= vec2(1.0f, 0.5f); } } m_textureBorderSize = vec2(m_borderSize/(float)m_data.getSize().x(), m_borderSize/(float)m_data.getSize().y() ); // draw the glyph m_font->drawGlyph(imageGlyphRaw, SIZE_GENERATION, tmpchar, m_borderSize); generateDistanceField(imageGlyphRaw, imageGlyphDistanceField); /* if (_val == 'Z') { for (int32_t yyy = 0; yyy < imageGlyphDistanceField.getSize().y(); ++yyy) { for (int32_t xxx = 0; xxx < imageGlyphDistanceField.getSize().x(); ++xxx) { std::cout << (int)(imageGlyphDistanceField.get(ivec2(xxx, yyy)).r()) << " "; } //std::cout << std::endl; } } */ m_data.insert(m_lastGlyphPos, imageGlyphDistanceField); // set image position tmpchar.m_texturePosStart.setValue( ((float)m_lastGlyphPos.x()+(m_borderSize*0.5f)) / (float)m_data.getSize().x(), ((float)m_lastGlyphPos.y()+(m_borderSize*0.5f)) / (float)m_data.getSize().y() ); tmpchar.m_texturePosSize.setValue( ((float)imageGlyphRaw.getSize().x()-m_borderSize) / (float)m_data.getSize().x(), ((float)imageGlyphRaw.getSize().y()-m_borderSize) / (float)m_data.getSize().y() ); // update the maximum of the line hight : if (m_lastRawHeigh < imageGlyphRaw.getSize().y()) { // note : +1 is for the overlapping of the glyph (Part 2) m_lastRawHeigh = imageGlyphRaw.getSize().y()+1; } // note : +1 is for the overlapping of the glyph (Part 3) // update the Bitmap position drawing : m_lastGlyphPos += ivec2(imageGlyphRaw.getSize().x()+1, 0); } else { EWOL_WARNING("Did not find char : '" << _val << "'=" << _val); tmpchar.setNotExist(); } m_listElement.push_back(tmpchar); //m_font[iii]->display(); // generate the kerning for all the characters : if (tmpchar.exist() == true) { // TODO : set the kerning back ... //m_font[iii]->generateKerning(m_size, m_listElement[iii]); } if (hasChange == true) { flush(); //egami::store(m_data, "fileFont.bmp"); // ==> for debug test only ... } return hasChange; }