Difference between revisions of "Creating a custom rendering routine"

From uGFX Wiki
Jump to: navigation, search
(The interface)
Line 2: Line 2:
  
 
== The interface ==
 
== The interface ==
Every widget provides an API call like the the following:
+
Every widget provides a function to submit a custom rendering function:
 +
<syntaxhighlight lang=c>
 +
void gwinSetCustomDraw(GHandle gh, CustomWidgetDrawFunction fn, void*param);
 +
</syntaxhighlight>
  
<syntaxhighlight lang=c>void gwinSetCustomDraw(GHandle gh, CustomWidgetDrawFunction fn, void *param);</syntaxhighlight>
+
The ''CustomWidgetDrawFunction'' is a typedef'ed function pointer:
The CustomWidgetDrawFunction is a typedef'ed function pointer:
+
<syntaxhighlight lang=c>
 +
typedef void (*CustomWidgetDrawFunction)(struct GWidgetObject* gw, void* param);
 +
</syntaxhighlight>
  
<syntaxhighlight lang=c>typedef void (*CustomWidgetDrawFunction)(struct GWidgetObject *gw, void *param);</syntaxhighlight>
+
The ''param'' parameter can be used to pass a custom parameter such as a file pointer in case of you're rendering routine needs to draw an image. However, in most of the cases, this parameter will be '''NULL'''.
The param parameter can be used to pass a custom parameter such as a file pointer. However, in most of the cases, this parameter will be '''NULL'''.
+
  
 
All the information required to write a custom render function for a widget, such as the position, size, state, text, fonts etc. can be obtained from the [[GHandle]].
 
All the information required to write a custom render function for a widget, such as the position, size, state, text, fonts etc. can be obtained from the [[GHandle]].
  
'''''Note:''' The pointer to the custom rendering routine can also be passed through the initialization struct. See above.''</br>
+
'''''Note:''' The pointer to the custom rendering routine can also be passed through the initialization struct. See above.''
 +
 
 
'''''Note:''' Do never use the <code>gwinDrawXxx()</code> calls inside a rendering routine as this would lock the widget again. Use <code>gdispDrawXxx()</code> instead ''
 
'''''Note:''' Do never use the <code>gwinDrawXxx()</code> calls inside a rendering routine as this would lock the widget again. Use <code>gdispDrawXxx()</code> instead ''

Revision as of 16:38, 21 June 2015

Every widget comes with a custom render interface. The default style in which a widget is drawn is very basic and minimalistic in order to make it run on the even lowest performance systems smoothly. However, the custom render interface allows you to submit your own rendering routines. This does not only provide a very flexible way to render a widget matching to your systems performance, but it gives you also the possibility to render a widget matching your applications style.

The interface

Every widget provides a function to submit a custom rendering function:

void gwinSetCustomDraw(GHandle gh, CustomWidgetDrawFunction fn, void*param);

The CustomWidgetDrawFunction is a typedef'ed function pointer:

typedef void (*CustomWidgetDrawFunction)(struct GWidgetObject* gw, void* param);

The param parameter can be used to pass a custom parameter such as a file pointer in case of you're rendering routine needs to draw an image. However, in most of the cases, this parameter will be NULL.

All the information required to write a custom render function for a widget, such as the position, size, state, text, fonts etc. can be obtained from the GHandle.

Note: The pointer to the custom rendering routine can also be passed through the initialization struct. See above.

Note: Do never use the gwinDrawXxx() calls inside a rendering routine as this would lock the widget again. Use gdispDrawXxx() instead