grid.crosshair: Draw crosshairs with grid

View source: R/crosshairGrob.R

grid.crosshairR Documentation

Draw crosshairs with grid

Description

grid.crosshair() draws crosshairs at the corners of a rectangular area. crosshairGrob() is its grid grob counterpart. They are intended for use in adding crosshairs at the corners of game pieces in print-and-play layouts.

Usage

crosshairGrob(
  ...,
  piece_side = "tile_back",
  suit = NA,
  rank = NA,
  cfg = getOption("piecepackr.cfg", pp_cfg()),
  x = unit(0.5, "npc"),
  y = unit(0.5, "npc"),
  angle = 0,
  width = NA,
  height = NA,
  scale = 1,
  default.units = "npc",
  envir = getOption("piecepackr.envir"),
  name = NULL,
  gp = gpar(),
  vp = NULL,
  ch_width = unit(1/6, "in"),
  ch_grob = squaresCrosshairGrob()
)

grid.crosshair(..., draw = TRUE)

segmentsCrosshairGrob(
  ...,
  x = unit(0.5, "npc"),
  y = unit(0.5, "npc"),
  width = unit(1, "snpc"),
  height = unit(1, "snpc"),
  default.units = "npc",
  name = NULL,
  gp = gpar(),
  vp = NULL
)

squaresCrosshairGrob(
  ...,
  x = unit(0.5, "npc"),
  y = unit(0.5, "npc"),
  width = unit(1, "snpc"),
  height = unit(1, "snpc"),
  default.units = "npc",
  name = NULL,
  gp = gpar(),
  vp = NULL
)

Arguments

...

crosshairGrob() ignores; grid.crosshair() passes to crosshairGrob().

piece_side

A string with piece and side separated by a underscore e.g. "coin_face"

suit

Number of suit (starting from 1).

rank

Number of rank (starting from 1)

cfg

Piecepack configuration list or pp_cfg object, a list of pp_cfg objects, or a character vector referring to names in envir or a character vector referring to object names that can be retrieved by base::dynGet().

x

Where to place piece on x axis of viewport

y

Where to place piece on y axis of viewport

angle

Angle (on xy plane) to draw piece at

width

Width of piece

height

Height of piece

scale

Multiplicative scaling factor to apply to width, height, and depth.

default.units

A string indicating the default units to use if 'x', 'y', 'width', and/or 'height' are only given as numeric vectors.

envir

Environment (or named list) containing configuration list(s).

name

A character identifier (for grid)

gp

An object of class “gpar”.

vp

A grid viewport object (or NULL).

ch_width

Width/height of ch_grob's viewport.

ch_grob

Crosshair grob. Will be drawn in each corner of the piece in a viewport with ch_width width and ch_width height. segmentsCrosshairGrob() simply wraps grid::segmentsGrob() while squaresCrosshairGrob() wraps grid::rectGrob() and alternates black/white squares for visibility on both light and dark backgrounds.

draw

A logical value indicating whether graphics output should be produced.

Details

One can use the lower level segmentsCrosshairGrob() and squaresCrosshairGrob() (which can be drawn with grid::grid.draw()) to add individual crosshairs to specified (x,y) locations.

Value

A grid grob.

Examples

if (requireNamespace("grid", quietly = TRUE) &&
    piecepackr:::device_supports_unicode()) {
  cfg <- pp_cfg(list(border_color = NA))
  grid::grid.newpage()
  df <- data.frame(piece_side = "tile_face", suit = 2, rank = 2,
                   x = 2, y = 2, angle = 0,
                   stringsAsFactors = FALSE)
  pmap_piece(df, grid.piece, cfg = cfg, default.units = "in")
  pmap_piece(df, grid.crosshair, cfg = cfg, default.units = "in")
}
if (requireNamespace("grid", quietly = TRUE) &&
    piecepackr:::device_supports_unicode()) {
  grid::grid.newpage()
  pmap_piece(df, grid.piece, cfg = cfg, default.units = "in")
  pmap_piece(df, grid.crosshair, cfg = cfg, default.units = "in",
             ch_grob = segmentsCrosshairGrob())
}

trevorld/piecepack documentation built on March 29, 2025, 4:33 p.m.