graphics_abstraction_layer.h 25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/*
 * This program source code file is part of KICAD, a free EDA CAD application.
 *
 * Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
 * Copyright (C) 2012 Kicad Developers, see change_log.txt for contributors.
 *
 * Graphics Abstraction Layer (GAL) - base class
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

#ifndef GRAPHICSABSTRACTIONLAYER_H_
#define GRAPHICSABSTRACTIONLAYER_H_

#include <deque>
#include <stack>
Maciej Suminski's avatar
Maciej Suminski committed
32
#include <limits>
33 34 35

#include <math/matrix3x3.h>

36
#include <gal/color4d.h>
37
#include <gal/definitions.h>
38 39
#include <gal/stroke_font.h>
#include <newstroke_font.h>
40

41
namespace KIGFX
42 43 44 45
{
/**
 * GridStyle: Type definition of the grid style
 */
46
enum GRID_STYLE
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
{
    GRID_STYLE_LINES,   ///< Use lines for the grid
    GRID_STYLE_DOTS     ///< Use dots for the grid
};

/**
 * @brief Class GAL is the abstract interface for drawing on a 2D-surface.
 *
 * The functions are optimized for drawing shapes of an EDA-program such as KiCad. Most methods
 * are abstract and need to be implemented by a lower layer, for example by a cairo or OpenGL implementation.
 * <br>
 * Almost all methods use world coordinates as arguments. The board design is defined in world space units;
 * for drawing purposes these are transformed to screen units with this layer. So zooming is handled here as well.
 *
 */
class GAL
{
public:
    // Constructor / Destructor
    GAL();
    virtual ~GAL();

    // ---------------
    // Drawing methods
    // ---------------

    /// @brief Begin the drawing, needs to be called for every new frame.
    virtual void BeginDrawing() = 0;

    /// @brief End the drawing, needs to be called for every new frame.
    virtual void EndDrawing() = 0;

    /**
     * @brief Draw a line.
     *
     * Start and end points are defined as 2D-Vectors.
     *
     * @param aStartPoint   is the start point of the line.
     * @param aEndPoint     is the end point of the line.
     */
87
    virtual void DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) = 0;
88

89 90 91 92 93 94 95 96 97 98 99
    /**
     * @brief Draw a rounded segment.
     *
     * Start and end points are defined as 2D-Vectors.
     *
     * @param aStartPoint   is the start point of the segment.
     * @param aEndPoint     is the end point of the segment.
     * @param aWidth        is a width of the segment
     */
    virtual void DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint, double aWidth ) = 0;

100 101 102 103 104 105 106 107 108 109 110 111 112
    /**
     * @brief Draw a polyline
     *
     * @param aPointList is a list of 2D-Vectors containing the polyline points.
     */
    virtual void DrawPolyline( std::deque<VECTOR2D>& aPointList ) = 0;

    /**
     * @brief Draw a circle using world coordinates.
     *
     * @param aCenterPoint is the center point of the circle.
     * @param aRadius is the radius of the circle.
     */
113
    virtual void DrawCircle( const VECTOR2D& aCenterPoint, double aRadius ) = 0;
114 115 116 117 118 119 120 121 122 123

    /**
     * @brief Draw an arc.
     *
     * @param aCenterPoint  is the center point of the arc.
     * @param aRadius       is the arc radius.
     * @param aStartAngle   is the start angle of the arc.
     * @param aEndAngle     is the end angle of the arc.
     */
    virtual void
124
    DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double aStartAngle, double aEndAngle ) = 0;
125 126 127 128 129 130 131

    /**
     * @brief Draw a rectangle.
     *
     * @param aStartPoint   is the start point of the rectangle.
     * @param aEndPoint     is the end point of the rectangle.
     */
132
    virtual void DrawRectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) = 0;
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

    /**
     * @brief Draw a polygon.
     *
     * @param aPointList is the list of the polygon points.
     */
    virtual void DrawPolygon( const std::deque<VECTOR2D>& aPointList ) = 0;

    /**
     * @brief Draw a cubic bezier spline.
     *
     * @param startPoint    is the start point of the spline.
     * @param controlPointA is the first control point.
     * @param controlPointB is the second control point.
     * @param endPoint      is the end point of the spline.
     */
