mirror of
https://gitlab.redox-os.org/redox-os/redox.git
synced 2026-06-24 05:44:17 +08:00
Merge branch 'CairoGraphics' into 'master'
Cairo Graphics support with C-Example See merge request redox-os/cookbook!197
This commit is contained in:
commit
574b12be63
43
recipes/cairo/recipe.sh
Executable file
43
recipes/cairo/recipe.sh
Executable file
@ -0,0 +1,43 @@
|
||||
VERSION="1.16.0"
|
||||
TAR=https://www.cairographics.org/releases/cairo-$VERSION.tar.xz
|
||||
BUILD_DEPENDS=(zlib pixman freetype libpng)
|
||||
|
||||
function recipe_version {
|
||||
echo "$VERSION"
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_update {
|
||||
echo "skipping update"
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_build {
|
||||
#Workaround to disable the not redox compatible tests
|
||||
printf "all:\n\ninstall:\n" > ./test/Makefile.in
|
||||
printf "all:\n\ninstall:\n" > ./perf/Makefile.in
|
||||
|
||||
sysroot="$(realpath ../sysroot)"
|
||||
export LDFLAGS="-L$sysroot/lib"
|
||||
export CPPFLAGS="-I$sysroot/include"
|
||||
CFLAGS="-DCAIRO_NO_MUTEX=1" ./configure --host=${HOST} --prefix=/ --enable-xlib=no --enable-script=no --enable-interpreter=no
|
||||
make
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_test {
|
||||
echo "skipping test"
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_clean {
|
||||
make clean
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_stage {
|
||||
echo "skipping stage"
|
||||
dest="$(realpath $1)"
|
||||
make DESTDIR="$dest" install
|
||||
skip=1
|
||||
}
|
||||
129
recipes/cairodemo/cairodemo.c
Executable file
129
recipes/cairodemo/cairodemo.c
Executable file
@ -0,0 +1,129 @@
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <cairo/cairo.h>
|
||||
#include <orbital.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265
|
||||
#endif
|
||||
|
||||
static int width = 800;
|
||||
static int height = 600;
|
||||
|
||||
static void
|
||||
travel_path (cairo_t *cr)
|
||||
{
|
||||
|
||||
cairo_pattern_t *pat;
|
||||
|
||||
pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0);
|
||||
cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
|
||||
cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
|
||||
cairo_rectangle (cr, 0, 0, 256, 256);
|
||||
cairo_set_source (cr, pat);
|
||||
cairo_fill (cr);
|
||||
cairo_pattern_destroy (pat);
|
||||
|
||||
pat = cairo_pattern_create_radial (115.2, 102.4, 25.6,
|
||||
102.4, 102.4, 128.0);
|
||||
cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
|
||||
cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
|
||||
cairo_set_source (cr, pat);
|
||||
cairo_arc (cr, 128.0, 128.0, 76.8, 0, 2 * M_PI);
|
||||
cairo_fill (cr);
|
||||
cairo_pattern_destroy (pat);
|
||||
|
||||
|
||||
double x = 305.6, /* parameters like cairo_rectangle */
|
||||
y = 25.6,
|
||||
width = 204.8,
|
||||
height = 204.8,
|
||||
aspect = 1.0, /* aspect ratio */
|
||||
corner_radius = height / 10.0; /* and corner curvature radius */
|
||||
|
||||
double radius = corner_radius / aspect;
|
||||
double degrees = M_PI / 180.0;
|
||||
|
||||
cairo_new_sub_path (cr);
|
||||
cairo_arc (cr, x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees);
|
||||
cairo_arc (cr, x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees);
|
||||
cairo_arc (cr, x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees);
|
||||
cairo_arc (cr, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
|
||||
cairo_close_path (cr);
|
||||
|
||||
cairo_set_source_rgb (cr, 0.5, 0.5, 1);
|
||||
cairo_fill_preserve (cr);
|
||||
cairo_set_source_rgba (cr, 0.5, 0, 0, 0.5);
|
||||
cairo_set_line_width (cr, 10.0);
|
||||
cairo_stroke (cr);
|
||||
|
||||
|
||||
double xc = 128.0;
|
||||
double yc = 128.0;
|
||||
radius = 100.0;
|
||||
double angle1 = 45.0 * (M_PI/180.0); /* angles are specified */
|
||||
double angle2 = 180.0 * (M_PI/180.0); /* in radians */
|
||||
|
||||
cairo_set_line_width (cr, 10.0);
|
||||
cairo_arc (cr, xc, yc, radius, angle1, angle2);
|
||||
cairo_stroke (cr);
|
||||
|
||||
/* draw helping lines */
|
||||
cairo_set_source_rgba (cr, 1, 0.2, 0.2, 0.6);
|
||||
cairo_set_line_width (cr, 6.0);
|
||||
|
||||
cairo_arc (cr, xc, yc, 10.0, 0, 2*M_PI);
|
||||
cairo_fill (cr);
|
||||
|
||||
cairo_arc (cr, xc, yc, radius, angle1, angle1);
|
||||
cairo_line_to (cr, xc, yc);
|
||||
cairo_arc (cr, xc, yc, radius, angle2, angle2);
|
||||
cairo_line_to (cr, xc, yc);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
|
||||
static void
|
||||
draw (cairo_surface_t *surface)
|
||||
{
|
||||
cairo_t *cr;
|
||||
cr = cairo_create (surface);
|
||||
travel_path (cr);
|
||||
cairo_destroy (cr);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
void * window = orb_window_new(-1, -1, width, height, "CairoDemo");
|
||||
|
||||
//Cairo
|
||||
uint32_t * frame_data = orb_window_data(window);
|
||||
cairo_surface_t *surface = cairo_image_surface_create_for_data((uint8_t*) frame_data, CAIRO_FORMAT_ARGB32, width, height, cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width));
|
||||
cairo_create(surface);
|
||||
draw (surface);
|
||||
|
||||
orb_window_sync(window);
|
||||
|
||||
char running = 1;
|
||||
while (running) {
|
||||
void * event_iter = orb_window_events(window);
|
||||
|
||||
OrbEventOption event_option;
|
||||
do {
|
||||
event_option = orb_events_next(event_iter);
|
||||
switch (event_option.tag) {
|
||||
case OrbEventOption_Quit:
|
||||
running = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (running && event_option.tag != OrbEventOption_None);
|
||||
|
||||
orb_events_destroy(event_iter);
|
||||
}
|
||||
orb_window_destroy(window);
|
||||
return 0; /* ANSI C requires main to return int. */
|
||||
}
|
||||
|
||||
44
recipes/cairodemo/recipe.sh
Executable file
44
recipes/cairodemo/recipe.sh
Executable file
@ -0,0 +1,44 @@
|
||||
BUILD_DEPENDS=(liborbital cairo pixman zlib libpng freetype)
|
||||
|
||||
function recipe_version {
|
||||
printf "1.0.0"
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_update {
|
||||
echo "skipping update"
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_prepare {
|
||||
rm -rf source
|
||||
mkdir source
|
||||
cp cairodemo.c source
|
||||
}
|
||||
|
||||
function recipe_build {
|
||||
sysroot="$(realpath ../sysroot)"
|
||||
export LDFLAGS="-L$sysroot/lib"
|
||||
export CPPFLAGS="-I$sysroot/include"
|
||||
set -x
|
||||
"${CXX}" -I "$sysroot/include" -L "$sysroot/lib" cairodemo.c -o cairodemo -lorbital -lcairo -lpixman-1 -lfreetype -lpng -lz -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -lm
|
||||
set +x
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_test {
|
||||
echo "skipping test"
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_clean {
|
||||
make clean
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_stage {
|
||||
dest="$(realpath $1)"
|
||||
mkdir -pv "$dest/bin"
|
||||
cp -v "cairodemo" "$dest/bin/cairodemo"
|
||||
skip=1
|
||||
}
|
||||
@ -16,7 +16,7 @@ function recipe_build {
|
||||
sysroot="$(realpath ../sysroot)"
|
||||
export LDFLAGS="-L$sysroot/lib"
|
||||
export CPPFLAGS="-I$sysroot/include"
|
||||
./autogen.sh
|
||||
#./autogen.sh
|
||||
chmod +w config.sub
|
||||
wget -O config.sub http://git.savannah.gnu.org/cgit/config.git/plain/config.sub
|
||||
./configure --host=${HOST} --prefix='/'
|
||||
|
||||
36
recipes/pixman/recipe.sh
Executable file
36
recipes/pixman/recipe.sh
Executable file
@ -0,0 +1,36 @@
|
||||
VERSION="0.36.0"
|
||||
TAR=https://www.cairographics.org/releases/pixman-$VERSION.tar.gz
|
||||
|
||||
function recipe_version {
|
||||
echo "$VERSION"
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_update {
|
||||
echo "skipping update"
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_build {
|
||||
sysroot="$(realpath ../sysroot)"
|
||||
./configure --host=${HOST} --prefix=/
|
||||
make -j"$(nproc)"
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_test {
|
||||
echo "skipping test"
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_clean {
|
||||
make clean
|
||||
skip=1
|
||||
}
|
||||
|
||||
function recipe_stage {
|
||||
echo "skipping stage"
|
||||
dest="$(realpath $1)"
|
||||
make DESTDIR="$dest" install
|
||||
skip=1
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user