diff --git a/uppdev/GTK/GTK.upp b/uppdev/GTK/GTK.upp index 4cef0512f..22d31868b 100644 --- a/uppdev/GTK/GTK.upp +++ b/uppdev/GTK/GTK.upp @@ -1,32 +1,33 @@ -uses - CtrlLib; - -library - gtk-x11-2.0, - gdk-x11-2.0, - atk-1.0, - gdk_pixbuf-2.0, - m, - pangocairo-1.0, - fontconfig, - Xext, - Xrender, - Xinerama, - Xi, - Xrandr, - Xcursor, - Xfixes, - pango-1.0, - cairo, - X11, - gobject-2.0, - gmodule-2.0, - dl, - glib-2.0; - -file - t.iml, - test.cpp; - -mainconfig - "" = "GUI"; +uses + CtrlLib; + +library + gtk-x11-2.0, + gdk-x11-2.0, + atk-1.0, + gdk_pixbuf-2.0, + m, + pangocairo-1.0, + fontconfig, + Xext, + Xrender, + Xinerama, + Xi, + Xrandr, + Xcursor, + Xfixes, + pango-1.0, + cairo, + X11, + gobject-2.0, + gmodule-2.0, + dl, + glib-2.0; + +file + t.iml, + test.cpp; + +mainconfig + "" = "GUI"; + diff --git a/uppdev/GTK/init b/uppdev/GTK/init new file mode 100644 index 000000000..8e903ed72 --- /dev/null +++ b/uppdev/GTK/init @@ -0,0 +1,4 @@ +#ifndef _GTK_icpp_init_stub +#define _GTK_icpp_init_stub +#include "CtrlLib/init" +#endif diff --git a/uppdev/GtkApp/BackDraw.cpp b/uppdev/GtkApp/BackDraw.cpp new file mode 100644 index 000000000..092f6edd3 --- /dev/null +++ b/uppdev/GtkApp/BackDraw.cpp @@ -0,0 +1,25 @@ +#include "GtkApp.h" + +class BackDraw : public SystemDraw { +public: + virtual bool IsPaintingOp(const Rect& r) const; // TODO! + +protected: + Pixmap pixmap; + Size size; + Draw *painting; + Point painting_offset; + +public: + void Put(SystemDraw& w, int x, int y); + void Put(SystemDraw& w, Point p) { Put(w, p.x, p.y); } + + void Create(SystemDraw& w, int cx, int cy); + void Create(SystemDraw& w, Size sz) { Create(w, sz.cx, sz.cy); } + void Destroy(); + + void SetPaintingDraw(Draw& w, Point off) { painting = &w; painting_offset = off; } + + BackDraw(); + ~BackDraw(); +}; diff --git a/uppdev/GtkApp/ImageDraw.cpp b/uppdev/GtkApp/ImageDraw.cpp new file mode 100644 index 000000000..e06e06405 --- /dev/null +++ b/uppdev/GtkApp/ImageDraw.cpp @@ -0,0 +1,84 @@ +#include "GtkApp.h" + +void CairoImageDraw::Init(Size sz) +{ + isz = sz; + surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, isz.cx, isz.cy); + cr = cairo_create(surface); + alpha_surface = NULL; +} + +Draw& CairoImageDraw::Alpha() +{ + if(!alpha_surface) { + alpha_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, isz.cx, isz.cy); + alpha.cr = cairo_create(alpha_surface); + } + return alpha; +} + +void CairoImageDraw::FetchStraight(ImageBuffer& b) const +{ + cairo_surface_flush(surface); + byte *a = (byte *)cairo_image_surface_get_data(surface); + int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, isz.cx); + RGBA *t = b; + byte *aa = NULL; + if(alpha_surface) { + cairo_surface_flush(alpha_surface); + aa = (byte *)cairo_image_surface_get_data(alpha_surface); + } + for(int yy = 0; yy < isz.cy; yy++) { + RGBA *s = (RGBA *)a; + RGBA *e = s + isz.cx; + if(aa) { + RGBA *ss = (RGBA *)aa; + while(s < e) { + *t = *s++; + (t++)->a = (ss++)->r; + } + aa += stride; + } + else + while(s < e) { + *t = *s++; + (t++)->a = 255; + } + a += stride; + } +} + +CairoImageDraw::operator Image() const +{ + ImageBuffer img(isz); + FetchStraight(img); + Premultiply(img); + return img; +} + +Image CairoImageDraw::GetStraight() const +{ + ImageBuffer img(isz); + FetchStraight(img); + return img; +} + +CairoImageDraw::CairoImageDraw(Size sz) +{ + Init(sz); +} + +CairoImageDraw::CairoImageDraw(int cx, int cy) +{ + Init(Size(cx, cy)); +} + +CairoImageDraw::~CairoImageDraw() +{ + cairo_destroy(cr); + cairo_surface_destroy(surface); + if(alpha_surface) { + cairo_destroy(alpha.cr); + cairo_surface_destroy(alpha_surface); + } +}