ok. capito come funziona sotto windows.
la portabilità sta nel fatto che "sono le api di disegno che lo sono"
la finestra me la creo come il sistema operativo vuole e (esempio in windows) mi limito a passargli i puntatori necessari per le superfici della finestra nella chiamata a on paint.
la velocità sembra discreta. un ciclo di pittura di 800*600 rettangoli a schermo mi è sembrato decentemente veloce. Alla fine io devo disegnare caratteri e ridisegnare continuamente le zone variate. Non arriverò mai a dover disegnare in blocco 480000 caratteri. se prendo uno schermo 1280*1024 usando come esempio un piccolo carattere box di 100 pixel (10*10) otterrei circa 13.000 caratteri. Su un 1600*1200 arriverei a 19200 caratteri.
Diciamo che le prestazioni sono buone.
Per ora vince cairo 1 a 0...
Il passo successivo sarà di vedere sotto aros come si comporta. A questo punto mi dovrò creare la mia brava finestra e vedere come interfacciarlo con cairo. Leggevo che sotto morphos è stato usato per webkit (quindi owb??)... sperem...
aggiungo a titolo di esempio il codice per la realizzazione di un rettangolo
#include <windows.h>
#include <cairo.h>
#include <cairo-win32.h>
#include<stdlib.h>
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "CodeBlocksWindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Code::Blocks Template Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nCmdShow);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT Ps;
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
case WM_PAINT:
int i,j;
hDC = BeginPaint(hwnd, &Ps);
// TODO: Add any drawing code here...
cairo_surface_t *surface;
cairo_t *cr;
//FUNZIONE WINDOWS PER RESTITUIRE IL PUNTATORE DEL CONTESTO FINESTRA WIN32 PER CREARE
//CONTESTO (LA SUPERFICIE) SULLA QUALE CAIRO DISEGNA
surface = cairo_win32_surface_create(hDC);
cr = cairo_create(surface);
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_rectangle (cr, 20+i,20+j,120+i,80+j);
cairo_fill (cr);
cairo_destroy(cr);
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}