ewol/ewol_tutorial_resources.html

194 lines
16 KiB
HTML

<!-- HTML header for doxygen 1.8.8-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- For Mobile Devices -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta name="generator" content="Doxygen 1.8.12"/>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<title>Ewol: Ewol Widget in OpenGl: EWOL: Resources management</title>
<!--<link href="tabs.css" rel="stylesheet" type="text/css"/>-->
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="doxy-boot.js"></script>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand">Ewol: Ewol Widget in OpenGl 0.10.0</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="index.html">Main&nbsp;Page</a></li>
<li><a href="pages.html">Related&nbsp;Pages</a></li>
<li><a href="namespaces.html">Namespaces</a></li>
<li><a href="annotated.html">Classes</a></li>
<li><a href="files.html">Files</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Link-libs<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="http://HeeroYui.github.io/lutin">lutin</a></li>
<li><a href="http://atria-soft.github.io/ewol">ewol</a></li>
<li><a href="http://atria-soft.github.io/echrono">echrono</a></li>
<li><a href="http://atria-soft.github.io/etk">etk</a></li>
<li><a href="http://atria-soft.github.io/ejson">ejson</a></li>
<li><a href="http://atria-soft.github.io/exml">exml</a></li>
<li><a href="http://atria-soft.github.io/esvg">esvg</a></li>
<li><a href="http://atria-soft.github.io/egami">egami</a></li>
<li><a href="http://atria-soft.github.io/gale">gale</a></li>
<li><a href="http://atria-soft.github.io/ege">ege</a></li>
<li><a href="http://atria-soft.github.io/elog">elog</a></li>
<li><a href="http://atria-soft.github.io/ememory">ememory</a></li>
<li><a href="http://atria-soft.github.io/enet">enet</a></li>
<li><a href="http://atria-soft.github.io/eproperty">eproperty</a></li>
<li><a href="http://atria-soft.github.io/esignal">esignal</a></li>
<li><a href="http://atria-soft.github.io/etranslate">etranslate</a></li>
<li><a href="http://atria-soft.github.io/zeus">zeus</a></li>
<li><a href="http://musicdsp.github.io/audio-ess">audio-ess</a></li>
<li><a href="http://musicdsp.github.io/audio">audio</a></li>
<li><a href="http://musicdsp.github.io/audio-drain">audio-drain</a></li>
<li><a href="http://musicdsp.github.io/audio-orchestra">audio-orchestra</a></li>
<li><a href="http://musicdsp.github.io/audio-river">audio-river</a></li>
</ul>
</li>
</ul>
<div id="search-box" class="input-group">
<div class="input-group-btn">
<button aria-expanded="false" type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="glyphicon glyphicon-search"></span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="#">All</a></li>
<li><a href="#">Classes</a></li>
<li><a href="#">Namespaces</a></li>
<li><a href="#">Files</a></li>
<li><a href="#">Functions</a></li>
<li><a href="#">Variables</a></li>
<li><a href="#">Typedefs</a></li>
<li><a href="#">Enumerations</a></li>
<li><a href="#">Enumerator</a></li>
<li><a href="#">Friends</a></li>
<li><a href="#">Macros</a></li>
<li><a href="#">Pages</a></li>
</ul>
</div>
<button id="search-close" type="button" class="close" aria-label="Close">
<span aria-hidden="true"></span>
</button>
<input id="search-field" class="form-control" accesskey="S" onkeydown="searchBox.OnSearchFieldChange(event);" placeholder="Search ..." type="text">
</div>
</div><!--/.nav-collapse -->
</div>
</nav>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div class="content" id="content">
<div class="container">
<div class="row">
<div class="col-sm-12 panel panel-default" style="padding-bottom: 15px;">
<div style="margin-bottom: 15px;margin-top: 60px;">
<!-- end header part -->
<!-- Generated by Doxygen 1.8.12 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">EWOL: Resources management </div> </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#ewol_tutorial_resources_objectif">Objectifs </a></li>
<li class="level1"><a href="#ewol_tutorial_resources_what">What is a resource: </a></li>
<li class="level1"><a href="#ewol_tutorial_resources_get">Get a resource: </a></li>
<li class="level1"><a href="#ewol_tutorial_resources_create">Create a new resource: </a><ul><li class="level2"><a href="#ewol_tutorial_resources_level">The Resource Level </a></li>
</ul>
</li>
</ul>
</div>
<div class="textblock"><p>Constructor MyObj(void) : propertyConfig(this, "file", "DATA:ExapleConfig.json", "no desc", &amp;appl::MyObj::onChangePropertyFile), m_configValId(-1) { // nothing to do.. } void <a class="elRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/namespaceetk.html#aa87d94d7a27bd41c9982fe0ba83d6f88">init()</a> { ewol::Object::init(); onChangePropertyFile(); } public: //!</p>
<h1><a class="anchor" id="ewol_tutorial_resources_objectif"></a>
Objectifs </h1>
<ul>
<li>Understand what is a resource</li>
<li>Use resources</li>
</ul>
<h1><a class="anchor" id="ewol_tutorial_resources_what"></a>
What is a resource: </h1>
<p>A resource is an unique element that can be used by many element like:</p><ul>
<li>An image (special resolution)</li>
<li>A configuration file</li>
<li>An application manager (special case)</li>
<li>A sound file</li>
<li>...</li>
</ul>
<p>A resource have an other objective, form some platform, the graphic interface can be stopped, then we need to reload texture in the graphic inteface... Then the texture is an other graphic interface.</p>
<h1><a class="anchor" id="ewol_tutorial_resources_get"></a>
Get a resource: </h1>
<p>For this example we will load a configuration file: </p><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="_object_8hpp.html">ewol/object/Object.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="_config_file_8hpp.html">ewol/resource/ConfigFile.hpp</a>&gt;</span></div><div class="line"><span class="keyword">namespace </span>appl {</div><div class="line"> <span class="keyword">class </span>MyObj : <span class="keyword">public</span> <a class="code" href="classewol_1_1_object.html">ewol::Object</a> {</div><div class="line"> <span class="keyword">public</span>:</div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/eproperty.tag:http://atria-soft.github.io/eproperty/" href="http://atria-soft.github.io/eproperty/classeproperty_1_1_value.html">eproperty::Value&lt;std::string&gt;</a> propertyConfig;</div><div class="line"> <span class="keyword">private</span>:</div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/ememory.tag:http://atria-soft.github.io/ememory/" href="http://atria-soft.github.io/ememory/classememory_1_1_shared_ptr.html">ememory::SharedPtr&lt;ewol::resource::ConfigFile&gt;</a> m_config;</div><div class="line"> int32_t m_configValId;</div><div class="line"> <span class="keyword">protected</span>:</div><div class="line"> <span class="keyword">virtual</span> ~MyObj() { }</div><div class="line"> DECLARE_FACTORY(MyObj);</div><div class="line"> <span class="keyword">public</span>:</div><div class="line"> <span class="keywordtype">void</span> onChangePropertyFile() {</div><div class="line"> m_config = ewol::resource::ConfigFile::create(*propertyConfig);</div><div class="line"> <span class="keywordflow">if</span> (m_config != <span class="keyword">nullptr</span>) {</div><div class="line"> m_configValId = m_config-&gt;request(<span class="stringliteral">&quot;exampleConfigName&quot;</span>);</div><div class="line"> }</div><div class="line"> }</div><div class="line"> <span class="keywordtype">void</span> process() {</div><div class="line"> <span class="keywordtype">double</span> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/ejson.tag:http://atria-soft.github.io/ejson/" href="http://atria-soft.github.io/ejson/namespaceejson.html#a6a37b3ae20a2b7bc207b268ab1439709a2063c1608d6e0baf80249c42e2be5804">value</a> = m_config-&gt;getNumber(m_configValId);</div><div class="line"> APPL_DEBUG(<span class="stringliteral">&quot;example value : &quot;</span> &lt;&lt; value);</div><div class="line"> }</div><div class="line"> }</div><div class="line">}</div></div><!-- fragment --><h1><a class="anchor" id="ewol_tutorial_resources_create"></a>
Create a new resource: </h1>
<p>A resource is a generic gale::Resource:</p><ul>
<li>DECLARE_RESOURCE_FACTORY(className) To declare a resource with no name (unique for every creation)</li>
<li>DECLARE_RESOURCE_NAMED_FACTORY(className) To create a resource that have a specific name. When created, we will find the previous resource with the specify name in the fanctory.</li>
<li>DECLARE_RESOURCE_SINGLE_FACTORY(className,uniqueName) This is to have a unique resource for all the application (name is specify in the Macro)</li>
</ul>
<p>we have now some specific interface to compleate (if needed):</p>
<h2><a class="anchor" id="ewol_tutorial_resources_level"></a>
The Resource Level </h2>
<p>The resources can be reloaded, then we need to reaload in the good order (level [0 .. 5])</p>
<p>The resources are loaded fron 0 to 5.</p>
<p>Then for basic resource:</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;ewol/object/Resource.hpp&gt;</span></div><div class="line"><span class="keyword">namespace </span>appl {</div><div class="line"> <span class="keyword">class </span>MyResource : <span class="keyword">public</span> gale::Resource {</div><div class="line"> <span class="keyword">protected</span>:</div><div class="line"> MyResource() :</div><div class="line"> m_configValId(-1) {</div><div class="line"> m_resourceLevel = 4;</div><div class="line"> addObjectType(<span class="stringliteral">&quot;appl::MyResource&quot;</span>);</div><div class="line"> }</div><div class="line"> <span class="keywordtype">void</span> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/elog.tag:http://atria-soft.github.io/elog/" href="http://atria-soft.github.io/elog/namespaceelog.html#a1005ac82c94e09b499d29b70a98cd5cc">init</a>(<span class="keyword">const</span> std::string&amp; _name) {</div><div class="line"> ewol::Resource::init(_name);</div><div class="line"> }</div><div class="line"> <span class="keyword">public</span>:</div><div class="line"> <span class="keyword">virtual</span> ~MyResource() { }</div><div class="line"> DECLARE_RESOURCE_NAMED_FACTORY(MyResource);</div><div class="line"> }</div><div class="line">}</div></div><!-- fragment --><p>Now we need to implement somme functions:</p>
<p>To send data on the hardware (openGL): </p><div class="fragment"><div class="line"><span class="keywordtype">void</span> updateContext();</div></div><!-- fragment --><p>To remove data from the the hardware (openGL): </p><div class="fragment"><div class="line"><span class="keywordtype">void</span> removeContext();</div></div><!-- fragment --><p>When loose hardware (juste update internal state the hardware is no more present): </p><div class="fragment"><div class="line"><span class="keywordtype">void</span> removeContextToLate();</div></div><!-- fragment --><p>When user request to reload all resources (can be usefull when using file type : THEME:GUI:xxx) </p><div class="fragment"><div class="line"><span class="keywordtype">void</span> reload();</div></div><!-- fragment --> </div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.8-->
<!-- start footer part -->
</div>
</div>
</div>
</div>
</div>
<hr class="footer"/><address class="footer"><small>
Generated on Mon Oct 24 2016 15:35:52 for Ewol: Ewol Widget in OpenGl by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.12
</small></address>
</body>
</html>