149 150
    virtual void DrawCurve( const VECTOR2D& startPoint,    const VECTOR2D& controlPointA,
                            const VECTOR2D& controlPointB, const VECTOR2D& endPoint ) = 0;
151 152 153 154 155 156 157 158 159 160 161 162

    // --------------
    // Screen methods
    // --------------

    /// @brief Resizes the canvas.
    virtual void ResizeScreen( int aWidth, int aHeight ) = 0;

    /// @brief Shows/hides the GAL canvas
    virtual bool Show( bool aShow ) = 0;

    /// @brief Returns GAL canvas size in pixels
163
    const VECTOR2I& GetScreenPixelSize() const
164 165 166 167 168 169 170
    {
        return screenSize;
    }

    /// @brief Force all remaining objects to be drawn.
    virtual void Flush() = 0;

171 172 173 174 175
    /**
     * @brief Clear the screen.
     * @param aColor is the color used for clearing.
     */
    virtual void ClearScreen( const COLOR4D& aColor ) = 0;
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205

    // -----------------
    // Attribute setting
    // -----------------

    /**
     * @brief Enable/disable fill.
     *
     * @param aIsFillEnabled is true, when the graphics objects should be filled, else false.
     */
    inline virtual void SetIsFill( bool aIsFillEnabled )
    {
        isFillEnabled = aIsFillEnabled;
    }

    /**
     * @brief Enable/disable stroked outlines.
     *
     * @param aIsStrokeEnabled is true, if the outline of an object should be stroked.
     */
    inline virtual void SetIsStroke( bool aIsStrokeEnabled )
    {
        isStrokeEnabled = aIsStrokeEnabled;
    }

    /**
     * @brief Set the fill color.
     *
     * @param aColor is the color for filling.
     */
206
    inline virtual void SetFillColor( const COLOR4D& aColor )
207 208 209 210 211 212 213 214 215
    {
        fillColor = aColor;
    }

    /**
     * @brief Set the stroke color.
     *
     * @param aColor is the color for stroking the outline.
     */
216
    inline virtual void SetStrokeColor( const COLOR4D& aColor )
217 218 219 220 221 222 223 224 225
    {
        strokeColor = aColor;
    }

    /**
     * @brief Get the stroke color.
     *
     * @return the color for stroking the outline.
     */
226
    inline const COLOR4D& GetStrokeColor() const
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
    {
        return strokeColor;
    }

    /**
     * @brief Set the line width.
     *
     * @param aLineWidth is the line width.
     */
    inline virtual void SetLineWidth( double aLineWidth )
    {
        lineWidth = aLineWidth;
    }

    /**
     * @brief Get the line width.
     *
     * @return the actual line width.
     */
246
    inline double GetLineWidth() const
247 248 249 250 251 252 253 254 255 256 257
    {
        return lineWidth;
    }

    /**
     * @brief Set the depth of the layer (position on the z-axis)
     *
     * @param aLayerDepth the layer depth for the objects.
     */
    inline virtual void SetLayerDepth( double aLayerDepth )
    {
258 259 260
        assert( aLayerDepth <= depthRange.y );
        assert( aLayerDepth >= depthRange.x );

261 262 263
        layerDepth = aLayerDepth;
    }

264 265 266 267 268 269 270 271 272 273
    // ----
    // Text
    // ----
    /**
     * @brief Draws a vector type text using preloaded Newstroke font.
     *
     * @param aText is the text to be drawn.
     * @param aPosition is the text position in world coordinates.
     * @param aRotationAngle is the text rotation angle.
     */
