pyhexlib.render module

class pyhexlib.render.HexGridRenderer(layers, radius=50, bg_color=(100, 100, 100), bg_image=None, assets=None, visible_size=None, origin=None)[source]

Bases: object

Parameters:
  • layers (HexGridManager)

  • radius (int)

  • bg_color (Tuple[int, int, int] | Tuple[int, int, int, int] | pygame.Color)

  • bg_image (pygame.Surface)

  • assets (Assets)

  • visible_size (Size)

  • origin (Hexagon)

__repr__()[source]

Return a concise developer representation showing: - hex size, surface size, background color, - grids container name, number of cached hexes, offsets, and whether assets are set.

Return type:

str

get_angle(h1, h2)[source]

Return the angle in degrees from hex h1 to hex h2.

Parameters:
Return type:

int

get_layer(name)[source]

Retrieves a named grid from the grid’s container.

Return type:

StyledGridLayer

get_renderer(layer)[source]
Parameters:

layer (HexGridLayer)

get_surface(layer)[source]

Get the rendered surface for a given layer, using caching to optimize performance.

Parameters:

layer (HexGridLayer)

Return type:

pygame.Surface

hex_at(x, y)[source]
Return type:

Hexagon

is_layer_visible(grid_name)[source]

Check visibility of a named grid in the grid’s container.

Parameters:

grid_name (str)

Return type:

bool

point_to_hex(p)[source]
Parameters:

p (pygame.Vector2)

Return type:

Hexagon

render()[source]
Return type:

pygame.Surface

render_background()[source]
render_layers()[source]
scroll(delta_r, delta_c)[source]

Scroll the grid by changing the origin hex’s row and column coordinates.

scroll_h(delta_c)[source]
Parameters:

delta_c (int)

scroll_v(delta_r)[source]
Parameters:

delta_r (int)

set_layer_visible(grid_name, visible)[source]

Set visibility of a named grid in the grid’s container.

Parameters:
  • grid_name (str)

  • visible (bool)

Return type:

None

set_origin(origin)[source]

Set the origin hex for rendering, which determines the clipping bounds.

Parameters:

origin (Hexagon)

set_renderer(layer_type, render_fn)[source]

Register a custom rendering function for a specific layer type.

Parameters:

layer_type (type | str)

Return type:

None

toggle_bg_visible()[source]

Toggle between background image and solid color fill.

Return type:

None

toggle_visible(grid_name)[source]

Toggle visibility of a named grid in the grid’s container.

Parameters:

grid_name (str)

Return type:

None

pyhexlib.render.load_font_from_resources()[source]
Return type:

pygame.font.Font