• Antelope Release 5.9 Mac OS X 10.13.2 2019-05-01

 

NAME

BQGlyphs - BRTT Qt graphics extension for a multi-glyph graphical object

SYNOPSIS


$(QTNATIVELIBS) -lbqplot_native -lbanner -lbrttutil -lbumapdata $(DBLIBS) $(TRLIBS)

#include "BQ.h"

DESCRIPTION

A BQGlyphs object can contain and manage an arbitrary number of BQGlyph objects. These objects act as master configurators and managers of BQGlyph objects. Each BQGlyphs object is registered with the master BQViewport as a single object and can be assigned to a BQLayer in the same way as other bqplot graphics item objects. BQGlyphs also provide default graphics context values for its BQGlyph objects, default mouse interaction with its BQGlyph objects and BQGlyphs objects can use BQGlyphsGraphicsContext(3) objects to provide convenient key-value and parameter file based configurators for complex graphics context definitions.

INHERITS FROM

BQViewportItem

CONSTRUCTOR

BQGlyphs(BQViewport *master, BQGlyphsGraphicsContext *ggc = NULL);

Where "master" is the bqplot BQViewport item that acts as the master for the BQGlyph object and ggc is an optional BQGlyphsGraphicsContext object that can be associated with this BQGlyphs object and can be used to configure its BQGlyph objects.

METHODS INHERITED FROM BQViewportItem

BQGlyphs METHODS

EXAMPLE

Following is example code that illustrates the use of BQGlyphs, BQGlyph and GraphicsContext objects for rapid animated display of a set of display glyphs.

% cat Makefile
BIN=        bqplot_test_glyphs

fflags=
ldflags=

cflags = -g
cxxflags = -g -I$(QTINCLUDE)
ldlibs    = -lbqplot_native $(QTNATIVELIBS) -lbanner -lbrttutil $(DBLIBS)

include $(ANTELOPEMAKE)

OBJS= bqplot_test_glyphs.o
$(BIN) : $(OBJS)
    $(CXX) $(CXXFLAGS) -g -o $(BIN) $(OBJS) $(LDFLAGS) $(LDLIBS)
%
% cat bqplot_test_glyphs.cc

#include "BQ.h"

int
main (int argc, char **argv)

