ctx
===

ctx is a vector ui engine and protocol for local and remote interactive vector
graphics. 

For rendering it uses a portable, configurable and resource efficient software
rasterizer, that runs on devices ranging from various 32bit microcontrollers to
phones or laptops, SPI displays and eink to floating point RGB and CMYK, with
capabilties to use subpixel rendering, rendering shared between main thread and
a rendering thread, automatic tiled change detection, and compression, between
frames.

In addition to providing rasterization the protocol and library provided by ctx
provides events handling for touch/mouse (including coordinate transforms) and
buttons/keyboard inputs.

Interactive applications using ctx generally follow this pattern:

///////////////////////////////////////////////////////////////////

#include "ctx.h"

typedef struct AnimState {
  float x;
  int playing;
} AnimState;

void exit_cb (CtxEvent *e, void *a, void *b)
{
  ctx_exit (e->ctx); 
}

void toggle_playing_cb (CtxEvent *e, void *a, void *b)
{
  AnimState *state = a;
  state->playing = !state->playing;
  ctx_queue_draw (e->ctx);
}

void anim_loop (Ctx *ctx, float delta_s, void *user_data)
{
  AnimState *state = user_data;
  float width  = ctx_width (ctx);
  float height = ctx_height (ctx);
  float em     = height * 0.2f;

  if (delta_s > 0.2) // ignore large delta-s we were probably paused
    delta_s = 0.0f;

  ctx_rgba (ctx, 0.0f,0.0f,0.0f,1.0f);
  ctx_paint (ctx);

  ctx_font_size (ctx, em);

  ctx_move_to (ctx, state->x, height * 0.5f);
  ctx_rgba (ctx, 1.0f,1.0f,0.2f,1.0f);
  ctx_text (ctx, "hello!");

  float text_width = ctx_text_width (ctx, "hello!");

  ctx_logo (ctx, state->x + 1.3 * em, height * 0.75, 2.0 * em);

  if (state->playing)
  {
    state->x += delta_s * em;  // move at font_size per second
    if (state->x > width)
      state->x = -text_width;
    ctx_queue_draw (ctx); // neccesary for ctx to know state is dirty and
                          // needs redraw
  }

  ctx_add_key_binding(ctx, "escape", "exit", "quit application", exit_cb, NULL);  
  ctx_add_key_binding(ctx, "space", "toggle playing", "toggle playing", toggle_playing_cb, state);  
}

int main (int argc, const char **argv)
{
  AnimState state;
  state.x = 0.0f;
  state.playing = 1;

  // you can pass in a ctx context instead of NULL - or eve reimplement
  // what ctx_main does yourself

  int ret = ctx_main (NULL, anim_loop, &state);

  // destruct state

  return ret;
}

///////////////////////////////////


for more examples look in the bin folder of the ctx release as well as the git repository.
