![]() | ![]() | ![]() | 9 Writing ipelets |
An ipelet is a dynamically loaded library (DLL), that you place on
Ipe's ipelet search path. Ipe loads all DLLs it can find on that path
during start-up. The DLL has to be written in C++, and must export a
function NewIpelet
that creates an object derived from the
class Ipelet
(defined in ipelet.h). Here is minimal
ipelet implementation:
#include "ipelet.h" class MyIpelet : public Ipelet { public: virtual int IpelibVersion() const { return IPELIB_VERSION; } virtual const char *Label() const { return "My label"; } virtual void Run(IpePage *page, IpeletHelper *helper); }; void MyIpelet::Run(int function, IpePage *page, IpeletHelper *helper) { // this is where you do all the work } IPELET_DECLARE Ipelet *NewIpelet() { return new MyIpelet; }When the ipelet is executed, Ipe hands it a pointer to the current page of the document. The ipelet can examine the selected objects, and modify the page in any way it wishes. It can also request services from the Ipe application through the
IpeHelper
object, for
instance to display a message in the status bar, to pop up message
boxes, to obtain input from the user, etc. Through the
IpeHelper
, it is also possible to access the complete document
(for instance to write an ipelet that allows the user to reorganize
the pages of the document), or to access some Ipe settings.
The Ipelib documentation in HTML-format is here. You may want to have a look at
the standard ipelets. Kgon, for instance, is a minimal ipelet
that you can use as the basis for your own development.
Goodies is an example of an ipelet that contains more than one
function--it also needs to implement the member functions
NumFunctions
and SubLabel
. Note that it is possible for
ipelets to define keyboard shortcuts (the Align ipelet does
that, for instance), but in general it is not a good idea to do that
for ipelets you plan to make available for others.
-mno-cygwin
option (it didn't always work for me--please let
me know if you find out why).
The Ipe Windows distribution contains the necessary header files and the library to compile ipelets, as well as the source of the "kgon" and "goodies" ipelets as examples. To compile the "kgon" example, open a command shell, make sure MinGW g++ is on your path, and say:
g++ -c -O2 -DWIN32 -fno-exceptions -fno-rtti -Iinclude kgon.cpp g++ -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import \ -Wl,-enable-runtime-pseudo-reloc -Wl,-s -shared -o kgon.dll kgon.o \ -Llib -lipePlace the resulting kgon.dll in the ipelets subdirectory, and restart Ipe.
![]() | ![]() | ![]() | 9 Writing ipelets |