File indexing completed on 2024-04-28 05:46:48

0001 /*****************************************************************************
0002  *   Copyright 2003 - 2010 Craig Drummond <craig.p.drummond@gmail.com>       *
0003  *   Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com>                     *
0004  *                                                                           *
0005  *   This program is free software; you can redistribute it and/or modify    *
0006  *   it under the terms of the GNU Lesser General Public License as          *
0007  *   published by the Free Software Foundation; either version 2.1 of the    *
0008  *   License, or (at your option) version 3, or any later version accepted   *
0009  *   by the membership of KDE e.V. (or its successor approved by the         *
0010  *   membership of KDE e.V.), which shall act as a proxy defined in          *
0011  *   Section 6 of version 3 of the license.                                  *
0012  *                                                                           *
0013  *   This program is distributed in the hope that it will be useful,         *
0014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
0015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
0016  *   Lesser General Public License for more details.                         *
0017  *                                                                           *
0018  *   You should have received a copy of the GNU Lesser General Public        *
0019  *   License along with this library. If not,                                *
0020  *   see <http://www.gnu.org/licenses/>.                                     *
0021  *****************************************************************************/
0022 
0023 #ifndef __QTC_CAIRO_DRAW_H__
0024 #define __QTC_CAIRO_DRAW_H__
0025 
0026 #include "utils.h"
0027 #include <pango/pango.h>
0028 
0029 #ifdef QTC_UTILS_GTK
0030 #include <gtk/gtk.h>
0031 #endif
0032 
0033 namespace QtCurve {
0034 enum class ArrowType {
0035     Up,
0036     Down,
0037     Left,
0038     Right,
0039     NONE,
0040 };
0041 
0042 namespace Cairo {
0043 
0044 void hLine(cairo_t *cr, int x, int y, int w, const _GdkColor *col, double a=1);
0045 void vLine(cairo_t *cr, int x, int y, int w, const _GdkColor *col, double a=1);
0046 void polygon(cairo_t *cr, const _GdkColor *col, const QtcRect *area,
0047              const _GdkPoint *points, int npoints, bool fill);
0048 void rect(cairo_t *cr, const QtcRect *area, int x, int y, int width,
0049           int height, const _GdkColor *col, double alpha=1);
0050 void fadedLine(cairo_t *cr, int x, int y, int width, int height,
0051                const QtcRect *area, const QtcRect *gap, bool fadeStart,
0052                bool fadeEnd, double fadeSize, bool horiz,
0053                const _GdkColor *col, double alpha=1);
0054 void stripes(cairo_t *cr, int x, int y, int w, int h,
0055              bool horizontal, int stripeWidth);
0056 void dot(cairo_t *cr, int x, int y, int w, int h, const _GdkColor *col);
0057 void dots(cairo_t *cr, int rx, int ry, int rwidth, int rheight,
0058           bool horiz, int nLines, int offset, const QtcRect *area,
0059           int startOffset, const _GdkColor *col1,
0060           const _GdkColor *col2);
0061 void layout(cairo_t *cr, const QtcRect *area, int x, int y,
0062             PangoLayout *layout, const _GdkColor *col);
0063 void arrow(cairo_t *cr, const _GdkColor *col,
0064            const QtcRect *area, ArrowType arrow_type,
0065            int x, int y, bool small, bool fill, bool varrow);
0066 
0067 #ifdef QTC_UTILS_GTK
0068 static inline ArrowType
0069 arrowType(GtkArrowType gtype)
0070 {
0071     switch (gtype) {
0072     case GTK_ARROW_UP:
0073         return ArrowType::Up;
0074     case GTK_ARROW_DOWN:
0075         return ArrowType::Down;
0076     case GTK_ARROW_LEFT:
0077         return ArrowType::Left;
0078     case GTK_ARROW_RIGHT:
0079         return ArrowType::Right;
0080     default:
0081         return ArrowType::NONE;
0082     }
0083 }
0084 
0085 static inline void
0086 arrow(cairo_t *cr, const _GdkColor *col,
0087       const QtcRect *area, GtkArrowType arrow_type,
0088       int x, int y, bool small, bool fill, bool varrow)
0089 {
0090     arrow(cr, col, area, arrowType(arrow_type), x, y, small, fill, varrow);
0091 }
0092 
0093 #endif
0094 
0095 }
0096 }
0097 
0098 #endif