274
    inline virtual void StrokeText( const wxString& aText, const VECTOR2D& aPosition,
275 276 277 278 279 280 281 282 283 284 285 286
                                    double aRotationAngle )
    {
        strokeFont.Draw( aText, aPosition, aRotationAngle );
    }

    /**
     * @brief Loads attributes of the given text (bold/italic/underline/mirrored and so on).
     *
     * @param aText is the text item.
     */
    virtual void SetTextAttributes( const EDA_TEXT* aText );

287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
    /// @copydoc STROKE_FONT::SetGlyphSize()
    inline void SetGlyphSize( const VECTOR2D aGlyphSize )
    {
        strokeFont.SetGlyphSize( aGlyphSize );
    }

    /// @copydoc STROKE_FONT::SetBold()
    inline void SetBold( const bool aBold )
    {
        strokeFont.SetBold( aBold );
    }

    /// @copydoc STROKE_FONT::SetItalic()
    inline void SetItalic( const bool aItalic )
    {
        strokeFont.SetItalic( aItalic );
    }

    /// @copydoc STROKE_FONT::SetMirrored()
    inline void SetMirrored( const bool aMirrored )
    {
        strokeFont.SetMirrored( aMirrored );
    }

    /// @copydoc STROKE_FONT::SetHorizontalJustify()
    inline void SetHorizontalJustify( const EDA_TEXT_HJUSTIFY_T aHorizontalJustify )
    {
        strokeFont.SetHorizontalJustify( aHorizontalJustify );
    }

    /// @copydoc STROKE_FONT::SetVerticalJustify()
    inline void SetVerticalJustify( const EDA_TEXT_VJUSTIFY_T aVerticalJustify )
    {
        strokeFont.SetVerticalJustify( aVerticalJustify );
    }

323 324 325 326 327 328 329 330 331
    // --------------
    // Transformation
    // --------------

    /**
     * @brief Transform the context.
     *
     * @param aTransformation is the ransformation matrix.
     */
332
    virtual void Transform( const MATRIX3x3D& aTransformation ) = 0;
333 334 335 336 337 338 339 340 341 342 343 344 345

    /**
     * @brief Rotate the context.
     *
     * @param aAngle is the rotation angle in radians.
     */
    virtual void Rotate( double aAngle ) = 0;

    /**
     * @brief Translate the context.
     *
     * @param aTranslation is the translation vector.
     */
346
    virtual void Translate( const VECTOR2D& aTranslation ) = 0;
347 348 349 350 351 352

    /**
     * @brief Scale the context.
     *
     * @param aScale is the scale factor for the x- and y-axis.
     */
353
    virtual void Scale( const VECTOR2D& aScale ) = 0;
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384

    /// @brief Save the context.
    virtual void Save() = 0;

    /// @brief Restore the context.
    virtual void Restore() = 0;

    // --------------------------------------------
    // Group methods
    // ---------------------------------------------

    /**
     * @brief Begin a group.
     *
     * A group is a collection of graphic items.
     * Hierarchical groups are possible, attributes and transformations can be used.
     *
     * @return the number of the group.
     */
    virtual int BeginGroup() = 0;

    /// @brief End the group.
    virtual void EndGroup() = 0;

    /**
     * @brief Draw the stored group.
     *
     * @param aGroupNumber is the group number.
     */
    virtual void DrawGroup( int aGroupNumber ) = 0;

385 386 387 388 389 390 391 392
    /**
     * @brief Changes the color used to draw the group.
     *
     * @param aGroupNumber is the group number.
     * @param aNewColor is the new color.
     */
    virtual void ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor ) = 0;

393 394 395 396 397 398 399 400
    /**
     * @brief Changes the depth (Z-axis position) of the group.
     *
     * @param aGroupNumber is the group number.
     * @param aDepth is the new depth.
     */
    virtual void ChangeGroupDepth( int aGroupNumber, int aDepth ) = 0;

401 402 403 404 405 406 407
    /**
     * @brief Delete the group from the memory.
     *
     * @param aGroupNumber is the group number.
     */
    virtual void DeleteGroup( int aGroupNumber ) = 0;

408 409 410 411 412
    /**
     * @brief Delete all data created during caching of graphic items.
     */
    virtual void ClearCache() = 0;

