KiCad PCB EDA Suite
CURSOR_STORE Class Reference

Simple class to construct and store cursors against unique ID keys. More...

#include <cursors.h>

Classes

struct  CURSOR_DEF
 Definition of a cursor. More...
 

Public Member Functions

 CURSOR_STORE (const std::vector< CURSOR_DEF > &aDefs)
 Construct a store with a pre-set list of cursors. More...
 
const wxCursor & Get (KICURSOR aIdKey) const
 Get a given cursor by its ID. More...
 

Static Public Member Functions

static const wxCursor GetCursor (KICURSOR aCursorType)
 
static const wxStockCursor GetStockCursor (KICURSOR aCursorType)
 

Private Attributes

std::map< KICURSOR, wxCursor > m_store
 < Internal store of cursors by ID More...
 

Detailed Description

Simple class to construct and store cursors against unique ID keys.

This can be used to lazily construct cursors as needed for specific applications.

Definition at line 71 of file cursors.h.

Constructor & Destructor Documentation

◆ CURSOR_STORE()

CURSOR_STORE::CURSOR_STORE ( const std::vector< CURSOR_DEF > &  aDefs)

Construct a store with a pre-set list of cursors.

In future, an "Add()" function could be added if stores need to dynamically add cursors.

Parameters
aDefsthe list of pre-set cursor definitions

Definition at line 372 of file cursors.cpp.

373 {
374  for( const auto& def : aDefs )
375  {
376  m_store[def.m_id_key] = constructCursor( def );
377  }
378 }
std::map< KICURSOR, wxCursor > m_store
< Internal store of cursors by ID
Definition: cursors.h:120
wxCursor constructCursor(const CURSOR_STORE::CURSOR_DEF &aDef)
Construct a cursor for the given definition.
Definition: cursors.cpp:318

References constructCursor(), and m_store.

Member Function Documentation

◆ Get()

const wxCursor & CURSOR_STORE::Get ( KICURSOR  aIdKey) const

Get a given cursor by its ID.

Parameters
aIdKeythe ID key to look up
Returns
the cursor, if found, else wxNullCursor

Definition at line 381 of file cursors.cpp.

382 {
383  const auto find_iter = m_store.find( aIdKey );
384 
385  if( find_iter != m_store.end() )
386  return find_iter->second;
387 
388  wxASSERT_MSG( false, wxString::Format( "Could not find cursor with ID %d",
389  static_cast<int>( aIdKey ) ) );
390  return wxNullCursor;
391 }
std::map< KICURSOR, wxCursor > m_store
< Internal store of cursors by ID
Definition: cursors.h:120
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References Format(), and m_store.

Referenced by GetCursor().

◆ GetCursor()

const wxCursor CURSOR_STORE::GetCursor ( KICURSOR  aCursorType)
static

Definition at line 394 of file cursors.cpp.

395 {
396  wxStockCursor stock =
397  GetStockCursor( aCursorType );
398  if( stock != wxCURSOR_MAX )
399  {
400  return wxCursor( stock );
401  }
402 
403  static CURSOR_STORE store( standard_cursors );
404  return store.Get( aCursorType );
405 }
Simple class to construct and store cursors against unique ID keys.
Definition: cursors.h:71
static const wxStockCursor GetStockCursor(KICURSOR aCursorType)
Definition: cursors.cpp:408
static const std::vector< CURSOR_STORE::CURSOR_DEF > standard_cursors
Definition: cursors.cpp:104

References Get(), GetStockCursor(), and standard_cursors.

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

◆ GetStockCursor()

const wxStockCursor CURSOR_STORE::GetStockCursor ( KICURSOR  aCursorType)
static

Definition at line 408 of file cursors.cpp.

409 {
410  wxStockCursor stockCursor;
411  switch( aCursorType )
412  {
413  case KICURSOR::MOVING:
414  stockCursor = wxCURSOR_SIZING;
415  break;
416  case KICURSOR::BULLSEYE:
417  stockCursor = wxCURSOR_BULLSEYE;
418  break;
419  case KICURSOR::HAND:
420  stockCursor = wxCURSOR_HAND;
421  break;
422  case KICURSOR::ARROW:
423  stockCursor = wxCURSOR_ARROW;
424  break;
425  default:
426  stockCursor = wxCURSOR_MAX;
427  break;
428  }
429 
430  if( !KIPLATFORM::UI::IsStockCursorOk( stockCursor ) )
431  {
432  stockCursor = wxCURSOR_MAX;
433  }
434 
435  return stockCursor;
436 }
bool IsStockCursorOk(wxStockCursor aCursor)
Checks if we designated a stock cursor for this OS as "OK" or else we may need to load a custom one.
Definition: gtk/ui.cpp:77

References ARROW, BULLSEYE, HAND, KIPLATFORM::UI::IsStockCursorOk(), and MOVING.

Referenced by GetCursor().

Member Data Documentation

◆ m_store

std::map<KICURSOR, wxCursor> CURSOR_STORE::m_store
private

< Internal store of cursors by ID

Definition at line 120 of file cursors.h.

Referenced by CURSOR_STORE(), and Get().


The documentation for this class was generated from the following files: