diff --git a/examples/Makefile b/examples/Makefile index 0ef85508b..00b8acafb 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -6,6 +6,7 @@ SHELL = /bin/sh # Executables ALL = browser-simple$(EXEEXT) \ + cairo-draw-x$(EXEEXT) \ chart-simple$(EXEEXT) \ draggable-group$(EXEEXT) \ howto-add_fd-and-popen$(EXEEXT) \ @@ -44,6 +45,14 @@ ALL = browser-simple$(EXEEXT) \ # default target -- build everything default all: $(ALL) +# Special rules for building cairo app +cairo-draw-x.o: cairo-draw-x.cxx + @echo "*** Compile $<..." + $(CXX) -I.. $(CXXFLAGS_CAIRO) -c $< -o $@ +cairo-draw-x$(EXEEXT): cairo-draw-x.o + @echo "*** Link $<..." + $(CXX) $< $(LINKFLTK) $(LINKFLTK_CAIRO) -o $@ + # clean everything clean: $(RM) $(ALL) diff --git a/examples/Makefile.FLTK b/examples/Makefile.FLTK index 52b72993a..902797c59 100644 --- a/examples/Makefile.FLTK +++ b/examples/Makefile.FLTK @@ -16,13 +16,15 @@ ifeq '$(OS)' "Windows_NT" EXEEXT = .exe endif -FLTKCONFIG = ../fltk-config -CXX = $(shell $(FLTKCONFIG) --cxx) -CXXFLAGS = $(shell $(FLTKCONFIG) --cxxflags) -Wall -I. -LINKFLTK = $(shell $(FLTKCONFIG) --ldstaticflags) -LINKFLTK_GL = $(shell $(FLTKCONFIG) --use-gl --ldstaticflags) -LINKFLTK_IMG = $(shell $(FLTKCONFIG) --use-images --ldstaticflags) -LINKFLTK_ALL = $(shell $(FLTKCONFIG) --use-images --use-gl --ldstaticflags) +FLTKCONFIG = ../fltk-config +CXX = $(shell $(FLTKCONFIG) --cxx) +CXXFLAGS = $(shell $(FLTKCONFIG) --cxxflags) -Wall -I. +LINKFLTK = $(shell $(FLTKCONFIG) --ldstaticflags) +LINKFLTK_GL = $(shell $(FLTKCONFIG) --use-gl --ldstaticflags) +LINKFLTK_IMG = $(shell $(FLTKCONFIG) --use-images --ldstaticflags) +LINKFLTK_ALL = $(shell $(FLTKCONFIG) --use-images --use-gl --ldstaticflags) +CXXFLAGS_CAIRO = $(shell $(FLTKCONFIG) --use-cairo --cxxflags) +LINKFLTK_CAIRO = $(shell $(FLTKCONFIG) --use-cairo --ldstaticflags) .SUFFIXES: .cxx .h .fl .o $(EXEEXT) # HOW TO COMPILE --- /dev/null 2021-12-02 19:01:23.965333243 -0800 +++ examples/cairo-draw-x.cxx 2021-12-31 17:24:32.719127071 -0800 @@ -0,0 +1,58 @@ +// +// Simple demo of drawing an "X" in Cairo (antialiased lines) +// +// Copyright 1998-2021 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// https://www.fltk.org/COPYING.php +// +// Please see the following page on how to report bugs and issues: +// +// https://www.fltk.org/bugs.php +// + +#include // includes + +#ifdef FLTK_HAVE_CAIRO // Builds example code only if cairo enabled +#include + +// Cairo rendering cb called during Fl_Cairo_Window::draw() +static void my_cairo_draw_cb(Fl_Cairo_Window *window, cairo_t *cr) { + const double xmax = (window->w() - 1); + const double ymax = (window->h() - 1); + + // Draw green "X" + // Draws an X to four corners of resizable window. + // See Fl_Cairo_Window docs for more info. + // + cairo_set_antialias(cr, CAIRO_ANTIALIAS_BEST); // use best antialiasing + cairo_set_line_width(cr, 1.00); // line width for drawing + cairo_set_source_rgb(cr, 1.0, 0.5, 0.0); // orange + cairo_move_to(cr, 0.0, 0.0); cairo_line_to(cr, xmax, ymax); // draw diagonal "\" + cairo_move_to(cr, 0.0, ymax); cairo_line_to(cr, xmax, 0.0); // draw diagonal "/" + cairo_stroke(cr); // stroke the lines +} + +int main(int argc, char **argv) { + Fl_Cairo_Window window(300, 300, "Cairo Draw 'X'"); + window.color(FL_BLACK); // cairo window's default bg color + window.size_range(50,50,-1,-1); // allow resize 50,50 and up + window.resizable(&window); // allow window to be resized + window.set_draw_cb(my_cairo_draw_cb); // draw callback for cairo drawing + window.show(argc, argv); + return Fl::run(); +} + +// The code that follows just allows the example to build even if cairo wasn't enabled. +#else // (!FLTK_HAVE_CAIRO) +#include +int main(int argc, char **argv) { + fl_message_title("This program needs a Cairo enabled FLTK library"); + fl_message("Please configure FLTK with Cairo enabled (--enable-cairo or --enable-cairoext)\n" + "or one of the CMake options OPTION_CAIRO or OPTION_CAIROEXT, respectively."); + return 0; +} +#endif // (FLTK_HAVE_CAIRO)