413 414 415 416 417
    // --------------------------------------------------------
    // Handling the world <-> screen transformation
    // --------------------------------------------------------

    /// @brief Compute the world <-> screen transformation matrix
Maciej Suminski's avatar
Maciej Suminski committed
418
    virtual void ComputeWorldScreenMatrix();
419 420 421 422 423 424

    /**
     * @brief Get the world <-> screen transformation matrix.
     *
     * @return the transformation matrix.
     */
425
    const MATRIX3x3D& GetWorldScreenMatrix() const
426 427 428 429
    {
        return worldScreenMatrix;
    }

430 431 432 433 434 435 436 437 438 439
    /**
     * @brief Get the screen <-> world transformation matrix.
     *
     * @return the transformation matrix.
     */
    const MATRIX3x3D& GetScreenWorldMatrix() const
    {
        return screenWorldMatrix;
    }

440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
    /**
     * @brief Set the world <-> screen transformation matrix.
     *
     * @param aMatrix is the 3x3 world <-> screen transformation matrix.
     */
    inline void SetWorldScreenMatrix( const MATRIX3x3D& aMatrix )
    {
        worldScreenMatrix = aMatrix;
    }

    /**
     * @brief Set the unit length.
     *
     * This defines the length [inch] per one integer. For instance a value 0.001 means
     * that the coordinate [1000, 1000] corresponds with a point at (1 inch, 1 inch) or
     * 1 mil resolution per integer.
     *
     * @param aWorldUnitLength is the world Unit length.
     */
    inline void SetWorldUnitLength( double aWorldUnitLength )
    {
        worldUnitLength = aWorldUnitLength;
    }

    /**
     * @brief Set the dots per inch of the screen.
     *
     * This value depends on the user screen, it should be configurable by the application.
     * For instance a typical notebook with HD+ resolution (1600x900) has 106 DPI.
     *
     * @param aScreenDPI are the screen DPI.
     */
    inline void SetScreenDPI( double aScreenDPI )
    {
        screenDPI = aScreenDPI;
    }

    /**
     * @brief Set the Point in world space to look at.
     *
     * This point corresponds with the center of the actual drawing area.
     *
     * @param aPoint is the look at point (center of the actual drawing area).
     */
    inline void SetLookAtPoint( const VECTOR2D& aPoint )
    {
        lookAtPoint = aPoint;
    }

    /**
     * @brief Get the look at point.
     *
     * @return the look at point.
     */
494
    inline const VECTOR2D& GetLookAtPoint() const
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
    {
        return lookAtPoint;
    }

    /**
     * @brief Set the zoom factor of the scene.
     *
     * @param aZoomFactor is the zoom factor.
     */
    inline void SetZoomFactor( double aZoomFactor )
    {
        zoomFactor = aZoomFactor;
    }

    /**
     * @brief Get the zoom factor
     *
     * @return the zoom factor.
     */
514
    inline double GetZoomFactor() const
515 516 517 518 519 520 521 522 523 524 525 526
    {
        return zoomFactor;
    }

    /**
     * @brief Set the range of the layer depth.
     *
     * Usually required for the OpenGL implementation, any object outside this range is not drawn.
     *
     * @param aDepthRange is the depth range where component x is the near clipping plane and y
     *        is the far clipping plane.
     */
527
    inline void SetDepthRange( const VECTOR2D& aDepthRange )
528 529 530 531
    {
        depthRange = aDepthRange;
    }

532 533 534
    /**
     * @brief Returns the minimum depth in the currently used range (the top).
     */
535
    inline double GetMinDepth() const
536 537 538 539 540 541 542
    {
        return depthRange.x;
    }

    /**
     * @brief Returns the maximum depth in the currently used range (the bottom).
     */
543
    inline double GetMaxDepth() const
544 545 546 547
    {
        return depthRange.y;
    }

548 549 550 551 552
    /**
     * @brief Get the world scale.
     *
     * @return the actual world scale factor.
     */
