1. What is this document?

This document is the index to the djnn libraries recipes. This cookbook is made for programmers who wish to learn from examples. It contains fragments of code that each show how to a achieve a given task: drawing a rectangle, opening multiple windows, connecting components, etc. Most examples are executable as is, some are not. Some address basic needs, while others are more complex recipes.

This cookbook is structured by topics, with no progression order. Do not hesitate to go directly to the topic that you need. In particular, one of the first questions that many programmers ask is how to connect djnn with existing code, and this is addressed at the end of this cookbook.

You can access the examples by following the links. In theory, your browser should think that the examples are pure text and display them. In practice, you might need to save them to disk and open them with a text editor. Some examples are executable. If you want to test them, you will need to save them to disk, compile and execute them, supposing that djnn is properly installed on your computer.

2. Drawing

2.1. Windowing

How to open windows on the screen.

2.2. Graphical objects

How to create shapes, gradients, etc.

2.3. Loading graphics

  • A SVG loader: How to load graphical components from a SVG file.

3. Behaviors

4. Input

5. Display

How to manage physical displays.

6. Power

How to track and use the status of the power sources on the computer.

7. Communication

7.1. Ivy

How to use the Ivy message bus.

8. Creating the component tree

8.1. Building components

- To be written: creating a simple component

8.2. Importing components

- Importing external components: Combining components from an XML file and a binary library file.

9. Modules and plugins

How to dynamically load modules and libraries.

10. Adding extensions in C

Whether you are an application programmer with existing code or an djnn programmer wishing to extend your djnn environment with new component types, you will need to connect djnn with your existing code. This amounts to creating bridges between djnn and your code, so that djnn sees your code as extra djnn components, and your code sees djnn a whatever it wants. Depending on the complexity of your code and how you want to access it from djnn bindings, FSMs and other control structures, you will create a single large component or a more detailed collection of components. The more refined your component model is, the more you will be able to take advantage from the djnn model.

Creating components to wrap C code can be done either directly in your application code, or by creating a new djnn module.

10.1. Creating native components

  • A random beat: Wrapping C code as an djnn event source (here, a clock that skips beats), so that your code controls the execution of djnn components.

  • A random counter: Wrapping C code as an djnn component with a numerical property that can be used to feed similar properties to other djnn components.

  • Creating and using a beeper: Wrapping C code as components that can be activated from other djnn components.

  • Creating and using a message logger: Wrapping C code as components with a property that can be fed from similar properties of other djnn components.

  • A parity tester: Creating a native data flow filter, aimed at being activated from djnn components, computing results, then making them available to otehr djnn components.

10.2. Creating modules

  • Creating a module: A dummy module that implements two useless component classes, and their parsing from XML. This module is structured as if it was going to be integrated in the djnn sources, but you do not have to do this.

10.3. Registering with the main loop

  • Tracking file contents: A source component that registers file handles with the system relay, and updates a text property with the additional file contents.

  • A random clock: Registering a timer with the main loop to create an event source.

10.4. Using djnn as a traditional UI toolkit

You can create djnn components and manipulate them from your C code without concerning yourself with the component model of djnn. Just activate components and set properties just like you would with a more traditional UI toolkit.

10.5. Combining with other toolkits

You can combine djnn components and widgets from other toolkits to create your applications. This also applies to non-UI toolkits such as networking frameworks.