KiCad PCB EDA Suite
KIGFX::OPENGL_GAL Class Reference

Class OpenGL_GAL is the OpenGL implementation of the Graphics Abstraction Layer. More...

#include <opengl_gal.h>

Inheritance diagram for KIGFX::OPENGL_GAL:
KIGFX::GAL KIGFX::GAL_DISPLAY_OPTIONS_OBSERVER

Classes

struct  TessParams
 

Public Member Functions

 OPENGL_GAL (GAL_DISPLAY_OPTIONS &aDisplayOptions, wxWindow *aParent, wxEvtHandler *aMouseListener=nullptr, wxEvtHandler *aPaintListener=nullptr, const wxString &aName=wxT("GLCanvas"))
 Constructor OPENGL_GAL. More...
 
virtual ~OPENGL_GAL ()
 
virtual bool IsInitialized () const override
 Returns the initalization status for the canvas. More...
 
bool IsVisible () const override
 > More...
 
virtual void BeginDrawing () override
 Begin the drawing, needs to be called for every new frame. More...
 
virtual void EndDrawing () override
 End the drawing, needs to be called for every new frame. More...
 
virtual void BeginUpdate () override
 Enables item update mode. More...
 
virtual void EndUpdate () override
 Disables item update mode. More...
 
virtual void DrawLine (const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
 Draw a line. More...
 
virtual void DrawSegment (const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, double aWidth) override
 Draw a rounded segment. More...
 
virtual void DrawCircle (const VECTOR2D &aCenterPoint, double aRadius) override
 Draw a circle using world coordinates. More...
 
virtual void DrawArc (const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double aEndAngle) override
 Draw an arc. More...
 
virtual void DrawArcSegment (const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double aEndAngle, double aWidth) override
 Draw an arc segment. More...
 
virtual void DrawRectangle (const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
 Draw a rectangle. More...
 
virtual void DrawPolyline (const std::deque< VECTOR2D > &aPointList) override
 Draw a polyline. More...
 
virtual void DrawPolyline (const VECTOR2D aPointList[], int aListSize) override
 
virtual void DrawPolyline (const SHAPE_LINE_CHAIN &aLineChain) override
 
virtual void DrawPolygon (const std::deque< VECTOR2D > &aPointList) override
 Draw a polygon. More...
 
virtual void DrawPolygon (const VECTOR2D aPointList[], int aListSize) override
 
virtual void DrawPolygon (const SHAPE_POLY_SET &aPolySet) override
 
virtual void DrawCurve (const VECTOR2D &startPoint, const VECTOR2D &controlPointA, const VECTOR2D &controlPointB, const VECTOR2D &endPoint) override
 Draw a cubic bezier spline. More...
 
virtual void BitmapText (const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle) override
 Draws a text using a bitmap font. More...
 
virtual void DrawGrid () override
 > More...
 
virtual void ResizeScreen (int aWidth, int aHeight) override
 Resizes the canvas. More...
 
virtual bool Show (bool aShow) override
 Shows/hides the GAL canvas. More...
 
virtual void Flush () override
 Force all remaining objects to be drawn. More...
 
virtual void ClearScreen (const COLOR4D &aColor) override
 Clear the screen. More...
 
virtual void Transform (const MATRIX3x3D &aTransformation) override
 Transform the context. More...
 
virtual void Rotate (double aAngle) override
 Rotate the context. More...
 
virtual void Translate (const VECTOR2D &aTranslation) override
 Translate the context. More...
 
virtual void Scale (const VECTOR2D &aScale) override
 Scale the context. More...
 
virtual void Save () override
 Save the context. More...
 
virtual void Restore () override
 Restore the context. More...
 
virtual int BeginGroup () override
 Begin a group. More...
 
virtual void EndGroup () override
 End the group. More...
 
virtual void DrawGroup (int aGroupNumber) override
 Draw the stored group. More...
 
virtual void ChangeGroupColor (int aGroupNumber, const COLOR4D &aNewColor) override
 Changes the color used to draw the group. More...
 
virtual void ChangeGroupDepth (int aGroupNumber, int aDepth) override
 Changes the depth (Z-axis position) of the group. More...
 
virtual void DeleteGroup (int aGroupNumber) override
 Delete the group from the memory. More...
 
virtual void ClearCache () override
 Delete all data created during caching of graphic items. More...
 
virtual void SaveScreen () override
 Save the screen contents. More...
 
virtual void RestoreScreen () override
 Restore the screen contents. More...
 
virtual void SetTarget (RENDER_TARGET aTarget) override
 Sets the target for rendering. More...
 
virtual RENDER_TARGET GetTarget () const override
 Gets the currently used target for rendering. More...
 
virtual void ClearTarget (RENDER_TARGET aTarget) override
 Clears the target for rendering. More...
 
virtual void DrawCursor (const VECTOR2D &aCursorPosition) override
 Draw the cursor. More...
 
void PostPaint ()
 Function PostPaint posts an event to m_paint_listener. More...
 
void SetMouseListener (wxEvtHandler *aMouseListener)
 
void SetPaintListener (wxEvtHandler *aPaintListener)
 Parameters passed to the GLU tesselator. More...
 
const VECTOR2IGetScreenPixelSize () const
 Returns GAL canvas size in pixels. More...
 
virtual void SetIsFill (bool aIsFillEnabled)
 Enable/disable fill. More...
 
virtual void SetIsStroke (bool aIsStrokeEnabled)
 Enable/disable stroked outlines. More...
 
virtual void SetFillColor (const COLOR4D &aColor)
 Set the fill color. More...
 
virtual void SetStrokeColor (const COLOR4D &aColor)
 Set the stroke color. More...
 
const COLOR4DGetStrokeColor () const
 Get the stroke color. More...
 
virtual void SetLineWidth (double aLineWidth)
 Set the line width. More...
 
double GetLineWidth () const
 Get the line width. More...
 
virtual void SetLayerDepth (double aLayerDepth)
 Set the depth of the layer (position on the z-axis) More...
 
const STROKE_FONTGetStrokeFont () const
 
virtual void StrokeText (const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle)
 Draws a vector type text using preloaded Newstroke font. More...
 
VECTOR2D GetTextLineSize (const UTF8 &aText) const
 Compute the X and Y size of a given text. More...
 
double GetOverbarVerticalPosition () const
 Compute the vertical position of an overbar, sometimes used in texts. More...
 
virtual void SetTextAttributes (const EDA_TEXT *aText)
 Loads attributes of the given text (bold/italic/underline/mirrored and so on). More...
 
void ResetTextAttributes ()
 Reset text attributes to default styling. More...
 
void SetGlyphSize (const VECTOR2D aGlyphSize)
 Set the font glyph size. More...
 
const VECTOR2DGetGlyphSize () const
 
void SetFontBold (const bool aBold)
 Set bold property of current font. More...
 
bool IsFontBold () const
 Returns true if current font has 'bold' attribute enabled. More...
 
void SetFontItalic (const bool aItalic)
 Set italic property of current font. More...
 
bool IsFontItalic () const
 Returns true if current font has 'italic' attribute enabled. More...
 
void SetTextMirrored (const bool aMirrored)
 Set a mirrored property of text. More...
 
bool IsTextMirrored () const
 Returns true if text should displayed mirrored. More...
 
void SetHorizontalJustify (const EDA_TEXT_HJUSTIFY_T aHorizontalJustify)
 Set the horizontal justify for text drawing. More...
 
EDA_TEXT_HJUSTIFY_T GetHorizontalJustify () const
 Returns current text horizontal justification setting. More...
 
void SetVerticalJustify (const EDA_TEXT_VJUSTIFY_T aVerticalJustify)
 Set the vertical justify for text drawing. More...
 
EDA_TEXT_VJUSTIFY_T GetVerticalJustify () const
 Returns current text vertical justification setting. More...
 
virtual void ComputeWorldScreenMatrix ()
 Compute the world <-> screen transformation matrix. More...
 
const MATRIX3x3DGetWorldScreenMatrix () const
 Get the world <-> screen transformation matrix. More...
 
const MATRIX3x3DGetScreenWorldMatrix () const
 Get the screen <-> world transformation matrix. More...
 
void SetWorldScreenMatrix (const MATRIX3x3D &aMatrix)
 Set the world <-> screen transformation matrix. More...
 
void SetWorldUnitLength (double aWorldUnitLength)
 Set the unit length. More...
 
void SetScreenDPI (double aScreenDPI)
 Set the dots per inch of the screen. More...
 
void SetLookAtPoint (const VECTOR2D &aPoint)
 Set the Point in world space to look at. More...
 
const VECTOR2DGetLookAtPoint () const
 Get the look at point. More...
 
void SetZoomFactor (double aZoomFactor)
 Set the zoom factor of the scene. More...
 
double GetZoomFactor () const
 Get the zoom factor. More...
 
void SetDepthRange (const VECTOR2D &aDepthRange)
 Set the range of the layer depth. More...
 
double GetMinDepth () const
 Returns the minimum depth in the currently used range (the top). More...
 
double GetMaxDepth () const
 Returns the maximum depth in the currently used range (the bottom). More...
 
double GetWorldScale () const
 Get the world scale. More...
 
void SetFlip (bool xAxis, bool yAxis)
 Sets flipping of the screen. More...
 
void SetGridVisibility (bool aVisibility)
 Sets the visibility setting of the grid. More...
 
void SetGridOrigin (const VECTOR2D &aGridOrigin)
 Set the origin point for the grid. More...
 
void SetGridSize (const VECTOR2D &aGridSize)
 Set the grid size. More...
 
const VECTOR2DGetGridSize () const
 Returns the grid size. More...
 
void SetGridColor (const COLOR4D &aGridColor)
 Set the grid color. More...
 
void SetAxesColor (const COLOR4D &aAxesColor)
 Set the axes color. More...
 
void SetAxesEnabled (bool aAxesEnabled)
 Enables drawing the axes. More...
 
void SetCoarseGrid (int aInterval)
 Draw every tick line wider. More...
 
double GetGridLineWidth () const
 Get the grid line width. More...
 
VECTOR2D GetGridPoint (const VECTOR2D &aPoint) const
 Function GetGridPoint() For a given point it returns the nearest point belonging to the grid in world coordinates. More...
 
VECTOR2D ToWorld (const VECTOR2D &aPoint) const
 Compute the point position in world coordinates from given screen coordinates. More...
 
VECTOR2D ToScreen (const VECTOR2D &aPoint) const
 Compute the point position in screen coordinates from given world coordinates. More...
 
void SetCursorEnabled (bool aCursorEnabled)
 Enable/disable cursor. More...
 
bool IsCursorEnabled () const
 Returns information about cursor visibility. More...
 
void SetCursorColor (const COLOR4D &aCursorColor)
 Set the cursor color. More...
 
void AdvanceDepth ()
 Changes the current depth to deeper, so it is possible to draw objects right beneath other. More...
 
void PushDepth ()
 Stores current drawing depth on the depth stack. More...
 
void PopDepth ()
 Restores previously stored drawing depth for the depth stack. More...
 

Static Public Attributes

static const double METRIC_UNIT_LENGTH = 1e9
 

Protected Member Functions

void computeWorldScale ()
 Compute the scaling factor for the world->screen matrix. More...
 
double computeMinGridSpacing () const
 compute minimum grid spacing from the grid settings More...
 
virtual void drawGridLine (const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
 Draw a grid line (usually a simplified line function). More...
 
COLOR4D getCursorColor () const
 Gets the actual cursor color to draw. More...
 
void OnGalDisplayOptionsChanged (const GAL_DISPLAY_OPTIONS &aOptions) override
 Handler for observer settings changes. More...
 

Protected Attributes

GAL_DISPLAY_OPTIONSoptions
 
UTIL::LINK observerLink
 
std::stack< double > depthStack
 Stored depth values. More...
 
VECTOR2I screenSize
 Screen size in screen coordinates. More...
 
double worldUnitLength
 The unit length of the world coordinates [inch]. More...
 
double screenDPI
 The dots per inch of the screen. More...
 
VECTOR2D lookAtPoint
 Point to be looked at in world space. More...
 
double zoomFactor
 The zoom factor. More...
 
MATRIX3x3D worldScreenMatrix
 World transformation. More...
 
MATRIX3x3D screenWorldMatrix
 Screen transformation. More...
 
double worldScale
 The scale factor world->screen. More...
 
bool globalFlipX
 Flag for X axis flipping. More...
 
bool globalFlipY
 Flag for Y axis flipping. More...
 
double lineWidth
 The line width. More...
 
bool isFillEnabled
 Is filling of graphic objects enabled ? More...
 
bool isStrokeEnabled
 Are the outlines stroked ? More...
 
COLOR4D fillColor
 The fill color. More...
 
COLOR4D strokeColor
 The color of the outlines. More...
 
double layerDepth
 The actual layer depth. More...
 
VECTOR2D depthRange
 Range of the depth. More...
 
bool gridVisibility
 Should the grid be shown. More...
 
GRID_STYLE gridStyle
 Grid display style. More...
 
VECTOR2D gridSize
 The grid size. More...
 
VECTOR2D gridOrigin
 The grid origin. More...
 
VECTOR2D gridOffset
 The grid offset to compensate cursor position. More...
 
COLOR4D gridColor
 Color of the grid. More...
 
COLOR4D axesColor
 Color of the axes. More...
 
bool axesEnabled
 Should the axes be drawn. More...
 
int gridTick
 Every tick line gets the double width. More...
 
double gridLineWidth
 Line width of the grid. More...
 
int gridMinSpacing
 Minimum screen size of the grid (pixels) below which the grid is not drawn. More...
 
bool isCursorEnabled
 Is the cursor enabled? More...
 
bool forceDisplayCursor
 Always show cursor. More...
 
COLOR4D cursorColor
 Cursor color. More...
 
bool fullscreenCursor
 Shape of the cursor (fullscreen or small cross) More...
 
VECTOR2D cursorPosition
 Current cursor position (world coordinates) More...
 
STROKE_FONT strokeFont
 Instance of object that stores information about how to draw texts. More...
 

Static Protected Attributes

static const int MIN_DEPTH = -1024
 Possible depth range. More...
 
static const int MAX_DEPTH = 1023
 
static const int GRID_DEPTH = MAX_DEPTH - 1
 Depth level on which the grid is drawn. More...
 

Private Types

typedef GAL super
 Super class definition. More...
 
typedef std::map< unsigned int, std::shared_ptr< VERTEX_ITEM > > GROUPS_MAP
 

Private Member Functions

bool updatedGalDisplayOptions (const GAL_DISPLAY_OPTIONS &aOptions) override
 Function updatedGalDisplayOptions. More...
 
void drawLineQuad (const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
 Draw a quad for the line. More...
 
void drawSemiCircle (const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
 Draw a semicircle. More...
 
void drawFilledSemiCircle (const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
 Draw a filled semicircle. More...
 
void drawStrokedSemiCircle (const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
 Draw a stroked semicircle. More...
 
void drawPolyline (std::function< VECTOR2D(int)> aPointGetter, int aPointCount)
 
void drawPolygon (GLdouble *aPoints, int aPointCount)
 Draws a filled polygon. More...
 
int drawBitmapChar (unsigned long aChar)
 Draws a single character using bitmap font. More...
 
void drawBitmapOverbar (double aLength, double aHeight)
 Draws an overbar over the currently drawn text. More...
 
std::pair< VECTOR2D, float > computeBitmapTextSize (const wxString &aText) const
 Computes a size of text drawn using bitmap font with current text setting applied. More...
 
void onPaint (wxPaintEvent &aEvent)
 This is the OnPaint event handler. More...
 
void skipMouseEvent (wxMouseEvent &aEvent)
 Skip the mouse event to the parent. More...
 
void blitCursor ()
 Blits cursor into the current screen. More...
 
unsigned int getNewGroupNumber ()
 Returns a valid key that can be used as a new group number. More...
 
double calcAngleStep (double aRadius) const
 Compute the angle step when drawing arcs/circles approximated with lines. More...
 
void init ()
 Basic OpenGL initialization. More...
 

Private Attributes

wxGLContext * glPrivContext
 Canvas-specific OpenGL context. More...
 
wxEvtHandler * mouseListener
 
wxEvtHandler * paintListener
 
GROUPS_MAP groups
 Stores informations about VBO objects (groups) More...
 
unsigned int groupCounter
 Counter used for generating keys for groups. More...
 
VERTEX_MANAGERcurrentManager
 Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs) More...
 
VERTEX_MANAGERcachedManager
 Container for storing cached VERTEX_ITEMs. More...
 
VERTEX_MANAGERnonCachedManager
 Container for storing non-cached VERTEX_ITEMs. More...
 
VERTEX_MANAGERoverlayManager
 Container for storing overlaid VERTEX_ITEMs. More...
 
OPENGL_COMPOSITORcompositor
 Handles multiple rendering targets. More...
 
unsigned int mainBuffer
 Main rendering target. More...
 
unsigned int overlayBuffer
 Auxiliary rendering target (for menus etc.) More...
 
RENDER_TARGET currentTarget
 Current rendering target. More...
 
bool isFramebufferInitialized
 Are the framebuffers initialized? More...
 
bool isBitmapFontInitialized
 Is the shader set to use bitmap fonts? More...
 
bool isInitialized
 Basic initialization flag, has to be done when the window is visible. More...
 
bool isGrouping
 Was a group started? More...
 
GLUtesselator * tesselator
 The tessellator. More...
 
std::deque< boost::shared_array< GLdouble > > tessIntersects
 Storage for intersecting points. More...
 

Static Private Attributes

static const int CIRCLE_POINTS = 64
 The number of points for circle approximation. More...
 
static const int CURVE_POINTS = 32
 The number of points for curve approximation. More...
 
static wxGLContext * glMainContext = NULL
 Parent OpenGL context. More...
 
static int instanceCounter = 0
 GL GAL instance counter. More...
 
static GLuint fontTexture = 0
 Bitmap font texture handle (shared) More...
 
static SHADERshader = NULL
 There is only one shader used for different objects. More...
 
static bool isBitmapFontLoaded = false
 Is the bitmap font texture loaded? More...
 

Detailed Description

Class OpenGL_GAL is the OpenGL implementation of the Graphics Abstraction Layer.

This is a direct OpenGL-implementation and uses low-level graphics primitives like triangles and quads. The purpose is to provide a fast graphics interface, that takes advantage of modern graphics card GPUs. All methods here benefit thus from the hardware acceleration.

Definition at line 65 of file opengl_gal.h.

Member Typedef Documentation

typedef std::map< unsigned int, std::shared_ptr<VERTEX_ITEM> > KIGFX::OPENGL_GAL::GROUPS_MAP
private

Definition at line 299 of file opengl_gal.h.

typedef GAL KIGFX::OPENGL_GAL::super
private

Super class definition.

Definition at line 285 of file opengl_gal.h.

Constructor & Destructor Documentation

OPENGL_GAL::OPENGL_GAL ( GAL_DISPLAY_OPTIONS aDisplayOptions,
wxWindow *  aParent,
wxEvtHandler *  aMouseListener = nullptr,
wxEvtHandler *  aPaintListener = nullptr,
const wxString &  aName = wxT( "GLCanvas" ) 
)

Constructor OPENGL_GAL.

Parameters
aParentis the wxWidgets immediate wxWindow parent of this object.
aMouseListeneris the wxEvtHandler that should receive the mouse events, this can be can be any wxWindow, but is often a wxFrame container.
aPaintListeneris the wxEvtHandler that should receive the paint event. This can be any wxWindow, but is often a derived instance of this class or a containing wxFrame. The "paint event" here is a wxCommandEvent holding EVT_GAL_REDRAW, as sent by PostPaint().
aNameis the name of this window for use by wxWindow::FindWindowByName()

Definition at line 66 of file opengl_gal.cpp.

References BLUE, cachedManager, compositor, GL_CONTEXT_MANAGER::CreateCtx(), GL_CONTEXT_MANAGER::Get(), KIGFX::GAL_DISPLAY_OPTIONS::gl_antialiasing_mode, glMainContext, glPrivContext, groupCounter, InitTesselatorCallbacks(), instanceCounter, isBitmapFontInitialized, isFramebufferInitialized, isGrouping, isInitialized, nonCachedManager, onPaint(), KIGFX::GAL::options, overlayManager, KIGFX::GAL::screenSize, KIGFX::OPENGL_COMPOSITOR::SetAntialiasingMode(), KIGFX::GAL::SetAxesColor(), KIGFX::GAL::SetGridColor(), SetTarget(), shader, skipMouseEvent(), KIGFX::TARGET_NONCACHED, and tesselator.

68  :
69  GAL( aDisplayOptions ),
70  wxGLCanvas( aParent, wxID_ANY, (int*) glAttributes, wxDefaultPosition, wxDefaultSize,
71  wxEXPAND, aName ),
72  mouseListener( aMouseListener ), paintListener( aPaintListener )
73 {
74  if( glMainContext == NULL )
75  {
78  shader = new SHADER();
79  }
80  else
81  {
83  }
84 
86 
89 
90  cachedManager = new VERTEX_MANAGER( true );
91  nonCachedManager = new VERTEX_MANAGER( false );
92  overlayManager = new VERTEX_MANAGER( false );
93 
94  // Initialize the flags
97  isInitialized = false;
98  isGrouping = false;
99  groupCounter = 0;
100 
101 #ifdef RETINA_OPENGL_PATCH
102  SetViewWantsBestResolution( true );
103 #endif
104 
105  // Connecting the event handlers
106  Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) );
107 
108  // Mouse events are skipped to the parent
109  Connect( wxEVT_MOTION, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
110  Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
111  Connect( wxEVT_LEFT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
112  Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
113  Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
114  Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
115  Connect( wxEVT_MIDDLE_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
116  Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
117  Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
118  Connect( wxEVT_RIGHT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
119  Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
120 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
121  Connect( wxEVT_MAGNIFY, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
122 #endif
123 #if defined _WIN32 || defined _WIN64
124  Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
125 #endif
126 
127  SetSize( aParent->GetSize() );
128  screenSize = VECTOR2I( aParent->GetSize() );
129 
130  // Grid color settings are different in Cairo and OpenGL
131  SetGridColor( COLOR4D( 0.8, 0.8, 0.8, 0.1 ) );
132  SetAxesColor( COLOR4D( BLUE ) );
133 
134  // Tesselator initialization
135  tesselator = gluNewTess();
137 
138  if( tesselator == NULL )
139  throw std::runtime_error( "Could not create the tesselator" );
140 
141  gluTessProperty( tesselator, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE );
142 
144 }
Definition: colors.h:57
static SHADER * shader
There is only one shader used for different objects.
Definition: opengl_gal.h:314
static wxGLContext * glMainContext
Parent OpenGL context.
Definition: opengl_gal.h:290
bool isBitmapFontInitialized
Is the shader set to use bitmap fonts?
Definition: opengl_gal.h:319
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:305
GAL_DISPLAY_OPTIONS & options
static void InitTesselatorCallbacks(GLUtesselator *aTesselator)
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
bool isGrouping
Was a group started?
Definition: opengl_gal.h:322
OPENGL_ANTIALIASING_MODE gl_antialiasing_mode
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
Auxiliary rendering target (noncached)
Definition: definitions.h:42
static int instanceCounter
GL GAL instance counter.
Definition: opengl_gal.h:292
void SetAntialiasingMode(OPENGL_ANTIALIASING_MODE aMode)
static GL_CONTEXT_MANAGER & Get()
Function Get returns the GL_CONTEXT_MANAGER instance (singleton).
GAL(GAL_DISPLAY_OPTIONS &aOptions)
void SetGridColor(const COLOR4D &aGridColor)
Set the grid color.
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:308
wxEvtHandler * mouseListener
Definition: opengl_gal.h:293
void SetAxesColor(const COLOR4D &aAxesColor)
Set the axes color.
static const int glAttributes[]
Definition: opengl_gal.cpp:57
void onPaint(wxPaintEvent &aEvent)
This is the OnPaint event handler.
bool isFramebufferInitialized
Are the framebuffers initialized?
Definition: opengl_gal.h:317
Class SHADER provides the access to the OpenGL shaders.
Definition: shader.h:74
GLUtesselator * tesselator
The tessellator.
Definition: opengl_gal.h:329
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
wxEvtHandler * paintListener
Definition: opengl_gal.h:294
virtual void SetTarget(RENDER_TARGET aTarget) override
Sets the target for rendering.
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:320
unsigned int groupCounter
Counter used for generating keys for groups.
Definition: opengl_gal.h:301
VECTOR2I screenSize
Screen size in screen coordinates.
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:291
wxGLContext * CreateCtx(wxGLCanvas *aCanvas, const wxGLContext *aOther=NULL)
Function CreateCtx creates a managed OpenGL context.
void skipMouseEvent(wxMouseEvent &aEvent)
Skip the mouse event to the parent.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
OPENGL_GAL::~OPENGL_GAL ( )
virtual

Definition at line 147 of file opengl_gal.cpp.

References cachedManager, ClearCache(), compositor, GL_CONTEXT_MANAGER::DestroyCtx(), fontTexture, GL_CONTEXT_MANAGER::Get(), glMainContext, glPrivContext, instanceCounter, isBitmapFontLoaded, GL_CONTEXT_MANAGER::LockCtx(), nonCachedManager, overlayManager, shader, tesselator, and GL_CONTEXT_MANAGER::UnlockCtx().

148 {
150 
151  --instanceCounter;
152  glFlush();
153  gluDeleteTess( tesselator );
154  ClearCache();
155 
156  delete compositor;
157  delete cachedManager;
158  delete nonCachedManager;
159  delete overlayManager;
160 
162 
163  // If it was the main context, then it will be deleted
164  // when the last OpenGL GAL instance is destroyed (a few lines below)
167 
168  // Are we destroying the last GAL instance?
169  if( instanceCounter == 0 )
170  {
172 
173  if( isBitmapFontLoaded )
174  {
175  glDeleteTextures( 1, &fontTexture );
176  isBitmapFontLoaded = false;
177  }
178 
179  delete shader;
180 
183  glMainContext = NULL;
184  }
185 }
static SHADER * shader
There is only one shader used for different objects.
Definition: opengl_gal.h:314
static wxGLContext * glMainContext
Parent OpenGL context.
Definition: opengl_gal.h:290
static GLuint fontTexture
Bitmap font texture handle (shared)
Definition: opengl_gal.h:296
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:305
void UnlockCtx(wxGLContext *aContext)
Function UnlockCtx allows other canvases to bind an OpenGL context.
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
static int instanceCounter
GL GAL instance counter.
Definition: opengl_gal.h:292
static GL_CONTEXT_MANAGER & Get()
Function Get returns the GL_CONTEXT_MANAGER instance (singleton).
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:308
virtual void ClearCache() override
Delete all data created during caching of graphic items.
GLUtesselator * tesselator
The tessellator.
Definition: opengl_gal.h:329
void LockCtx(wxGLContext *aContext, wxGLCanvas *aCanvas)
Function LockCtx sets a context as current and prevents other canvases from switching it...
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:291
void DestroyCtx(wxGLContext *aContext)
Function DestroyCtx destroys a managed OpenGL context.
static bool isBitmapFontLoaded
Is the bitmap font texture loaded?
Definition: opengl_gal.h:318

Member Function Documentation

void KIGFX::GAL::AdvanceDepth ( )
inlineinherited

Changes the current depth to deeper, so it is possible to draw objects right beneath other.

Definition at line 939 of file graphics_abstraction_layer.h.

References KIGFX::GAL::layerDepth.

940  {
941  layerDepth -= 0.05;
942  }
double layerDepth
The actual layer depth.
void OPENGL_GAL::BeginDrawing ( )
overridevirtual

Begin the drawing, needs to be called for every new frame.

Reimplemented from KIGFX::GAL.

Definition at line 209 of file opengl_gal.cpp.

References KIGFX::SHADER::AddParameter(), KIGFX::OPENGL_COMPOSITOR::Begin(), KIGFX::VERTEX_MANAGER::BeginDrawing(), cachedManager, checkGlError(), KIGFX::VERTEX_MANAGER::Clear(), compositor, KIGFX::GAL::ComputeWorldScreenMatrix(), KIGFX::OPENGL_COMPOSITOR::CreateBuffer(), KIGFX::SHADER::Deactivate(), KIGFX::GAL::depthRange, KIGFX::OPENGL_COMPOSITOR::DIRECT_RENDERING, KIGFX::GAL::fillColor, KIGFX::BUILTIN_FONT::font_image, fontTexture, GL_CONTEXT_MANAGER::Get(), glPrivContext, KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::height, init(), KIGFX::OPENGL_COMPOSITOR::Initialize(), isBitmapFontInitialized, isBitmapFontLoaded, isFramebufferInitialized, isInitialized, GL_CONTEXT_MANAGER::LockCtx(), MATRIX3x3< T >::m_data, mainBuffer, PROF_COUNTER::msecs(), nonCachedManager, overlayBuffer, overlayManager, KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::pixels, KIGFX::GAL::screenSize, KIGFX::OPENGL_COMPOSITOR::SetBuffer(), KIGFX::GAL::SetFillColor(), KIGFX::SHADER::SetParameter(), KIGFX::GAL::SetStrokeColor(), shader, PROF_COUNTER::Stop(), KIGFX::GAL::strokeColor, GL_CONTEXT_MANAGER::UnlockCtx(), KIGFX::SHADER::Use(), KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::width, KIGFX::GAL::worldScreenMatrix, VECTOR2< T >::x, and VECTOR2< T >::y.

210 {
211  if( !IsShownOnScreen() )
212  return;
213 
214 #ifdef __WXDEBUG__
215  PROF_COUNTER totalRealTime( "OPENGL_GAL::BeginDrawing()", true );
216 #endif /* __WXDEBUG__ */
217 
218  if( !isInitialized )
219  init();
220 
222 
223  // Set up the view port
224  glMatrixMode( GL_PROJECTION );
225  glLoadIdentity();
226 
227  // Create the screen transformation (Do the RH-LH conversion here)
228  glOrtho( 0, (GLint) screenSize.x, (GLsizei) screenSize.y, 0, -depthRange.x, -depthRange.y );
229 
231  {
232  try
233  {
234  // Prepare rendering target buffers
238  }
239  catch( std::runtime_error& )
240  {
242  throw; // DRAW_PANEL_GAL will handle it
243  }
244 
246  }
247 
248  compositor->Begin();
249 
250  // Disable 2D Textures
251  glDisable( GL_TEXTURE_2D );
252 
253  glShadeModel( GL_FLAT );
254 
255  // Enable the depth buffer
256  glEnable( GL_DEPTH_TEST );
257  glDepthFunc( GL_LESS );
258 
259  // Setup blending, required for transparent objects
260  glEnable( GL_BLEND );
261  glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
262 
263  glMatrixMode( GL_MODELVIEW );
264 
265  // Set up the world <-> screen transformation
267  GLdouble matrixData[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
268  matrixData[0] = worldScreenMatrix.m_data[0][0];
269  matrixData[1] = worldScreenMatrix.m_data[1][0];
270  matrixData[2] = worldScreenMatrix.m_data[2][0];
271  matrixData[4] = worldScreenMatrix.m_data[0][1];
272  matrixData[5] = worldScreenMatrix.m_data[1][1];
273  matrixData[6] = worldScreenMatrix.m_data[2][1];
274  matrixData[12] = worldScreenMatrix.m_data[0][2];
275  matrixData[13] = worldScreenMatrix.m_data[1][2];
276  matrixData[14] = worldScreenMatrix.m_data[2][2];
277  glLoadMatrixd( matrixData );
278 
279  // Set defaults
282 
283  // Remove all previously stored items
286 
290 
292  {
293  // Keep bitmap font texture always bound to the second texturing unit
294  const GLint FONT_TEXTURE_UNIT = 2;
295 
296  // Either load the font atlas to video memory, or simply bind it to a texture unit
297  if( !isBitmapFontLoaded )
298  {
299  glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT );
300  glGenTextures( 1, &fontTexture );
301  glBindTexture( GL_TEXTURE_2D, fontTexture );
302  glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, font_image.width, font_image.height,
303  0, GL_RGB, GL_UNSIGNED_BYTE, font_image.pixels );
304  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
305  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
306  checkGlError( "loading bitmap font" );
307 
308  glActiveTexture( GL_TEXTURE0 );
309 
310  isBitmapFontLoaded = true;
311  }
312  else
313  {
314  glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT );
315  glBindTexture( GL_TEXTURE_2D, fontTexture );
316  glActiveTexture( GL_TEXTURE0 );
317  }
318 
319  // Set shader parameter
320  GLint ufm_fontTexture = shader->AddParameter( "fontTexture" );
321  GLint ufm_fontTextureWidth = shader->AddParameter( "fontTextureWidth" );
322  shader->Use();
323  shader->SetParameter( ufm_fontTexture, (int) FONT_TEXTURE_UNIT );
324  shader->SetParameter( ufm_fontTextureWidth, (int) font_image.width );
325  shader->Deactivate();
326  checkGlError( "setting bitmap font sampler as shader parameter" );
327 
329  }
330 
331  // Something betreen BeginDrawing and EndDrawing seems to depend on
332  // this texture unit being active, but it does not assure it itself.
333  glActiveTexture( GL_TEXTURE0 );
334 
335  // Unbind buffers - set compositor for direct drawing
337 
338 #ifdef __WXDEBUG__
339  totalRealTime.Stop();
340  wxLogTrace( "GAL_PROFILE",
341  wxT( "OPENGL_GAL::BeginDrawing(): %.1f ms" ), totalRealTime.msecs() );
342 #endif /* __WXDEBUG__ */
343 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
static SHADER * shader
There is only one shader used for different objects.
Definition: opengl_gal.h:314
void Clear() const
Function Clear() removes all the stored vertices from the container.
unsigned int overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:310
virtual void Begin() override
Function Begin() Call this at the beginning of each frame.
bool isBitmapFontInitialized
Is the shader set to use bitmap fonts?
Definition: opengl_gal.h:319
void Use()
Use the shader.
Definition: shader.h:130
void SetParameter(int aParameterNumber, float aValue) const
Set a parameter of the shader.
Definition: shader.cpp:137
static GLuint fontTexture
Bitmap font texture handle (shared)
Definition: opengl_gal.h:296
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:305
COLOR4D fillColor
The fill color.
VECTOR2D depthRange
Range of the depth.
int checkGlError(const std::string &aInfo, bool aThrow)
Checks if one of recent OpenGL operations has failed.
Definition: utils.cpp:30
static const unsigned int DIRECT_RENDERING
virtual void ComputeWorldScreenMatrix()
Compute the world <-> screen transformation matrix.
The class PROF_COUNTER is a small class to help profiling.
Definition: profile.h:45
void UnlockCtx(wxGLContext *aContext)
Function UnlockCtx allows other canvases to bind an OpenGL context.
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
T m_data[3][3]
Definition: matrix3x3.h:64
static GL_CONTEXT_MANAGER & Get()
Function Get returns the GL_CONTEXT_MANAGER instance (singleton).
void init()
Basic OpenGL initialization.
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:308
unsigned int mainBuffer
Main rendering target.
Definition: opengl_gal.h:309
COLOR4D strokeColor
The color of the outlines.
int AddParameter(const std::string &aParameterName)
Add a parameter to the parameter queue.
Definition: shader.cpp:124
void Deactivate()
Deactivate the shader and use the default OpenGL program.
Definition: shader.h:139
bool isFramebufferInitialized
Are the framebuffers initialized?
Definition: opengl_gal.h:317
FONT_IMAGE_TYPE font_image
Definition: gl_resources.cpp:4
unsigned char pixels[1024 *1024 *3]
Definition: gl_resources.h:38
MATRIX3x3D worldScreenMatrix
World transformation.
virtual void SetBuffer(unsigned int aBufferHandle) override
Function SetBuffer() sets the selected buffer as the rendering target.
void BeginDrawing() const
Function BeginDrawing() prepares buffers and items to start drawing.
void LockCtx(wxGLContext *aContext, wxGLCanvas *aCanvas)
Function LockCtx sets a context as current and prevents other canvases from switching it...
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
virtual void Initialize() override
Function Reset() performs primary initialiation, necessary to use the object.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:320
VECTOR2I screenSize
Screen size in screen coordinates.
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:291
virtual unsigned int CreateBuffer() override
Function CreateBuffer() prepares a new buffer that may be used as a rendering target.
static bool isBitmapFontLoaded
Is the bitmap font texture loaded?
Definition: opengl_gal.h:318
int OPENGL_GAL::BeginGroup ( )
overridevirtual

Begin a group.

A group is a collection of graphic items. Hierarchical groups are possible, attributes and transformations can be used.

Returns
the number of the group.

Reimplemented from KIGFX::GAL.

Definition at line 1206 of file opengl_gal.cpp.

References getNewGroupNumber(), groups, and isGrouping.

1207 {
1208  isGrouping = true;
1209 
1210  std::shared_ptr<VERTEX_ITEM> newItem = std::make_shared<VERTEX_ITEM>( *cachedManager );
1211  int groupNumber = getNewGroupNumber();
1212  groups.insert( std::make_pair( groupNumber, newItem ) );
1213 
1214  return groupNumber;
1215 }
bool isGrouping
Was a group started?
Definition: opengl_gal.h:322
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:300
unsigned int getNewGroupNumber()
Returns a valid key that can be used as a new group number.
void OPENGL_GAL::BeginUpdate ( )
overridevirtual

Enables item update mode.

Reimplemented from KIGFX::GAL.

Definition at line 380 of file opengl_gal.cpp.

References cachedManager, GL_CONTEXT_MANAGER::Get(), glPrivContext, init(), isInitialized, GL_CONTEXT_MANAGER::LockCtx(), and KIGFX::VERTEX_MANAGER::Map().

381 {
382  if( !IsShownOnScreen() )
383  return;
384 
385  if( !isInitialized )
386  init();
387 
389  cachedManager->Map();
390 }
static GL_CONTEXT_MANAGER & Get()
Function Get returns the GL_CONTEXT_MANAGER instance (singleton).
void init()
Basic OpenGL initialization.
void Map()
Function Map() maps vertex buffer.
void LockCtx(wxGLContext *aContext, wxGLCanvas *aCanvas)
Function LockCtx sets a context as current and prevents other canvases from switching it...
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:320
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:291
void OPENGL_GAL::BitmapText ( const wxString &  aText,
const VECTOR2D aPosition,
double  aRotationAngle 
)
overridevirtual

Draws a text using a bitmap font.

It should be faster than StrokeText(), but can be used only for non-Gerber elements.

Parameters
aTextis the text to be drawn.
aPositionis the text position in world coordinates.
aRotationAngleis the text rotation angle.

Reimplemented from KIGFX::GAL.

Definition at line 831 of file opengl_gal.cpp.

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), computeBitmapTextSize(), currentManager, drawBitmapChar(), drawBitmapOverbar(), KIGFX::COLOR4D::g, KIGFX::GAL::GetGlyphSize(), KIGFX::GAL::GetHorizontalJustify(), KIGFX::GAL::GetVerticalJustify(), KIGFX::GAL::globalFlipX, KIGFX::GAL::globalFlipY, GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, KIGFX::GAL::IsTextMirrored(), KIGFX::GAL::layerDepth, KIGFX::BUILTIN_FONT::LookupGlyph(), KIGFX::COLOR4D::r, Restore(), KIGFX::VERTEX_MANAGER::Rotate(), Save(), KIGFX::VERTEX_MANAGER::Scale(), KIGFX::GAL::strokeColor, KIGFX::VERTEX_MANAGER::Translate(), Translate(), VECTOR2< T >::x, and VECTOR2< T >::y.

833 {
834  wxASSERT_MSG( !IsTextMirrored(), "No support for mirrored text using bitmap fonts." );
835 
836  // Compute text size, so it can be properly justified
837  VECTOR2D textSize;
838  float commonOffset;
839  std::tie( textSize, commonOffset ) = computeBitmapTextSize( aText );
840 
841  const double SCALE = GetGlyphSize().y / textSize.y;
842  int tildas = 0;
843  bool overbar = false;
844 
845  int overbarLength = 0;
846  double overbarHeight = textSize.y;
847 
848  Save();
849 
851  currentManager->Translate( aPosition.x, aPosition.y, layerDepth );
852  currentManager->Rotate( aRotationAngle, 0.0f, 0.0f, -1.0f );
853 
854  double sx = SCALE * ( globalFlipX ? -1.0 : 1.0 );
855  double sy = SCALE * ( globalFlipY ? -1.0 : 1.0 );
856 
857  currentManager->Scale( sx, sy, 0 );
858  currentManager->Translate( 0, -commonOffset, 0 );
859 
860  switch( GetHorizontalJustify() )
861  {
863  Translate( VECTOR2D( -textSize.x / 2.0, 0 ) );
864  break;
865 
867  //if( !IsTextMirrored() )
868  Translate( VECTOR2D( -textSize.x, 0 ) );
869  break;
870 
872  //if( IsTextMirrored() )
873  //Translate( VECTOR2D( -textSize.x, 0 ) );
874  break;
875  }
876 
877  switch( GetVerticalJustify() )
878  {
880  Translate( VECTOR2D( 0, -textSize.y ) );
881  overbarHeight = -textSize.y / 2.0;
882  break;
883 
885  Translate( VECTOR2D( 0, -textSize.y / 2.0 ) );
886  overbarHeight = 0;
887  break;
888 
890  break;
891  }
892 
893  for( unsigned int ii = 0; ii < aText.length(); ++ii )
894  {
895  const unsigned int c = aText[ii];
896 
897  wxASSERT_MSG( LookupGlyph(c) != nullptr, wxT( "Missing character in bitmap font atlas." ) );
898  wxASSERT_MSG( c != '\n' && c != '\r', wxT( "No support for multiline bitmap text yet" ) );
899 
900  // Handle overbar
901  if( c == '~' )
902  {
903  overbar = !overbar;
904  ++tildas;
905  continue;
906  }
907  else if( tildas > 0 )
908  {
909  if( tildas % 2 == 1 )
910  {
911  if( overbar ) // Overbar begins
912  overbarLength = 0;
913  else if( overbarLength > 0 ) // Overbar finishes
914  drawBitmapOverbar( overbarLength, overbarHeight );
915 
916  --tildas;
917  }
918 
919  // Draw tilda characters if there are any remaining
920  for( int jj = 0; jj < tildas / 2; ++jj )
921  overbarLength += drawBitmapChar( '~' );
922 
923  tildas = 0;
924  }
925 
926  overbarLength += drawBitmapChar( c );
927  }
928 
929  // Handle the case when overbar is active till the end of the drawn text
930  currentManager->Translate( 0, commonOffset, 0 );
931 
932  if( overbar )
933  drawBitmapOverbar( overbarLength, overbarHeight );
934 
935  Restore();
936 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
EDA_TEXT_HJUSTIFY_T GetHorizontalJustify() const
Returns current text horizontal justification setting.
EDA_TEXT_VJUSTIFY_T GetVerticalJustify() const
Returns current text vertical justification setting.
double layerDepth
The actual layer depth.
virtual void Translate(const VECTOR2D &aTranslation) override
Translate the context.
virtual void Restore() override
Restore the context.
void Rotate(GLfloat aAngle, GLfloat aX, GLfloat aY, GLfloat aZ)
Function Rotate() multiplies the current matrix by a rotation matrix, so the newly vertices will be r...
double g
Green component.
Definition: color4d.h:282
bool globalFlipX
Flag for X axis flipping.
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
double b
Blue component.
Definition: color4d.h:283
virtual void Save() override
Save the context.
double a
Alpha component.
Definition: color4d.h:284
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
COLOR4D strokeColor
The color of the outlines.
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Function Translate() multiplies the current matrix by a translation matrix, so newly vertices will be...
const VECTOR2D & GetGlyphSize() const
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices...
bool globalFlipY
Flag for Y axis flipping.
int drawBitmapChar(unsigned long aChar)
Draws a single character using bitmap font.
void Scale(GLfloat aX, GLfloat aY, GLfloat aZ)
Function Scale() multiplies the current matrix by a scaling matrix, so the newly vertices will be sca...
std::pair< VECTOR2D, float > computeBitmapTextSize(const wxString &aText) const
Computes a size of text drawn using bitmap font with current text setting applied.
double r
Red component.
Definition: color4d.h:281
bool IsTextMirrored() const
Returns true if text should displayed mirrored.
void drawBitmapOverbar(double aLength, double aHeight)
Draws an overbar over the currently drawn text.
void OPENGL_GAL::blitCursor ( )
private

Blits cursor into the current screen.

Definition at line 1658 of file opengl_gal.cpp.

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, color, compositor, KIGFX::GAL::cursorPosition, KIGFX::OPENGL_COMPOSITOR::DIRECT_RENDERING, KIGFX::GAL::fullscreenCursor, KIGFX::COLOR4D::g, KIGFX::GAL::getCursorColor(), KIGFX::GAL::IsCursorEnabled(), KIGFX::COLOR4D::r, KIGFX::OPENGL_COMPOSITOR::SetBuffer(), KIGFX::GAL::worldScale, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by EndDrawing().

1659 {
1660  if( !IsCursorEnabled() )
1661  return;
1662 
1664 
1665  const int cursorSize = fullscreenCursor ? 8000 : 80;
1666 
1667  VECTOR2D cursorBegin = cursorPosition - cursorSize / ( 2 * worldScale );
1668  VECTOR2D cursorEnd = cursorPosition + cursorSize / ( 2 * worldScale );
1669  VECTOR2D cursorCenter = ( cursorBegin + cursorEnd ) / 2;
1670 
1671  const COLOR4D cColor = getCursorColor();
1672  const COLOR4D color( cColor.r * cColor.a, cColor.g * cColor.a,
1673  cColor.b * cColor.a, 1.0 );
1674 
1675  glDisable( GL_TEXTURE_2D );
1676  glLineWidth( 1.0 );
1677  glColor4d( color.r, color.g, color.b, color.a );
1678 
1679  glBegin( GL_LINES );
1680  glVertex2d( cursorCenter.x, cursorBegin.y );
1681  glVertex2d( cursorCenter.x, cursorEnd.y );
1682 
1683  glVertex2d( cursorBegin.x, cursorCenter.y );
1684  glVertex2d( cursorEnd.x, cursorCenter.y );
1685  glEnd();
1686 }
bool IsCursorEnabled() const
Returns information about cursor visibility.
VECTOR2D cursorPosition
Current cursor position (world coordinates)
double g
Green component.
Definition: color4d.h:282
static const unsigned int DIRECT_RENDERING
double b
Blue component.
Definition: color4d.h:283
double a
Alpha component.
Definition: color4d.h:284
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:308
bool fullscreenCursor
Shape of the cursor (fullscreen or small cross)
COLOR4D getCursorColor() const
Gets the actual cursor color to draw.
virtual void SetBuffer(unsigned int aBufferHandle) override
Function SetBuffer() sets the selected buffer as the rendering target.
double worldScale
The scale factor world->screen.
double r
Red component.
Definition: color4d.h:281
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
double KIGFX::OPENGL_GAL::calcAngleStep ( double  aRadius) const
inlineprivate

Compute the angle step when drawing arcs/circles approximated with lines.

Definition at line 446 of file opengl_gal.h.

References min.

Referenced by DrawArc(), and DrawArcSegment().

447  {
448  // Bigger arcs need smaller alpha increment to make them look smooth
449  return std::min( 1e6 / aRadius, 2.0 * M_PI / CIRCLE_POINTS );
450  }
CIRCLE_POINTS
#define min(a, b)
Definition: auxiliary.h:85
void OPENGL_GAL::ChangeGroupColor ( int  aGroupNumber,
const COLOR4D aNewColor 
)
overridevirtual

Changes the color used to draw the group.

Parameters
aGroupNumberis the group number.
aNewColoris the new color.

Reimplemented from KIGFX::GAL.

Definition at line 1231 of file opengl_gal.cpp.

References cachedManager, KIGFX::VERTEX_MANAGER::ChangeItemColor(), and groups.

1232 {
1233  cachedManager->ChangeItemColor( *groups[aGroupNumber], aNewColor );
1234 }
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:300
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
void ChangeItemColor(const VERTEX_ITEM &aItem, const COLOR4D &aColor) const
Function ChangeItemColor() changes the color of all vertices owned by an item.
void OPENGL_GAL::ChangeGroupDepth ( int  aGroupNumber,
int  aDepth 
)
overridevirtual

Changes the depth (Z-axis position) of the group.

Parameters
aGroupNumberis the group number.
aDepthis the new depth.

Reimplemented from KIGFX::GAL.

Definition at line 1237 of file opengl_gal.cpp.

References cachedManager, KIGFX::VERTEX_MANAGER::ChangeItemDepth(), and groups.

1238 {
1239  cachedManager->ChangeItemDepth( *groups[aGroupNumber], aDepth );
1240 }
void ChangeItemDepth(const VERTEX_ITEM &aItem, GLfloat aDepth) const
Function ChangeItemDepth() changes the depth of all vertices owned by an item.
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:300
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
void OPENGL_GAL::ClearCache ( )
overridevirtual

Delete all data created during caching of graphic items.

Reimplemented from KIGFX::GAL.

Definition at line 1250 of file opengl_gal.cpp.

References cachedManager, KIGFX::VERTEX_MANAGER::Clear(), and groups.

Referenced by ~OPENGL_GAL().

1251 {
1252  groups.clear();
1253  cachedManager->Clear();
1254 }
void Clear() const
Function Clear() removes all the stored vertices from the container.
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:300
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
void OPENGL_GAL::ClearScreen ( const COLOR4D aColor)
overridevirtual

Clear the screen.

Parameters
aColoris the color used for clearing.

Reimplemented from KIGFX::GAL.

Definition at line 1149 of file opengl_gal.cpp.

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, compositor, KIGFX::OPENGL_COMPOSITOR::DIRECT_RENDERING, KIGFX::COLOR4D::g, KIGFX::COLOR4D::r, and KIGFX::OPENGL_COMPOSITOR::SetBuffer().

1150 {
1151  // Clear screen
1153  glClearColor( aColor.r, aColor.g, aColor.b, aColor.a );
1154  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
1155 }
double g
Green component.
Definition: color4d.h:282
static const unsigned int DIRECT_RENDERING
double b
Blue component.
Definition: color4d.h:283
double a
Alpha component.
Definition: color4d.h:284
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:308
virtual void SetBuffer(unsigned int aBufferHandle) override
Function SetBuffer() sets the selected buffer as the rendering target.
double r
Red component.
Definition: color4d.h:281
void OPENGL_GAL::ClearTarget ( RENDER_TARGET  aTarget)
overridevirtual

Clears the target for rendering.

Parameters
aTargetis the target to be cleared.

Reimplemented from KIGFX::GAL.

Definition at line 1297 of file opengl_gal.cpp.

References KIGFX::OPENGL_COMPOSITOR::ClearBuffer(), compositor, KIGFX::OPENGL_COMPOSITOR::GetBuffer(), mainBuffer, overlayBuffer, KIGFX::OPENGL_COMPOSITOR::SetBuffer(), KIGFX::TARGET_CACHED, KIGFX::TARGET_NONCACHED, and KIGFX::TARGET_OVERLAY.

1298 {
1299  // Save the current state
1300  unsigned int oldTarget = compositor->GetBuffer();
1301 
1302  switch( aTarget )
1303  {
1304  // Cached and noncached items are rendered to the same buffer
1305  default:
1306  case TARGET_CACHED:
1307  case TARGET_NONCACHED:
1309  break;
1310 
1311  case TARGET_OVERLAY:
1313  break;
1314  }
1315 
1317 
1318  // Restore the previous state
1319  compositor->SetBuffer( oldTarget );
1320 }
unsigned int overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:310
Auxiliary rendering target (noncached)
Definition: definitions.h:42
virtual void ClearBuffer() override
Function ClearBuffer() clears the selected buffer (set by the SetBuffer() function).
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:308
unsigned int mainBuffer
Main rendering target.
Definition: opengl_gal.h:309
Items that may change while the view stays the same (noncached)
Definition: definitions.h:43
virtual void SetBuffer(unsigned int aBufferHandle) override
Function SetBuffer() sets the selected buffer as the rendering target.
Main rendering target (cached)
Definition: definitions.h:41
virtual unsigned int GetBuffer() const override
Function GetBuffer() returns currently used buffer handle.
std::pair< VECTOR2D, float > OPENGL_GAL::computeBitmapTextSize ( const wxString &  aText) const
private

Computes a size of text drawn using bitmap font with current text setting applied.

Parameters
aTextis the text to be drawn.
Returns
Pair containing text bounding box and common Y axis offset. The values are expressed as a number of pixels on the bitmap font texture and need to be scaled before drawing.

Definition at line 1605 of file opengl_gal.cpp.

References KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::advance, KIGFX::BUILTIN_FONT::font_information, KIGFX::BUILTIN_FONT::LookupGlyph(), max, KIGFX::BUILTIN_FONT::FONT_INFO_TYPE::max_y, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::maxy, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::miny, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BitmapText().

1606 {
1607  VECTOR2D textSize( 0, 0 );
1608  float commonOffset = std::numeric_limits<float>::max();
1609  bool wasTilda = false;
1610 
1611  for( unsigned int i = 0; i < aText.length(); ++i )
1612  {
1613  // Remove overbar control characters
1614  if( aText[i] == '~' )
1615  {
1616  if( !wasTilda )
1617  {
1618  // Only double tildas are counted as characters, so skip it as it might
1619  // be an overbar control character
1620  wasTilda = true;
1621  continue;
1622  }
1623  else
1624  {
1625  // Double tilda detected, reset the state and process as a normal character
1626  wasTilda = false;
1627  }
1628  }
1629 
1630  const FONT_GLYPH_TYPE* glyph = LookupGlyph(aText[i]);
1631  if( glyph ) {
1632  textSize.x += glyph->advance;
1633  textSize.y = std::max<float>( textSize.y, font_information.max_y - glyph->miny );
1634  commonOffset = std::min<float>( font_information.max_y - glyph->maxy, commonOffset );
1635  }
1636  }
1637 
1638  textSize.y -= commonOffset;
1639 
1640  return std::make_pair( textSize, commonOffset );
1641 }
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
FONT_INFO_TYPE font_information
Definition: gl_resources.cpp:3
#define max(a, b)
Definition: auxiliary.h:86
double GAL::computeMinGridSpacing ( ) const
protectedinherited

compute minimum grid spacing from the grid settings

Returns
the minimum spacing to use for drawing the grid

Definition at line 205 of file graphics_abstraction_layer.cpp.

References KIGFX::GAL::gridMinSpacing.

Referenced by DrawGrid(), and KIGFX::GAL::DrawGrid().

206 {
207  // just return the current value. This could be cleverer and take
208  // into account other settings in future
209  return gridMinSpacing;
210 }
int gridMinSpacing
Minimum screen size of the grid (pixels) below which the grid is not drawn.
void KIGFX::GAL::computeWorldScale ( )
inlineprotectedinherited

Compute the scaling factor for the world->screen matrix.

Definition at line 1019 of file graphics_abstraction_layer.h.

References KIGFX::GAL::zoomFactor.

Referenced by KIGFX::GAL::ComputeWorldScreenMatrix(), and KIGFX::GAL::GAL().

1020  {
1022  }
double zoomFactor
The zoom factor.
double worldUnitLength
The unit length of the world coordinates [inch].
double worldScale
The scale factor world->screen.
double screenDPI
The dots per inch of the screen.
void GAL::ComputeWorldScreenMatrix ( )
virtualinherited

Compute the world <-> screen transformation matrix.

Definition at line 177 of file graphics_abstraction_layer.cpp.

References KIGFX::GAL::computeWorldScale(), KIGFX::GAL::globalFlipX, KIGFX::GAL::globalFlipY, MATRIX3x3< T >::Inverse(), KIGFX::GAL::lookAtPoint, scale, KIGFX::GAL::screenSize, KIGFX::GAL::screenWorldMatrix, MATRIX3x3< T >::SetIdentity(), MATRIX3x3< T >::SetScale(), MATRIX3x3< T >::SetTranslation(), KIGFX::GAL::worldScale, and KIGFX::GAL::worldScreenMatrix.

Referenced by BeginDrawing(), KIGFX::CAIRO_GAL::initSurface(), KIGFX::VIEW::SetCenter(), and KIGFX::VIEW::SetScale().

178 {
180 
182 
183  MATRIX3x3D translation;
184  translation.SetIdentity();
185  translation.SetTranslation( 0.5 * VECTOR2D( screenSize ) );
186 
188  scale.SetIdentity();
189  scale.SetScale( VECTOR2D( worldScale, worldScale ) );
190 
191  MATRIX3x3D flip;
192 
193  flip.SetIdentity();
194  flip.SetScale( VECTOR2D( globalFlipX ? -1.0 : 1.0, globalFlipY ? -1.0 : 1.0 ) );
195 
196  MATRIX3x3D lookat;
197  lookat.SetIdentity();
198  lookat.SetTranslation( -lookAtPoint );
199 
200  worldScreenMatrix = translation * flip * scale * lookat * worldScreenMatrix;
201  screenWorldMatrix = worldScreenMatrix.Inverse();
202 }
MATRIX3x3 Inverse() const
Determine the inverse of the matrix.
Definition: matrix3x3.h:343
MATRIX3x3D screenWorldMatrix
Screen transformation.
bool globalFlipX
Flag for X axis flipping.
void SetIdentity()
Set the matrix to the identity matrix.
Definition: matrix3x3.h:214
VECTOR2D lookAtPoint
Point to be looked at in world space.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
MATRIX3x3D worldScreenMatrix
World transformation.
void computeWorldScale()
Compute the scaling factor for the world->screen matrix.
const int scale
void SetScale(VECTOR2< T > aScale)
Set the scale components of the matrix.
Definition: matrix3x3.h:261
bool globalFlipY
Flag for Y axis flipping.
double worldScale
The scale factor world->screen.
VECTOR2I screenSize
Screen size in screen coordinates.
void SetTranslation(VECTOR2< T > aTranslation)
Set the translation components of the matrix.
Definition: matrix3x3.h:230
void OPENGL_GAL::DeleteGroup ( int  aGroupNumber)
overridevirtual

Delete the group from the memory.

Parameters
aGroupNumberis the group number.

Reimplemented from KIGFX::GAL.

Definition at line 1243 of file opengl_gal.cpp.

References groups.

1244 {
1245  // Frees memory in the container as well
1246  groups.erase( aGroupNumber );
1247 }
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:300
void OPENGL_GAL::DrawArc ( const VECTOR2D aCenterPoint,
double  aRadius,
double  aStartAngle,
double  aEndAngle 
)
overridevirtual

Draw an arc.

Parameters
aCenterPointis the center point of the arc.
aRadiusis the arc radius.
aStartAngleis the start angle of the arc.
aEndAngleis the end angle of the arc.

Reimplemented from KIGFX::GAL.

Definition at line 526 of file opengl_gal.cpp.

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, calcAngleStep(), KIGFX::VERTEX_MANAGER::Color(), currentManager, DrawLine(), KIGFX::GAL::fillColor, KIGFX::COLOR4D::g, KIGFX::GAL::isFillEnabled, KIGFX::GAL::isStrokeEnabled, KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Reserve(), Restore(), Save(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_NONE, KIGFX::GAL::strokeColor, SWAP, KIGFX::VERTEX_MANAGER::Translate(), KIGFX::VERTEX_MANAGER::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

528 {
529  if( aRadius <= 0 )
530  return;
531 
532  // Swap the angles, if start angle is greater than end angle
533  SWAP( aStartAngle, >, aEndAngle );
534 
535  const double alphaIncrement = calcAngleStep( aRadius );
536 
537  Save();
538  currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
539 
540  if( isStrokeEnabled )
541  {
543 
544  VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
545  double alpha;
546 
547  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
548  {
549  VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
550  DrawLine( p, p_next );
551 
552  p = p_next;
553  }
554 
555  // Draw the last missing part
556  if( alpha != aEndAngle )
557  {
558  VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
559  DrawLine( p, p_last );
560  }
561  }
562 
563  if( isFillEnabled )
564  {
565  double alpha;
568 
569  // Triangle fan
570  for( alpha = aStartAngle; ( alpha + alphaIncrement ) < aEndAngle; )
571  {
572  currentManager->Reserve( 3 );
573  currentManager->Vertex( 0.0, 0.0, 0.0 );
574  currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius, 0.0 );
575  alpha += alphaIncrement;
576  currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius, 0.0 );
577  }
578 
579  // The last missing triangle
580  const VECTOR2D endPoint( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
581 
582  currentManager->Reserve( 3 );
583  currentManager->Vertex( 0.0, 0.0, 0.0 );
584  currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius, 0.0 );
585  currentManager->Vertex( endPoint.x, endPoint.y, 0.0 );
586  }
587 
588  Restore();
589 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
double calcAngleStep(double aRadius) const
Compute the angle step when drawing arcs/circles approximated with lines.
Definition: opengl_gal.h:446
bool Reserve(unsigned int aSize)
Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls...
virtual void Restore() override
Restore the context.
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
double g
Green component.
Definition: color4d.h:282
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:283
virtual void Save() override
Save the context.
double a
Alpha component.
Definition: color4d.h:284
bool isStrokeEnabled
Are the outlines stroked ?
COLOR4D strokeColor
The color of the outlines.
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Function Translate() multiplies the current matrix by a translation matrix, so newly vertices will be...
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
Definition: opengl_gal.cpp:403
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices...
bool isFillEnabled
Is filling of graphic objects enabled ?
#define SWAP(varA, condition, varB)
Swap the variables if a condition is met.
Definition: definitions.h:31
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...
double r
Red component.
Definition: color4d.h:281
void OPENGL_GAL::DrawArcSegment ( const VECTOR2D aCenterPoint,
double  aRadius,
double  aStartAngle,
double  aEndAngle,
double  aWidth 
)
overridevirtual

Draw an arc segment.

This method differs from DrawArc() in what happens when fill/stroke are on or off. DrawArc() draws a "pie piece" when fill is turned on, and a thick stroke when fill is off. DrawArcSegment() with fill on behaves like DrawArc() with fill off. DrawArcSegment() with fill off draws the outline of what it would have drawn with fill on.

Parameters
aCenterPointis the center point of the arc.
aRadiusis the arc radius.
aStartAngleis the start angle of the arc.
aEndAngleis the end angle of the arc.

Reimplemented from KIGFX::GAL.

Definition at line 592 of file opengl_gal.cpp.

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, calcAngleStep(), KIGFX::VERTEX_MANAGER::Color(), currentManager, DrawLine(), drawStrokedSemiCircle(), KIGFX::GAL::fillColor, KIGFX::COLOR4D::g, KIGFX::GAL::isFillEnabled, KIGFX::GAL::isStrokeEnabled, KIGFX::COLOR4D::r, Restore(), Save(), KIGFX::GAL::SetLineWidth(), KIGFX::GAL::strokeColor, SWAP, KIGFX::VERTEX_MANAGER::Translate(), VECTOR2< T >::x, and VECTOR2< T >::y.

594 {
595  if( aRadius <= 0 )
596  return;
597 
598  // Swap the angles, if start angle is greater than end angle
599  SWAP( aStartAngle, >, aEndAngle );
600 
601  const double alphaIncrement = calcAngleStep( aRadius );
602 
603  Save();
604  currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
605 
606  if( isStrokeEnabled )
607  {
609 
610  double width = aWidth / 2.0;
611  VECTOR2D startPoint( cos( aStartAngle ) * aRadius,
612  sin( aStartAngle ) * aRadius );
613  VECTOR2D endPoint( cos( aEndAngle ) * aRadius,
614  sin( aEndAngle ) * aRadius );
615 
616  drawStrokedSemiCircle( startPoint, width, aStartAngle + M_PI );
617  drawStrokedSemiCircle( endPoint, width, aEndAngle );
618 
619  VECTOR2D pOuter( cos( aStartAngle ) * ( aRadius + width ),
620  sin( aStartAngle ) * ( aRadius + width ) );
621 
622  VECTOR2D pInner( cos( aStartAngle ) * ( aRadius - width ),
623  sin( aStartAngle ) * ( aRadius - width ) );
624 
625  double alpha;
626 
627  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
628  {
629  VECTOR2D pNextOuter( cos( alpha ) * ( aRadius + width ),
630  sin( alpha ) * ( aRadius + width ) );
631  VECTOR2D pNextInner( cos( alpha ) * ( aRadius - width ),
632  sin( alpha ) * ( aRadius - width ) );
633 
634  DrawLine( pOuter, pNextOuter );
635  DrawLine( pInner, pNextInner );
636 
637  pOuter = pNextOuter;
638  pInner = pNextInner;
639  }
640 
641  // Draw the last missing part
642  if( alpha != aEndAngle )
643  {
644  VECTOR2D pLastOuter( cos( aEndAngle ) * ( aRadius + width ),
645  sin( aEndAngle ) * ( aRadius + width ) );
646  VECTOR2D pLastInner( cos( aEndAngle ) * ( aRadius - width ),
647  sin( aEndAngle ) * ( aRadius - width ) );
648 
649  DrawLine( pOuter, pLastOuter );
650  DrawLine( pInner, pLastInner );
651  }
652  }
653 
654  if( isFillEnabled )
655  {
657  SetLineWidth( aWidth );
658 
659  VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
660  double alpha;
661 
662  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
663  {
664  VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
665  DrawLine( p, p_next );
666 
667  p = p_next;
668  }
669 
670  // Draw the last missing part
671  if( alpha != aEndAngle )
672  {
673  VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
674  DrawLine( p, p_last );
675  }
676  }
677 
678  Restore();
679 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
double calcAngleStep(double aRadius) const
Compute the angle step when drawing arcs/circles approximated with lines.
Definition: opengl_gal.h:446
virtual void Restore() override
Restore the context.
double g
Green component.
Definition: color4d.h:282
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:283
virtual void Save() override
Save the context.
double a
Alpha component.
Definition: color4d.h:284
virtual void SetLineWidth(double aLineWidth)
Set the line width.
bool isStrokeEnabled
Are the outlines stroked ?
COLOR4D strokeColor
The color of the outlines.
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Function Translate() multiplies the current matrix by a translation matrix, so newly vertices will be...
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
Definition: opengl_gal.cpp:403
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices...
void drawStrokedSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a stroked semicircle.
bool isFillEnabled
Is filling of graphic objects enabled ?
#define SWAP(varA, condition, varB)
Swap the variables if a condition is met.
Definition: definitions.h:31
double r
Red component.
Definition: color4d.h:281
int OPENGL_GAL::drawBitmapChar ( unsigned long  aChar)
private

Draws a single character using bitmap font.

Its main purpose is to be used in BitmapText() function.

Parameters
aCharacteris the character to be drawn.
Returns
Width of the drawn glyph.

Definition at line 1523 of file opengl_gal.cpp.

References KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::advance, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::atlas_h, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::atlas_w, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::atlas_x, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::atlas_y, currentManager, KIGFX::BUILTIN_FONT::font_image, KIGFX::BUILTIN_FONT::font_information, KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::height, KIGFX::BUILTIN_FONT::LookupGlyph(), KIGFX::BUILTIN_FONT::FONT_INFO_TYPE::max_y, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::maxy, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::minx, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::miny, KIGFX::VERTEX_MANAGER::Reserve(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_FONT, KIGFX::BUILTIN_FONT::FONT_INFO_TYPE::smooth_pixels, Translate(), KIGFX::VERTEX_MANAGER::Vertex(), and KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::width.

Referenced by BitmapText().

1524 {
1525  const float TEX_X = font_image.width;
1526  const float TEX_Y = font_image.height;
1527 
1528  const FONT_GLYPH_TYPE* glyph = LookupGlyph(aChar);
1529  if( !glyph ) return 0;
1530 
1531  const float X = glyph->atlas_x + font_information.smooth_pixels;
1532  const float Y = glyph->atlas_y + font_information.smooth_pixels;
1533  const float XOFF = glyph->minx;
1534 
1535  // adjust for height rounding
1536  const float round_adjust = ( glyph->maxy - glyph->miny )
1537  - float( glyph->atlas_h - font_information.smooth_pixels * 2 );
1538  const float top_adjust = font_information.max_y - glyph->maxy;
1539  const float YOFF = round_adjust + top_adjust;
1540  const float W = glyph->atlas_w - font_information.smooth_pixels *2;
1541  const float H = glyph->atlas_h - font_information.smooth_pixels *2;
1542  const float B = 0;
1543 
1544  currentManager->Reserve( 6 );
1545  Translate( VECTOR2D( XOFF, YOFF ) );
1546  /* Glyph:
1547  * v0 v1
1548  * +--+
1549  * | /|
1550  * |/ |
1551  * +--+
1552  * v2 v3
1553  */
1554  currentManager->Shader( SHADER_FONT, X / TEX_X, ( Y + H ) / TEX_Y );
1555  currentManager->Vertex( -B, -B, 0 ); // v0
1556 
1557  currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y );
1558  currentManager->Vertex( W + B, -B, 0 ); // v1
1559 
1560  currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y );
1561  currentManager->Vertex( -B, H + B, 0 ); // v2
1562 
1563 
1564  currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y );
1565  currentManager->Vertex( W + B, -B, 0 ); // v1
1566 
1567  currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y );
1568  currentManager->Vertex( -B, H + B, 0 ); // v2
1569 
1570  currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, Y / TEX_Y );
1571  currentManager->Vertex( W + B, H + B, 0 ); // v3
1572 
1573  Translate( VECTOR2D( -XOFF + glyph->advance, -YOFF ) );
1574 
1575  return glyph->advance;
1576 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
virtual void Translate(const VECTOR2D &aTranslation) override
Translate the context.
bool Reserve(unsigned int aSize)
Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls...
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
FONT_IMAGE_TYPE font_image
Definition: gl_resources.cpp:4
FONT_INFO_TYPE font_information
Definition: gl_resources.cpp:3
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...
void OPENGL_GAL::drawBitmapOverbar ( double  aLength,
double  aHeight 
)
private

Draws an overbar over the currently drawn text.

Its main purpose is to be used in BitmapText() function. This method requires appropriate scaling to be applied (as is done in BitmapText() function). The current X coordinate will be the overbar ending.

Parameters
aLengthis the width of the overbar.
aHeightis the height for the overbar.

Definition at line 1579 of file opengl_gal.cpp.

References KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, KIGFX::COLOR4D::g, KIGFX::BUILTIN_FONT::LookupGlyph(), KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::maxy, KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::miny, KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Reserve(), Restore(), Save(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::GAL::strokeColor, Translate(), and KIGFX::VERTEX_MANAGER::Vertex().

Referenced by BitmapText().

1580 {
1581  // To draw an overbar, simply draw an overbar
1582  const FONT_GLYPH_TYPE* glyph = LookupGlyph( '_' );
1583  const float H = glyph->maxy - glyph->miny;
1584 
1585  Save();
1586 
1587  Translate( VECTOR2D( -aLength, -aHeight-1.5*H ) );
1588 
1589  currentManager->Reserve( 6 );
1591 
1592  currentManager->Shader( 0 );
1593 
1594  currentManager->Vertex( 0, 0, 0 ); // v0
1595  currentManager->Vertex( aLength, 0, 0 ); // v1
1596  currentManager->Vertex( 0, H, 0 ); // v2
1597 
1598  currentManager->Vertex( aLength, 0, 0 ); // v1
1599  currentManager->Vertex( 0, H, 0 ); // v2
1600  currentManager->Vertex( aLength, H, 0 ); // v3
1601 
1602  Restore();
1603 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
virtual void Translate(const VECTOR2D &aTranslation) override
Translate the context.
bool Reserve(unsigned int aSize)
Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls...
virtual void Restore() override
Restore the context.
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
double g
Green component.
Definition: color4d.h:282
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
double b
Blue component.
Definition: color4d.h:283
virtual void Save() override
Save the context.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
COLOR4D strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices...
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...
double r
Red component.
Definition: color4d.h:281
void OPENGL_GAL::DrawCircle ( const VECTOR2D aCenterPoint,
double  aRadius 
)
overridevirtual

Draw a circle using world coordinates.

Parameters
aCenterPointis the center point of the circle.
aRadiusis the radius of the circle.

Reimplemented from KIGFX::GAL.

Definition at line 466 of file opengl_gal.cpp.

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, KIGFX::GAL::fillColor, KIGFX::COLOR4D::g, KIGFX::GAL::isFillEnabled, KIGFX::GAL::isStrokeEnabled, KIGFX::GAL::layerDepth, KIGFX::GAL::lineWidth, KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Reserve(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_FILLED_CIRCLE, KIGFX::SHADER_STROKED_CIRCLE, KIGFX::GAL::strokeColor, KIGFX::VERTEX_MANAGER::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

467 {
468  if( isFillEnabled )
469  {
470  currentManager->Reserve( 3 );
472 
473  /* Draw a triangle that contains the circle, then shade it leaving only the circle.
474  * Parameters given to Shader() are indices of the triangle's vertices
475  * (if you want to understand more, check the vertex shader source [shader.vert]).
476  * Shader uses this coordinates to determine if fragments are inside the circle or not.
477  * v2
478  * /\
479  * //\\
480  * v0 /_\/_\ v1
481  */
483  currentManager->Vertex( aCenterPoint.x - aRadius * sqrt( 3.0f ), // v0
484  aCenterPoint.y - aRadius, layerDepth );
485 
487  currentManager->Vertex( aCenterPoint.x + aRadius * sqrt( 3.0f), // v1
488  aCenterPoint.y - aRadius, layerDepth );
489 
491  currentManager->Vertex( aCenterPoint.x, aCenterPoint.y + aRadius * 2.0f, // v2
492  layerDepth );
493  }
494 
495  if( isStrokeEnabled )
496  {
497  currentManager->Reserve( 3 );
499 
500  /* Draw a triangle that contains the circle, then shade it leaving only the circle.
501  * Parameters given to Shader() are indices of the triangle's vertices
502  * (if you want to understand more, check the vertex shader source [shader.vert]).
503  * and the line width. Shader uses this coordinates to determine if fragments are
504  * inside the circle or not.
505  * v2
506  * /\
507  * //\\
508  * v0 /_\/_\ v1
509  */
510  double outerRadius = aRadius + ( lineWidth / 2 );
512  currentManager->Vertex( aCenterPoint.x - outerRadius * sqrt( 3.0f ), // v0
513  aCenterPoint.y - outerRadius, layerDepth );
514 
516  currentManager->Vertex( aCenterPoint.x + outerRadius * sqrt( 3.0f ), // v1
517  aCenterPoint.y - outerRadius, layerDepth );
518 
520  currentManager->Vertex( aCenterPoint.x, aCenterPoint.y + outerRadius * 2.0f, // v2
521  layerDepth );
522  }
523 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
double layerDepth
The actual layer depth.
bool Reserve(unsigned int aSize)
Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls...
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
double g
Green component.
Definition: color4d.h:282
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:283
double lineWidth
The line width.
double a
Alpha component.
Definition: color4d.h:284
bool isStrokeEnabled
Are the outlines stroked ?
COLOR4D strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices...
bool isFillEnabled
Is filling of graphic objects enabled ?
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...
double r
Red component.
Definition: color4d.h:281
void OPENGL_GAL::DrawCursor ( const VECTOR2D aCursorPosition)
overridevirtual

Draw the cursor.

Parameters
aCursorPositionis the cursor position in screen coordinates.

Reimplemented from KIGFX::GAL.

Definition at line 1323 of file opengl_gal.cpp.

References KIGFX::GAL::cursorPosition.

1324 {
1325  // Now we should only store the position of the mouse cursor
1326  // The real drawing routines are in blitCursor()
1327  //VECTOR2D screenCursor = worldScreenMatrix * aCursorPosition;
1328  //cursorPosition = screenWorldMatrix * VECTOR2D( screenCursor.x, screenCursor.y );
1329  cursorPosition = aCursorPosition;
1330 }
VECTOR2D cursorPosition
Current cursor position (world coordinates)
void OPENGL_GAL::DrawCurve ( const VECTOR2D startPoint,
const VECTOR2D controlPointA,
const VECTOR2D controlPointB,
const VECTOR2D endPoint 
)
overridevirtual

Draw a cubic bezier spline.

Parameters
startPointis the start point of the spline.
controlPointAis the first control point.
controlPointBis the second control point.
endPointis the end point of the spline.

Reimplemented from KIGFX::GAL.

Definition at line 799 of file opengl_gal.cpp.

References CURVE_POINTS, and DrawPolyline().

801 {
802  // FIXME The drawing quality needs to be improved
803  // FIXME Perhaps choose a quad/triangle strip instead?
804  // FIXME Brute force method, use a better (recursive?) algorithm
805 
806  std::deque<VECTOR2D> pointList;
807 
808  double t = 0.0;
809  double dt = 1.0 / (double) CURVE_POINTS;
810 
811  for( int i = 0; i <= CURVE_POINTS; i++ )
812  {
813  double omt = 1.0 - t;
814  double omt2 = omt * omt;
815  double omt3 = omt * omt2;
816  double t2 = t * t;
817  double t3 = t * t2;
818 
819  VECTOR2D vertex = omt3 * aStartPoint + 3.0 * t * omt2 * aControlPointA
820  + 3.0 * t2 * omt * aControlPointB + t3 * aEndPoint;
821 
822  pointList.push_back( vertex );
823 
824  t += dt;
825  }
826 
827  DrawPolyline( pointList );
828 }
static const int CURVE_POINTS
The number of points for curve approximation.
Definition: opengl_gal.h:288
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
Definition: opengl_gal.cpp:720
void OPENGL_GAL::drawFilledSemiCircle ( const VECTOR2D aCenterPoint,
double  aRadius,
double  aAngle 
)
private

Draw a filled semicircle.

Parameters
aCenterPointis the center point.
aRadiusis the radius of the semicircle.
aAngleis the angle of the semicircle.

Definition at line 1401 of file opengl_gal.cpp.

References currentManager, KIGFX::GAL::layerDepth, KIGFX::VERTEX_MANAGER::Reserve(), Restore(), KIGFX::VERTEX_MANAGER::Rotate(), Save(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_FILLED_CIRCLE, KIGFX::VERTEX_MANAGER::Translate(), KIGFX::VERTEX_MANAGER::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DrawLine(), drawPolyline(), DrawSegment(), and drawSemiCircle().

1403 {
1404  Save();
1405 
1406  currentManager->Reserve( 3 );
1407  currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
1408  currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1409 
1410  /* Draw a triangle that contains the semicircle, then shade it to leave only
1411  * the semicircle. Parameters given to Shader() are indices of the triangle's vertices
1412  * (if you want to understand more, check the vertex shader source [shader.vert]).
1413  * Shader uses these coordinates to determine if fragments are inside the semicircle or not.
1414  * v2
1415  * /\
1416  * /__\
1417  * v0 //__\\ v1
1418  */
1420  currentManager->Vertex( -aRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v0
1421 
1423  currentManager->Vertex( aRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v1
1424 
1426  currentManager->Vertex( 0.0f, aRadius * 2.0f, layerDepth ); // v2
1427 
1428  Restore();
1429 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
double layerDepth
The actual layer depth.
bool Reserve(unsigned int aSize)
Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls...
virtual void Restore() override
Restore the context.
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
void Rotate(GLfloat aAngle, GLfloat aX, GLfloat aY, GLfloat aZ)
Function Rotate() multiplies the current matrix by a rotation matrix, so the newly vertices will be r...
virtual void Save() override
Save the context.
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Function Translate() multiplies the current matrix by a translation matrix, so newly vertices will be...
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...
void OPENGL_GAL::DrawGrid ( )
overridevirtual

>

Draw the grid

Reimplemented from KIGFX::GAL.

Definition at line 939 of file opengl_gal.cpp.

References abs, KIGFX::GAL::axesColor, KIGFX::GAL::axesEnabled, KIGFX::COLOR4D::b, compositor, KIGFX::GAL::computeMinGridSpacing(), KIGFX::DOTS, KIGFX::COLOR4D::g, KIGFX::GAL::gridColor, KIGFX::GAL::gridLineWidth, KIGFX::GAL::gridOrigin, KIGFX::GAL::gridSize, KIGFX::GAL::gridStyle, KIGFX::GAL::gridTick, KIGFX::GAL::gridVisibility, KiROUND(), mainBuffer, max, KIGFX::COLOR4D::r, KIGFX::GAL::screenSize, KIGFX::GAL::screenWorldMatrix, KIGFX::OPENGL_COMPOSITOR::SetBuffer(), SetTarget(), KIGFX::SMALL_CROSS, KIGFX::TARGET_NONCACHED, KIGFX::GAL::worldScale, VECTOR2< T >::x, and VECTOR2< T >::y.

940 {
943 
944  // sub-pixel lines all render the same
945  double minorLineWidth = std::max( 1.0, gridLineWidth );
946  double majorLineWidth = minorLineWidth * 2.0;
947 
948  // Draw the axis and grid
949  // For the drawing the start points, end points and increments have
950  // to be calculated in world coordinates
951  VECTOR2D worldStartPoint = screenWorldMatrix * VECTOR2D( 0.0, 0.0 );
952  VECTOR2D worldEndPoint = screenWorldMatrix * VECTOR2D( screenSize );
953 
954  // Draw axes if desired
955  if( axesEnabled )
956  {
957  glLineWidth( minorLineWidth );
958  glColor4d( axesColor.r, axesColor.g, axesColor.b, 1.0 );
959 
960  glBegin( GL_LINES );
961  glVertex2d( worldStartPoint.x, 0 );
962  glVertex2d( worldEndPoint.x, 0 );
963  glEnd();
964 
965  glBegin( GL_LINES );
966  glVertex2d( 0, worldStartPoint.y );
967  glVertex2d( 0, worldEndPoint.y );
968  glEnd();
969  }
970 
971  if( !gridVisibility )
972  return;
973 
974  int gridScreenSizeDense = KiROUND( gridSize.x * worldScale );
975  int gridScreenSizeCoarse = KiROUND( gridSize.x * static_cast<double>( gridTick ) * worldScale );
976 
977  const double gridThreshold = computeMinGridSpacing();
978 
979  // Check if the grid would not be too dense
980  if( std::max( gridScreenSizeDense, gridScreenSizeCoarse ) < gridThreshold )
981  return;
982 
983  // Compute grid variables
984  int gridStartX = KiROUND( worldStartPoint.x / gridSize.x );
985  int gridEndX = KiROUND( worldEndPoint.x / gridSize.x );
986  int gridStartY = KiROUND( worldStartPoint.y / gridSize.y );
987  int gridEndY = KiROUND( worldEndPoint.y / gridSize.y );
988 
989  // Correct the index, else some lines are not correctly painted
990  gridStartY -= std::abs( gridOrigin.y / gridSize.y ) + 1;
991  gridEndY -= std::abs( gridOrigin.y / gridSize.y ) - 1;
992 
993  gridStartX -= std::abs( gridOrigin.x / gridSize.x ) + 1;
994  gridEndX -= std::abs( gridOrigin.x / gridSize.x ) - 1;
995 
996  int dirX = gridStartX >= gridEndX ? -1 : 1;
997  int dirY = gridStartY >= gridEndY ? -1 : 1;
998 
999  glDisable( GL_DEPTH_TEST );
1000  glDisable( GL_TEXTURE_2D );
1001 
1002  if( gridStyle == GRID_STYLE::DOTS )
1003  {
1004  glEnable( GL_STENCIL_TEST );
1005  glStencilFunc( GL_ALWAYS, 1, 1 );
1006  glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
1007  glColor4d( 0.0, 0.0, 0.0, 0.0 );
1008  }
1009  else
1010  {
1011  glColor4d( gridColor.r, gridColor.g, gridColor.b, 1.0 );
1012  }
1013 
1015  {
1016  glLineWidth( minorLineWidth );
1017 
1018  // calculate a line len = 2 minorLineWidth, in internal unit value
1019  // (in fact the size of cross is lineLen*2)
1020  int lineLen = KiROUND( minorLineWidth / worldScale *2 );
1021 
1022  // Vertical positions
1023  for( int j = gridStartY; j != gridEndY; j += dirY )
1024  {
1025  if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
1026  || gridScreenSizeDense > gridThreshold )
1027  {
1028  int posY = j * gridSize.y + gridOrigin.y;
1029 
1030  // Horizontal positions
1031  for( int i = gridStartX; i != gridEndX; i += dirX )
1032  {
1033  if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
1034  || gridScreenSizeDense > gridThreshold )
1035  {
1036  int posX = i * gridSize.x + gridOrigin.x;
1037 
1038  glBegin( GL_LINES );
1039  glVertex2d( posX -lineLen, posY );
1040  glVertex2d( posX + lineLen, posY );
1041  glVertex2d( posX, posY - lineLen );
1042  glVertex2d( posX, posY + lineLen );
1043  glEnd();
1044  }
1045  }
1046  }
1047  }
1048  }
1049  else
1050  {
1051  // Vertical lines
1052  for( int j = gridStartY; j != gridEndY; j += dirY )
1053  {
1054  const double y = j * gridSize.y + gridOrigin.y;
1055 
1056  // If axes are drawn, skip the lines that would cover them
1057  if( axesEnabled && y == 0 )
1058  continue;
1059 
1060  if( j % gridTick == 0 && gridScreenSizeDense > gridThreshold )
1061  glLineWidth( majorLineWidth );
1062  else
1063  glLineWidth( minorLineWidth );
1064 
1065  if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
1066  || gridScreenSizeDense > gridThreshold )
1067  {
1068  glBegin( GL_LINES );
1069  glVertex2d( gridStartX * gridSize.x + gridOrigin.x, y );
1070  glVertex2d( gridEndX * gridSize.x + gridOrigin.x, y );
1071  glEnd();
1072  }
1073  }
1074 
1075  if( gridStyle == GRID_STYLE::DOTS )
1076  {
1077  glStencilFunc( GL_NOTEQUAL, 0, 1 );
1078  glColor4d( gridColor.r, gridColor.g, gridColor.b, 1.0 );
1079  }
1080 
1081  // Horizontal lines
1082  for( int i = gridStartX; i != gridEndX; i += dirX )
1083  {
1084  const double x = i * gridSize.x + gridOrigin.x;
1085 
1086  // If axes are drawn, skip the lines that would cover them
1087  if( axesEnabled && x == 0 )
1088  continue;
1089 
1090  if( i % gridTick == 0 && gridScreenSizeDense > gridThreshold )
1091  glLineWidth( majorLineWidth );
1092  else
1093  glLineWidth( minorLineWidth );
1094 
1095  if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
1096  || gridScreenSizeDense > gridThreshold )
1097  {
1098  glBegin( GL_LINES );
1099  glVertex2d( x, gridStartY * gridSize.y + gridOrigin.y );
1100  glVertex2d( x, gridEndY * gridSize.y + gridOrigin.y );
1101  glEnd();
1102  }
1103  }
1104 
1105  if( gridStyle == GRID_STYLE::DOTS )
1106  glDisable( GL_STENCIL_TEST );
1107  }
1108 
1109  glEnable( GL_DEPTH_TEST );
1110  glEnable( GL_TEXTURE_2D );
1111 }
double computeMinGridSpacing() const
compute minimum grid spacing from the grid settings
int gridTick
Every tick line gets the double width.
bool axesEnabled
Should the axes be drawn.
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
GRID_STYLE gridStyle
Grid display style.
double g
Green component.
Definition: color4d.h:282
MATRIX3x3D screenWorldMatrix
Screen transformation.
#define abs(a)
Definition: auxiliary.h:84
double b
Blue component.
Definition: color4d.h:283
Auxiliary rendering target (noncached)
Definition: definitions.h:42
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:308
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
unsigned int mainBuffer
Main rendering target.
Definition: opengl_gal.h:309
COLOR4D axesColor
Color of the axes.
VECTOR2D gridOrigin
The grid origin.
virtual void SetBuffer(unsigned int aBufferHandle) override
Function SetBuffer() sets the selected buffer as the rendering target.
Use dots for the grid.
Use small cross instead of dots for the grid.
virtual void SetTarget(RENDER_TARGET aTarget) override
Sets the target for rendering.
COLOR4D gridColor
Color of the grid.
bool gridVisibility
Should the grid be shown.
#define max(a, b)
Definition: auxiliary.h:86
double worldScale
The scale factor world->screen.
VECTOR2D gridSize
The grid size.
VECTOR2I screenSize
Screen size in screen coordinates.
double r
Red component.
Definition: color4d.h:281
double gridLineWidth
Line width of the grid.
virtual void KIGFX::GAL::drawGridLine ( const VECTOR2D aStartPoint,
const VECTOR2D aEndPoint 
)
inlineprotectedvirtualinherited

Draw a grid line (usually a simplified line function).

Parameters
aStartPointis the start point of the line.
aEndPointis the end point of the line.

Reimplemented in KIGFX::CAIRO_GAL.

Definition at line 1037 of file graphics_abstraction_layer.h.

Referenced by KIGFX::GAL::DrawGrid().

1037 {};
void OPENGL_GAL::DrawGroup ( int  aGroupNumber)
overridevirtual

Draw the stored group.

Parameters
aGroupNumberis the group number.

Reimplemented from KIGFX::GAL.

Definition at line 1225 of file opengl_gal.cpp.

References cachedManager, KIGFX::VERTEX_MANAGER::DrawItem(), and groups.

1226 {
1227  cachedManager->DrawItem( *groups[aGroupNumber] );
1228 }
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:300
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
void DrawItem(const VERTEX_ITEM &aItem) const
Function DrawItem() draws an item to the buffer.
void OPENGL_GAL::DrawLine ( const VECTOR2D aStartPoint,
const VECTOR2D aEndPoint 
)
overridevirtual

Draw a line.

Start and end points are defined as 2D-Vectors.

Parameters
aStartPointis the start point of the line.
aEndPointis the end point of the line.

Reimplemented from KIGFX::GAL.

Definition at line 403 of file opengl_gal.cpp.

References KIGFX::COLOR4D::a, VECTOR2< T >::Angle(), KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, drawFilledSemiCircle(), drawLineQuad(), KIGFX::COLOR4D::g, KIGFX::GAL::lineWidth, KIGFX::COLOR4D::r, and KIGFX::GAL::strokeColor.

Referenced by DrawArc(), and DrawArcSegment().

404 {
405  const VECTOR2D startEndVector = aEndPoint - aStartPoint;
406  double lineAngle = startEndVector.Angle();
407 
409 
410  drawLineQuad( aStartPoint, aEndPoint );
411 
412  // Line caps
413  if( lineWidth > 1.0 )
414  {
415  drawFilledSemiCircle( aStartPoint, lineWidth / 2, lineAngle + M_PI / 2 );
416  drawFilledSemiCircle( aEndPoint, lineWidth / 2, lineAngle - M_PI / 2 );
417  }
418 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
double g
Green component.
Definition: color4d.h:282
double b
Blue component.
Definition: color4d.h:283
double lineWidth
The line width.
double Angle() const
Function Angle computes the angle of the vector.
Definition: vector2d.h:309
double a
Alpha component.
Definition: color4d.h:284
COLOR4D strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices...
double r
Red component.
Definition: color4d.h:281
void drawFilledSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a filled semicircle.
void OPENGL_GAL::drawLineQuad ( const VECTOR2D aStartPoint,
const VECTOR2D aEndPoint 
)
private

Draw a quad for the line.

Parameters
aStartPointis the start point of the line.
aEndPointis the end point of the line.

Definition at line 1333 of file opengl_gal.cpp.

References currentManager, VECTOR2< T >::EuclideanNorm(), KIGFX::VERTEX_MANAGER::GetTransformation(), KIGFX::GAL::layerDepth, KIGFX::GAL::lineWidth, KIGFX::VERTEX_MANAGER::Reserve(), scale, KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_LINE, KIGFX::VERTEX_MANAGER::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DrawLine(), drawPolyline(), and DrawSegment().

1334 {
1335  /* Helper drawing: ____--- v3 ^
1336  * ____---- ... \ \
1337  * ____---- ... \ end \
1338  * v1 ____---- ... ____---- \ width
1339  * ---- ...___---- \ \
1340  * \ ___...-- \ v
1341  * \ ____----... ____---- v2
1342  * ---- ... ____----
1343  * start \ ... ____----
1344  * \... ____----
1345  * ----
1346  * v0
1347  * dots mark triangles' hypotenuses
1348  */
1349 
1350  VECTOR2D startEndVector = aEndPoint - aStartPoint;
1351  double lineLength = startEndVector.EuclideanNorm();
1352 
1353  if( lineLength <= 0.0 )
1354  return;
1355 
1356  double scale = 0.5 * lineWidth / lineLength;
1357 
1358  // The perpendicular vector also needs transformations
1359  glm::vec4 vector = currentManager->GetTransformation() *
1360  glm::vec4( -startEndVector.y * scale, startEndVector.x * scale, 0.0, 0.0 );
1361 
1362  currentManager->Reserve( 6 );
1363 
1364  // Line width is maintained by the vertex shader
1365  currentManager->Shader( SHADER_LINE, vector.x, vector.y, lineWidth );
1366  currentManager->Vertex( aStartPoint.x, aStartPoint.y, layerDepth ); // v0
1367 
1368  currentManager->Shader( SHADER_LINE, -vector.x, -vector.y, lineWidth );
1369  currentManager->Vertex( aStartPoint.x, aStartPoint.y, layerDepth ); // v1
1370 
1371  currentManager->Shader( SHADER_LINE, -vector.x, -vector.y, lineWidth );
1372  currentManager->Vertex( aEndPoint.x, aEndPoint.y, layerDepth ); // v3
1373 
1374  currentManager->Shader( SHADER_LINE, vector.x, vector.y, lineWidth );
1375  currentManager->Vertex( aStartPoint.x, aStartPoint.y, layerDepth ); // v0
1376 
1377  currentManager->Shader( SHADER_LINE, -vector.x, -vector.y, lineWidth );
1378  currentManager->Vertex( aEndPoint.x, aEndPoint.y, layerDepth ); // v3
1379 
1380  currentManager->Shader( SHADER_LINE, vector.x, vector.y, lineWidth );
1381  currentManager->Vertex( aEndPoint.x, aEndPoint.y, layerDepth ); // v2
1382 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
double layerDepth
The actual layer depth.
bool Reserve(unsigned int aSize)
Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls...
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
double lineWidth
The line width.
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:295
const int scale
const glm::mat4 & GetTransformation() const
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...
void OPENGL_GAL::DrawPolygon ( const std::deque< VECTOR2D > &  aPointList)
overridevirtual

Draw a polygon.

Parameters
aPointListis the list of the polygon points.

Reimplemented from KIGFX::GAL.

Definition at line 743 of file opengl_gal.cpp.

References drawPolygon(), and KIGFX::GAL::layerDepth.

744 {
745  auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aPointList.size()] );
746  GLdouble* ptr = points.get();
747 
748  for( const VECTOR2D& p : aPointList )
749  {
750  *ptr++ = p.x;
751  *ptr++ = p.y;
752  *ptr++ = layerDepth;
753  }
754 
755  drawPolygon( points.get(), aPointList.size() );
756 }
double layerDepth
The actual layer depth.
void drawPolygon(GLdouble *aPoints, int aPointCount)
Draws a filled polygon.
void OPENGL_GAL::DrawPolygon ( const VECTOR2D  aPointList[],
int  aListSize 
)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 759 of file opengl_gal.cpp.

References drawPolygon(), KIGFX::GAL::layerDepth, VECTOR2< T >::x, and VECTOR2< T >::y.

760 {
761  auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aListSize] );
762  GLdouble* target = points.get();
763  const VECTOR2D* src = aPointList;
764 
765  for( int i = 0; i < aListSize; ++i )
766  {
767  *target++ = src->x;
768  *target++ = src->y;
769  *target++ = layerDepth;
770  ++src;
771  }
772 
773  drawPolygon( points.get(), aListSize );
774 }
double layerDepth
The actual layer depth.
void drawPolygon(GLdouble *aPoints, int aPointCount)
Draws a filled polygon.
void OPENGL_GAL::DrawPolygon ( const SHAPE_POLY_SET aPolySet)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 777 of file opengl_gal.cpp.

References SHAPE_POLY_SET::COutline(), SHAPE_LINE_CHAIN::CPoint(), drawPolygon(), KIGFX::GAL::layerDepth, SHAPE_POLY_SET::OutlineCount(), SHAPE_LINE_CHAIN::PointCount(), VECTOR2< T >::x, and VECTOR2< T >::y.

778 {
779  for( int j = 0; j < aPolySet.OutlineCount(); ++j )
780  {
781  const SHAPE_LINE_CHAIN& outline = aPolySet.COutline( j );
782  const int pointCount = outline.PointCount();
783  std::unique_ptr<GLdouble[]> points( new GLdouble[3 * pointCount] );
784  GLdouble* ptr = points.get();
785 
786  for( int i = 0; i < outline.PointCount(); ++i )
787  {
788  const VECTOR2I& p = outline.CPoint( i );
789  *ptr++ = p.x;
790  *ptr++ = p.y;
791  *ptr++ = layerDepth;
792  }
793 
794  drawPolygon( points.get(), pointCount );
795  }
796 }
double layerDepth
The actual layer depth.
int PointCount() const
Function PointCount()
void drawPolygon(GLdouble *aPoints, int aPointCount)
Draws a filled polygon.
int OutlineCount() const
Returns the number of outlines in the set
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
Class SHAPE_LINE_CHAIN.
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
void OPENGL_GAL::drawPolygon ( GLdouble *  aPoints,
int  aPointCount 
)
private

Draws a filled polygon.

It does not need the last point to have the same coordinates as the first one.

Parameters
aPointsis the vertices data (3 coordinates: x, y, z).
aPointCountis the number of points.

Definition at line 1466 of file opengl_gal.cpp.

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, KIGFX::GAL::fillColor, KIGFX::COLOR4D::g, KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_NONE, tesselator, and tessIntersects.

Referenced by DrawPolygon().

1467 {
1470 
1471  // Any non convex polygon needs to be tesselated
1472  // for this purpose the GLU standard functions are used
1473  TessParams params = { currentManager, tessIntersects };
1474  gluTessBeginPolygon( tesselator, &params );
1475  gluTessBeginContour( tesselator );
1476 
1477  GLdouble* point = aPoints;
1478 
1479  for( int i = 0; i < aPointCount; ++i )
1480  {
1481  gluTessVertex( tesselator, point, point );
1482  point += 3; // 3 coordinates
1483  }
1484 
1485  gluTessEndContour( tesselator );
1486  gluTessEndPolygon( tesselator );
1487 
1488  // Free allocated intersecting points
1489  tessIntersects.clear();
1490 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
double g
Green component.
Definition: color4d.h:282
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:283
double a
Alpha component.
Definition: color4d.h:284
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices...
GLUtesselator * tesselator
The tessellator.
Definition: opengl_gal.h:329
std::deque< boost::shared_array< GLdouble > > tessIntersects
Storage for intersecting points.
Definition: opengl_gal.h:331
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...
double r
Red component.
Definition: color4d.h:281
void OPENGL_GAL::DrawPolyline ( const std::deque< VECTOR2D > &  aPointList)
overridevirtual

Draw a polyline.

Parameters
aPointListis a list of 2D-Vectors containing the polyline points.

Reimplemented from KIGFX::GAL.

Definition at line 720 of file opengl_gal.cpp.

References drawPolyline().

Referenced by DrawCurve(), and DrawRectangle().

721 {
722  drawPolyline( [&](int idx) { return aPointList[idx]; }, aPointList.size() );
723 }
void drawPolyline(std::function< VECTOR2D(int)> aPointGetter, int aPointCount)
void OPENGL_GAL::DrawPolyline ( const VECTOR2D  aPointList[],
int  aListSize 
)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 726 of file opengl_gal.cpp.

References drawPolyline().

727 {
728  drawPolyline( [&](int idx) { return aPointList[idx]; }, aListSize );
729 }
void drawPolyline(std::function< VECTOR2D(int)> aPointGetter, int aPointCount)
void OPENGL_GAL::DrawPolyline ( const SHAPE_LINE_CHAIN aLineChain)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 732 of file opengl_gal.cpp.

References SHAPE_LINE_CHAIN::CPoint(), drawPolyline(), SHAPE_LINE_CHAIN::IsClosed(), and SHAPE_LINE_CHAIN::PointCount().

733 {
734  auto numPoints = aLineChain.PointCount();
735 
736  if( aLineChain.IsClosed() )
737  numPoints += 1;
738 
739  drawPolyline( [&](int idx) { return aLineChain.CPoint(idx); }, numPoints );
740 }
void drawPolyline(std::function< VECTOR2D(int)> aPointGetter, int aPointCount)
int PointCount() const
Function PointCount()
bool IsClosed() const
Function IsClosed()
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
void OPENGL_GAL::drawPolyline ( std::function< VECTOR2D(int)>  aPointGetter,
int  aPointCount 
)
private
Parameters
Genericway of drawing a polyline stored in different containers.
aPointGetteris a function to obtain coordinates of n-th vertex.
aPointCountis the number of points to be drawn.

Definition at line 1493 of file opengl_gal.cpp.

References KIGFX::COLOR4D::a, VECTOR2< T >::Angle(), KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, drawFilledSemiCircle(), drawLineQuad(), KIGFX::COLOR4D::g, KIGFX::GAL::lineWidth, KIGFX::COLOR4D::r, and KIGFX::GAL::strokeColor.

Referenced by DrawPolyline().

1494 {
1495  if( aPointCount < 2 )
1496  return;
1497 
1499  int i;
1500 
1501  for( i = 1; i < aPointCount; ++i )
1502  {
1503  auto start = aPointGetter( i - 1 );
1504  auto end = aPointGetter( i );
1505  const VECTOR2D startEndVector = ( end - start );
1506  double lineAngle = startEndVector.Angle();
1507 
1508  drawLineQuad( start, end );
1509 
1510  // There is no need to draw line caps on both ends of polyline's segments
1511  drawFilledSemiCircle( start, lineWidth / 2, lineAngle + M_PI / 2 );
1512  }
1513 
1514  // ..and now - draw the ending cap
1515  auto start = aPointGetter( i - 2 );
1516  auto end = aPointGetter( i - 1 );
1517  const VECTOR2D startEndVector = ( end - start );
1518  double lineAngle = startEndVector.Angle();
1519  drawFilledSemiCircle( end, lineWidth / 2, lineAngle - M_PI / 2 );
1520 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
double g
Green component.
Definition: color4d.h:282
double b
Blue component.
Definition: color4d.h:283
double lineWidth
The line width.
double Angle() const
Function Angle computes the angle of the vector.
Definition: vector2d.h:309
double a
Alpha component.
Definition: color4d.h:284
COLOR4D strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices...
double r
Red component.
Definition: color4d.h:281
void drawFilledSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a filled semicircle.
void OPENGL_GAL::DrawRectangle ( const VECTOR2D aStartPoint,
const VECTOR2D aEndPoint 
)
overridevirtual

Draw a rectangle.

Parameters
aStartPointis the start point of the rectangle.
aEndPointis the end point of the rectangle.

Reimplemented from KIGFX::GAL.

Definition at line 682 of file opengl_gal.cpp.

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, DrawPolyline(), KIGFX::GAL::fillColor, KIGFX::COLOR4D::g, KIGFX::GAL::isFillEnabled, KIGFX::GAL::isStrokeEnabled, KIGFX::GAL::layerDepth, KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Reserve(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_NONE, KIGFX::GAL::strokeColor, KIGFX::VERTEX_MANAGER::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

683 {
684  // Compute the diagonal points of the rectangle
685  VECTOR2D diagonalPointA( aEndPoint.x, aStartPoint.y );
686  VECTOR2D diagonalPointB( aStartPoint.x, aEndPoint.y );
687 
688  // Stroke the outline
689  if( isStrokeEnabled )
690  {
692 
693  std::deque<VECTOR2D> pointList;
694  pointList.push_back( aStartPoint );
695  pointList.push_back( diagonalPointA );
696  pointList.push_back( aEndPoint );
697  pointList.push_back( diagonalPointB );
698  pointList.push_back( aStartPoint );
699  DrawPolyline( pointList );
700  }
701 
702  // Fill the rectangle
703  if( isFillEnabled )
704  {
705  currentManager->Reserve( 6 );
708 
709  currentManager->Vertex( aStartPoint.x, aStartPoint.y, layerDepth );
710  currentManager->Vertex( diagonalPointA.x, diagonalPointA.y, layerDepth );
711  currentManager->Vertex( aEndPoint.x, aEndPoint.y, layerDepth );
712 
713  currentManager->Vertex( aStartPoint.x, aStartPoint.y, layerDepth );
714  currentManager->Vertex( aEndPoint.x, aEndPoint.y, layerDepth );
715  currentManager->Vertex( diagonalPointB.x, diagonalPointB.y, layerDepth );
716  }
717 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
double layerDepth
The actual layer depth.
bool Reserve(unsigned int aSize)
Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls...
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
double g
Green component.
Definition: color4d.h:282
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:283
double a
Alpha component.
Definition: color4d.h:284
bool isStrokeEnabled
Are the outlines stroked ?
COLOR4D strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices...
bool isFillEnabled
Is filling of graphic objects enabled ?
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
Definition: opengl_gal.cpp:720
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...
double r
Red component.
Definition: color4d.h:281
void OPENGL_GAL::DrawSegment ( const VECTOR2D aStartPoint,
const VECTOR2D aEndPoint,
double  aWidth 
)
overridevirtual

Draw a rounded segment.

Start and end points are defined as 2D-Vectors.

Parameters
aStartPointis the start point of the segment.
aEndPointis the end point of the segment.
aWidthis a width of the segment

Reimplemented from KIGFX::GAL.

Definition at line 421 of file opengl_gal.cpp.

References KIGFX::COLOR4D::a, VECTOR2< T >::Angle(), KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, drawFilledSemiCircle(), drawLineQuad(), drawStrokedSemiCircle(), VECTOR2< T >::EuclideanNorm(), KIGFX::GAL::fillColor, KIGFX::COLOR4D::g, KIGFX::GAL::isFillEnabled, KIGFX::COLOR4D::r, Restore(), KIGFX::VERTEX_MANAGER::Rotate(), Save(), KIGFX::GAL::SetLineWidth(), KIGFX::GAL::strokeColor, and KIGFX::VERTEX_MANAGER::Translate().

423 {
424  VECTOR2D startEndVector = aEndPoint - aStartPoint;
425  double lineAngle = startEndVector.Angle();
426 
427  if( isFillEnabled )
428  {
429  // Filled tracks
431 
432  SetLineWidth( aWidth );
433  drawLineQuad( aStartPoint, aEndPoint );
434 
435  // Draw line caps
436  drawFilledSemiCircle( aStartPoint, aWidth / 2, lineAngle + M_PI / 2 );
437  drawFilledSemiCircle( aEndPoint, aWidth / 2, lineAngle - M_PI / 2 );
438  }
439  else
440  {
441  // Outlined tracks
442  double lineLength = startEndVector.EuclideanNorm();
443 
445 
446  Save();
447 
448  currentManager->Translate( aStartPoint.x, aStartPoint.y, 0.0 );
449  currentManager->Rotate( lineAngle, 0.0f, 0.0f, 1.0f );
450 
451  drawLineQuad( VECTOR2D( 0.0, aWidth / 2.0 ),
452  VECTOR2D( lineLength, aWidth / 2.0 ) );
453 
454  drawLineQuad( VECTOR2D( 0.0, -aWidth / 2.0 ),
455  VECTOR2D( lineLength, -aWidth / 2.0 ) );
456 
457  // Draw line caps
458  drawStrokedSemiCircle( VECTOR2D( 0.0, 0.0 ), aWidth / 2, M_PI / 2 );
459  drawStrokedSemiCircle( VECTOR2D( lineLength, 0.0 ), aWidth / 2, -M_PI / 2 );
460 
461  Restore();
462  }
463 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
virtual void Restore() override
Restore the context.
void Rotate(GLfloat aAngle, GLfloat aX, GLfloat aY, GLfloat aZ)
Function Rotate() multiplies the current matrix by a rotation matrix, so the newly vertices will be r...
double g
Green component.
Definition: color4d.h:282
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:283
double Angle() const
Function Angle computes the angle of the vector.
Definition: vector2d.h:309
virtual void Save() override
Save the context.
double a
Alpha component.
Definition: color4d.h:284
virtual void SetLineWidth(double aLineWidth)
Set the line width.
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:295
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
COLOR4D strokeColor
The color of the outlines.
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Function Translate() multiplies the current matrix by a translation matrix, so newly vertices will be...
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices...
void drawStrokedSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a stroked semicircle.
bool isFillEnabled
Is filling of graphic objects enabled ?
double r
Red component.
Definition: color4d.h:281
void drawFilledSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a filled semicircle.
void OPENGL_GAL::drawSemiCircle ( const VECTOR2D aCenterPoint,
double  aRadius,
double  aAngle 
)
private

Draw a semicircle.

Depending on settings (isStrokeEnabled & isFilledEnabled) it runs the proper function (drawStrokedSemiCircle or drawFilledSemiCircle).

Parameters
aCenterPointis the center point.
aRadiusis the radius of the semicircle.
aAngleis the angle of the semicircle.

Definition at line 1385 of file opengl_gal.cpp.

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, drawFilledSemiCircle(), drawStrokedSemiCircle(), KIGFX::GAL::fillColor, KIGFX::COLOR4D::g, KIGFX::GAL::isFillEnabled, KIGFX::GAL::isStrokeEnabled, KIGFX::COLOR4D::r, and KIGFX::GAL::strokeColor.

1386 {
1387  if( isFillEnabled )
1388  {
1390  drawFilledSemiCircle( aCenterPoint, aRadius, aAngle );
1391  }
1392 
1393  if( isStrokeEnabled )
1394  {
1396  drawStrokedSemiCircle( aCenterPoint, aRadius, aAngle );
1397  }
1398 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
double g
Green component.
Definition: color4d.h:282
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:283
double a
Alpha component.
Definition: color4d.h:284
bool isStrokeEnabled
Are the outlines stroked ?
COLOR4D strokeColor
The color of the outlines.
void Color(const COLOR4D &aColor)
Function Color() changes currently used color that will be applied to newly added vertices...
void drawStrokedSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a stroked semicircle.
bool isFillEnabled
Is filling of graphic objects enabled ?
double r
Red component.
Definition: color4d.h:281
void drawFilledSemiCircle(const VECTOR2D &aCenterPoint, double aRadius, double aAngle)
Draw a filled semicircle.
void OPENGL_GAL::drawStrokedSemiCircle ( const VECTOR2D aCenterPoint,
double  aRadius,
double  aAngle 
)
private

Draw a stroked semicircle.

Parameters
aCenterPointis the center point.
aRadiusis the radius of the semicircle.
aAngleis the angle of the semicircle.

Definition at line 1432 of file opengl_gal.cpp.

References currentManager, KIGFX::GAL::layerDepth, KIGFX::GAL::lineWidth, KIGFX::VERTEX_MANAGER::Reserve(), Restore(), KIGFX::VERTEX_MANAGER::Rotate(), Save(), KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_STROKED_CIRCLE, KIGFX::VERTEX_MANAGER::Translate(), KIGFX::VERTEX_MANAGER::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DrawArcSegment(), DrawSegment(), and drawSemiCircle().

1434 {
1435  double outerRadius = aRadius + ( lineWidth / 2 );
1436 
1437  Save();
1438 
1439  currentManager->Reserve( 3 );
1440  currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
1441  currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1442 
1443  /* Draw a triangle that contains the semicircle, then shade it to leave only
1444  * the semicircle. Parameters given to Shader() are indices of the triangle's vertices
1445  * (if you want to understand more, check the vertex shader source [shader.vert]), the
1446  * radius and the line width. Shader uses these coordinates to determine if fragments are
1447  * inside the semicircle or not.
1448  * v2
1449  * /\
1450  * /__\
1451  * v0 //__\\ v1
1452  */
1454  currentManager->Vertex( -outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v0
1455 
1457  currentManager->Vertex( outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v1
1458 
1460  currentManager->Vertex( 0.0f, outerRadius * 2.0f, layerDepth ); // v2
1461 
1462  Restore();
1463 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
double layerDepth
The actual layer depth.
bool Reserve(unsigned int aSize)
Function Reserve() allocates space for vertices, so it will be used with subsequent Vertex() calls...
virtual void Restore() override
Restore the context.
bool Vertex(const VERTEX &aVertex)
Function Vertex() adds a vertex with the given coordinates to the currently set item.
void Rotate(GLfloat aAngle, GLfloat aX, GLfloat aY, GLfloat aZ)
Function Rotate() multiplies the current matrix by a rotation matrix, so the newly vertices will be r...
double lineWidth
The line width.
virtual void Save() override
Save the context.
void Translate(GLfloat aX, GLfloat aY, GLfloat aZ)
Function Translate() multiplies the current matrix by a translation matrix, so newly vertices will be...
void Shader(GLfloat aShaderType, GLfloat aParam1=0.0f, GLfloat aParam2=0.0f, GLfloat aParam3=0.0f)
Function Shader() changes currently used shader and its parameters that will be applied to newly adde...
void OPENGL_GAL::EndDrawing ( )
overridevirtual

End the drawing, needs to be called for every new frame.

Reimplemented from KIGFX::GAL.

Definition at line 346 of file opengl_gal.cpp.

References blitCursor(), cachedManager, compositor, KIGFX::OPENGL_COMPOSITOR::DrawBuffer(), KIGFX::VERTEX_MANAGER::EndDrawing(), GL_CONTEXT_MANAGER::Get(), glPrivContext, mainBuffer, PROF_COUNTER::msecs(), nonCachedManager, overlayBuffer, overlayManager, KIGFX::OPENGL_COMPOSITOR::Present(), KIGFX::OPENGL_COMPOSITOR::SetBuffer(), PROF_COUNTER::Stop(), and GL_CONTEXT_MANAGER::UnlockCtx().

347 {
348 #ifdef __WXDEBUG__
349  PROF_COUNTER totalRealTime( "OPENGL_GAL::EndDrawing()", true );
350 #endif /* __WXDEBUG__ */
351 
352  // Cached & non-cached containers are rendered to the same buffer
356 
357  // Overlay container is rendered to a different buffer
360 
361  // Be sure that the framebuffer is not colorized (happens on specific GPU&drivers combinations)
362  glColor4d( 1.0, 1.0, 1.0, 1.0 );
363 
364  // Draw the remaining contents, blit the rendering targets to the screen, swap the buffers
367  compositor->Present();
368  blitCursor();
369 
370  SwapBuffers();
372 
373 #ifdef __WXDEBUG__
374  totalRealTime.Stop();
375  wxLogTrace( "GAL_PROFILE", wxT( "OPENGL_GAL::EndDrawing(): %.1f ms" ), totalRealTime.msecs() );
376 #endif /* __WXDEBUG__ */
377 }
virtual void DrawBuffer(unsigned int aBufferHandle) override
Function DrawBuffer() draws the selected buffer to the output buffer.
unsigned int overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:310
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:305
The class PROF_COUNTER is a small class to help profiling.
Definition: profile.h:45
void UnlockCtx(wxGLContext *aContext)
Function UnlockCtx allows other canvases to bind an OpenGL context.
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
static GL_CONTEXT_MANAGER & Get()
Function Get returns the GL_CONTEXT_MANAGER instance (singleton).
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:308
virtual void Present() override
Function Present() Call this to present the output buffer to the screen.
unsigned int mainBuffer
Main rendering target.
Definition: opengl_gal.h:309
void EndDrawing() const
Function EndDrawing() finishes drawing operations.
virtual void SetBuffer(unsigned int aBufferHandle) override
Function SetBuffer() sets the selected buffer as the rendering target.
void blitCursor()
Blits cursor into the current screen.
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:291
void OPENGL_GAL::EndGroup ( )
overridevirtual

End the group.

Reimplemented from KIGFX::GAL.

Definition at line 1218 of file opengl_gal.cpp.

References cachedManager, KIGFX::VERTEX_MANAGER::FinishItem(), and isGrouping.

1219 {
1221  isGrouping = false;
1222 }
bool isGrouping
Was a group started?
Definition: opengl_gal.h:322
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
void FinishItem() const
Function FinishItem() does the cleaning after adding an item.
void OPENGL_GAL::EndUpdate ( )
overridevirtual

Disables item update mode.

Reimplemented from KIGFX::GAL.

Definition at line 393 of file opengl_gal.cpp.

References cachedManager, GL_CONTEXT_MANAGER::Get(), glPrivContext, isInitialized, GL_CONTEXT_MANAGER::UnlockCtx(), and KIGFX::VERTEX_MANAGER::Unmap().

394 {
395  if( !isInitialized )
396  return;
397 
398  cachedManager->Unmap();
400 }
void UnlockCtx(wxGLContext *aContext)
Function UnlockCtx allows other canvases to bind an OpenGL context.
static GL_CONTEXT_MANAGER & Get()
Function Get returns the GL_CONTEXT_MANAGER instance (singleton).
void Unmap()
Function Unmap() unmaps vertex buffer.
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:320
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:291
void OPENGL_GAL::Flush ( )
overridevirtual

Force all remaining objects to be drawn.

Reimplemented from KIGFX::GAL.

Definition at line 1143 of file opengl_gal.cpp.

1144 {
1145  glFlush();
1146 }
COLOR4D GAL::getCursorColor ( ) const
protectedinherited

Gets the actual cursor color to draw.

Definition at line 407 of file graphics_abstraction_layer.cpp.

References color, KIGFX::GAL::cursorColor, and KIGFX::GAL::isCursorEnabled.

Referenced by KIGFX::CAIRO_GAL::blitCursor(), and blitCursor().

408 {
409  auto color = cursorColor;
410 
411  // dim the cursor if it's only on because it was forced
412  // (this helps to provide a hint for active tools)
413  if( !isCursorEnabled )
414  {
415  color.a = color.a * 0.5;
416  }
417 
418  return color;
419 }
bool isCursorEnabled
Is the cursor enabled?
COLOR4D cursorColor
Cursor color.
double KIGFX::GAL::GetGridLineWidth ( ) const
inlineinherited

Get the grid line width.

Returns
the grid line width

Definition at line 860 of file graphics_abstraction_layer.h.

References KIGFX::GAL::gridLineWidth.

861  {
862  return gridLineWidth;
863  }
double gridLineWidth
Line width of the grid.
VECTOR2D GAL::GetGridPoint ( const VECTOR2D aPoint) const
inherited

Function GetGridPoint() For a given point it returns the nearest point belonging to the grid in world coordinates.

Parameters
aPointis the point for which the grid point is searched.
Returns
The nearest grid point in world coordinates.

Definition at line 396 of file graphics_abstraction_layer.cpp.

References KIGFX::GAL::gridOffset, KIGFX::GAL::gridSize, KiROUND(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by KIGFX::WX_VIEW_CONTROLS::GetCursorPosition(), and EDIT_POINTS_FACTORY::Make().

397 {
398  return VECTOR2D( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
399  KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
400 }
VECTOR2D gridOffset
The grid offset to compensate cursor position.
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
VECTOR2D gridSize
The grid size.
const VECTOR2D& KIGFX::GAL::GetGridSize ( ) const
inlineinherited

Returns the grid size.

Returns
A vector containing the grid size in x and y direction.

Definition at line 812 of file graphics_abstraction_layer.h.

References KIGFX::GAL::gridSize.

813  {
814  return gridSize;
815  }
VECTOR2D gridSize
The grid size.
EDA_TEXT_HJUSTIFY_T KIGFX::GAL::GetHorizontalJustify ( ) const
inlineinherited

Returns current text horizontal justification setting.

Definition at line 457 of file graphics_abstraction_layer.h.

References KIGFX::GAL::TEXT_PROPERTIES::m_horizontalJustify, and KIGFX::GAL::textProperties.

Referenced by BitmapText(), and KIGFX::STROKE_FONT::drawSingleLineText().

458  {
460  }
struct KIGFX::GAL::TEXT_PROPERTIES textProperties
EDA_TEXT_HJUSTIFY_T m_horizontalJustify
Horizontal justification.
double KIGFX::GAL::GetLineWidth ( void  ) const
inlineinherited
const VECTOR2D& KIGFX::GAL::GetLookAtPoint ( ) const
inlineinherited

Get the look at point.

Returns
the look at point.

Definition at line 652 of file graphics_abstraction_layer.h.

References KIGFX::GAL::lookAtPoint.

653  {
654  return lookAtPoint;
655  }
VECTOR2D lookAtPoint
Point to be looked at in world space.
double KIGFX::GAL::GetMaxDepth ( ) const
inlineinherited

Returns the maximum depth in the currently used range (the bottom).

Definition at line 701 of file graphics_abstraction_layer.h.

References KIGFX::GAL::depthRange, and VECTOR2< T >::y.

702  {
703  return depthRange.y;
704  }
VECTOR2D depthRange
Range of the depth.
double KIGFX::GAL::GetMinDepth ( ) const
inlineinherited

Returns the minimum depth in the currently used range (the top).

Definition at line 693 of file graphics_abstraction_layer.h.

References KIGFX::GAL::depthRange, and VECTOR2< T >::x.

694  {
695  return depthRange.x;
696  }
VECTOR2D depthRange
Range of the depth.
unsigned int OPENGL_GAL::getNewGroupNumber ( )
private

Returns a valid key that can be used as a new group number.

Returns
An unique group number that is not used by any other group.

Definition at line 1689 of file opengl_gal.cpp.

References groupCounter, groups, and max.

Referenced by BeginGroup().

1690 {
1691  wxASSERT_MSG( groups.size() < std::numeric_limits<unsigned int>::max(),
1692  wxT( "There are no free slots to store a group" ) );
1693 
1694  while( groups.find( groupCounter ) != groups.end() )
1695  {
1696  groupCounter++;
1697  }
1698 
1699  return groupCounter++;
1700 }
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:300
#define max(a, b)
Definition: auxiliary.h:86
unsigned int groupCounter
Counter used for generating keys for groups.
Definition: opengl_gal.h:301
double KIGFX::GAL::GetOverbarVerticalPosition ( ) const
inlineinherited

Compute the vertical position of an overbar, sometimes used in texts.

This is the distance between the text base line and the overbar.

Returns
the relative position of the overbar axis.

Definition at line 352 of file graphics_abstraction_layer.h.

References KIGFX::STROKE_FONT::computeOverbarVerticalPosition(), and KIGFX::GAL::strokeFont.

353  {
355  }
STROKE_FONT strokeFont
Instance of object that stores information about how to draw texts.
double computeOverbarVerticalPosition() const
Compute the vertical position of an overbar, sometimes used in texts.
const VECTOR2I& KIGFX::GAL::GetScreenPixelSize ( ) const
inlineinherited
const MATRIX3x3D& KIGFX::GAL::GetScreenWorldMatrix ( ) const
inlineinherited

Get the screen <-> world transformation matrix.

Returns
the transformation matrix.

Definition at line 593 of file graphics_abstraction_layer.h.

References KIGFX::GAL::screenWorldMatrix.

Referenced by KIGFX::VIEW::ToWorld().

594  {
595  return screenWorldMatrix;
596  }
MATRIX3x3D screenWorldMatrix
Screen transformation.
const COLOR4D& KIGFX::GAL::GetStrokeColor ( ) const
inlineinherited

Get the stroke color.

Returns
the color for stroking the outline.

Definition at line 255 of file graphics_abstraction_layer.h.

References KIGFX::GAL::strokeColor.

256  {
257  return strokeColor;
258  }
COLOR4D strokeColor
The color of the outlines.
const STROKE_FONT& KIGFX::GAL::GetStrokeFont ( ) const
inlineinherited

Definition at line 297 of file graphics_abstraction_layer.h.

References KIGFX::GAL::strokeFont.

Referenced by EDA_TEXT::GetTextBox().

298  {
299  return strokeFont;
300  }
STROKE_FONT strokeFont
Instance of object that stores information about how to draw texts.
RENDER_TARGET OPENGL_GAL::GetTarget ( ) const
overridevirtual

Gets the currently used target for rendering.

Returns
The current rendering target.

Reimplemented from KIGFX::GAL.

Definition at line 1291 of file opengl_gal.cpp.

References currentTarget.

1292 {
1293  return currentTarget;
1294 }
RENDER_TARGET currentTarget
Current rendering target.
Definition: opengl_gal.h:311
VECTOR2D GAL::GetTextLineSize ( const UTF8 aText) const
inherited

Compute the X and Y size of a given text.

The text is expected to be a only one line text.

Parameters
aTextis the text string (one line).
Returns
is the text size.

Definition at line 168 of file graphics_abstraction_layer.cpp.

References KIGFX::STROKE_FONT::computeTextLineSize(), and KIGFX::GAL::strokeFont.

Referenced by GraphicTextWidth(), and EDA_TEXT::LenSize().

169 {
170  // Compute the X and Y size of a given text.
171  // Because computeTextLineSize expects a one line text,
172  // aText is expected to be only one line text.
173  return strokeFont.computeTextLineSize( aText );
174 }
STROKE_FONT strokeFont
Instance of object that stores information about how to draw texts.
VECTOR2D computeTextLineSize(const UTF8 &aText) const
Compute the X and Y size of a given text.
EDA_TEXT_VJUSTIFY_T KIGFX::GAL::GetVerticalJustify ( ) const
inlineinherited

Returns current text vertical justification setting.

Definition at line 475 of file graphics_abstraction_layer.h.

References KIGFX::GAL::TEXT_PROPERTIES::m_verticalJustify, and KIGFX::GAL::textProperties.

Referenced by BitmapText(), and KIGFX::STROKE_FONT::Draw().

476  {
478  }
EDA_TEXT_VJUSTIFY_T m_verticalJustify
Vertical justification.
struct KIGFX::GAL::TEXT_PROPERTIES textProperties
double KIGFX::GAL::GetWorldScale ( ) const
inlineinherited
const MATRIX3x3D& KIGFX::GAL::GetWorldScreenMatrix ( ) const
inlineinherited

Get the world <-> screen transformation matrix.

Returns
the transformation matrix.

Definition at line 583 of file graphics_abstraction_layer.h.

References KIGFX::GAL::worldScreenMatrix.

Referenced by KIGFX::VIEW::ToScreen().

584  {
585  return worldScreenMatrix;
586  }
MATRIX3x3D worldScreenMatrix
World transformation.
double KIGFX::GAL::GetZoomFactor ( ) const
inlineinherited

Get the zoom factor.

Returns
the zoom factor.

Definition at line 672 of file graphics_abstraction_layer.h.

References KIGFX::GAL::zoomFactor.

Referenced by EDA_DRAW_PANEL_GAL::GetLegacyZoom(), EDA_DRAW_FRAME::GetZoomLevelIndicator(), EDA_DRAW_FRAME::UseGalCanvas(), and COMMON_TOOLS::ZoomPreset().

673  {
674  return zoomFactor;
675  }
double zoomFactor
The zoom factor.
void OPENGL_GAL::init ( )
private

Basic OpenGL initialization.

Definition at line 1703 of file opengl_gal.cpp.

References cachedManager, KIGFX::BUILTIN_FONT::font_image, GL_CONTEXT_MANAGER::Get(), glPrivContext, KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::height, isInitialized, KIGFX::SHADER::IsLinked(), KIGFX::BUILTIN_SHADERS::kicad_fragment_shader, KIGFX::BUILTIN_SHADERS::kicad_vertex_shader, KIGFX::SHADER::Link(), KIGFX::SHADER::LoadShaderFromStrings(), GL_CONTEXT_MANAGER::LockCtx(), nonCachedManager, overlayManager, KIGFX::VERTEX_MANAGER::SetShader(), shader, KIGFX::SHADER_TYPE_FRAGMENT, KIGFX::SHADER_TYPE_VERTEX, GL_CONTEXT_MANAGER::UnlockCtx(), and KIGFX::BUILTIN_FONT::FONT_IMAGE_TYPE::width.

Referenced by BeginDrawing(), and BeginUpdate().

1704 {
1705  wxASSERT( IsShownOnScreen() );
1706 
1708 
1709  GLenum err = glewInit();
1710 
1711  try
1712  {
1713  if( GLEW_OK != err )
1714  throw std::runtime_error( (const char*) glewGetErrorString( err ) );
1715 
1716  // Check the OpenGL version (minimum 2.1 is required)
1717  if( !GLEW_VERSION_2_1 )
1718  throw std::runtime_error( "OpenGL 2.1 or higher is required!" );
1719 
1720  // Framebuffers have to be supported
1721  if( !GLEW_EXT_framebuffer_object )
1722  throw std::runtime_error( "Framebuffer objects are not supported!" );
1723 
1724  // Vertex buffer has to be supported
1725  if( !GLEW_ARB_vertex_buffer_object )
1726  throw std::runtime_error( "Vertex buffer objects are not supported!" );
1727 
1728  // Prepare shaders
1730  throw std::runtime_error( "Cannot compile vertex shader!" );
1731 
1733  throw std::runtime_error( "Cannot compile fragment shader!" );
1734 
1735  if( !shader->IsLinked() && !shader->Link() )
1736  throw std::runtime_error( "Cannot link the shaders!" );
1737 
1738  // Check if video card supports textures big enough to fit the font atlas
1739  int maxTextureSize;
1740  glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxTextureSize );
1741 
1742  if( maxTextureSize < (int) font_image.width || maxTextureSize < (int)font_image.height )
1743  {
1744  // TODO implement software texture scaling
1745  // for bitmap fonts and use a higher resolution texture?
1746  throw std::runtime_error( "Requested texture size is not supported" );
1747  }
1748  }
1749  catch( std::runtime_error& )
1750  {
1752  throw;
1753  }
1754 
1755  // Make VBOs use shaders
1759 
1761  isInitialized = true;
1762 }
static SHADER * shader
There is only one shader used for different objects.
Definition: opengl_gal.h:314
bool IsLinked() const
Returns true if shaders are linked correctly.
Definition: shader.h:122
bool LoadShaderFromStrings(SHADER_TYPE aShaderType, Args &&...aArgs)
Add a shader and compile the shader sources.
Definition: shader.h:97
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:305
Fragment shader.
Definition: shader.h:45
bool Link()
Link the shaders.
Definition: shader.cpp:96
void UnlockCtx(wxGLContext *aContext)
Function UnlockCtx allows other canvases to bind an OpenGL context.
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
static GL_CONTEXT_MANAGER & Get()
Function Get returns the GL_CONTEXT_MANAGER instance (singleton).
FONT_IMAGE_TYPE font_image
Definition: gl_resources.cpp:4
Vertex shader.
Definition: shader.h:44
void LockCtx(wxGLContext *aContext, wxGLCanvas *aCanvas)
Function LockCtx sets a context as current and prevents other canvases from switching it...
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:320
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:291
void SetShader(SHADER &aShader) const
Function SetShader() sets a shader program that is going to be used during rendering.
bool KIGFX::GAL::IsCursorEnabled ( ) const
inlineinherited

Returns information about cursor visibility.

Returns
True if cursor is visible.

Definition at line 913 of file graphics_abstraction_layer.h.

References KIGFX::GAL::forceDisplayCursor, and KIGFX::GAL::isCursorEnabled.

Referenced by KIGFX::CAIRO_GAL::blitCursor(), and blitCursor().

914  {
916  }
bool isCursorEnabled
Is the cursor enabled?
bool forceDisplayCursor
Always show cursor.
bool KIGFX::GAL::IsFontBold ( ) const
inlineinherited

Returns true if current font has 'bold' attribute enabled.

Definition at line 403 of file graphics_abstraction_layer.h.

References KIGFX::GAL::TEXT_PROPERTIES::m_bold, and KIGFX::GAL::textProperties.

Referenced by KIGFX::STROKE_FONT::Draw().

404  {
405  return textProperties.m_bold;
406  }
struct KIGFX::GAL::TEXT_PROPERTIES textProperties
bool KIGFX::GAL::IsFontItalic ( ) const
inlineinherited

Returns true if current font has 'italic' attribute enabled.

Definition at line 421 of file graphics_abstraction_layer.h.

References KIGFX::GAL::TEXT_PROPERTIES::m_italic, and KIGFX::GAL::textProperties.

Referenced by KIGFX::STROKE_FONT::ComputeStringBoundaryLimits(), and KIGFX::STROKE_FONT::drawSingleLineText().

422  {
423  return textProperties.m_italic;
424  }
struct KIGFX::GAL::TEXT_PROPERTIES textProperties
virtual bool KIGFX::OPENGL_GAL::IsInitialized ( ) const
inlineoverridevirtual

Returns the initalization status for the canvas.

Reimplemented from KIGFX::GAL.

Definition at line 90 of file opengl_gal.h.

91  {
92  // is*Initialized flags, but it is enough for OpenGL to show up
93  return IsShownOnScreen();
94  }
bool KIGFX::GAL::IsTextMirrored ( ) const
inlineinherited

Returns true if text should displayed mirrored.

Definition at line 439 of file graphics_abstraction_layer.h.

References KIGFX::GAL::TEXT_PROPERTIES::m_mirrored, and KIGFX::GAL::textProperties.

Referenced by BitmapText(), and KIGFX::STROKE_FONT::drawSingleLineText().

440  {
441  return textProperties.m_mirrored;
442  }
struct KIGFX::GAL::TEXT_PROPERTIES textProperties
bool KIGFX::OPENGL_GAL::IsVisible ( ) const
inlineoverridevirtual

>

Returns true if the GAL canvas is visible on the screen.

Reimplemented from KIGFX::GAL.

Definition at line 97 of file opengl_gal.h.

98  {
99  return IsShownOnScreen();
100  }
void GAL::OnGalDisplayOptionsChanged ( const GAL_DISPLAY_OPTIONS aOptions)
overrideprotectedvirtualinherited

Handler for observer settings changes.

Implements KIGFX::GAL_DISPLAY_OPTIONS_OBSERVER.

Definition at line 88 of file graphics_abstraction_layer.cpp.

References KIGFX::GAL::updatedGalDisplayOptions().

89 {
90  // defer to the child class first
91  updatedGalDisplayOptions( aOptions );
92 
93  // there is no refresh to do at this level
94 }
virtual bool updatedGalDisplayOptions(const GAL_DISPLAY_OPTIONS &aOptions)
Function updatedGalDisplayOptions.
void OPENGL_GAL::onPaint ( wxPaintEvent &  aEvent)
private

This is the OnPaint event handler.

Parameters
aEventis the OnPaint event.

Definition at line 1644 of file opengl_gal.cpp.

References PostPaint().

Referenced by OPENGL_GAL().

1645 {
1646  PostPaint();
1647 }
void PostPaint()
Function PostPaint posts an event to m_paint_listener.
Definition: opengl_gal.h:254
void KIGFX::GAL::PopDepth ( )
inlineinherited

Restores previously stored drawing depth for the depth stack.

Definition at line 955 of file graphics_abstraction_layer.h.

References KIGFX::GAL::depthStack, and KIGFX::GAL::layerDepth.

956  {
957  layerDepth = depthStack.top();
958  depthStack.pop();
959  }
double layerDepth
The actual layer depth.
std::stack< double > depthStack
Stored depth values.
void KIGFX::OPENGL_GAL::PostPaint ( )
inline

Function PostPaint posts an event to m_paint_listener.

A post is used so that the actual drawing function can use a device context type that is not specific to the wxEVT_PAINT event.

Definition at line 254 of file opengl_gal.h.

References paintListener.

Referenced by onPaint().

255  {
256  if( paintListener )
257  {
258  wxPaintEvent redrawEvent;
259  wxPostEvent( paintListener, redrawEvent );
260  }
261  }
wxEvtHandler * paintListener
Definition: opengl_gal.h:294
void KIGFX::GAL::PushDepth ( )
inlineinherited

Stores current drawing depth on the depth stack.

Definition at line 947 of file graphics_abstraction_layer.h.

References KIGFX::GAL::depthStack, and KIGFX::GAL::layerDepth.

948  {
949  depthStack.push( layerDepth );
950  }
double layerDepth
The actual layer depth.
std::stack< double > depthStack
Stored depth values.
void GAL::ResetTextAttributes ( )
inherited

Reset text attributes to default styling.

Normally, custom attributes will be set individually after this, otherwise you can use SetTextAttributes()

Definition at line 153 of file graphics_abstraction_layer.cpp.

References GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER, KIGFX::GAL::SetFontBold(), KIGFX::GAL::SetFontItalic(), KIGFX::GAL::SetGlyphSize(), KIGFX::GAL::SetHorizontalJustify(), KIGFX::GAL::SetTextMirrored(), and KIGFX::GAL::SetVerticalJustify().

Referenced by KIGFX::GAL::GAL().

154 {
155  // Tiny but non-zero - this will always need setting
156  // there is no built-in default
157  SetGlyphSize( { 1.0, 1.0 } );
158 
161 
162  SetFontBold( false );
163  SetFontItalic( false );
164  SetTextMirrored( false );
165 }
void SetFontItalic(const bool aItalic)
Set italic property of current font.
void SetFontBold(const bool aBold)
Set bold property of current font.
void SetTextMirrored(const bool aMirrored)
Set a mirrored property of text.
void SetVerticalJustify(const EDA_TEXT_VJUSTIFY_T aVerticalJustify)
Set the vertical justify for text drawing.
void SetGlyphSize(const VECTOR2D aGlyphSize)
Set the font glyph size.
void SetHorizontalJustify(const EDA_TEXT_HJUSTIFY_T aHorizontalJustify)
Set the horizontal justify for text drawing.
void OPENGL_GAL::ResizeScreen ( int  aWidth,
int  aHeight 
)
overridevirtual

Resizes the canvas.

Reimplemented from KIGFX::GAL.

Definition at line 1114 of file opengl_gal.cpp.

References compositor, isFramebufferInitialized, KIGFX::OPENGL_COMPOSITOR::Resize(), and KIGFX::GAL::screenSize.

1115 {
1116  screenSize = VECTOR2I( aWidth, aHeight );
1117 
1118 #ifdef RETINA_OPENGL_PATCH
1119  const float scaleFactor = GetBackingScaleFactor();
1120 #else
1121  const float scaleFactor = 1.0f;
1122 #endif
1123 
1124  // Resize framebuffers
1125  compositor->Resize( aWidth * scaleFactor, aHeight * scaleFactor );
1126  isFramebufferInitialized = false;
1127 
1128  wxGLCanvas::SetSize( aWidth, aHeight );
1129 }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:308
bool isFramebufferInitialized
Are the framebuffers initialized?
Definition: opengl_gal.h:317
virtual void Resize(unsigned int aWidth, unsigned int aHeight) override
Function Resize() clears the state of COMPOSITOR, so it has to be reinitialized again with the new di...
VECTOR2I screenSize
Screen size in screen coordinates.
void OPENGL_GAL::Restore ( )
overridevirtual

Restore the context.

Reimplemented from KIGFX::GAL.

Definition at line 1200 of file opengl_gal.cpp.

References currentManager, and KIGFX::VERTEX_MANAGER::PopMatrix().

Referenced by BitmapText(), DrawArc(), DrawArcSegment(), drawBitmapOverbar(), drawFilledSemiCircle(), DrawSegment(), and drawStrokedSemiCircle().

1201 {
1203 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
void PopMatrix()
Function PopMatrix() pops the current transformation matrix stack.
void OPENGL_GAL::RestoreScreen ( )
overridevirtual

Restore the screen contents.

Reimplemented from KIGFX::GAL.

Definition at line 1263 of file opengl_gal.cpp.

1264 {
1265  wxASSERT_MSG( false, wxT( "Not implemented yet" ) );
1266 }
void OPENGL_GAL::Rotate ( double  aAngle)
overridevirtual

Rotate the context.

Parameters
aAngleis the rotation angle in radians.

Reimplemented from KIGFX::GAL.

Definition at line 1176 of file opengl_gal.cpp.

References currentManager, and KIGFX::VERTEX_MANAGER::Rotate().

1177 {
1178  currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1179 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
void Rotate(GLfloat aAngle, GLfloat aX, GLfloat aY, GLfloat aZ)
Function Rotate() multiplies the current matrix by a rotation matrix, so the newly vertices will be r...
void OPENGL_GAL::Save ( )
overridevirtual

Save the context.

Reimplemented from KIGFX::GAL.

Definition at line 1194 of file opengl_gal.cpp.

References currentManager, and KIGFX::VERTEX_MANAGER::PushMatrix().

Referenced by BitmapText(), DrawArc(), DrawArcSegment(), drawBitmapOverbar(), drawFilledSemiCircle(), DrawSegment(), and drawStrokedSemiCircle().

1195 {
1197 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
void PushMatrix()
Function PushMatrix() pushes the current transformation matrix stack.
void OPENGL_GAL::SaveScreen ( )
overridevirtual

Save the screen contents.

Reimplemented from KIGFX::GAL.

Definition at line 1257 of file opengl_gal.cpp.

1258 {
1259  wxASSERT_MSG( false, wxT( "Not implemented yet" ) );
1260 }
void OPENGL_GAL::Scale ( const VECTOR2D aScale)
overridevirtual

Scale the context.

Parameters
aScaleis the scale factor for the x- and y-axis.

Reimplemented from KIGFX::GAL.

Definition at line 1188 of file opengl_gal.cpp.

References currentManager, KIGFX::VERTEX_MANAGER::Scale(), VECTOR2< T >::x, and VECTOR2< T >::y.

1189 {
1190  currentManager->Scale( aScale.x, aScale.y, 0.0f );
1191 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
void Scale(GLfloat aX, GLfloat aY, GLfloat aZ)
Function Scale() multiplies the current matrix by a scaling matrix, so the newly vertices will be sca...
void KIGFX::GAL::SetAxesColor ( const COLOR4D aAxesColor)
inlineinherited

Set the axes color.

Parameters
aAxesColoris the color to draw the axes if enabled.

Definition at line 832 of file graphics_abstraction_layer.h.

References KIGFX::GAL::axesColor.

Referenced by KIGFX::CAIRO_GAL::CAIRO_GAL(), and OPENGL_GAL().

833  {
834  axesColor = aAxesColor;
835  }
COLOR4D axesColor
Color of the axes.
void KIGFX::GAL::SetAxesEnabled ( bool  aAxesEnabled)
inlineinherited

Enables drawing the axes.

Definition at line 840 of file graphics_abstraction_layer.h.

References KIGFX::GAL::axesEnabled.

Referenced by KIGFX::GAL::GAL(), and FOOTPRINT_EDIT_FRAME::UseGalCanvas().

841  {
842  axesEnabled = aAxesEnabled;
843  }
bool axesEnabled
Should the axes be drawn.
void KIGFX::GAL::SetCoarseGrid ( int  aInterval)
inlineinherited

Draw every tick line wider.

Parameters
aIntervalincrease the width of every aInterval line, if 0 do not use this feature.

Definition at line 850 of file graphics_abstraction_layer.h.

References KIGFX::GAL::gridTick.

Referenced by KIGFX::GAL::GAL().

851  {
852  gridTick = aInterval;
853  }
int gridTick
Every tick line gets the double width.
void KIGFX::GAL::SetCursorColor ( const COLOR4D aCursorColor)
inlineinherited

Set the cursor color.

Parameters
aCursorColoris the color of the cursor.

Definition at line 923 of file graphics_abstraction_layer.h.

References KIGFX::GAL::cursorColor.

Referenced by KIGFX::GAL::GAL().

924  {
925  cursorColor = aCursorColor;
926  }
COLOR4D cursorColor
Cursor color.
void KIGFX::GAL::SetCursorEnabled ( bool  aCursorEnabled)
inlineinherited

Enable/disable cursor.

Parameters
aCursorEnabledis true if the cursor should be drawn, else false.

Definition at line 904 of file graphics_abstraction_layer.h.

References KIGFX::GAL::isCursorEnabled.

Referenced by KIGFX::GAL::GAL(), and KIGFX::VIEW_CONTROLS::ShowCursor().

905  {
906  isCursorEnabled = aCursorEnabled;
907  }
bool isCursorEnabled
Is the cursor enabled?
void KIGFX::GAL::SetDepthRange ( const VECTOR2D aDepthRange)
inlineinherited

Set the range of the layer depth.

Usually required for the OpenGL implementation, any object outside this range is not drawn.

Parameters
aDepthRangeis the depth range where component x is the near clipping plane and y is the far clipping plane.

Definition at line 685 of file graphics_abstraction_layer.h.

References KIGFX::GAL::depthRange.

Referenced by KIGFX::GAL::GAL().

686  {
687  depthRange = aDepthRange;
688  }
VECTOR2D depthRange
Range of the depth.
virtual void KIGFX::GAL::SetFillColor ( const COLOR4D aColor)
inlinevirtualinherited
void KIGFX::GAL::SetFlip ( bool  xAxis,
bool  yAxis 
)
inlineinherited

Sets flipping of the screen.

Parameters
xAxisis the flip flag for the X axis.
yAxisis the flip flag for the Y axis.

Definition at line 722 of file graphics_abstraction_layer.h.

References KIGFX::GAL::globalFlipX, and KIGFX::GAL::globalFlipY.

Referenced by KIGFX::GAL::GAL(), and KIGFX::VIEW::SetMirror().

723  {
724  globalFlipX = xAxis;
725  globalFlipY = yAxis;
726  }
bool globalFlipX
Flag for X axis flipping.
bool globalFlipY
Flag for Y axis flipping.
void KIGFX::GAL::SetFontBold ( const bool  aBold)
inlineinherited

Set bold property of current font.

Parameters
aBoldtells if the font should be bold or not.

Definition at line 395 of file graphics_abstraction_layer.h.

References KIGFX::GAL::TEXT_PROPERTIES::m_bold, and KIGFX::GAL::textProperties.

Referenced by KIGFX::PCB_PAINTER::draw(), GraphicTextWidth(), EDA_TEXT::LenSize(), KIGFX::GAL::ResetTextAttributes(), and KIGFX::GAL::SetTextAttributes().

396  {
397  textProperties.m_bold = aBold;
398  }
struct KIGFX::GAL::TEXT_PROPERTIES textProperties
void KIGFX::GAL::SetFontItalic ( const bool  aItalic)
inlineinherited

Set italic property of current font.

Parameters
aItalictells if the font should be italic or not.

Definition at line 413 of file graphics_abstraction_layer.h.

References KIGFX::GAL::TEXT_PROPERTIES::m_italic, and KIGFX::GAL::textProperties.

Referenced by KIGFX::PCB_PAINTER::draw(), GraphicTextWidth(), EDA_TEXT::LenSize(), KIGFX::GAL::ResetTextAttributes(), and KIGFX::GAL::SetTextAttributes().

414  {
415  textProperties.m_italic = aItalic;
416  }
struct KIGFX::GAL::TEXT_PROPERTIES textProperties
void KIGFX::GAL::SetGlyphSize ( const VECTOR2D  aGlyphSize)
inlineinherited

Set the font glyph size.

Parameters
aGlyphSizeis the new font glyph size.

Definition at line 377 of file graphics_abstraction_layer.h.

References KIGFX::GAL::TEXT_PROPERTIES::m_glyphSize, and KIGFX::GAL::textProperties.

Referenced by KIGFX::PCB_PAINTER::draw(), GraphicTextWidth(), EDA_TEXT::LenSize(), KIGFX::GAL::ResetTextAttributes(), KIGFX::PREVIEW::SetConstantGlyphHeight(), and KIGFX::GAL::SetTextAttributes().

378  {
379  textProperties.m_glyphSize = aGlyphSize;
380  }
struct KIGFX::GAL::TEXT_PROPERTIES textProperties
VECTOR2D m_glyphSize
Size of the glyphs.
void KIGFX::GAL::SetGridColor ( const COLOR4D aGridColor)
inlineinherited

Set the grid color.

Parameters
aGridColoris the grid color, it should have a low alpha value for the best effect.

Definition at line 822 of file graphics_abstraction_layer.h.

References KIGFX::GAL::gridColor.

Referenced by KIGFX::CAIRO_GAL::CAIRO_GAL(), EDA_DRAW_PANEL_GAL::onPaint(), and OPENGL_GAL().

823  {
824  gridColor = aGridColor;
825  }
COLOR4D gridColor
Color of the grid.
void KIGFX::GAL::SetGridOrigin ( const VECTOR2D aGridOrigin)
inlineinherited

Set the origin point for the grid.

Parameters
aGridOriginis a vector containing the grid origin point, in world coordinates.

Definition at line 783 of file graphics_abstraction_layer.h.

References KIGFX::GAL::gridOffset, KIGFX::GAL::gridOrigin, KIGFX::GAL::gridSize, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PCB_BASE_EDIT_FRAME::SetBoard(), setOrigin(), and EDA_DRAW_FRAME::UseGalCanvas().

784  {
785  gridOrigin = aGridOrigin;
786 
787  if( gridSize.x == 0.0 || gridSize.y == 0.0 )
788  gridOffset = VECTOR2D(0.0, 0.0);
789  else
790  gridOffset = VECTOR2D( (long) gridOrigin.x % (long) gridSize.x,
791  (long) gridOrigin.y % (long) gridSize.y );
792  }
VECTOR2D gridOffset
The grid offset to compensate cursor position.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
VECTOR2D gridOrigin
The grid origin.
VECTOR2D gridSize
The grid size.
void KIGFX::GAL::SetGridSize ( const VECTOR2D aGridSize)
inlineinherited

Set the grid size.

Parameters
aGridSizeis a vector containing the grid size in x and y direction.

Definition at line 799 of file graphics_abstraction_layer.h.

References KIGFX::GAL::gridOffset, KIGFX::GAL::gridOrigin, KIGFX::GAL::gridSize, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by COMMON_TOOLS::updateGrid(), PCBNEW_CONTROL::updateGrid(), and EDA_DRAW_FRAME::UseGalCanvas().

800  {
801  gridSize = aGridSize;
802 
803  gridOffset = VECTOR2D( (long) gridOrigin.x % (long) gridSize.x,
804  (long) gridOrigin.y % (long) gridSize.y );
805  }
VECTOR2D gridOffset
The grid offset to compensate cursor position.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
VECTOR2D gridOrigin
The grid origin.
VECTOR2D gridSize
The grid size.
void KIGFX::GAL::SetGridVisibility ( bool  aVisibility)
inlineinherited

Sets the visibility setting of the grid.

Parameters
aVisibilityis the new visibility setting of the grid.

Definition at line 773 of file graphics_abstraction_layer.h.

References KIGFX::GAL::gridVisibility.

Referenced by KIGFX::GAL::GAL(), PCB_LAYER_WIDGET::OnRenderEnable(), EDA_DRAW_FRAME::OnToggleGridState(), and EDA_DRAW_FRAME::UseGalCanvas().

774  {
775  gridVisibility = aVisibility;
776  }
bool gridVisibility
Should the grid be shown.
void KIGFX::GAL::SetHorizontalJustify ( const EDA_TEXT_HJUSTIFY_T  aHorizontalJustify)
inlineinherited

Set the horizontal justify for text drawing.

Parameters
aHorizontalJustifyis the horizontal justify value.

Definition at line 449 of file graphics_abstraction_layer.h.

References KIGFX::GAL::TEXT_PROPERTIES::m_horizontalJustify, and KIGFX::GAL::textProperties.

Referenced by KIGFX::PCB_PAINTER::draw(), KIGFX::PREVIEW::DrawTextNextToCursor(), drawTicksAlongLine(), KIGFX::GAL::ResetTextAttributes(), and KIGFX::GAL::SetTextAttributes().

450  {
451  textProperties.m_horizontalJustify = aHorizontalJustify;
452  }
struct KIGFX::GAL::TEXT_PROPERTIES textProperties
EDA_TEXT_HJUSTIFY_T m_horizontalJustify
Horizontal justification.
virtual void KIGFX::GAL::SetIsFill ( bool  aIsFillEnabled)
inlinevirtualinherited

Enable/disable fill.

Parameters
aIsFillEnabledis true, when the graphics objects should be filled, else false.

Reimplemented in KIGFX::CAIRO_GAL.

Definition at line 215 of file graphics_abstraction_layer.h.

References KIGFX::GAL::isFillEnabled.

Referenced by KIGFX::WORKSHEET_VIEWITEM::draw(), KIGFX::PCB_PAINTER::draw(), KIGFX::WORKSHEET_VIEWITEM::drawBorder(), DrawGraphicText(), KIGFX::GAL::DrawGrid(), KIGFX::PREVIEW::DrawTextNextToCursor(), KIGFX::GAL::GAL(), and KIGFX::PREVIEW::SIMPLE_OVERLAY_ITEM::setupGal().

216  {
217  isFillEnabled = aIsFillEnabled;
218  }
bool isFillEnabled
Is filling of graphic objects enabled ?
virtual void KIGFX::GAL::SetIsStroke ( bool  aIsStrokeEnabled)
inlinevirtualinherited

Enable/disable stroked outlines.

Parameters
aIsStrokeEnabledis true, if the outline of an object should be stroked.

Reimplemented in KIGFX::CAIRO_GAL.

Definition at line 225 of file graphics_abstraction_layer.h.

References KIGFX::GAL::isStrokeEnabled.

Referenced by KIGFX::STROKE_FONT::Draw(), KIGFX::WORKSHEET_VIEWITEM::draw(), KIGFX::PCB_PAINTER::draw(), KIGFX::WORKSHEET_VIEWITEM::drawBorder(), KIGFX::GAL::DrawGrid(), KIGFX::GAL::GAL(), KIGFX::PREVIEW::SIMPLE_OVERLAY_ITEM::setupGal(), PCB_BRIGHT_BOX::ViewDraw(), KIGFX::RATSNEST_VIEWITEM::ViewDraw(), KIGFX::ORIGIN_VIEWITEM::ViewDraw(), and BRIGHT_BOX::ViewDraw().

226  {
227  isStrokeEnabled = aIsStrokeEnabled;
228  }
bool isStrokeEnabled
Are the outlines stroked ?
virtual void KIGFX::GAL::SetLayerDepth ( double  aLayerDepth)
inlinevirtualinherited

Set the depth of the layer (position on the z-axis)

Parameters
aLayerDepththe layer depth for the objects.

Reimplemented in KIGFX::CAIRO_GAL.

Definition at line 285 of file graphics_abstraction_layer.h.

References KIGFX::GAL::depthRange, KIGFX::GAL::layerDepth, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by KIGFX::VIEW::draw(), KIGFX::GAL::DrawGrid(), KIGFX::GAL::GAL(), KIGFX::VIEW::redrawRect(), KIGFX::CAIRO_GAL::SetLayerDepth(), KIGFX::VIEW::updateItemGeometry(), and ROUTER_PREVIEW_ITEM::ViewDraw().

286  {
287  assert( aLayerDepth <= depthRange.y );
288  assert( aLayerDepth >= depthRange.x );
289 
290  layerDepth = aLayerDepth;
291  }
double layerDepth
The actual layer depth.
VECTOR2D depthRange
Range of the depth.
virtual void KIGFX::GAL::SetLineWidth ( double  aLineWidth)
inlinevirtualinherited
void KIGFX::GAL::SetLookAtPoint ( const VECTOR2D aPoint)
inlineinherited

Set the Point in world space to look at.

This point corresponds with the center of the actual drawing area.

Parameters
aPointis the look at point (center of the actual drawing area).

Definition at line 642 of file graphics_abstraction_layer.h.

References KIGFX::GAL::lookAtPoint.

Referenced by KIGFX::GAL::GAL(), and KIGFX::VIEW::SetCenter().

643  {
644  lookAtPoint = aPoint;
645  }
VECTOR2D lookAtPoint
Point to be looked at in world space.
void KIGFX::OPENGL_GAL::SetMouseListener ( wxEvtHandler *  aMouseListener)
inline

Definition at line 263 of file opengl_gal.h.

References mouseListener.

264  {
265  mouseListener = aMouseListener;
266  }
wxEvtHandler * mouseListener
Definition: opengl_gal.h:293
void KIGFX::OPENGL_GAL::SetPaintListener ( wxEvtHandler *  aPaintListener)
inline

Parameters passed to the GLU tesselator.

Definition at line 268 of file opengl_gal.h.

References paintListener.

void KIGFX::GAL::SetScreenDPI ( double  aScreenDPI)
inlineinherited

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.

Parameters
aScreenDPIare the screen DPI.

Definition at line 630 of file graphics_abstraction_layer.h.

References KIGFX::GAL::screenDPI.

Referenced by KIGFX::GAL::GAL().

631  {
632  screenDPI = aScreenDPI;
633  }
double screenDPI
The dots per inch of the screen.
virtual void KIGFX::GAL::SetStrokeColor ( const COLOR4D aColor)
inlinevirtualinherited
void OPENGL_GAL::SetTarget ( RENDER_TARGET  aTarget)
overridevirtual

Sets the target for rendering.

Parameters
aTargetis the new target for rendering.

Reimplemented from KIGFX::GAL.

Definition at line 1269 of file opengl_gal.cpp.

References cachedManager, currentManager, currentTarget, nonCachedManager, overlayManager, KIGFX::TARGET_CACHED, KIGFX::TARGET_NONCACHED, and KIGFX::TARGET_OVERLAY.

Referenced by DrawGrid(), and OPENGL_GAL().

1270 {
1271  switch( aTarget )
1272  {
1273  default:
1274  case TARGET_CACHED:
1276  break;
1277 
1278  case TARGET_NONCACHED:
1280  break;
1281 
1282  case TARGET_OVERLAY:
1284  break;
1285  }
1286 
1287  currentTarget = aTarget;
1288 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:302
RENDER_TARGET currentTarget
Current rendering target.
Definition: opengl_gal.h:311
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:305
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:304
Auxiliary rendering target (noncached)
Definition: definitions.h:42
Items that may change while the view stays the same (noncached)
Definition: definitions.h:43
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:303
Main rendering target (cached)
Definition: definitions.h:41
void GAL::SetTextAttributes ( const EDA_TEXT aText)
virtualinherited

Loads attributes of the given text (bold/italic/underline/mirrored and so on).

Parameters
aTextis the text item.

Definition at line 142 of file graphics_abstraction_layer.cpp.

References EDA_TEXT::GetHorizJustify(), EDA_TEXT::GetTextSize(), EDA_TEXT::GetVertJustify(), EDA_TEXT::IsBold(), EDA_TEXT::IsItalic(), EDA_TEXT::IsMirrored(), KIGFX::GAL::SetFontBold(), KIGFX::GAL::SetFontItalic(), KIGFX::GAL::SetGlyphSize(), KIGFX::GAL::SetHorizontalJustify(), KIGFX::GAL::SetTextMirrored(), and KIGFX::GAL::SetVerticalJustify().

Referenced by KIGFX::WORKSHEET_VIEWITEM::draw(), KIGFX::PCB_PAINTER::draw(), and DrawGraphicText().

143 {
144  SetGlyphSize( VECTOR2D( aText->GetTextSize() ) );
147  SetFontBold( aText->IsBold() );
148  SetFontItalic( aText->IsItalic() );
149  SetTextMirrored( aText->IsMirrored() );
150 }
void SetFontItalic(const bool aItalic)
Set italic property of current font.
bool IsItalic() const
Definition: eda_text.h:170
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:190
bool IsBold() const
Definition: eda_text.h:173
void SetFontBold(const bool aBold)
Set bold property of current font.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
void SetTextMirrored(const bool aMirrored)
Set a mirrored property of text.
void SetVerticalJustify(const EDA_TEXT_VJUSTIFY_T aVerticalJustify)
Set the vertical justify for text drawing.
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:191
bool IsMirrored() const
Definition: eda_text.h:179
void SetGlyphSize(const VECTOR2D aGlyphSize)
Set the font glyph size.
const wxSize & GetTextSize() const
Definition: eda_text.h:215
void SetHorizontalJustify(const EDA_TEXT_HJUSTIFY_T aHorizontalJustify)
Set the horizontal justify for text drawing.
void KIGFX::GAL::SetTextMirrored ( const bool  aMirrored)
inlineinherited

Set a mirrored property of text.

Parameters
aMirroredtells if the text should be mirrored or not.

Definition at line 431 of file graphics_abstraction_layer.h.

References KIGFX::GAL::TEXT_PROPERTIES::m_mirrored, and KIGFX::GAL::textProperties.

Referenced by KIGFX::PCB_PAINTER::draw(), KIGFX::GAL::ResetTextAttributes(), and KIGFX::GAL::SetTextAttributes().

432  {
433  textProperties.m_mirrored = aMirrored;
434  }
struct KIGFX::GAL::TEXT_PROPERTIES textProperties
void KIGFX::GAL::SetVerticalJustify ( const EDA_TEXT_VJUSTIFY_T  aVerticalJustify)
inlineinherited

Set the vertical justify for text drawing.

Parameters
aVerticalJustifyis the vertical justify value.

Definition at line 467 of file graphics_abstraction_layer.h.

References KIGFX::GAL::TEXT_PROPERTIES::m_verticalJustify, and KIGFX::GAL::textProperties.

Referenced by KIGFX::PCB_PAINTER::draw(), KIGFX::GAL::ResetTextAttributes(), and KIGFX::GAL::SetTextAttributes().

468  {
469  textProperties.m_verticalJustify = aVerticalJustify;
470  }
EDA_TEXT_VJUSTIFY_T m_verticalJustify
Vertical justification.
struct KIGFX::GAL::TEXT_PROPERTIES textProperties
void KIGFX::GAL::SetWorldScreenMatrix ( const MATRIX3x3D aMatrix)
inlineinherited

Set the world <-> screen transformation matrix.

Parameters
aMatrixis the 3x3 world <-> screen transformation matrix.

Definition at line 603 of file graphics_abstraction_layer.h.

References KIGFX::GAL::worldScreenMatrix.

604  {
605  worldScreenMatrix = aMatrix;
606  }
MATRIX3x3D worldScreenMatrix
World transformation.
void KIGFX::GAL::SetWorldUnitLength ( double  aWorldUnitLength)
inlineinherited

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.

Parameters
aWorldUnitLengthis the world Unit length.

Definition at line 617 of file graphics_abstraction_layer.h.

References KIGFX::GAL::worldUnitLength.

Referenced by KIGFX::GAL::GAL().

618  {
619  worldUnitLength = aWorldUnitLength;
620  }
double worldUnitLength
The unit length of the world coordinates [inch].
void KIGFX::GAL::SetZoomFactor ( double  aZoomFactor)
inlineinherited

Set the zoom factor of the scene.

Parameters
aZoomFactoris the zoom factor.

Definition at line 662 of file graphics_abstraction_layer.h.

References KIGFX::GAL::zoomFactor.

Referenced by KIGFX::GAL::GAL(), and KIGFX::VIEW::SetScale().

663  {
664  zoomFactor = aZoomFactor;
665  }
double zoomFactor
The zoom factor.
bool OPENGL_GAL::Show ( bool  aShow)
overridevirtual

Shows/hides the GAL canvas.

Reimplemented from KIGFX::GAL.

Definition at line 1132 of file opengl_gal.cpp.

1133 {
1134  bool s = wxGLCanvas::Show( aShow );
1135 
1136  if( aShow )
1137  wxGLCanvas::Raise();
1138 
1139  return s;
1140 }
void OPENGL_GAL::skipMouseEvent ( wxMouseEvent &  aEvent)
private

Skip the mouse event to the parent.

Parameters
aEventis the mouse event.

Definition at line 1650 of file opengl_gal.cpp.

References mouseListener.

Referenced by OPENGL_GAL().

1651 {
1652  // Post the mouse event to the event listener registered in constructor, if any
1653  if( mouseListener )
1654  wxPostEvent( mouseListener, aEvent );
1655 }
wxEvtHandler * mouseListener
Definition: opengl_gal.h:293
virtual void KIGFX::GAL::StrokeText ( const wxString &  aText,
const VECTOR2D aPosition,
double  aRotationAngle 
)
inlinevirtualinherited

Draws a vector type text using preloaded Newstroke font.

Parameters
aTextis the text to be drawn.
aPositionis the text position in world coordinates.
aRotationAngleis the text rotation angle.

Definition at line 309 of file graphics_abstraction_layer.h.

References KIGFX::STROKE_FONT::Draw(), and KIGFX::GAL::strokeFont.

Referenced by KIGFX::GAL::BitmapText(), KIGFX::WORKSHEET_VIEWITEM::draw(), KIGFX::PCB_PAINTER::draw(), and DrawGraphicText().

311  {
312  strokeFont.Draw( aText, aPosition, aRotationAngle );
313  }
STROKE_FONT strokeFont
Instance of object that stores information about how to draw texts.
void Draw(const UTF8 &aText, const VECTOR2D &aPosition, double aRotationAngle)
Draw a string.
VECTOR2D KIGFX::GAL::ToScreen ( const VECTOR2D aPoint) const
inlineinherited

Compute the point position in screen coordinates from given world coordinates.

Parameters
aPointthe pointposition in world coordinates.
Returns
the point position in screen coordinates.

Definition at line 894 of file graphics_abstraction_layer.h.

References KIGFX::GAL::worldScreenMatrix.

Referenced by KIGFX::CAIRO_GAL::blitCursor().

895  {
896  return VECTOR2D( worldScreenMatrix * aPoint );
897  }
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
MATRIX3x3D worldScreenMatrix
World transformation.
VECTOR2D KIGFX::GAL::ToWorld ( const VECTOR2D aPoint) const
inlineinherited

Compute the point position in world coordinates from given screen coordinates.

Parameters
aPointthe pointposition in screen coordinates.
Returns
the point position in world coordinates.

Definition at line 883 of file graphics_abstraction_layer.h.

References KIGFX::GAL::screenWorldMatrix.

884  {
885  return VECTOR2D( screenWorldMatrix * aPoint );
886  }
MATRIX3x3D screenWorldMatrix
Screen transformation.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
void OPENGL_GAL::Transform ( const MATRIX3x3D aTransformation)
overridevirtual

Transform the context.

Parameters
aTransformationis the ransformation matrix.

Reimplemented from KIGFX::GAL.

Definition at line 1158 of file opengl_gal.cpp.

References MATRIX3x3< T >::m_data.

1159 {
1160  GLdouble matrixData[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
1161 
1162  matrixData[0] = aTransformation.m_data[0][0];
1163  matrixData[1] = aTransformation.m_data[1][0];
1164  matrixData[2] = aTransformation.m_data[2][0];
1165  matrixData[4] = aTransformation.m_data[0][1];
1166  matrixData[5] = aTransformation.m_data[1][1];
1167  matrixData[6] = aTransformation.m_data[2][1];
1168  matrixData[12] = aTransformation.m_data[0][2];
1169  matrixData[13] = aTransformation.m_data[1][2];
1170  matrixData[14] = aTransformation.m_data[2][2];
1171 
1172  glMultMatrixd( matrixData );
1173 }
T m_data[3][3]
Definition: matrix3x3.h:64
void OPENGL_GAL::Translate ( const VECTOR2D aTranslation)