553
    inline double GetWorldScale() const
554 555 556 557
    {
        return worldScale;
    }

558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
    /**
     * @brief Sets flipping of the screen.
     *
     * @param xAxis is the flip flag for the X axis.
     * @param yAxis is the flip flag for the Y axis.
     */
    inline void SetFlip( bool xAxis, bool yAxis )
    {
        if( xAxis )
            flipX = -1.0;   // flipped
        else
            flipX = 1.0;    // regular

        if( yAxis )
            flipY = -1.0;   // flipped
        else
            flipY = 1.0;    // regular
    }

577 578 579 580
    // ---------------------------
    // Buffer manipulation methods
    // ---------------------------

581 582 583 584 585 586
    /**
     * @brief Save the screen contents.
     */
    virtual void SaveScreen() = 0;

    /**
587
     * @brief Restore the screen contents.
588 589 590
     */
    virtual void RestoreScreen() = 0;

591 592 593 594 595
    /**
     * @brief Sets the target for rendering.
     *
     * @param aTarget is the new target for rendering.
     */
Maciej Suminski's avatar
Maciej Suminski committed
596
    virtual void SetTarget( RENDER_TARGET aTarget ) = 0;
597

598 599 600 601 602
    /**
     * @brief Gets the currently used target for rendering.
     *
     * @return The current rendering target.
     */
Maciej Suminski's avatar
Maciej Suminski committed
603
    virtual RENDER_TARGET GetTarget() const = 0;
604

605 606 607 608 609
    /**
     * @brief Clears the target for rendering.
     *
     * @param aTarget is the target to be cleared.
     */
Maciej Suminski's avatar
Maciej Suminski committed
610
    virtual void ClearTarget( RENDER_TARGET aTarget ) = 0;
611

612 613 614 615
    // -------------
    // Grid methods
    // -------------

616 617 618 619 620 621 622 623 624 625
    /**
     * @brief Sets the visibility setting of the grid.
     *
     * @param aVisibility is the new visibility setting of the grid.
     */
    inline void SetGridVisibility( bool aVisibility )
    {
        gridVisibility = aVisibility;
    }

626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
    /**
     * @brief Set the origin point for the grid.
     *
     * @param aGridOrigin is a vector containing the grid origin point, in world coordinates.
     */
    inline void SetGridOrigin( const VECTOR2D& aGridOrigin )
    {
        gridOrigin = aGridOrigin;
    }

    /**
     * @brief Sets the screen size of the grid origin marker
     *
     * @param aSize is the radius of the origin marker, in pixels.
     */
    inline void SetGridOriginMarkerSize( int aSize )
    {
        gridOriginMarkerSize = aSize;
    }

    /**
     * @brief Set the threshold for grid drawing.
     *
     * @param aThreshold is the minimum grid cell size (in pixels) for which the grid is drawn.
     */
    inline void SetGridDrawThreshold( int aThreshold )
    {
        gridDrawThreshold = aThreshold;
    }

    /**
     * @brief Set the grid size.
     *
Maciej Suminski's avatar
Maciej Suminski committed
659
     * @param aGridSize is a vector containing the grid size in x and y direction.
660 661 662 663 664 665
     */
    inline void SetGridSize( const VECTOR2D& aGridSize )
    {
        gridSize = aGridSize;
    }

Maciej Suminski's avatar
Maciej Suminski committed
666 667 668 669 670 671 672 673 674 675
    /**
     * @brief Returns the grid size.
     *
     * @return A vector containing the grid size in x and y direction.
     */
    inline const VECTOR2D& GetGridSize() const
    {
        return gridSize;
    }

676 677 678 679 680
    /**
     * @brief Set the grid color.
     *
     * @param aGridColor is the grid color, it should have a low alpha value for the best effect.
     */
