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 HIDPI_GL_CANVAS 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 DrawBitmap (const BITMAP_BASE &aBitmap) override
 Draw a bitmap image. 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 () 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 SetNegativeDrawMode (bool aSetting) override
 Sets negative draw mode in the renderer. 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...
 
void SetClearColor (const COLOR4D &aColor)
 
const COLOR4DGetClearColor () const
 
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...
 
virtual wxSize GetClientSize () const
 
virtual float GetBackingScaleFactor () const
 

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...
 
COLOR4D m_clearColor
 
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::unordered_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 (const std::function< VECTOR2D(int)> &aPointGetter, int aPointCount)
 Generic way of drawing a polyline stored in different containers. More...
 
void drawPolygon (GLdouble *aPoints, int aPointCount)
 Draws a filled polygon. More...
 
void drawTriangulatedPolyset (const SHAPE_POLY_SET &aPoly)
 Draws a set of polygons with a cached triangulation. 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 UTF8 &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...
 
std::unique_ptr< GL_BITMAP_CACHEbitmapCache
 Update handler for OpenGL settings. 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::unordered_map< unsigned int, std::shared_ptr<VERTEX_ITEM> > KIGFX::OPENGL_GAL::GROUPS_MAP
private

Definition at line 305 of file opengl_gal.h.

typedef GAL KIGFX::OPENGL_GAL::super
private

Super class definition.

Definition at line 291 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 163 of file opengl_gal.cpp.

References bitmapCache, BLUE, 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, onPaint(), KIGFX::GAL::options, KIGFX::GAL::screenSize, KIGFX::OPENGL_COMPOSITOR::SetAntialiasingMode(), KIGFX::GAL::SetAxesColor(), KIGFX::GAL::SetGridColor(), SetTarget(), shader, skipMouseEvent(), KIGFX::TARGET_NONCACHED, and tesselator.