{
    QApplication qapp(argc, argv);

    qapp.setApplicationName("bqplot_test_glyphs");

    QWidget *widget = new QWidget();
    widget->setWindowTitle("bqplot_test_glyphs");
    widget->show();
    widget->resize (800, 800);

    BQViewport *myvp = new BQViewport(widget);

    myvp->configure (
            "xleft",      "-1.0",
            "xright",     "5.0",
            "ybottom",    "-1.1",
            "ytop",       "1.1",
            "mleft",      "80",
            "mright",     "20",
            "mbottom",    "50",
            "mtop",       "30",
            "fill_frame", "lightblue",
            "fill",       "#e0e0e0",
            NULL);

    BQAxes *myax = new BQAxes(myvp);
    myax->configure (
             "xlabel",               "My X-stuff",
             "ylabel",               "My Y-stuff",
             "xformat",              "%.1f",
             "yformat",              "%.1f",
             "linewidth_box",        "0",
             "linewidth_tics",       "2",
             "linewidth_tics_small", "0",
             "axis_style",           "sw",
             "tic_style",            "siwinoeo",
             "linewidth_grids",      "2",
             "linewidth_grids_small","0",
             "color_grids",          "black",
             "color_grids_small",    "#c0c0c0",
             NULL);

    BQ_XY points[] = {
        {1.2, 0.4},
        {-0.5, -0.7},
        {3.7, 0.3},
        {2.1, 0.9},
        {4.1, -0.5}
    };

    int n = sizeof(points) / sizeof(BQ_XY);

    int symbols[] = {
        BQ_GRAPHICS_CONTEXT_SYMBOL_TYPE_CIRCLE,
        BQ_GRAPHICS_CONTEXT_SYMBOL_TYPE_SQUARE,
        BQ_GRAPHICS_CONTEXT_SYMBOL_TYPE_TRIANGLE,
        BQ_GRAPHICS_CONTEXT_SYMBOL_TYPE_DIAMOND,
        BQ_GRAPHICS_CONTEXT_SYMBOL_TYPE_STAR,
    };

    BQGraphicsContext *gc = new BQGraphicsContext ();
    gc->setGcItem ("symbol:outline_color", BQ_GRAPHICS_CONTEXT_TYPE_COLOR_PEN, QColor("#80000000"));
    gc->setGcItem ("symbol:outline_width", BQ_GRAPHICS_CONTEXT_TYPE_LINEWIDTHF, 0.5);
    gc->setGcItem ("symbol:fill_color", BQ_GRAPHICS_CONTEXT_TYPE_COLOR_BRUSH, QColor("#a0ffff00"));
    gc->setGcItem ("symbol:size", BQ_GRAPHICS_CONTEXT_TYPE_SIZE, 20.0);
    gc->setGcItem ("symbol:opacity", BQ_GRAPHICS_CONTEXT_TYPE_OPACITY, 0.8);

    BqGraphicsContextCoding *coding_color = new BqGraphicsContextCoding[3];
    BQGraphicsContext::setGcCoding (&(coding_color[0]), 0.0, 0.0, 240.0, 240.0);
    BQGraphicsContext::setGcCoding (&(coding_color[1]), 0.0, 1.0, 10.0, 1.0);
    BQGraphicsContext::setGcCoding (&(coding_color[2]), 0.0, 0.6, 10.0, 0.6);
    gc->setGcItemCoding ("symbol:fill_color", BQ_GRAPHICS_CONTEXT_CODING_TYPE_COLOR_HSL, coding_color);
    coding_color = new BqGraphicsContextCoding[1];
    BQGraphicsContext::setGcCoding (&(coding_color[0]), 10.0, 10.0, 20.0, 20.0, 10.0, 50.0);
    gc->setGcItemCoding ("symbol:size", BQ_GRAPHICS_CONTEXT_CODING_TYPE_SCALAR, coding_color);

    BqGraphicsContext *gc_symbol = gc->getGc ("symbol");

    BQGlyphs *glyphs = new BQGlyphs(myvp);
    glyphs->setInteractionMode(BQ_INTERACTION_MODE_MOVE);

    QList<BQGlyph *> glyph_list;
    for (int i=0; i<n; i++) {
        BQGlyph *glyph = new BQGlyph(myvp, glyphs);
        glyph->setPosition (points[i].x, points[i].y);
        glyph->setGlyph (symbols[i], NULL, gc_symbol);
        glyph->setCodingValue ("symbol:fill_color", i*(360.0/n));
        glyph->setCodingValue ("symbol:size", 10.0+i*(40.0/n));
        glyph_list.append (glyph);
    }

    double t0 = now();
    QTimer *timer = new QTimer (widget);
    widget->connect (timer, &QTimer::timeout, [widget, glyph_list, t0]() {
            foreach (BQGlyph *glyph, glyph_list) {
                double hue_increment = 5.0;
                double size_increment = 0.5 - sin((now() - t0)*0.3);
                double hue = glyph->getCodingValue ("symbol:fill_color");
                hue += hue_increment;
                glyph->setCodingValue ("symbol:fill_color", hue);
                double size = glyph->getCodingValue ("symbol:size");
                size += size_increment;
                glyph->setCodingValue ("symbol:size", size);
                double xwalk = ((double)qrand()/RAND_MAX) - 0.5;
                double ywalk = ((double)qrand()/RAND_MAX) - 0.5;
                double xw, yw;
                glyph->getPosition (&xw, &yw);
                xw += xwalk*0.02;
                yw += ywalk*0.02;
                glyph->setPosition (xw, yw);
            }
            widget->update();
        });
    timer->start (100);

    qapp.exec();

    exit (0);
}

SEE ALSO

bqplot(3), BQViewport(3), BQViewportItem(3), BQLayer(3), BQGlyph(3), BQGlyphsContextItem(3), BQContextItem(3)

AUTHOR

Danny Harvey, BRTT
Printer icon