681
    inline void SetGridColor( const COLOR4D& aGridColor )
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
    {
        gridColor = aGridColor;
    }

    /**
     * @brief Draw every tick line wider.
     *
     * @param aInterval increase the width of every aInterval line, if 0 do not use this feature.
     */
    inline void SetCoarseGrid( int aInterval )
    {
        gridTick = aInterval;
    }

    /**
     * @brief Get the grid line width.
     *
     * @return the grid line width
     */
701
    inline double GetGridLineWidth() const
702 703 704 705 706 707 708 709 710 711 712 713 714 715
    {
        return gridLineWidth;
    }

    /**
     * @brief Set the grid line width.
     *
     * @param aGridLineWidth is the rid line width.
     */
    inline void SetGridLineWidth( double aGridLineWidth )
    {
        gridLineWidth = aGridLineWidth;
    }

716
    ///> @brief Draw the grid
717 718
    void DrawGrid();

Maciej Suminski's avatar
Maciej Suminski committed
719 720
    /**
     * Function GetGridPoint()
721
     * For a given point it returns the nearest point belonging to the grid in world coordinates.
Maciej Suminski's avatar
Maciej Suminski committed
722 723
     *
     * @param aPoint is the point for which the grid point is searched.
724
     * @return The nearest grid point in world coordinates.
Maciej Suminski's avatar
Maciej Suminski committed
725
     */
726
    VECTOR2D GetGridPoint( const VECTOR2D& aPoint ) const;
Maciej Suminski's avatar
Maciej Suminski committed
727

728 729 730 731 732 733 734 735 736
    /**
     * @brief Change the grid display style.
     *
     * @param aGridStyle is the new style for grid.
     */
    inline virtual void SetGridStyle( GRID_STYLE aGridStyle )
    {
        gridStyle = aGridStyle;
    }
737

738 739 740 741 742 743
    /**
     * @brief Compute the point position in world coordinates from given screen coordinates.
     *
     * @param aPoint the pointposition in screen coordinates.
     * @return the point position in world coordinates.
     */
744
    inline VECTOR2D ToWorld( const VECTOR2D& aPoint ) const
745 746 747
    {
        return VECTOR2D( screenWorldMatrix * aPoint );
    }
748 749

    /**
750
     * @brief Compute the point position in screen coordinates from given world coordinates.
751
     *
752 753
     * @param aPoint the pointposition in world coordinates.
     * @return the point position in screen coordinates.
754
     */
755
    inline VECTOR2D ToScreen( const VECTOR2D& aPoint ) const
756 757 758
    {
        return VECTOR2D( worldScreenMatrix * aPoint );
    }
759 760

    /**
761
     * @brief Enable/disable cursor.
762
     *
763
     * @param aCursorEnabled is true if the cursor should be drawn, else false.
764
     */
765
    inline void SetCursorEnabled( bool aCursorEnabled )
766
    {
767
        isCursorEnabled = aCursorEnabled;
768 769 770 771 772 773 774
    }

    /**
     * @brief Set the cursor color.
     *
     * @param aCursorColor is the color of the cursor.
     */
775
    inline void SetCursorColor( const COLOR4D& aCursorColor )
776 777 778 779
    {
        cursorColor = aCursorColor;
    }

780 781 782
    /**
     * @brief Set the cursor size.
     *
783
     * @param aCursorSize is the size of the cursor expressed in pixels.
784 785 786 787 788 789
     */
    inline void SetCursorSize( unsigned int aCursorSize )
    {
        cursorSize = aCursorSize;
    }

790 791 792 793 794
    /**
     * @brief Draw the cursor.
     *
     * @param aCursorPosition is the cursor position in screen coordinates.
     */
795
    virtual void DrawCursor( const VECTOR2D& aCursorPosition ) = 0;
796

Maciej Suminski's avatar
Maciej Suminski committed
797 798 799 800
    /**
     * @brief Changes the current depth to deeper, so it is possible to draw objects right beneath
     * other.
     */
Maciej Suminski's avatar
Maciej Suminski committed
801
    inline void AdvanceDepth()
802
    {
803
        layerDepth -= 0.001;
804 805
    }

806 807 808
    /**
     * @brief Stores current drawing depth on the depth stack.
     */