165  :
166  GAL( aDisplayOptions ),
167  HIDPI_GL_CANVAS( aParent, wxID_ANY, (int*) glAttributes, wxDefaultPosition, wxDefaultSize,
168  wxEXPAND, aName ),
169  mouseListener( aMouseListener ), paintListener( aPaintListener ), currentManager( nullptr ),
170  cachedManager( nullptr ), nonCachedManager( nullptr ), overlayManager( nullptr ), mainBuffer( 0 ), overlayBuffer( 0 )
171 {
172 // IsDisplayAttr() handles WX_GL_{MAJOR,MINOR}_VERSION correctly only in 3.0.4
173 // starting with 3.1.0 one should use wxGLContext::IsOk() (done by GL_CONTEXT_MANAGER)
174 #if wxCHECK_VERSION( 3, 0, 3 ) and !wxCHECK_VERSION( 3, 1, 0 )
175  const int attr[] = { WX_GL_MAJOR_VERSION, 2, WX_GL_MINOR_VERSION, 1, 0 };
176 
177  if( !IsDisplaySupported( attr ) )
178  throw std::runtime_error( "OpenGL 2.1 or higher is required!" );
179 #endif /* wxCHECK_VERSION( 3, 0, 3 ) */
180 
181  if( glMainContext == NULL )
182  {
184 
185  if( !glMainContext )
186  throw std::runtime_error( "Could not create the main OpenGL context" );
187 
189  shader = new SHADER();
190  }
191  else
192  {
194 
195  if( !glPrivContext )
196  throw std::runtime_error( "Could not create a private OpenGL context" );
197  }
198 
199  ++instanceCounter;
200 
201  bitmapCache.reset( new GL_BITMAP_CACHE );
202 
205 
206  // Initialize the flags
207  isFramebufferInitialized = false;
208  isBitmapFontInitialized = false;
209  isInitialized = false;
210  isGrouping = false;
211  groupCounter = 0;
212 
213  // Connecting the event handlers
214  Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) );
215 
216  // Mouse events are skipped to the parent
217  Connect( wxEVT_MOTION, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
218  Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
219  Connect( wxEVT_LEFT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
220  Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
221  Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
222  Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
223  Connect( wxEVT_MIDDLE_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
224  Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
225  Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
226  Connect( wxEVT_RIGHT_DCLICK, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
227  Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
228 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
229  Connect( wxEVT_MAGNIFY, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
230 #endif
231 #if defined _WIN32 || defined _WIN64
232  Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( OPENGL_GAL::skipMouseEvent ) );
233 #endif
234 
235  SetSize( aParent->GetClientSize() );
236  screenSize = VECTOR2I( aParent->GetClientSize() );
237 
238  // Grid color settings are different in Cairo and OpenGL
239  SetGridColor( COLOR4D( 0.8, 0.8, 0.8, 0.1 ) );
240  SetAxesColor( COLOR4D( BLUE ) );
241 
242  // Tesselator initialization
243  tesselator = gluNewTess();
245 
246  if( tesselator == NULL )
247  throw std::runtime_error( "Could not create the tesselator" );
248 
249  gluTessProperty( tesselator, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE );
250 
252 }
Definition: colors.h:57
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
static SHADER * shader
There is only one shader used for different objects.
Definition: opengl_gal.h:320
static wxGLContext * glMainContext
Parent OpenGL context.
Definition: opengl_gal.h:296
unsigned int overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:316
bool isBitmapFontInitialized
Is the shader set to use bitmap fonts?
Definition: opengl_gal.h:325
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:311
GAL_DISPLAY_OPTIONS & options
std::unique_ptr< GL_BITMAP_CACHE > bitmapCache
Update handler for OpenGL settings.
Definition: opengl_gal.h:330
static void InitTesselatorCallbacks(GLUtesselator *aTesselator)
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
bool isGrouping
Was a group started?
Definition: opengl_gal.h:328
OPENGL_ANTIALIASING_MODE gl_antialiasing_mode
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:310
Auxiliary rendering target (noncached)
Definition: definitions.h:42
static int instanceCounter
GL GAL instance counter.
Definition: opengl_gal.h:298
void SetAntialiasingMode(OPENGL_ANTIALIASING_MODE aMode)
HIDPI_GL_CANVAS(wxWindow *parent, wxWindowID id=wxID_ANY, const int *attribList=NULL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxGLCanvasName, const wxPalette &palette=wxNullPalette)
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:314
unsigned int mainBuffer
Main rendering target.
Definition: opengl_gal.h:315
wxEvtHandler * mouseListener
Definition: opengl_gal.h:299
void SetAxesColor(const COLOR4D &aAxesColor)
Set the axes color.
static const int glAttributes[]
Definition: opengl_gal.cpp:59
void onPaint(wxPaintEvent &aEvent)
This is the OnPaint event handler.
bool isFramebufferInitialized
Are the framebuffers initialized?
Definition: opengl_gal.h:323
Class SHADER provides the access to the OpenGL shaders.
Definition: shader.h:74
GLUtesselator * tesselator
The tessellator.
Definition: opengl_gal.h:337
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:309
wxEvtHandler * paintListener
Definition: opengl_gal.h:300
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:326
unsigned int groupCounter
Counter used for generating keys for groups.
Definition: opengl_gal.h:307
VECTOR2I screenSize
Screen size in screen coordinates.
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:297
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 255 of file opengl_gal.cpp.

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

256 {
258 
259  --instanceCounter;
260  glFlush();
261  gluDeleteTess( tesselator );
262  ClearCache();
263 
264  delete compositor;
265 
266  if( isInitialized )
267  {
268  delete cachedManager;
269  delete nonCachedManager;
270  delete overlayManager;
271  }
272 
274 
275  // If it was the main context, then it will be deleted
276  // when the last OpenGL GAL instance is destroyed (a few lines below)
279 
280  // Are we destroying the last GAL instance?
281  if( instanceCounter == 0 )
282  {
284 
285  if( isBitmapFontLoaded )
286  {
287  glDeleteTextures( 1, &fontTexture );
288  isBitmapFontLoaded = false;
289  }
290 
291  delete shader;
292 
295  glMainContext = NULL;
296  }
297 }
static SHADER * shader
There is only one shader used for different objects.
Definition: opengl_gal.h:320
static wxGLContext * glMainContext
Parent OpenGL context.
Definition: opengl_gal.h:296
static GLuint fontTexture
Bitmap font texture handle (shared)
Definition: opengl_gal.h:302
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:311
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:310
static int instanceCounter
GL GAL instance counter.
Definition: opengl_gal.h:298
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:314
virtual void ClearCache() override
Delete all data created during caching of graphic items.
GLUtesselator * tesselator
The tessellator.
Definition: opengl_gal.h:337
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:309
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:326
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:297
void DestroyCtx(wxGLContext *aContext)
Function DestroyCtx destroys a managed OpenGL context.
static bool isBitmapFontLoaded
Is the bitmap font texture loaded?
Definition: opengl_gal.h:324

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 969 of file graphics_abstraction_layer.h.

References KIGFX::GAL::layerDepth.

970  {
971  layerDepth -= 0.05;
972  }
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 321 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.

Referenced by IsVisible().

322 {
323  if( !IsShownOnScreen() )
324  return;
325 
326 #ifdef __WXDEBUG__
327  PROF_COUNTER totalRealTime( "OPENGL_GAL::BeginDrawing()", true );
328 #endif /* __WXDEBUG__ */
329 
330  if( !isInitialized )
331  init();
332 
334 
335  // Set up the view port
336  glMatrixMode( GL_PROJECTION );
337  glLoadIdentity();
338 
339  // Create the screen transformation (Do the RH-LH conversion here)
340  glOrtho( 0, (GLint) screenSize.x, (GLsizei) screenSize.y, 0, -depthRange.x, -depthRange.y );
341 
343  {
344  try
345  {
346  // Prepare rendering target buffers
350  }
351  catch( std::runtime_error& )
352  {
354  throw; // DRAW_PANEL_GAL will handle it
355  }
356 
358  }
359 
360  compositor->Begin();
361 
362  // Disable 2D Textures
363  glDisable( GL_TEXTURE_2D );
364 
365  glShadeModel( GL_FLAT );
366 
367  // Enable the depth buffer
368  glEnable( GL_DEPTH_TEST );
369  glDepthFunc( GL_LESS );
370 
371  // Setup blending, required for transparent objects
372  glEnable( GL_BLEND );
373  glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
374 
375  glMatrixMode( GL_MODELVIEW );
376 
377  // Set up the world <-> screen transformation
379  GLdouble matrixData[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
380  matrixData[0] = worldScreenMatrix.m_data[0][0];
381  matrixData[1] = worldScreenMatrix.m_data[1][0];
382  matrixData[2] = worldScreenMatrix.m_data[2][0];
383  matrixData[4] = worldScreenMatrix.m_data[0][1];
384  matrixData[5] = worldScreenMatrix.m_data[1][1];
385  matrixData[6] = worldScreenMatrix.m_data[2][1];
386  matrixData[12] = worldScreenMatrix.m_data[0][2];
387  matrixData[13] = worldScreenMatrix.m_data[1][2];
388  matrixData[14] = worldScreenMatrix.m_data[2][2];
389  glLoadMatrixd( matrixData );
390 
391  // Set defaults
394 
395  // Remove all previously stored items
398 
402 
404  {
405  // Keep bitmap font texture always bound to the second texturing unit
406  const GLint FONT_TEXTURE_UNIT = 2;
407 
408  // Either load the font atlas to video memory, or simply bind it to a texture unit
409  if( !isBitmapFontLoaded )
410  {
411  glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT );
412  glGenTextures( 1, &fontTexture );
413  glBindTexture( GL_TEXTURE_2D, fontTexture );
414  glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, font_image.width, font_image.height,
415  0, GL_RGB, GL_UNSIGNED_BYTE, font_image.pixels );
416  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
417  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
418  checkGlError( "loading bitmap font" );
419 
420  glActiveTexture( GL_TEXTURE0 );
421 
422  isBitmapFontLoaded = true;
423  }
424  else
425  {
426  glActiveTexture( GL_TEXTURE0 + FONT_TEXTURE_UNIT );
427  glBindTexture( GL_TEXTURE_2D, fontTexture );
428  glActiveTexture( GL_TEXTURE0 );
429  }
430 
431  // Set shader parameter
432  GLint ufm_fontTexture = shader->AddParameter( "fontTexture" );
433  GLint ufm_fontTextureWidth = shader->AddParameter( "fontTextureWidth" );
434  shader->Use();
435  shader->SetParameter( ufm_fontTexture, (int) FONT_TEXTURE_UNIT );
436  shader->SetParameter( ufm_fontTextureWidth, (int) font_image.width );
437  shader->Deactivate();
438  checkGlError( "setting bitmap font sampler as shader parameter" );
439 
441  }
442 
443  // Something betreen BeginDrawing and EndDrawing seems to depend on
444  // this texture unit being active, but it does not assure it itself.
445  glActiveTexture( GL_TEXTURE0 );
446 
447  // Unbind buffers - set compositor for direct drawing
449 
450 #ifdef __WXDEBUG__
451  totalRealTime.Stop();
452  wxLogTrace( "GAL_PROFILE",
453  wxT( "OPENGL_GAL::BeginDrawing(): %.1f ms" ), totalRealTime.msecs() );
454 #endif /* __WXDEBUG__ */
455 }
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:320
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:316
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:325
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:302
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:311
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:310
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:314
unsigned int mainBuffer
Main rendering target.
Definition: opengl_gal.h:315
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:323
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:309
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:326
VECTOR2I screenSize
Screen size in screen coordinates.
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:297
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:324
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 1417 of file opengl_gal.cpp.

References getNewGroupNumber(), groups, and isGrouping.

Referenced by IsVisible().

1418 {
1419  isGrouping = true;
1420 
1421  std::shared_ptr<VERTEX_ITEM> newItem = std::make_shared<VERTEX_ITEM>( *cachedManager );
1422  int groupNumber = getNewGroupNumber();
1423  groups.insert( std::make_pair( groupNumber, newItem ) );
1424 
1425  return groupNumber;
1426 }
bool isGrouping
Was a group started?
Definition: opengl_gal.h:328
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:306
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 492 of file opengl_gal.cpp.

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

Referenced by IsVisible().

493 {
494  if( !IsShownOnScreen() )
495  return;
496 
497  if( !isInitialized )
498  init();
499 
501  cachedManager->Map();
502 }
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:309
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:326
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:297
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 1049 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, i, KIGFX::GAL::IsTextMirrored(), KIGFX::GAL::layerDepth, ProcessOverbars(), 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.

Referenced by IsVisible().

1051 {
1052  wxASSERT_MSG( !IsTextMirrored(), "No support for mirrored text using bitmap fonts." );
1053 
1054  auto processedText = ProcessOverbars( aText );
1055  const auto& text = processedText.first;
1056  const auto& overbars = processedText.second;
1057 
1058  // Compute text size, so it can be properly justified
1059  VECTOR2D textSize;
1060  float commonOffset;
1061  std::tie( textSize, commonOffset ) = computeBitmapTextSize( text );
1062 
1063  const double SCALE = 1.4 * GetGlyphSize().y / textSize.y;
1064  bool overbar = false;
1065 
1066  int overbarLength = 0;
1067  double overbarHeight = textSize.y;
1068 
1069  Save();
1070 
1072  currentManager->Translate( aPosition.x, aPosition.y, layerDepth );
1073  currentManager->Rotate( aRotationAngle, 0.0f, 0.0f, -1.0f );
1074 
1075  double sx = SCALE * ( globalFlipX ? -1.0 : 1.0 );
1076  double sy = SCALE * ( globalFlipY ? -1.0 : 1.0 );
1077 
1078  currentManager->Scale( sx, sy, 0 );
1079  currentManager->Translate( 0, -commonOffset, 0 );
1080 
1081  switch( GetHorizontalJustify() )
1082  {
1084  Translate( VECTOR2D( -textSize.x / 2.0, 0 ) );
1085  break;
1086 
1088  //if( !IsTextMirrored() )
1089  Translate( VECTOR2D( -textSize.x, 0 ) );
1090  break;
1091 
1092  case GR_TEXT_HJUSTIFY_LEFT:
1093  //if( IsTextMirrored() )
1094  //Translate( VECTOR2D( -textSize.x, 0 ) );
1095  break;
1096  }
1097 
1098  switch( GetVerticalJustify() )
1099  {
1100  case GR_TEXT_VJUSTIFY_TOP:
1101  Translate( VECTOR2D( 0, -textSize.y ) );
1102  overbarHeight = -textSize.y / 2.0;
1103  break;
1104 
1106  Translate( VECTOR2D( 0, -textSize.y / 2.0 ) );
1107  overbarHeight = 0;
1108  break;
1109 
1111  break;
1112  }
1113 
1114  int i = 0;
1115 
1116  for( UTF8::uni_iter chIt = text.ubegin(), end = text.uend(); chIt < end; ++chIt )
1117  {
1118  unsigned int c = *chIt;
1119  wxASSERT_MSG( c != '\n' && c != '\r', wxT( "No support for multiline bitmap text yet" ) );
1120 
1121  // Handle overbar
1122  if( overbars[i] && !overbar )
1123  {
1124  overbar = true; // beginning of an overbar
1125  }
1126  else if( overbar && !overbars[i] )
1127  {
1128  overbar = false; // end of an overbar
1129  drawBitmapOverbar( overbarLength, overbarHeight );
1130  overbarLength = 0;
1131  }
1132 
1133  if( overbar )
1134  overbarLength += drawBitmapChar( c );
1135  else
1136  drawBitmapChar( c );
1137 
1138  ++i;
1139  }
1140 
1141  // Handle the case when overbar is active till the end of the drawn text
1142  currentManager->Translate( 0, commonOffset, 0 );
1143 
1144  if( overbar && overbarLength > 0 )
1145  drawBitmapOverbar( overbarLength, overbarHeight );
1146 
1147  Restore();
1148 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
EDA_TEXT_HJUSTIFY_T GetHorizontalJustify() const
Returns current text horizontal justification setting.
EDA_TEXT_VJUSTIFY_T GetVerticalJustify() const
Returns current text vertical justification setting.
std::pair< UTF8, std::vector< bool > > ProcessOverbars(const UTF8 &aText)
Processes a text to extract the raw text and overbar flags.
Definition: text_utils.cpp:27
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:292
bool globalFlipX
Flag for X axis flipping.
double b
Blue component.
Definition: color4d.h:293
virtual void Save() override
Save the context.
double a
Alpha component.
Definition: color4d.h:294
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
std::pair< VECTOR2D, float > computeBitmapTextSize(const UTF8 &aText) const
Computes a size of text drawn using bitmap font with current text setting applied.
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...
class uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded ...
Definition: utf8.h:207
bool globalFlipY
Flag for Y axis flipping.
int drawBitmapChar(unsigned long aChar)
Draws a single character using bitmap font.
size_t i
Definition: json11.cpp:597
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...
double r
Red component.
Definition: color4d.h:291
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 1896 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().

1897 {
1898  if( !IsCursorEnabled() )
1899  return;
1900 
1902 
1903  const int cursorSize = fullscreenCursor ? 8000 : 80;
1904 
1905  VECTOR2D cursorBegin = cursorPosition - cursorSize / ( 2 * worldScale );
1906  VECTOR2D cursorEnd = cursorPosition + cursorSize / ( 2 * worldScale );
1907  VECTOR2D cursorCenter = ( cursorBegin + cursorEnd ) / 2;
1908 
1909  const COLOR4D cColor = getCursorColor();
1910  const COLOR4D color( cColor.r * cColor.a, cColor.g * cColor.a,
1911  cColor.b * cColor.a, 1.0 );
1912 
1913  glActiveTexture( GL_TEXTURE0 );
1914  glDisable( GL_TEXTURE_2D );
1915  glLineWidth( 1.0 );
1916  glColor4d( color.r, color.g, color.b, color.a );
1917 
1918  glBegin( GL_LINES );
1919  glVertex2d( cursorCenter.x, cursorBegin.y );
1920  glVertex2d( cursorCenter.x, cursorEnd.y );
1921 
1922  glVertex2d( cursorBegin.x, cursorCenter.y );
1923  glVertex2d( cursorEnd.x, cursorCenter.y );
1924  glEnd();
1925 }
bool IsCursorEnabled() const
Returns information about cursor visibility.
VECTOR2D cursorPosition
Current cursor position (world coordinates)
int color
Definition: DXF_plotter.cpp:62
double g
Green component.
Definition: color4d.h:292
static const unsigned int DIRECT_RENDERING
double b
Blue component.
Definition: color4d.h:293
double a
Alpha component.
Definition: color4d.h:294
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:314
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:291
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 460 of file opengl_gal.h.

References init(), and min.

Referenced by DrawArc(), and DrawArcSegment().

461  {
462  // Bigger arcs need smaller alpha increment to make them look smooth
463  return std::min( 1e6 / aRadius, 2.0 * M_PI / CIRCLE_POINTS );
464  }
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 1442 of file opengl_gal.cpp.

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

Referenced by IsVisible().

1443 {
1444  cachedManager->ChangeItemColor( *groups[aGroupNumber], aNewColor );
1445 }
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:306
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:309
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 1448 of file opengl_gal.cpp.

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

Referenced by IsVisible().

1449 {
1450  cachedManager->ChangeItemDepth( *groups[aGroupNumber], aDepth );
1451 }
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:306
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:309
void OPENGL_GAL::ClearCache ( )
overridevirtual

Delete all data created during caching of graphic items.

Reimplemented from KIGFX::GAL.

Definition at line 1461 of file opengl_gal.cpp.

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

Referenced by IsVisible(), and ~OPENGL_GAL().

1462 {
1463  bitmapCache.reset( new GL_BITMAP_CACHE );
1464 
1465  groups.clear();
1466 
1467  if( isInitialized )
1468  cachedManager->Clear();
1469 }
void Clear() const
Function Clear() removes all the stored vertices from the container.
std::unique_ptr< GL_BITMAP_CACHE > bitmapCache
Update handler for OpenGL settings.
Definition: opengl_gal.h:330
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:306
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:309
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:326
void OPENGL_GAL::ClearScreen ( )
overridevirtual

Clear the screen.

Parameters
aColoris the color used for clearing.

Reimplemented from KIGFX::GAL.

Definition at line 1359 of file opengl_gal.cpp.

References compositor, KIGFX::OPENGL_COMPOSITOR::DIRECT_RENDERING, and KIGFX::OPENGL_COMPOSITOR::SetBuffer().

Referenced by IsVisible().

1360 {
1361  // Clear screen
1363  // NOTE: Black used here instead of m_clearColor; it will be composited later
1364  glClearColor( 0, 0, 0, 1 );
1365  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
1366 }
static const unsigned int DIRECT_RENDERING
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:314
virtual void SetBuffer(unsigned int aBufferHandle) override
Function SetBuffer() sets the selected buffer as the rendering target.
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 1512 of file opengl_gal.cpp.

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

Referenced by IsVisible().

1513 {
1514  // Save the current state
1515  unsigned int oldTarget = compositor->GetBuffer();
1516 
1517  switch( aTarget )
1518  {
1519  // Cached and noncached items are rendered to the same buffer
1520  default:
1521  case TARGET_CACHED:
1522  case TARGET_NONCACHED:
1524  break;
1525 
1526  case TARGET_OVERLAY:
1528  break;
1529  }
1530 
1531 
1532  if( aTarget != TARGET_OVERLAY )
1534  else
1536 
1537  // Restore the previous state
1538  compositor->SetBuffer( oldTarget );
1539 }
unsigned int overlayBuffer
Auxiliary rendering target (for menus etc.)
Definition: opengl_gal.h:316
static const COLOR4D BLACK
Definition: color4d.h:301
Auxiliary rendering target (noncached)
Definition: definitions.h:42
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:314
unsigned int mainBuffer
Main rendering target.
Definition: opengl_gal.h:315
virtual void ClearBuffer(const COLOR4D &aColor) override
Function ClearBuffer() clears the selected buffer (set by the SetBuffer() function).
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 UTF8 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 1848 of file opengl_gal.cpp.

References KIGFX::BUILTIN_FONT::FONT_GLYPH_TYPE::advance, KIGFX::BUILTIN_FONT::font_information, Format(), KIGFX::BUILTIN_FONT::LookupGlyph(), max, KIGFX::BUILTIN_FONT::FONT_INFO_TYPE::max_y, UTF8::ubegin(), UTF8::uend(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BitmapText().

1849 {
1850  VECTOR2D textSize( 0, 0 );
1851  float commonOffset = std::numeric_limits<float>::max();
1852  static const auto defaultGlyph = LookupGlyph( '(' ); // for strange chars
1853 
1854  for( UTF8::uni_iter chIt = aText.ubegin(), end = aText.uend(); chIt < end; ++chIt )
1855  {
1856  unsigned int c = *chIt;
1857 
1858  const FONT_GLYPH_TYPE* glyph = LookupGlyph( c );
1859  // Debug: show not coded char in the atlas
1860  wxASSERT_MSG( glyph, wxString::Format( "missing char in font: code 0x%x <%c>", c, c ) );
1861 
1862  if( !glyph || // Not coded in font
1863  c == '-' || c == '_' ) // Strange size of these 2 chars
1864  {
1865  glyph = defaultGlyph;
1866  }
1867 
1868  if( glyph )
1869  {
1870  textSize.x += glyph->advance;
1871  }
1872  }
1873 
1874  textSize.y = std::max<float>( textSize.y, font_information.max_y - defaultGlyph->miny );
1875  commonOffset = std::min<float>( font_information.max_y - defaultGlyph->maxy, commonOffset );
1876  textSize.y -= commonOffset;
1877 
1878  return std::make_pair( textSize, commonOffset );
1879 }
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
uni_iter ubegin() const
Function ubegin returns a uni_iter initialized to the start of "this" UTF8 byte sequence.
Definition: utf8.h:285
FONT_INFO_TYPE font_information
Definition: gl_resources.cpp:3
class uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded ...
Definition: utf8.h:207
uni_iter uend() const
Function uend returns a uni_iter initialized to the end of "this" UTF8 byte sequence.
Definition: utf8.h:294
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#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 KIGFX::GAL::computeWorldScale(), 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 1050 of file graphics_abstraction_layer.h.

References KIGFX::GAL::computeMinGridSpacing(), and KIGFX::GAL::zoomFactor.

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

1051  {
1053  }
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::GAL::ClearCache(), 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:586
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 1454 of file opengl_gal.cpp.

References groups.

Referenced by IsVisible().

1455 {
1456  // Frees memory in the container as well
1457  groups.erase( aGroupNumber );
1458 }
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:306
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 642 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.

Referenced by IsVisible().

644 {
645  if( aRadius <= 0 )
646  return;
647 
648  // Swap the angles, if start angle is greater than end angle
649  SWAP( aStartAngle, >, aEndAngle );
650 
651  const double alphaIncrement = calcAngleStep( aRadius );
652 
653  Save();
654  currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
655 
656  if( isStrokeEnabled )
657  {
659 
660  VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
661  double alpha;
662 
663  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
664  {
665  VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
666  DrawLine( p, p_next );
667 
668  p = p_next;
669  }
670 
671  // Draw the last missing part
672  if( alpha != aEndAngle )
673  {
674  VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
675  DrawLine( p, p_last );
676  }
677  }
678 
679  if( isFillEnabled )
680  {
681  double alpha;
684 
685  // Triangle fan
686  for( alpha = aStartAngle; ( alpha + alphaIncrement ) < aEndAngle; )
687  {
688  currentManager->Reserve( 3 );
689  currentManager->Vertex( 0.0, 0.0, 0.0 );
690  currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius, 0.0 );
691  alpha += alphaIncrement;
692  currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius, 0.0 );
693  }
694 
695  // The last missing triangle
696  const VECTOR2D endPoint( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
697 
698  currentManager->Reserve( 3 );
699  currentManager->Vertex( 0.0, 0.0, 0.0 );
700  currentManager->Vertex( cos( alpha ) * aRadius, sin( alpha ) * aRadius, 0.0 );
701  currentManager->Vertex( endPoint.x, endPoint.y, 0.0 );
702  }
703 
704  Restore();
705 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
double calcAngleStep(double aRadius) const
Compute the angle step when drawing arcs/circles approximated with lines.
Definition: opengl_gal.h:460
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:292
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:293
virtual void Save() override
Save the context.
double a
Alpha component.
Definition: color4d.h:294
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:515
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:291
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.
aWidthis the thickness of the arc (pen size).

Reimplemented from KIGFX::GAL.

Definition at line 708 of file opengl_gal.cpp.

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, calcAngleStep(), KIGFX::VERTEX_MANAGER::Color(), currentManager, DrawCircle(), 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.

Referenced by IsVisible().

710 {
711  if( aRadius <= 0 )
712  {
713  // Arcs of zero radius are a circle of aWidth diameter
714  if( aWidth > 0 )
715  DrawCircle( aCenterPoint, aWidth / 2.0 );
716 
717  return;
718  }
719 
720  // Swap the angles, if start angle is greater than end angle
721  SWAP( aStartAngle, >, aEndAngle );
722 
723  const double alphaIncrement = calcAngleStep( aRadius );
724 
725  Save();
726  currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
727 
728  if( isStrokeEnabled )
729  {
731 
732  double width = aWidth / 2.0;
733  VECTOR2D startPoint( cos( aStartAngle ) * aRadius,
734  sin( aStartAngle ) * aRadius );
735  VECTOR2D endPoint( cos( aEndAngle ) * aRadius,
736  sin( aEndAngle ) * aRadius );
737 
738  drawStrokedSemiCircle( startPoint, width, aStartAngle + M_PI );
739  drawStrokedSemiCircle( endPoint, width, aEndAngle );
740 
741  VECTOR2D pOuter( cos( aStartAngle ) * ( aRadius + width ),
742  sin( aStartAngle ) * ( aRadius + width ) );
743 
744  VECTOR2D pInner( cos( aStartAngle ) * ( aRadius - width ),
745  sin( aStartAngle ) * ( aRadius - width ) );
746 
747  double alpha;
748 
749  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
750  {
751  VECTOR2D pNextOuter( cos( alpha ) * ( aRadius + width ),
752  sin( alpha ) * ( aRadius + width ) );
753  VECTOR2D pNextInner( cos( alpha ) * ( aRadius - width ),
754  sin( alpha ) * ( aRadius - width ) );
755 
756  DrawLine( pOuter, pNextOuter );
757  DrawLine( pInner, pNextInner );
758 
759  pOuter = pNextOuter;
760  pInner = pNextInner;
761  }
762 
763  // Draw the last missing part
764  if( alpha != aEndAngle )
765  {
766  VECTOR2D pLastOuter( cos( aEndAngle ) * ( aRadius + width ),
767  sin( aEndAngle ) * ( aRadius + width ) );
768  VECTOR2D pLastInner( cos( aEndAngle ) * ( aRadius - width ),
769  sin( aEndAngle ) * ( aRadius - width ) );
770 
771  DrawLine( pOuter, pLastOuter );
772  DrawLine( pInner, pLastInner );
773  }
774  }
775 
776  if( isFillEnabled )
777  {
779  SetLineWidth( aWidth );
780 
781  VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
782  double alpha;
783 
784  for( alpha = aStartAngle + alphaIncrement; alpha <= aEndAngle; alpha += alphaIncrement )
785  {
786  VECTOR2D p_next( cos( alpha ) * aRadius, sin( alpha ) * aRadius );
787  DrawLine( p, p_next );
788 
789  p = p_next;
790  }
791 
792  // Draw the last missing part
793  if( alpha != aEndAngle )
794  {
795  VECTOR2D p_last( cos( aEndAngle ) * aRadius, sin( aEndAngle ) * aRadius );
796  DrawLine( p, p_last );
797  }
798  }
799 
800  Restore();
801 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
double calcAngleStep(double aRadius) const
Compute the angle step when drawing arcs/circles approximated with lines.
Definition: opengl_gal.h:460
virtual void Restore() override
Restore the context.
double g
Green component.
Definition: color4d.h:292
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:293
virtual void Save() override
Save the context.
double a
Alpha component.
Definition: color4d.h:294
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:515
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:291
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius) override
Draw a circle using world coordinates.
Definition: opengl_gal.cpp:582
void OPENGL_GAL::DrawBitmap ( const BITMAP_BASE aBitmap)
overridevirtual

Draw a bitmap image.

Reimplemented from KIGFX::GAL.

Definition at line 1000 of file opengl_gal.cpp.

References bitmapCache, currentManager, BITMAP_BASE::GetPPI(), BITMAP_BASE::GetSizePixels(), GetTarget(), KIGFX::VERTEX_MANAGER::GetTransformation(), KIGFX::GAL::layerDepth, SetTarget(), KIGFX::TARGET_NONCACHED, and KIGFX::GAL::worldUnitLength.

Referenced by IsVisible().

1001 {
1002  int ppi = aBitmap.GetPPI();
1003  double worldIU_per_mm = 1.0 / ( worldUnitLength / 2.54 )/ 1000;
1004  double pix_size_iu = worldIU_per_mm * ( 25.4 / ppi );
1005 
1006  double w = aBitmap.GetSizePixels().x * pix_size_iu;
1007  double h = aBitmap.GetSizePixels().y * pix_size_iu;
1008 
1009  auto xform = currentManager->GetTransformation();
1010 
1011  glm::vec4 v0 = xform * glm::vec4( -w/2, -h/2, 0.0, 0.0 );
1012  glm::vec4 v1 = xform * glm::vec4( w/2, h/2, 0.0, 0.0 );
1013  glm::vec4 trans = xform[3];
1014 
1015  auto id = bitmapCache->RequestBitmap( &aBitmap );
1016 
1017  auto oldTarget = GetTarget();
1018 
1019  glPushMatrix();
1020  glTranslated( trans.x, trans.y, trans.z );
1021 
1023  glEnable(GL_TEXTURE_2D);
1024  glActiveTexture( GL_TEXTURE0 );
1025  glBindTexture( GL_TEXTURE_2D, id );
1026 
1027  glBegin( GL_QUADS );
1028  glColor4f(1.0, 1.0, 1.0, 1.0);
1029  glTexCoord2f(0.0, 0.0);
1030  glVertex3f( v0.x, v0.y, layerDepth );
1031  glColor4f(1.0, 1.0, 1.0, 1.0);
1032  glTexCoord2f(1.0, 0.0);
1033  glVertex3f( v1.x, v0.y, layerDepth );
1034  glColor4f(1.0, 1.0, 1.0, 1.0);
1035  glTexCoord2f(1.0, 1.0);
1036  glVertex3f( v1.x, v1.y, layerDepth );
1037  glColor4f(1.0, 1.0, 1.0, 1.0);
1038  glTexCoord2f(0.0, 1.0);
1039  glVertex3f( v0.x, v1.y, layerDepth );
1040  glEnd();
1041 
1042  SetTarget( oldTarget );
1043  glBindTexture( GL_TEXTURE_2D, 0 );
1044 
1045  glPopMatrix();
1046 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
double layerDepth
The actual layer depth.
std::unique_ptr< GL_BITMAP_CACHE > bitmapCache
Update handler for OpenGL settings.
Definition: opengl_gal.h:330
Auxiliary rendering target (noncached)
Definition: definitions.h:42
virtual RENDER_TARGET GetTarget() const override
Gets the currently used target for rendering.
double worldUnitLength
The unit length of the world coordinates [inch].
wxSize GetSizePixels() const
Function GetSizePixels.
Definition: bitmap_base.h:131
virtual void SetTarget(RENDER_TARGET aTarget) override
Sets the target for rendering.
int GetPPI() const
Definition: bitmap_base.h:143
const glm::mat4 & GetTransformation() const
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
aCharis the character to be drawn.
Returns
Width of the drawn glyph.

Definition at line 1751 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, H, 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().

1752 {
1753  const float TEX_X = font_image.width;
1754  const float TEX_Y = font_image.height;
1755 
1756  // handle space
1757  if( aChar == ' ' )
1758  {
1759  const FONT_GLYPH_TYPE* g = LookupGlyph( 'x' );
1760  wxASSERT( g );
1761  Translate( VECTOR2D( g->advance, 0 ) );
1762  return g->advance;
1763  }
1764 
1765  const FONT_GLYPH_TYPE* glyph = LookupGlyph( aChar );
1766  wxASSERT( glyph );
1767 
1768  if( !glyph )
1769  return 0;
1770 
1771  const float X = glyph->atlas_x + font_information.smooth_pixels;
1772  const float Y = glyph->atlas_y + font_information.smooth_pixels;
1773  const float XOFF = glyph->minx;
1774 
1775  // adjust for height rounding
1776  const float round_adjust = ( glyph->maxy - glyph->miny )
1777  - float( glyph->atlas_h - font_information.smooth_pixels * 2 );
1778  const float top_adjust = font_information.max_y - glyph->maxy;
1779  const float YOFF = round_adjust + top_adjust;
1780  const float W = glyph->atlas_w - font_information.smooth_pixels *2;
1781  const float H = glyph->atlas_h - font_information.smooth_pixels *2;
1782  const float B = 0;
1783 
1784  currentManager->Reserve( 6 );
1785  Translate( VECTOR2D( XOFF, YOFF ) );
1786  /* Glyph:
1787  * v0 v1
1788  * +--+
1789  * | /|
1790  * |/ |
1791  * +--+
1792  * v2 v3
1793  */
1794  currentManager->Shader( SHADER_FONT, X / TEX_X, ( Y + H ) / TEX_Y );
1795  currentManager->Vertex( -B, -B, 0 ); // v0
1796 
1797  currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y );
1798  currentManager->Vertex( W + B, -B, 0 ); // v1
1799 
1800  currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y );
1801  currentManager->Vertex( -B, H + B, 0 ); // v2
1802 
1803 
1804  currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, ( Y + H ) / TEX_Y );
1805  currentManager->Vertex( W + B, -B, 0 ); // v1
1806 
1807  currentManager->Shader( SHADER_FONT, X / TEX_X, Y / TEX_Y );
1808  currentManager->Vertex( -B, H + B, 0 ); // v2
1809 
1810  currentManager->Shader( SHADER_FONT, ( X + W ) / TEX_X, Y / TEX_Y );
1811  currentManager->Vertex( W + B, H + B, 0 ); // v3
1812 
1813  Translate( VECTOR2D( -XOFF + glyph->advance, -YOFF ) );
1814 
1815  return glyph->advance;
1816 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
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:586
FONT_IMAGE_TYPE font_image
Definition: gl_resources.cpp:4
FONT_INFO_TYPE font_information
Definition: gl_resources.cpp:3
#define H(x, y, z)
Definition: md5_hash.cpp:17
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 1819 of file opengl_gal.cpp.

References KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, KIGFX::COLOR4D::g, H, 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().

1820 {
1821  // To draw an overbar, simply draw an overbar
1822  const FONT_GLYPH_TYPE* glyph = LookupGlyph( '_' );
1823  wxCHECK( glyph, /* void */ );
1824 
1825  const float H = glyph->maxy - glyph->miny;
1826 
1827  Save();
1828 
1829  Translate( VECTOR2D( -aLength, -aHeight-1.5*H ) );
1830 
1831  currentManager->Reserve( 6 );
1833 
1834  currentManager->Shader( 0 );
1835 
1836  currentManager->Vertex( 0, 0, 0 ); // v0
1837  currentManager->Vertex( aLength, 0, 0 ); // v1
1838  currentManager->Vertex( 0, H, 0 ); // v2
1839 
1840  currentManager->Vertex( aLength, 0, 0 ); // v1
1841  currentManager->Vertex( 0, H, 0 ); // v2
1842  currentManager->Vertex( aLength, H, 0 ); // v3
1843 
1844  Restore();
1845 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
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:292
const FONT_GLYPH_TYPE * LookupGlyph(unsigned int aCodepoint)
double b
Blue component.
Definition: color4d.h:293
virtual void Save() override
Save the context.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
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...
#define H(x, y, z)
Definition: md5_hash.cpp:17
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:291
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 582 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.

Referenced by DrawArcSegment(), and IsVisible().

583 {
584  if( isFillEnabled )
585  {
586  currentManager->Reserve( 3 );
588 
589  /* Draw a triangle that contains the circle, then shade it leaving only the circle.
590  * Parameters given to Shader() are indices of the triangle's vertices
591  * (if you want to understand more, check the vertex shader source [shader.vert]).
592  * Shader uses this coordinates to determine if fragments are inside the circle or not.
593  * v2
594  * /\
595  * //\\
596  * v0 /_\/_\ v1
597  */
599  currentManager->Vertex( aCenterPoint.x - aRadius * sqrt( 3.0f ), // v0
600  aCenterPoint.y - aRadius, layerDepth );
601 
603  currentManager->Vertex( aCenterPoint.x + aRadius * sqrt( 3.0f), // v1
604  aCenterPoint.y - aRadius, layerDepth );
605 
607  currentManager->Vertex( aCenterPoint.x, aCenterPoint.y + aRadius * 2.0f, // v2
608  layerDepth );
609  }
610 
611  if( isStrokeEnabled )
612  {
613  currentManager->Reserve( 3 );
615 
616  /* Draw a triangle that contains the circle, then shade it leaving only the circle.
617  * Parameters given to Shader() are indices of the triangle's vertices
618  * (if you want to understand more, check the vertex shader source [shader.vert]).
619  * and the line width. Shader uses this coordinates to determine if fragments are
620  * inside the circle or not.
621  * v2
622  * /\
623  * //\\
624  * v0 /_\/_\ v1
625  */
626  double outerRadius = aRadius + ( lineWidth / 2 );
628  currentManager->Vertex( aCenterPoint.x - outerRadius * sqrt( 3.0f ), // v0
629  aCenterPoint.y - outerRadius, layerDepth );
630 
632  currentManager->Vertex( aCenterPoint.x + outerRadius * sqrt( 3.0f ), // v1
633  aCenterPoint.y - outerRadius, layerDepth );
634 
636  currentManager->Vertex( aCenterPoint.x, aCenterPoint.y + outerRadius * 2.0f, // v2
637  layerDepth );
638  }
639 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
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:292
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:293
double lineWidth
The line width.
double a
Alpha component.
Definition: color4d.h:294
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:291
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 1542 of file opengl_gal.cpp.

References KIGFX::GAL::cursorPosition.

Referenced by SetNegativeDrawMode().

1543 {
1544  // Now we should only store the position of the mouse cursor
1545  // The real drawing routines are in blitCursor()
1546  //VECTOR2D screenCursor = worldScreenMatrix * aCursorPosition;
1547  //cursorPosition = screenWorldMatrix * VECTOR2D( screenCursor.x, screenCursor.y );
1548  cursorPosition = aCursorPosition;
1549 }
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 968 of file opengl_gal.cpp.

References CURVE_POINTS, DrawPolyline(), and i.

Referenced by IsVisible().

970 {
971  // FIXME The drawing quality needs to be improved
972  // FIXME Perhaps choose a quad/triangle strip instead?
973  // FIXME Brute force method, use a better (recursive?) algorithm
974 
975  std::deque<VECTOR2D> pointList;
976 
977  double t = 0.0;
978  double dt = 1.0 / (double) CURVE_POINTS;
979 
980  for( int i = 0; i <= CURVE_POINTS; i++ )
981  {
982  double omt = 1.0 - t;
983  double omt2 = omt * omt;
984  double omt3 = omt * omt2;
985  double t2 = t * t;
986  double t3 = t * t2;
987 
988  VECTOR2D vertex = omt3 * aStartPoint + 3.0 * t * omt2 * aControlPointA
989  + 3.0 * t2 * omt * aControlPointB + t3 * aEndPoint;
990 
991  pointList.push_back( vertex );
992 
993  t += dt;
994  }
995 
996  DrawPolyline( pointList );
997 }
static const int CURVE_POINTS
The number of points for curve approximation.
Definition: opengl_gal.h:294
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
Definition: opengl_gal.cpp:842
size_t i
Definition: json11.cpp:597
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 1620 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().

1622 {
1623  Save();
1624 
1625  currentManager->Reserve( 3 );
1626  currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
1627  currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1628 
1629  /* Draw a triangle that contains the semicircle, then shade it to leave only
1630  * the semicircle. Parameters given to Shader() are indices of the triangle's vertices
1631  * (if you want to understand more, check the vertex shader source [shader.vert]).
1632  * Shader uses these coordinates to determine if fragments are inside the semicircle or not.
1633  * v2
1634  * /\
1635  * /__\
1636  * v0 //__\\ v1
1637  */
1639  currentManager->Vertex( -aRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v0
1640 
1642  currentManager->Vertex( aRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v1
1643 
1645  currentManager->Vertex( 0.0f, aRadius * 2.0f, layerDepth ); // v2
1646 
1647  Restore();
1648 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
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 1151 of file opengl_gal.cpp.

References KIGFX::COLOR4D::a, 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, i, 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.

Referenced by IsVisible().

1152 {
1155 
1156  // sub-pixel lines all render the same
1157  double minorLineWidth = std::max( 1.0, gridLineWidth );
1158  double majorLineWidth = minorLineWidth * 2.0;
1159 
1160  // Draw the axis and grid
1161  // For the drawing the start points, end points and increments have
1162  // to be calculated in world coordinates
1163  VECTOR2D worldStartPoint = screenWorldMatrix * VECTOR2D( 0.0, 0.0 );
1164  VECTOR2D worldEndPoint = screenWorldMatrix * VECTOR2D( screenSize );
1165 
1166  // Draw axes if desired
1167  if( axesEnabled )
1168  {
1169  glLineWidth( minorLineWidth );
1170  glColor4d( axesColor.r, axesColor.g, axesColor.b, axesColor.a );
1171 
1172  glBegin( GL_LINES );
1173  glVertex2d( worldStartPoint.x, 0 );
1174  glVertex2d( worldEndPoint.x, 0 );
1175  glEnd();
1176 
1177  glBegin( GL_LINES );
1178  glVertex2d( 0, worldStartPoint.y );
1179  glVertex2d( 0, worldEndPoint.y );
1180  glEnd();
1181  }
1182 
1183  if( !gridVisibility )
1184  return;
1185 
1186  int gridScreenSizeDense = KiROUND( gridSize.x * worldScale );
1187  int gridScreenSizeCoarse = KiROUND( gridSize.x * static_cast<double>( gridTick ) * worldScale );
1188 
1189  const double gridThreshold = computeMinGridSpacing();
1190 
1191  // Check if the grid would not be too dense
1192  if( std::max( gridScreenSizeDense, gridScreenSizeCoarse ) < gridThreshold )
1193  return;
1194 
1195  // Compute grid staring and ending indexes to draw grid points on the
1196  // visible screen area
1197  // Note: later any point coordinate will be offsetted by gridOrigin
1198  int gridStartX = KiROUND( ( worldStartPoint.x - gridOrigin.x ) / gridSize.x );
1199  int gridEndX = KiROUND( ( worldEndPoint.x - gridOrigin.x ) / gridSize.x );
1200  int gridStartY = KiROUND( ( worldStartPoint.y - gridOrigin.y ) / gridSize.y );
1201  int gridEndY = KiROUND( ( worldEndPoint.y - gridOrigin.y ) / gridSize.y );
1202 
1203  // Ensure start coordinate > end coordinate
1204  if( gridStartX > gridEndX )
1205  std::swap( gridStartX, gridEndX );
1206 
1207  if( gridStartY > gridEndY )
1208  std::swap( gridStartY, gridEndY );
1209 
1210  // Ensure the grid fills the screen
1211  --gridStartX; ++gridEndX;
1212  --gridStartY; ++gridEndY;
1213 
1214  glDisable( GL_DEPTH_TEST );
1215  glDisable( GL_TEXTURE_2D );
1216 
1217  if( gridStyle == GRID_STYLE::DOTS )
1218  {
1219  glEnable( GL_STENCIL_TEST );
1220  glStencilFunc( GL_ALWAYS, 1, 1 );
1221  glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
1222  glColor4d( 0.0, 0.0, 0.0, 0.0 );
1223  }
1224  else
1225  {
1226  glColor4d( gridColor.r, gridColor.g, gridColor.b, gridColor.a );
1227  }
1228 
1230  {
1231  glLineWidth( minorLineWidth );
1232 
1233  // calculate a line len = 2 minorLineWidth, in internal unit value
1234  // (in fact the size of cross is lineLen*2)
1235  int lineLen = KiROUND( minorLineWidth / worldScale * 2 );
1236 
1237  // Vertical positions
1238  for( int j = gridStartY; j <= gridEndY; j++ )
1239  {
1240  if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
1241  || gridScreenSizeDense > gridThreshold )
1242  {
1243  int posY = j * gridSize.y + gridOrigin.y;
1244 
1245  // Horizontal positions
1246  for( int i = gridStartX; i <= gridEndX; i++ )
1247  {
1248  if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
1249  || gridScreenSizeDense > gridThreshold )
1250  {
1251  int posX = i * gridSize.x + gridOrigin.x;
1252 
1253  glBegin( GL_LINES );
1254  glVertex2d( posX -lineLen, posY );
1255  glVertex2d( posX + lineLen, posY );
1256  glVertex2d( posX, posY - lineLen );
1257  glVertex2d( posX, posY + lineLen );
1258  glEnd();
1259  }
1260  }
1261  }
1262  }
1263  }
1264  else
1265  {
1266  // Vertical lines
1267  for( int j = gridStartY; j <= gridEndY; j++ )
1268  {
1269  const double y = j * gridSize.y + gridOrigin.y;
1270 
1271  // If axes are drawn, skip the lines that would cover them
1272  if( axesEnabled && y == 0 )
1273  continue;
1274 
1275  if( j % gridTick == 0 && gridScreenSizeDense > gridThreshold )
1276  glLineWidth( majorLineWidth );
1277  else
1278  glLineWidth( minorLineWidth );
1279 
1280  if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
1281  || gridScreenSizeDense > gridThreshold )
1282  {
1283  glBegin( GL_LINES );
1284  glVertex2d( gridStartX * gridSize.x + gridOrigin.x, y );
1285  glVertex2d( gridEndX * gridSize.x + gridOrigin.x, y );
1286  glEnd();
1287  }
1288  }
1289 
1290  if( gridStyle == GRID_STYLE::DOTS )
1291  {
1292  glStencilFunc( GL_NOTEQUAL, 0, 1 );
1293  glColor4d( gridColor.r, gridColor.g, gridColor.b, gridColor.a );
1294  }
1295 
1296  // Horizontal lines
1297  for( int i = gridStartX; i <= gridEndX; i++ )
1298  {
1299  const double x = i * gridSize.x + gridOrigin.x;
1300 
1301  // If axes are drawn, skip the lines that would cover them
1302  if( axesEnabled && x == 0 )
1303  continue;
1304 
1305  if( i % gridTick == 0 && gridScreenSizeDense > gridThreshold )
1306  glLineWidth( majorLineWidth );
1307  else
1308  glLineWidth( minorLineWidth );
1309 
1310  if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
1311  || gridScreenSizeDense > gridThreshold )
1312  {
1313  glBegin( GL_LINES );
1314  glVertex2d( x, gridStartY * gridSize.y + gridOrigin.y );
1315  glVertex2d( x, gridEndY * gridSize.y + gridOrigin.y );
1316  glEnd();
1317  }
1318  }
1319 
1320  if( gridStyle == GRID_STYLE::DOTS )
1321  glDisable( GL_STENCIL_TEST );
1322  }
1323 
1324  glEnable( GL_DEPTH_TEST );
1325  glEnable( GL_TEXTURE_2D );
1326 }
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)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
GRID_STYLE gridStyle
Grid display style.
double g
Green component.
Definition: color4d.h:292
MATRIX3x3D screenWorldMatrix
Screen transformation.
double b
Blue component.
Definition: color4d.h:293
Auxiliary rendering target (noncached)
Definition: definitions.h:42
double a
Alpha component.
Definition: color4d.h:294
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:314
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
unsigned int mainBuffer
Main rendering target.
Definition: opengl_gal.h:315
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.
size_t i
Definition: json11.cpp:597
VECTOR2I screenSize
Screen size in screen coordinates.
double r
Red component.
Definition: color4d.h:291
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 1068 of file graphics_abstraction_layer.h.

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

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

Draw the stored group.

Parameters
aGroupNumberis the group number.

Reimplemented from KIGFX::GAL.

Definition at line 1436 of file opengl_gal.cpp.

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

Referenced by IsVisible().

1437 {
1438  cachedManager->DrawItem( *groups[aGroupNumber] );
1439 }
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:306
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:309
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 515 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(), DrawArcSegment(), and IsVisible().

516 {
517  const VECTOR2D startEndVector = aEndPoint - aStartPoint;
518  double lineAngle = startEndVector.Angle();
519 
521 
522  drawLineQuad( aStartPoint, aEndPoint );
523 
524  // Line caps
525  if( lineWidth > 1.0 )
526  {
527  drawFilledSemiCircle( aStartPoint, lineWidth / 2, lineAngle + M_PI / 2 );
528  drawFilledSemiCircle( aEndPoint, lineWidth / 2, lineAngle - M_PI / 2 );
529  }
530 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
double g
Green component.
Definition: color4d.h:292
double b
Blue component.
Definition: color4d.h:293
double lineWidth
The line width.
double Angle() const
Function Angle computes the angle of the vector.
Definition: vector2d.h:306
double a
Alpha component.
Definition: color4d.h:294
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:291
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 1552 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().

1553 {
1554  /* Helper drawing: ____--- v3 ^
1555  * ____---- ... \ \
1556  * ____---- ... \ end \
1557  * v1 ____---- ... ____---- \ width
1558  * ---- ...___---- \ \
1559  * \ ___...-- \ v
1560  * \ ____----... ____---- v2
1561  * ---- ... ____----
1562  * start \ ... ____----
1563  * \... ____----
1564  * ----
1565  * v0
1566  * dots mark triangles' hypotenuses
1567  */
1568 
1569  VECTOR2D startEndVector = aEndPoint - aStartPoint;
1570  double lineLength = startEndVector.EuclideanNorm();
1571 
1572  if( lineLength <= 0.0 )
1573  return;
1574 
1575  double scale = 0.5 * lineWidth / lineLength;
1576 
1577  // The perpendicular vector also needs transformations
1578  glm::vec4 vector = currentManager->GetTransformation() *
1579  glm::vec4( -startEndVector.y * scale, startEndVector.x * scale, 0.0, 0.0 );
1580 
1581  currentManager->Reserve( 6 );
1582 
1583  // Line width is maintained by the vertex shader
1584  currentManager->Shader( SHADER_LINE, vector.x, vector.y, lineWidth );
1585  currentManager->Vertex( aStartPoint.x, aStartPoint.y, layerDepth ); // v0
1586 
1587  currentManager->Shader( SHADER_LINE, -vector.x, -vector.y, lineWidth );
1588  currentManager->Vertex( aStartPoint.x, aStartPoint.y, layerDepth ); // v1
1589 
1590  currentManager->Shader( SHADER_LINE, -vector.x, -vector.y, lineWidth );
1591  currentManager->Vertex( aEndPoint.x, aEndPoint.y, layerDepth ); // v3
1592 
1593  currentManager->Shader( SHADER_LINE, vector.x, vector.y, lineWidth );
1594  currentManager->Vertex( aStartPoint.x, aStartPoint.y, layerDepth ); // v0
1595 
1596  currentManager->Shader( SHADER_LINE, -vector.x, -vector.y, lineWidth );
1597  currentManager->Vertex( aEndPoint.x, aEndPoint.y, layerDepth ); // v3
1598 
1599  currentManager->Shader( SHADER_LINE, vector.x, vector.y, lineWidth );
1600  currentManager->Vertex( aEndPoint.x, aEndPoint.y, layerDepth ); // v2
1601 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
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:292
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 865 of file opengl_gal.cpp.

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

Referenced by IsVisible().

866 {
867  auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aPointList.size()] );
868  GLdouble* ptr = points.get();
869 
870  for( const VECTOR2D& p : aPointList )
871  {
872  *ptr++ = p.x;
873  *ptr++ = p.y;
874  *ptr++ = layerDepth;
875  }
876 
877  drawPolygon( points.get(), aPointList.size() );
878 }
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 881 of file opengl_gal.cpp.

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

882 {
883  auto points = std::unique_ptr<GLdouble[]>( new GLdouble[3 * aListSize] );
884  GLdouble* target = points.get();
885  const VECTOR2D* src = aPointList;
886 
887  for( int i = 0; i < aListSize; ++i )
888  {
889  *target++ = src->x;
890  *target++ = src->y;
891  *target++ = layerDepth;
892  ++src;
893  }
894 
895  drawPolygon( points.get(), aListSize );
896 }
double layerDepth
The actual layer depth.
void drawPolygon(GLdouble *aPoints, int aPointCount)
Draws a filled polygon.
size_t i
Definition: json11.cpp:597
void OPENGL_GAL::DrawPolygon ( const SHAPE_POLY_SET aPolySet)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 936 of file opengl_gal.cpp.

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

937 {
938  if ( aPolySet.IsTriangulationUpToDate() )
939  {
940  drawTriangulatedPolyset( aPolySet );
941  return;
942  }
943 
944  for( int j = 0; j < aPolySet.OutlineCount(); ++j )
945  {
946  const SHAPE_LINE_CHAIN& outline = aPolySet.COutline( j );
947 
948  if( outline.SegmentCount() == 0 )
949  continue;
950 
951  const int pointCount = outline.SegmentCount() + 1;
952  std::unique_ptr<GLdouble[]> points( new GLdouble[3 * pointCount] );
953  GLdouble* ptr = points.get();
954 
955  for( int i = 0; i < pointCount; ++i )
956  {
957  const VECTOR2I& p = outline.CPoint( i );
958  *ptr++ = p.x;
959  *ptr++ = p.y;
960  *ptr++ = layerDepth;
961  }
962 
963  drawPolygon( points.get(), pointCount );
964  }
965 }
double layerDepth
The actual layer depth.
void drawPolygon(GLdouble *aPoints, int aPointCount)
Draws a filled polygon.
bool IsTriangulationUpToDate() const
int OutlineCount() const
Returns the number of outlines in the set
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
void drawTriangulatedPolyset(const SHAPE_POLY_SET &aPoly)
Draws a set of polygons with a cached triangulation.
Definition: opengl_gal.cpp:899
Class SHAPE_LINE_CHAIN.
size_t i
Definition: json11.cpp:597
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
int SegmentCount() const
Function SegmentCount()
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 1685 of file opengl_gal.cpp.

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

Referenced by DrawPolygon().

1686 {
1687  if( isFillEnabled )
1688  {
1691 
1692  // Any non convex polygon needs to be tesselated
1693  // for this purpose the GLU standard functions are used
1694  TessParams params = { currentManager, tessIntersects };
1695  gluTessBeginPolygon( tesselator, &params );
1696  gluTessBeginContour( tesselator );
1697 
1698  GLdouble* point = aPoints;
1699 
1700  for( int i = 0; i < aPointCount; ++i )
1701  {
1702  gluTessVertex( tesselator, point, point );
1703  point += 3; // 3 coordinates
1704  }
1705 
1706  gluTessEndContour( tesselator );
1707  gluTessEndPolygon( tesselator );
1708 
1709  // Free allocated intersecting points
1710  tessIntersects.clear();
1711  }
1712 
1713  if( isStrokeEnabled )
1714  {
1715  drawPolyline( [&](int idx) { return VECTOR2D( aPoints[idx * 3], aPoints[idx * 3 + 1] ); },
1716  aPointCount );
1717  }
1718 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
double g
Green component.
Definition: color4d.h:292
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:293
double a
Alpha component.
Definition: color4d.h:294
bool isStrokeEnabled
Are the outlines stroked ?
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
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:337
bool isFillEnabled
Is filling of graphic objects enabled ?
std::deque< boost::shared_array< GLdouble > > tessIntersects
Storage for intersecting points.
Definition: opengl_gal.h:339
size_t i
Definition: json11.cpp:597
void drawPolyline(const std::function< VECTOR2D(int)> &aPointGetter, int aPointCount)
Generic way of drawing a polyline stored in different containers.
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:291
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 842 of file opengl_gal.cpp.

References drawPolyline().

Referenced by DrawCurve(), DrawRectangle(), drawTriangulatedPolyset(), and IsVisible().

843 {
844  drawPolyline( [&](int idx) { return aPointList[idx]; }, aPointList.size() );
845 }
void drawPolyline(const std::function< VECTOR2D(int)> &aPointGetter, int aPointCount)
Generic way of drawing a polyline stored in different containers.
void OPENGL_GAL::DrawPolyline ( const VECTOR2D  aPointList[],
int  aListSize 
)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 848 of file opengl_gal.cpp.

References drawPolyline().

849 {
850  drawPolyline( [&](int idx) { return aPointList[idx]; }, aListSize );
851 }
void drawPolyline(const std::function< VECTOR2D(int)> &aPointGetter, int aPointCount)
Generic way of drawing a polyline stored in different containers.
void OPENGL_GAL::DrawPolyline ( const SHAPE_LINE_CHAIN aLineChain)
overridevirtual

Reimplemented from KIGFX::GAL.

Definition at line 854 of file opengl_gal.cpp.

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

855 {
856  auto numPoints = aLineChain.PointCount();
857 
858  if( aLineChain.IsClosed() )
859  numPoints += 1;
860 
861  drawPolyline( [&](int idx) { return aLineChain.CPoint(idx); }, numPoints );
862 }
int PointCount() const
Function PointCount()
bool IsClosed() const
Function IsClosed()
void drawPolyline(const std::function< VECTOR2D(int)> &aPointGetter, int aPointCount)
Generic way of drawing a polyline stored in different containers.
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
void OPENGL_GAL::drawPolyline ( const std::function< VECTOR2D(int)> &  aPointGetter,
int  aPointCount 
)
private

Generic way of drawing a polyline stored in different containers.

Parameters
aPointGetteris a function to obtain coordinates of n-th vertex.
aPointCountis the number of points to be drawn.

Definition at line 1721 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, i, KIGFX::GAL::lineWidth, KIGFX::COLOR4D::r, and KIGFX::GAL::strokeColor.

Referenced by drawPolygon(), and DrawPolyline().

1722 {
1723  if( aPointCount < 2 )
1724  return;
1725 
1727  int i;
1728 
1729  for( i = 1; i < aPointCount; ++i )
1730  {
1731  auto start = aPointGetter( i - 1 );
1732  auto end = aPointGetter( i );
1733  const VECTOR2D startEndVector = ( end - start );
1734  double lineAngle = startEndVector.Angle();
1735 
1736  drawLineQuad( start, end );
1737 
1738  // There is no need to draw line caps on both ends of polyline's segments
1739  drawFilledSemiCircle( start, lineWidth / 2, lineAngle + M_PI / 2 );
1740  }
1741 
1742  // ..and now - draw the ending cap
1743  auto start = aPointGetter( i - 2 );
1744  auto end = aPointGetter( i - 1 );
1745  const VECTOR2D startEndVector = ( end - start );
1746  double lineAngle = startEndVector.Angle();
1747  drawFilledSemiCircle( end, lineWidth / 2, lineAngle - M_PI / 2 );
1748 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
void drawLineQuad(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a quad for the line.
double g
Green component.
Definition: color4d.h:292
double b
Blue component.
Definition: color4d.h:293
double lineWidth
The line width.
double Angle() const
Function Angle computes the angle of the vector.
Definition: vector2d.h:306
double a
Alpha component.
Definition: color4d.h:294
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...
size_t i
Definition: json11.cpp:597
double r
Red component.
Definition: color4d.h:291
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 804 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.

Referenced by IsVisible().

805 {
806  // Compute the diagonal points of the rectangle
807  VECTOR2D diagonalPointA( aEndPoint.x, aStartPoint.y );
808  VECTOR2D diagonalPointB( aStartPoint.x, aEndPoint.y );
809 
810  // Stroke the outline
811  if( isStrokeEnabled )
812  {
814 
815  std::deque<VECTOR2D> pointList;
816  pointList.push_back( aStartPoint );
817  pointList.push_back( diagonalPointA );
818  pointList.push_back( aEndPoint );
819  pointList.push_back( diagonalPointB );
820  pointList.push_back( aStartPoint );
821  DrawPolyline( pointList );
822  }
823 
824  // Fill the rectangle
825  if( isFillEnabled )
826  {
827  currentManager->Reserve( 6 );
830 
831  currentManager->Vertex( aStartPoint.x, aStartPoint.y, layerDepth );
832  currentManager->Vertex( diagonalPointA.x, diagonalPointA.y, layerDepth );
833  currentManager->Vertex( aEndPoint.x, aEndPoint.y, layerDepth );
834 
835  currentManager->Vertex( aStartPoint.x, aStartPoint.y, layerDepth );
836  currentManager->Vertex( aEndPoint.x, aEndPoint.y, layerDepth );
837  currentManager->Vertex( diagonalPointB.x, diagonalPointB.y, layerDepth );
838  }
839 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
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:292
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:293
double a
Alpha component.
Definition: color4d.h:294
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:842
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:291
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 533 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().

Referenced by IsVisible().

535 {
536  VECTOR2D startEndVector = aEndPoint - aStartPoint;
537  double lineAngle = startEndVector.Angle();
538 
539  // Width must be nonzero for anything to appear
540  if( aWidth <= 0 )
541  aWidth = 1.0;
542 
543  if( isFillEnabled )
544  {
545  // Filled tracks
547 
548  SetLineWidth( aWidth );
549  drawLineQuad( aStartPoint, aEndPoint );
550 
551  // Draw line caps
552  drawFilledSemiCircle( aStartPoint, aWidth / 2, lineAngle + M_PI / 2 );
553  drawFilledSemiCircle( aEndPoint, aWidth / 2, lineAngle - M_PI / 2 );
554  }
555  else
556  {
557  // Outlined tracks
558  double lineLength = startEndVector.EuclideanNorm();
559 
561 
562  Save();
563 
564  currentManager->Translate( aStartPoint.x, aStartPoint.y, 0.0 );
565  currentManager->Rotate( lineAngle, 0.0f, 0.0f, 1.0f );
566 
567  drawLineQuad( VECTOR2D( 0.0, aWidth / 2.0 ),
568  VECTOR2D( lineLength, aWidth / 2.0 ) );
569 
570  drawLineQuad( VECTOR2D( 0.0, -aWidth / 2.0 ),
571  VECTOR2D( lineLength, -aWidth / 2.0 ) );
572 
573  // Draw line caps
574  drawStrokedSemiCircle( VECTOR2D( 0.0, 0.0 ), aWidth / 2, M_PI / 2 );
575  drawStrokedSemiCircle( VECTOR2D( lineLength, 0.0 ), aWidth / 2, -M_PI / 2 );
576 
577  Restore();
578  }
579 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
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:292
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:293
double Angle() const
Function Angle computes the angle of the vector.
Definition: vector2d.h:306
virtual void Save() override
Save the context.
double a
Alpha component.
Definition: color4d.h:294
virtual void SetLineWidth(double aLineWidth)
Set the line width.
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:292
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
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:291
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 1604 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.

1605 {
1606  if( isFillEnabled )
1607  {
1609  drawFilledSemiCircle( aCenterPoint, aRadius, aAngle );
1610  }
1611 
1612  if( isStrokeEnabled )
1613  {
1615  drawStrokedSemiCircle( aCenterPoint, aRadius, aAngle );
1616  }
1617 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
double g
Green component.
Definition: color4d.h:292
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:293
double a
Alpha component.
Definition: color4d.h:294
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:291
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 1651 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().

1653 {
1654  double outerRadius = aRadius + ( lineWidth / 2 );
1655 
1656  Save();
1657 
1658  currentManager->Reserve( 3 );
1659  currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0f );
1660  currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1661 
1662  /* Draw a triangle that contains the semicircle, then shade it to leave only
1663  * the semicircle. Parameters given to Shader() are indices of the triangle's vertices
1664  * (if you want to understand more, check the vertex shader source [shader.vert]), the
1665  * radius and the line width. Shader uses these coordinates to determine if fragments are
1666  * inside the semicircle or not.
1667  * v2
1668  * /\
1669  * /__\
1670  * v0 //__\\ v1
1671  */
1673  currentManager->Vertex( -outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v0
1674 
1676  currentManager->Vertex( outerRadius * 3.0f / sqrt( 3.0f ), 0.0f, layerDepth ); // v1
1677 
1679  currentManager->Vertex( 0.0f, outerRadius * 2.0f, layerDepth ); // v2
1680 
1681  Restore();
1682 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
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::drawTriangulatedPolyset ( const SHAPE_POLY_SET aPoly)
private

Draws a set of polygons with a cached triangulation.

Way faster than drawPolygon.

Definition at line 899 of file opengl_gal.cpp.

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::VERTEX_MANAGER::Color(), currentManager, DrawPolyline(), KIGFX::GAL::fillColor, KIGFX::COLOR4D::g, i, KIGFX::GAL::isFillEnabled, KIGFX::GAL::isStrokeEnabled, KIGFX::GAL::layerDepth, SHAPE_POLY_SET::OutlineCount(), SHAPE_POLY_SET::Polygon(), KIGFX::COLOR4D::r, KIGFX::VERTEX_MANAGER::Shader(), KIGFX::SHADER_NONE, SHAPE_POLY_SET::TriangulatedPolyCount(), SHAPE_POLY_SET::TriangulatedPolygon(), KIGFX::VERTEX_MANAGER::Vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DrawPolygon().

900 {
903 
904  if( isFillEnabled )
905  {
906  for( unsigned int j = 0; j < aPolySet.TriangulatedPolyCount(); ++j )
907  {
908  auto triPoly = aPolySet.TriangulatedPolygon( j );
909 
910  for( int i = 0; i < triPoly->GetTriangleCount(); i++ )
911  {
912  VECTOR2I a, b, c;
913  triPoly->GetTriangle( i ,a,b,c);
914  currentManager->Vertex( a.x, a.y, layerDepth );
915  currentManager->Vertex( b.x, b.y, layerDepth );
916  currentManager->Vertex( c.x, c.y, layerDepth );
917  }
918  }
919  }
920 
921  if( isStrokeEnabled )
922  {
923  for( int j = 0; j < aPolySet.OutlineCount(); ++j )
924  {
925  const auto& poly = aPolySet.Polygon( j );
926 
927  for( const auto& lc : poly )
928  {
929  DrawPolyline( lc );
930  }
931  }
932  }
933 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
double layerDepth
The actual layer depth.
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:292
COLOR4D fillColor
The fill color.
double b
Blue component.
Definition: color4d.h:293
double a
Alpha component.
Definition: color4d.h:294
bool isStrokeEnabled
Are the outlines stroked ?
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:842
size_t i
Definition: json11.cpp:597
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:291
void OPENGL_GAL::EndDrawing ( )
overridevirtual

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

Reimplemented from KIGFX::GAL.

Definition at line 458 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().

Referenced by IsVisible().

459 {
460 #ifdef __WXDEBUG__
461  PROF_COUNTER totalRealTime( "OPENGL_GAL::EndDrawing()", true );
462 #endif /* __WXDEBUG__ */
463 
464  // Cached & non-cached containers are rendered to the same buffer
468 
469  // Overlay container is rendered to a different buffer
472 
473  // Be sure that the framebuffer is not colorized (happens on specific GPU&drivers combinations)
474  glColor4d( 1.0, 1.0, 1.0, 1.0 );
475 
476  // Draw the remaining contents, blit the rendering targets to the screen, swap the buffers
479  compositor->Present();
480  blitCursor();
481 
482  SwapBuffers();
484 
485 #ifdef __WXDEBUG__
486  totalRealTime.Stop();
487  wxLogTrace( "GAL_PROFILE", wxT( "OPENGL_GAL::EndDrawing(): %.1f ms" ), totalRealTime.msecs() );
488 #endif /* __WXDEBUG__ */
489 }
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:316
VERTEX_MANAGER * overlayManager
Container for storing overlaid VERTEX_ITEMs.
Definition: opengl_gal.h:311
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:310
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:314
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:315
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:309
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:297
void OPENGL_GAL::EndGroup ( )
overridevirtual

End the group.

Reimplemented from KIGFX::GAL.

Definition at line 1429 of file opengl_gal.cpp.

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

Referenced by IsVisible().

1430 {
1432  isGrouping = false;
1433 }
bool isGrouping
Was a group started?
Definition: opengl_gal.h:328
VERTEX_MANAGER * cachedManager
Container for storing cached VERTEX_ITEMs.
Definition: opengl_gal.h:309
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 505 of file opengl_gal.cpp.

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

Referenced by IsVisible().

506 {
507  if( !isInitialized )
508  return;
509 
510  cachedManager->Unmap();
512 }
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:309
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:326
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:297
void OPENGL_GAL::Flush ( )
overridevirtual

Force all remaining objects to be drawn.

Reimplemented from KIGFX::GAL.

Definition at line 1353 of file opengl_gal.cpp.

Referenced by IsVisible().

1354 {
1355  glFlush();
1356 }
float HIDPI_GL_CANVAS::GetBackingScaleFactor ( ) const
virtualinherited

Definition at line 59 of file hidpi_gl_canvas.cpp.

Referenced by HIDPI_GL_CANVAS::GetClientSize(), and ResizeScreen().

60 {
61 #ifdef RETINA_OPENGL_PATCH
62  // this is ugly, but original method isn't marked const although it doesn't modify anything
63  // => clean up when it officially has arrived in wxWidgets
64  return static_cast< wxGLCanvas* >( const_cast< HIDPI_GL_CANVAS* >( this ))->GetBackingScaleFactor();
65 #else
66  return 1.0f;
67 #endif
68 }
wxGLCanvas wrapper for HiDPI/Retina support.
const COLOR4D& KIGFX::GAL::GetClearColor ( ) const
inlineinherited

Definition at line 212 of file graphics_abstraction_layer.h.

References KIGFX::GAL::m_clearColor.

213  {
214  return m_clearColor;
215  }
wxSize HIDPI_GL_CANVAS::GetClientSize ( ) const
virtualinherited

Definition at line 46 of file hidpi_gl_canvas.cpp.

References HIDPI_GL_CANVAS::GetBackingScaleFactor().

Referenced by C3D_MODEL_VIEWER::OnMouseMove(), EDA_3D_CANVAS::OnMouseMove(), C3D_MODEL_VIEWER::OnPaint(), and EDA_3D_CANVAS::OnPaint().

47 {
48  wxSize size = wxGLCanvas::GetClientSize();
49 
50 #ifdef RETINA_OPENGL_PATCH
51  const float scaleFactor = GetBackingScaleFactor();
52  size.x *= scaleFactor;
53  size.y *= scaleFactor;
54 #endif
55 
56  return size;
57 }
virtual float GetBackingScaleFactor() const
COLOR4D GAL::getCursorColor ( ) const
protectedinherited

Gets the actual cursor color to draw.

Definition at line 421 of file graphics_abstraction_layer.cpp.

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

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

422 {
423  auto color = cursorColor;
424 
425  // dim the cursor if it's only on because it was forced
426  // (this helps to provide a hint for active tools)
427  if( !isCursorEnabled )
428  {
429  color.a = color.a * 0.5;
430  }
431 
432  return color;
433 }
bool isCursorEnabled
Is the cursor enabled?
int color
Definition: DXF_plotter.cpp:62
COLOR4D cursorColor
Cursor color.
double KIGFX::GAL::GetGridLineWidth ( ) const
inlineinherited

Get the grid line width.

Returns
the grid line width

Definition at line 890 of file graphics_abstraction_layer.h.

References KIGFX::GAL::DrawGrid(), KIGFX::GAL::GetGridPoint(), and KIGFX::GAL::gridLineWidth.

891  {
892  return gridLineWidth;
893  }
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 399 of file graphics_abstraction_layer.cpp.

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

Referenced by EDIT_POINTS_FACTORY::buildForPolyOutline(), KIGFX::GAL::GetGridLineWidth(), and KIGFX::WX_VIEW_CONTROLS::GetRawCursorPosition().

400 {
401 #if 0
402  // This old code expects a non zero grid size, which can be wrong here.
403  return VECTOR2D( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
404  KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
405 #else
406  // if grid size == 0.0 there is no grid, so use aPoint as grid reference position
407  double cx = gridSize.x > 0.0 ? KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x
408  : aPoint.x;
409  double cy = gridSize.y > 0.0 ? KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y
410  : aPoint.y;
411 
412  return VECTOR2D( cx, cy );
413 #endif
414 }
VECTOR2D gridOffset
The grid offset to compensate cursor position.
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
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 842 of file graphics_abstraction_layer.h.

References KIGFX::GAL::gridSize.

843  {
844  return gridSize;
845  }
VECTOR2D gridSize
The grid size.
EDA_TEXT_HJUSTIFY_T KIGFX::GAL::GetHorizontalJustify ( ) const
inlineinherited

Returns current text horizontal justification setting.

Definition at line 474 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().

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

Get the look at point.

Returns
the look at point.

Definition at line 669 of file graphics_abstraction_layer.h.

References KIGFX::GAL::lookAtPoint.

670  {
671  return lookAtPoint;
672  }
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 718 of file graphics_abstraction_layer.h.

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

719  {
720  return depthRange.y;
721  }
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 710 of file graphics_abstraction_layer.h.

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

711  {
712  return depthRange.x;
713  }
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 1928 of file opengl_gal.cpp.

References groupCounter, groups, and max.

Referenced by BeginGroup().

1929 {
1930  wxASSERT_MSG( groups.size() < std::numeric_limits<unsigned int>::max(),
1931  wxT( "There are no free slots to store a group" ) );
1932 
1933  while( groups.find( groupCounter ) != groups.end() )
1934  {
1935  groupCounter++;
1936  }
1937 
1938  return groupCounter++;
1939 }
GROUPS_MAP groups
Stores informations about VBO objects (groups)
Definition: opengl_gal.h:306
#define max(a, b)
Definition: auxiliary.h:86
unsigned int groupCounter
Counter used for generating keys for groups.
Definition: opengl_gal.h:307
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 369 of file graphics_abstraction_layer.h.

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

370  {
372  }
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 610 of file graphics_abstraction_layer.h.

References KIGFX::GAL::screenWorldMatrix.

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

611  {
612  return screenWorldMatrix;
613  }
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 272 of file graphics_abstraction_layer.h.

References KIGFX::GAL::strokeColor.

273  {
274  return strokeColor;
275  }
COLOR4D strokeColor
The color of the outlines.
const STROKE_FONT& KIGFX::GAL::GetStrokeFont ( ) const
inlineinherited

Definition at line 314 of file graphics_abstraction_layer.h.

References KIGFX::GAL::strokeFont.

Referenced by EDA_TEXT::GetTextBox().

315  {
316  return strokeFont;
317  }
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 1506 of file opengl_gal.cpp.

References currentTarget.

Referenced by DrawBitmap(), and IsVisible().

1507 {
1508  return currentTarget;
1509 }
RENDER_TARGET currentTarget
Current rendering target.
Definition: opengl_gal.h:317
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 KIGFX::GAL::BitmapText(), 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 492 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().

493  {
495  }
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 600 of file graphics_abstraction_layer.h.

References KIGFX::GAL::worldScreenMatrix.

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

601  {
602  return worldScreenMatrix;
603  }
MATRIX3x3D worldScreenMatrix
World transformation.
double KIGFX::GAL::GetZoomFactor ( ) const
inlineinherited

Get the zoom factor.

Returns
the zoom factor.

Definition at line 689 of file graphics_abstraction_layer.h.

References KIGFX::GAL::zoomFactor.

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

690  {
691  return zoomFactor;
692  }
double zoomFactor
The zoom factor.
void OPENGL_GAL::init ( )
private

Basic OpenGL initialization.

Definition at line 1942 of file opengl_gal.cpp.

References cachedManager, enableGlDebug(), err, 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(), BeginUpdate(), and calcAngleStep().

1943 {
1944  wxASSERT( IsShownOnScreen() );
1945 
1947 
1948  GLenum err = glewInit();
1949 
1950  try
1951  {
1952  if( GLEW_OK != err )
1953  throw std::runtime_error( (const char*) glewGetErrorString( err ) );
1954 
1955  // Check the OpenGL version (minimum 2.1 is required)
1956  if( !GLEW_VERSION_2_1 )
1957  throw std::runtime_error( "OpenGL 2.1 or higher is required!" );
1958 
1959 #if defined (__LINUX__) // calling enableGlDebug crashes opengl on some OS (OSX and some Windows)
1960 #ifdef DEBUG
1961  if( GLEW_ARB_debug_output )
1962  enableGlDebug( true );
1963 #endif
1964 #endif
1965 
1966  // Framebuffers have to be supported
1967  if( !GLEW_EXT_framebuffer_object )
1968  throw std::runtime_error( "Framebuffer objects are not supported!" );
1969 
1970  // Vertex buffer has to be supported
1971  if( !GLEW_ARB_vertex_buffer_object )
1972  throw std::runtime_error( "Vertex buffer objects are not supported!" );
1973 
1974  // Prepare shaders
1976  throw std::runtime_error( "Cannot compile vertex shader!" );
1977 
1979  throw std::runtime_error( "Cannot compile fragment shader!" );
1980 
1981  if( !shader->IsLinked() && !shader->Link() )
1982  throw std::runtime_error( "Cannot link the shaders!" );
1983 
1984  // Check if video card supports textures big enough to fit the font atlas
1985  int maxTextureSize;
1986  glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxTextureSize );
1987 
1988  if( maxTextureSize < (int) font_image.width || maxTextureSize < (int)font_image.height )
1989  {
1990  // TODO implement software texture scaling
1991  // for bitmap fonts and use a higher resolution texture?
1992  throw std::runtime_error( "Requested texture size is not supported" );
1993  }
1994  }
1995  catch( std::runtime_error& )
1996  {
1998  throw;
1999  }
2000 
2001  cachedManager = new VERTEX_MANAGER( true );
2002  nonCachedManager = new VERTEX_MANAGER( false );
2003  overlayManager = new VERTEX_MANAGER( false );
2004 
2005  // Make VBOs use shaders
2009 
2011  isInitialized = true;
2012 }
static SHADER * shader
There is only one shader used for different objects.
Definition: opengl_gal.h:320
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:311
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.
void enableGlDebug(bool aEnable)
Enables/disables OpenGL driver messages output.
Definition: utils.cpp:103
VERTEX_MANAGER * nonCachedManager
Container for storing non-cached VERTEX_ITEMs.
Definition: opengl_gal.h:310
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
string & err
Definition: json11.cpp:598
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:309
bool isInitialized
Basic initialization flag, has to be done when the window is visible.
Definition: opengl_gal.h:326
wxGLContext * glPrivContext
Canvas-specific OpenGL context.
Definition: opengl_gal.h:297
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 943 of file graphics_abstraction_layer.h.

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

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

944  {
946  }
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 420 of file graphics_abstraction_layer.h.

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

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

421  {
422  return textProperties.m_bold;
423  }
struct KIGFX::GAL::TEXT_PROPERTIES textProperties
bool KIGFX::GAL::IsFontItalic ( ) const
inlineinherited

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

Definition at line 438 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().

439  {
440  return textProperties.m_italic;
441  }
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 456 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().

457  {
458  return textProperties.m_mirrored;
459  }
struct KIGFX::GAL::TEXT_PROPERTIES textProperties
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 1882 of file opengl_gal.cpp.

References PostPaint().

Referenced by OPENGL_GAL().

1883 {
1884  PostPaint();
1885 }
void PostPaint()
Function PostPaint posts an event to m_paint_listener.
Definition: opengl_gal.h:260
void KIGFX::GAL::PopDepth ( )
inlineinherited

Restores previously stored drawing depth for the depth stack.

Definition at line 985 of file graphics_abstraction_layer.h.

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

986  {
987  layerDepth = depthStack.top();
988  depthStack.pop();
989  }
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 260 of file opengl_gal.h.

References paintListener.

Referenced by onPaint().

261  {
262  if( paintListener )
263  {
264  wxPaintEvent redrawEvent;
265  wxPostEvent( paintListener, redrawEvent );
266  }
267  }
wxEvtHandler * paintListener
Definition: opengl_gal.h:300
void KIGFX::GAL::PushDepth ( )
inlineinherited

Stores current drawing depth on the depth stack.

Definition at line 977 of file graphics_abstraction_layer.h.

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

978  {
979  depthStack.push( layerDepth );
980  }
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::PCB_PAINTER::draw(), KIGFX::GAL::GAL(), and KIGFX::GAL::GetOverbarVerticalPosition().

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 1329 of file opengl_gal.cpp.

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

Referenced by IsVisible().

1330 {
1331  screenSize = VECTOR2I( aWidth, aHeight );
1332 
1333  // Resize framebuffers
1334  const float scaleFactor = GetBackingScaleFactor();
1335  compositor->Resize( aWidth * scaleFactor, aHeight * scaleFactor );
1336  isFramebufferInitialized = false;
1337 
1338  wxGLCanvas::SetSize( aWidth, aHeight );
1339 }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
OPENGL_COMPOSITOR * compositor
Handles multiple rendering targets.
Definition: opengl_gal.h:314
bool isFramebufferInitialized
Are the framebuffers initialized?
Definition: opengl_gal.h:323
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...
virtual float GetBackingScaleFactor() const
VECTOR2I screenSize
Screen size in screen coordinates.
void OPENGL_GAL::Restore ( )
overridevirtual

Restore the context.

Reimplemented from KIGFX::GAL.

Definition at line 1411 of file opengl_gal.cpp.

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

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

1412 {
1414 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
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 1478 of file opengl_gal.cpp.

Referenced by IsVisible().

1479 {
1480  wxASSERT_MSG( false, wxT( "Not implemented yet" ) );
1481 }
void OPENGL_GAL::Rotate ( double  aAngle)
overridevirtual

Rotate the context.

Parameters
aAngleis the rotation angle in radians.

Reimplemented from KIGFX::GAL.

Definition at line 1387 of file opengl_gal.cpp.

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

Referenced by IsVisible().

1388 {
1389  currentManager->Rotate( aAngle, 0.0f, 0.0f, 1.0f );
1390 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
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 1405 of file opengl_gal.cpp.

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

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

1406 {
1408 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
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 1472 of file opengl_gal.cpp.

Referenced by IsVisible().

1473 {
1474  wxASSERT_MSG( false, wxT( "Not implemented yet" ) );
1475 }
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 1399 of file opengl_gal.cpp.

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

Referenced by IsVisible().

1400 {
1401  currentManager->Scale( aScale.x, aScale.y, 0.0f );
1402 }
VERTEX_MANAGER * currentManager
Currently used VERTEX_MANAGER (for storing VERTEX_ITEMs)
Definition: opengl_gal.h:308
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 862 of file graphics_abstraction_layer.h.

References KIGFX::GAL::axesColor.

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

863  {
864  axesColor = aAxesColor;
865  }
COLOR4D axesColor
Color of the axes.
void KIGFX::GAL::SetAxesEnabled ( bool  aAxesEnabled)
inlineinherited

Enables drawing the axes.

Definition at line 870 of file graphics_abstraction_layer.h.

References KIGFX::GAL::axesEnabled.

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

871  {
872  axesEnabled = aAxesEnabled;
873  }
bool axesEnabled
Should the axes be drawn.
void KIGFX::GAL::SetClearColor ( const COLOR4D aColor)
inlineinherited

Definition at line 207 of file graphics_abstraction_layer.h.

References KIGFX::GAL::m_clearColor.

Referenced by EDA_DRAW_PANEL_GAL::onPaint().

208  {
209  m_clearColor = aColor;
210  }
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 880 of file graphics_abstraction_layer.h.

References KIGFX::GAL::gridTick.

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

881  {
882  gridTick = aInterval;
883  }
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 953 of file graphics_abstraction_layer.h.

References KIGFX::GAL::cursorColor.

Referenced by KIGFX::GAL::GAL(), EDA_DRAW_PANEL_GAL::onPaint(), and PCB_DRAW_PANEL_GAL::UseColorScheme().

954  {
955  cursorColor = aCursorColor;
956  }
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 934 of file graphics_abstraction_layer.h.

References KIGFX::GAL::isCursorEnabled.

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

935  {
936  isCursorEnabled = aCursorEnabled;
937  }
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 702 of file graphics_abstraction_layer.h.

References KIGFX::GAL::depthRange.

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

703  {
704  depthRange = aDepthRange;
705  }
VECTOR2D depthRange
Range of the depth.
virtual void KIGFX::GAL::SetFillColor ( const COLOR4D aColor)
inlinevirtualinherited

Set the fill color.

Parameters
aColoris the color for filling.

Reimplemented in KIGFX::CAIRO_GAL.

Definition at line 252 of file graphics_abstraction_layer.h.

References KIGFX::GAL::fillColor.

Referenced by BeginDrawing(), KIGFX::WORKSHEET_VIEWITEM::draw(), KIGFX::GERBVIEW_PAINTER::draw(), KIGFX::PCB_PAINTER::draw(), KIGFX::GAL::DrawGrid(), KIGFX::GAL::GAL(), KIGFX::PREVIEW::SIMPLE_OVERLAY_ITEM::setupGal(), and EDIT_POINTS::ViewDraw().

253  {
254  fillColor = aColor;
255  }
COLOR4D fillColor
The fill color.
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 739 of file graphics_abstraction_layer.h.

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

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

740  {
741  globalFlipX = xAxis;
742  globalFlipY = yAxis;
743  }
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 412 of file graphics_abstraction_layer.h.

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

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

413  {
414  textProperties.m_bold = aBold;
415  }
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 430 of file graphics_abstraction_layer.h.

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

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

431  {
432  textProperties.m_italic = aItalic;
433  }
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 394 of file graphics_abstraction_layer.h.

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

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

395  {
396  textProperties.m_glyphSize = aGlyphSize;
397  }
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 852 of file graphics_abstraction_layer.h.

References KIGFX::GAL::gridColor.

Referenced by KIGFX::CAIRO_GAL::CAIRO_GAL(), PCB_LAYER_WIDGET::OnRenderColorChange(), OPENGL_GAL(), GERBVIEW_FRAME::SetGridColor(), PCB_DRAW_PANEL_GAL::UseColorScheme(), and GERBVIEW_FRAME::UseGalCanvas().

853  {
854  gridColor = aGridColor;
855  }
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 813 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 PCBNEW_CONTROL::DoSetGridOrigin(), PCB_BASE_EDIT_FRAME::SetBoard(), and EDA_DRAW_FRAME::UseGalCanvas().

814  {
815  gridOrigin = aGridOrigin;
816 
817  if( gridSize.x == 0.0 || gridSize.y == 0.0 )
818  gridOffset = VECTOR2D(0.0, 0.0);
819  else
820  gridOffset = VECTOR2D( (long) gridOrigin.x % (long) gridSize.x,
821  (long) gridOrigin.y % (long) gridSize.y );
822  }
VECTOR2D gridOffset
The grid offset to compensate cursor position.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
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 829 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 DIALOG_PAD_PROPERTIES::prepareCanvas(), COMMON_TOOLS::updateGrid(), PCBNEW_CONTROL::updateGrid(), and EDA_DRAW_FRAME::UseGalCanvas().

830  {
831  gridSize = aGridSize;
832 
833  gridOffset = VECTOR2D( (long) gridOrigin.x % (long) gridSize.x,
834  (long) gridOrigin.y % (long) gridSize.y );
835  }
VECTOR2D gridOffset
The grid offset to compensate cursor position.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
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 803 of file graphics_abstraction_layer.h.

References KIGFX::GAL::gridVisibility.

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

804  {
805  gridVisibility = aVisibility;
806  }
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 466 of file graphics_abstraction_layer.h.

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

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

4