struct CrystGLFW::Monitor

Overview

A Monitor represents a physical monitor connected to the system.

Defined in:

crystglfw/monitors/gamma_ramp.cr
crystglfw/monitors/monitor.cr
crystglfw/monitors/video_mode.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.primary : Monitor #

Returns the primary monitor, which is inferred by GLFW as the window that includes the task bar.

monitor = CrystGLFW::Monitor.primary
puts "Monitor #{monitor.name} is the primary monitor."

NOTE This method must be called from within a CrystGLFW#run block definition.


[View source]

Class Method Detail

def self.all : Array(Monitor) #

Returns all monitors currently connected to the system as an Array.

monitors = CrystGLFW::Monitor.all
monitors.each { |m| puts m.name } # Prints out the name of each connected monitor.

NOTE This method must be called from within a CrystGLFW#run block definition.


[View source]
def self.on_toggle_connection(&callback : ToggleConnectionCallback) #

Defines the behavior that gets triggered when a monitor is either connected or disconnected.

monitor = CrystGLFW::Monitor.primary
monitor.on_toggle_connection do |event|
  if event.connected?
    puts "Welcome back, #{event.monitor.name}!"
  else
    puts "Farewell, #{event.monitor.name}."
  end
end

[View source]

Instance Method Detail

def gamma=(gamma : Number) #

Alternate syntax for #set_gamma.

This method accepts the following arguments:

  • gamma, the exponent used to generate the new gamma ramp.

NOTE This method must be called inside a CrystGLFW#run block definition.


[View source]
def gamma_ramp : GammaRamp #

Returns the monitor's current gamma ramp.

NOTE This method must be called inside a CrystGLFW#run block definition.


[View source]
def gamma_ramp=(gamma_ramp : GammaRamp) #

Alternate syntax for #set_gamma_ramp.


[View source]
def name : String #

Returns the monitor's name, as set by the manufacturer.

# Retrieve the primary monitor.
monitor = CrystGLFW::Monitor.primary

# Print out the name of the monitor.
puts "The name of the primary monitor is #{monitor.name}"

NOTE This method must be called from within a CrystGLFW#run block definition.


[View source]
def physical_size : NamedTuple() #

Returns the physical size of the monitor in millimeters.

# Retrieve the primary monitor.
monitor = CrystGLFW::Monitor.primary

# Calculate the area of the monitor using its physical size.
monitor_area = monitor.physical_size[:width] * monitor.physical_size[:height]

# Print the area of the monitor in millimeters.
puts "The area of the monitor is #{monitor_area} millimeters squared."

NOTE This method must be called from within a CrystGLFW#run block definition.


[View source]
def position : NamedTuple() #

Returns the position of the upper-left corner of the monitor in screen coordinates relative to the virtual screen.

# Retrieve all monitors.
monitors = CrystGLFW::Monitors.all

# Find the monitor that is furthest to the left.
leftmost_monitor = monitors.min_by { |monitor| monitor.position[:x] }

NOTE This method must be called from within a CrystGLFW#run block definition.


[View source]
def set_gamma(gamma : Number) #

Generates a gamma ramp from the given exponent and sets it as the monitor's gamma ramp.

This method accepts the following arguments:

  • gamma, the exponent used to generate the new gamma ramp.

NOTE This method must be called inside a CrystGLFW#run block definition.


[View source]
def set_gamma_ramp(gamma_ramp : GammaRamp) #

Sets the monitor's gamma ramp to the given gamma ramp.


[View source]
def video_mode : VideoMode #

Returns the monitor's current video mode.

# Retrieve the primary monitor.
monitor = CrystGLFW::Monitor.primary

current_video_mode = monitor.video_mode

TODO Improve this example with something useful.

NOTE This method must be called inside a CrystGLFW#run block definition.


[View source]
def video_modes : Array(VideoMode) #

Returns the monitor's supported video modes.

TODO Add an example here.

NOTE This method must be called from within a CrystGLFW#run block definition.


[View source]