Maciej Suminski's avatar
Maciej Suminski committed
809
    inline void PushDepth()
810 811 812 813
    {
        depthStack.push( layerDepth );
    }

814 815 816
    /**
     * @brief Restores previously stored drawing depth for the depth stack.
     */
Maciej Suminski's avatar
Maciej Suminski committed
817
    inline void PopDepth()
818 819 820 821 822
    {
        layerDepth = depthStack.top();
        depthStack.pop();
    }

823 824 825
    /// Depth level on which the grid is drawn
    static const int GRID_DEPTH = 1024;

826
    static const double METRIC_UNIT_LENGTH;
827

828 829
protected:
    std::stack<double> depthStack;             ///< Stored depth values
830
    VECTOR2I           screenSize;             ///< Screen size in screen coordinates
831 832 833 834 835 836 837

    double             worldUnitLength;        ///< The unit length of the world coordinates [inch]
    double             screenDPI;              ///< The dots per inch of the screen
    VECTOR2D           lookAtPoint;            ///< Point to be looked at in world space

    double             zoomFactor;             ///< The zoom factor
    MATRIX3x3D         worldScreenMatrix;      ///< World transformation
838
    MATRIX3x3D         screenWorldMatrix;      ///< Screen transformation
839
    double             worldScale;             ///< The scale factor world->screen
840 841
    double             flipX;                  ///< Flag for X axis flipping
    double             flipY;                  ///< Flag for Y axis flipping
842 843 844 845 846 847 848 849 850 851 852 853

    double             lineWidth;              ///< The line width

    bool               isFillEnabled;          ///< Is filling of graphic objects enabled ?
    bool               isStrokeEnabled;        ///< Are the outlines stroked ?

    COLOR4D            fillColor;              ///< The fill color
    COLOR4D            strokeColor;            ///< The color of the outlines

    double             layerDepth;             ///< The actual layer depth
    VECTOR2D           depthRange;             ///< Range of the depth

854 855
    // Grid settings
    bool               gridVisibility;         ///< Should the grid be shown
856
    GRID_STYLE         gridStyle;              ///< Grid display style
857 858
    VECTOR2D           gridSize;               ///< The grid size
    VECTOR2D           gridOrigin;             ///< The grid origin
859
    VECTOR2D           gridOffset;             ///< The grid offset to compensate cursor position
860 861 862 863
    COLOR4D            gridColor;              ///< Color of the grid
    int                gridTick;               ///< Every tick line gets the double width
    double             gridLineWidth;          ///< Line width of the grid
    int                gridDrawThreshold;      ///< Minimum screen size of the grid (pixels)
864
                                               ///< below which the grid is not drawn
865 866
    int                gridOriginMarkerSize;   ///< Grid origin indicator size (pixels)

867
    // Cursor settings
868 869
    bool               isCursorEnabled;        ///< Is the cursor enabled?
    COLOR4D            cursorColor;            ///< Cursor color
870 871
    unsigned int       cursorSize;             ///< Size of the cursor in pixels
    VECTOR2D           cursorPosition;         ///< Current cursor position (world coordinates)
872

873 874 875
    /// Instance of object that stores information about how to draw texts
    STROKE_FONT        strokeFont;

876 877 878 879 880 881 882 883 884 885 886 887
    /// Compute the scaling factor for the world->screen matrix
    inline void ComputeWorldScale()
    {
        worldScale = screenDPI * worldUnitLength * zoomFactor;
    }

    /**
     * @brief Draw a grid line (usually a simplified line function).
     *
     * @param aStartPoint is the start point of the line.
     * @param aEndPoint is the end point of the line.
     */
Maciej Suminski's avatar
Maciej Suminski committed
888
    virtual void drawGridLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) = 0;
889

890 891
    static const int MIN_DEPTH = -2048;
    static const int MAX_DEPTH = 2047;
892
};
893
}    // namespace KIGFX
894 895

#endif /* GRAPHICSABSTRACTIONLAYER_H_ */