The BScreen class provides methods to retrieve and change display settings. More...
Public Member Functions | |
BScreen (BWindow *window) | |
Creates a BScreen object which represents the display that contains window. | |
BScreen (screen_id id=B_MAIN_SCREEN_ID) | |
Creates a BScreen object which represents the display connected to the computer with the given screen_id. | |
~BScreen () | |
Frees the resources used by the BScreen object and unlocks the screen. | |
Utility Methods | |
bool | IsValid () |
Checks that the BScreen object represents a real display that is connected to the computer. | |
status_t | SetToNext () |
Sets the BScreen object to the next display in the screen list. | |
color_space | ColorSpace () |
Returns the color_space of the display. | |
BRect | Frame () |
Gets the frame of the screen in the screen's coordinate system. | |
screen_id | ID () |
Gets the identifier of the display. | |
status_t | WaitForRetrace () |
Blocks until the monitor has finished its current vertical retrace. | |
status_t | WaitForRetrace (bigtime_t timeout) |
Blocks until the monitor has finished its current vertical retrace or until timeout has expired. | |
Color | |
uint8 | IndexForColor (rgb_color color) |
Returns the 8-bit color index that most closely matches a 32-bit color. | |
uint8 | IndexForColor (uint8 red, uint8 green, uint8 blue, uint8 alpha=255) |
Returns the 8-bit color index that most closely matches a set of red, green, blue, and alpha values. | |
rgb_color | ColorForIndex (uint8 index) |
Gets the 32-bit color representation of an 8-bit color index. | |
uint8 | InvertIndex (uint8 index) |
Gets the "Inversion" of an 8-bit color index. | |
const color_map * | ColorMap () |
Gets the color_map of the BScreen. | |
Bitmap | |
status_t | GetBitmap (BBitmap **_bitmap, bool drawCursor=true, BRect *frame=NULL) |
Allocates a BBitmap and copies the contents of the screen into it. | |
status_t | ReadBitmap (BBitmap *bitmap, bool drawCursor=true, BRect *frame=NULL) |
Copies the contents of the screen into a BBitmap. | |
Desktop Color | |
rgb_color | DesktopColor () |
Gets the background color of the current workspace. | |
rgb_color | DesktopColor (uint32 workspace) |
Gets the background color of the specified workspace. | |
void | SetDesktopColor (rgb_color color, bool stick=true) |
Set the background color of the current workspace. | |
void | SetDesktopColor (rgb_color color, uint32 workspace, bool stick=true) |
Set the background color of the specified workspace. | |
Display Mode | |
The following methods retrieve and alter the display_mode structure of a screen. The display_mode structure contains screen size, pixel depth, and display timings settings. | |
status_t | ProposeMode (display_mode *target, const display_mode *low, const display_mode *high) |
Adjust the target mode to make it a supported mode. | |
status_t | GetModeList (display_mode **_modeList, uint32 *_count) |
Allocates and returns a list of the display modes supported by the graphics card into _modeList. | |
status_t | GetMode (display_mode *mode) |
Fills out the display_mode struct from the current workspace. | |
status_t | GetMode (uint32 workspace, display_mode *mode) |
Fills out the display_mode struct from the specified workspace. | |
status_t | SetMode (display_mode *mode, bool makeDefault=false) |
Sets the screen in the current workspace to the given mode. | |
status_t | SetMode (uint32 workspace, display_mode *mode, bool makeDefault=false) |
Set the screen in the specified workspace to the given mode. | |
Display and Graphics Card Info | |
status_t | GetDeviceInfo (accelerant_device_info *info) |
Fills out the info struct with information about a graphics card. | |
status_t | GetMonitorInfo (monitor_info *info) |
Fills out the info struct with information about a monitor. | |
status_t | GetPixelClockLimits (display_mode *mode, uint32 *_low, uint32 *_high) |
Gets the minimum and maximum pixel clock rates that are possible for the specified mode. | |
status_t | GetTimingConstraints (display_timing_constraints *timingConstraints) |
Fills out the constraints structure with the timing constraints of the current display mode. | |
VESA Display Power Management Signaling Settings | |
VESA Display Power Management Signaling (or DPMS) is a standard from the VESA consortium for managing the power usage of displays through the graphics card. DPMS allows you to shut off the display after the computer has been unused for some time to save power. DPMS states include:
Power usage in each of the above states depends on the monitor used. CRT monitors typically receive larger power savings than LCD monitors in low-power states. | |
status_t | SetDPMS (uint32 state) |
Sets the VESA Display Power Management Signaling (DPMS) state for the display. | |
uint32 | DPMSState () |
Gets the current VESA Display Power Management Signaling (DPMS) state of the screen. | |
uint32 | DPMSCapabilites () |
Gets the VESA Display Power Management Signaling (DPMS) modes that the display supports as a bit mask. | |
The BScreen class provides methods to retrieve and change display settings.
Each BScreen object describes one display connected to the computer. Multiple BScreen objects can represent the same physical display.
B_MAIN_SCREEN_ID
contains the origin in its top left corner. Additional displays, when they become supported, will extend the coordinates of the main screen.Some utility methods provided by this class are ColorSpace() to get the color space of the screen, Frame() to get the frame rectangle, and ID() to get the identifier of the screen.
Methods to convert between 8-bit and 32-bit colors are provided by IndexForColor() and ColorForIndex().
You can also use this class to take a screenshot of the entire screen or a particular portion of it. To take a screenshot use either the GetBitmap() or ReadBitmap() method.
Furthermore, you can use this class get and set the background color of a workspace. To get the background color call DesktopColor() or to set the background color use SetDesktopColor().
This class provides methods to get and set the resolution, pixel depth, and color map of a display. To get a list of the display modes supported by the graphics card use the GetModeList() method. You can get and set the screen resolution by calling the GetMode() and SetMode() methods. The color map of the display can be retrieved by calling the ColorMap() method.
You can use this class to get information about the graphics card and monitor connected to the computer by calling the GetDeviceInfo() and GetMonitorInfo() methods.
VESA Display Power Management Signaling support allow you to put the monitor into a low-power mode. Call DPMSCapabilites() to check what modes are supported by your monitor. DPMSState() tells you what state your monitor is currently in and SetDPMS() allows you to change it.
BScreen::BScreen | ( | screen_id | id = B_MAIN_SCREEN_ID | ) |
Creates a BScreen object which represents the display connected to the computer with the given screen_id.
In the current implementation, there is only one display (B_MAIN_SCREEN_ID
). To be sure that the object was constructed correctly, call IsValid().
id | The screen_id of the screen to create a BScreen object from. |
BScreen::BScreen | ( | BWindow * | window | ) |
BScreen::~BScreen | ( | ) |
Frees the resources used by the BScreen object and unlocks the screen.
Gets the 32-bit color representation of an 8-bit color index.
index | The 8-bit color index to convert to a 32-bit color. |
const color_map * BScreen::ColorMap | ( | ) |
color_space BScreen::ColorSpace | ( | ) |
Returns the color_space of the display.
B_CMAP8
, B_RGB15
, B_RGB32
, or B_NO_COLOR_SPACE
if the BScreen object is invalid.rgb_color BScreen::DesktopColor | ( | ) |
Gets the background color of the current workspace.
Gets the background color of the specified workspace.
workspace | The workspace index to get the desktop background color of. |
uint32 BScreen::DPMSCapabilites | ( | ) |
Gets the VESA Display Power Management Signaling (DPMS) modes that the display supports as a bit mask.
B_DPMS_ON
is worth 1B_DPMS_STAND_BY
is worth 2B_DPMS_SUSPEND
is worth 4B_DPMS_OFF
is worth 8uint32 BScreen::DPMSState | ( | ) |
Gets the current VESA Display Power Management Signaling (DPMS) state of the screen.
BRect BScreen::Frame | ( | ) |
Gets the frame of the screen in the screen's coordinate system.
For example if the BScreen object points to the main screen with a resolution of 1,366x768 then this method returns BRect(0.0, 0.0, 1365.0, 767.0). If the BScreen object is invalid then this method returns an empty rectangle i.e. BRect(0.0, 0.0, 0.0, 0.0)
You can set the frame programmatically by calling the SetMode() method.
Allocates a BBitmap and copies the contents of the screen into it.
_bitmap | A pointer to a BBitmap pointer where this method will store the contents of the display. |
drawCursor | Specifies whether or not to draw the cursor. |
bounds | Specifies the screen area that you want copied. If bounds is NULL then the entire screen is copied. |
B_OK
if the operation was successful, B_ERROR
otherwise.status_t BScreen::GetDeviceInfo | ( | accelerant_device_info * | info | ) |
Fills out the info struct with information about a graphics card.
info | An accelerant_device_info struct to store the device info. |
B_OK | if the operation was successful. |
B_BAD_VALUE | if info is invalid. |
B_ERROR | for all other errors. |
status_t BScreen::GetMode | ( | display_mode * | mode | ) |
Fills out the display_mode struct from the current workspace.
mode | A pointer to a display_mode struct to copy into. |
B_OK | if the operation was successful. |
B_BAD_VALUE | if mode is invalid. |
B_ERROR | for all other errors. |
Fills out the display_mode struct from the specified workspace.
workspace | The index of the workspace to query. |
mode | A pointer to a display_mode structure to copy into. |
B_OK | if the operation was successful |
B_BAD_VALUE | if mode is invalid. |
B_ERROR | for all other errors. |
Allocates and returns a list of the display modes supported by the graphics card into _modeList.
_modeList | A pointer to a display_mode pointer, where the function will allocate an array of display_mode structures. |
_count | A pointer to an integer used to store the count of available display modes. |
B_OK | if the operation was successful. |
B_ERROR | for all other errors. |
status_t BScreen::GetMonitorInfo | ( | monitor_info * | info | ) |
Fills out the info struct with information about a monitor.
info | A monitor_info struct to store the monitor info. |
B_OK | if the operation was successful. |
B_BAD_VALUE | if info is invalid. |
B_ERROR | for all other errors. |
Gets the minimum and maximum pixel clock rates that are possible for the specified mode.
mode | A pointer to a display_mode structure. |
_low | A pointer to a uint32 where the method stores the lowest available pixel clock. |
_high | A pointer to a uint32 where the method stores the highest available pixel clock. |
B_OK | if the operation was successful. |
B_BAD_VALUE | if mode, low, or high is invalid. |
B_ERROR | for all other errors. |
status_t BScreen::GetTimingConstraints | ( | display_timing_constraints * | constraints | ) |
Fills out the constraints structure with the timing constraints of the current display mode.
constraints | A pointer to a display_timing_constraints structure to store the timing constraints. |
B_OK | if the operation was successful. |
B_BAD_VALUE | if constraints is invalid. |
B_ERROR | for all other errors. |
screen_id BScreen::ID | ( | ) |
Gets the identifier of the display.
In the current implementation this method returns B_MAIN_SCREEN_ID
even if the object is invalid.
Returns the 8-bit color index that most closely matches a 32-bit color.
color | The 32-bit color to get the 8-bit index of. |
References rgb_color::alpha, rgb_color::blue, rgb_color::green, IndexForColor(), and rgb_color::red.
Referenced by IndexForColor().
Returns the 8-bit color index that most closely matches a set of red, green, blue, and alpha values.
red | The red value. |
green | The green value. |
blue | The blue value. |
alpha | The alpha value. |
Gets the "Inversion" of an 8-bit color index.
Inverted colors are useful for highlighting.
index | The 8-bit color index. |
bool BScreen::IsValid | ( | ) |
status_t BScreen::ProposeMode | ( | display_mode * | target, |
const display_mode * | low, | ||
const display_mode * | high | ||
) |
Adjust the target mode to make it a supported mode.
The list of supported modes for the graphics card is supplied by the GetModeList() method.
target | The mode you want adjust. |
low | The lower display mode limit. |
high | The higher display mode limit. |
B_OK | if target is supported and falls within the low and high limits. |
B_BAD_VALUE | if target is supported but does not fall within the low and high limits. |
B_ERROR | if the target mode isn't supported. |
Copies the contents of the screen into a BBitmap.
bitmap | A pointer to a pre-allocated BBitmap where this method will store the contents of the display. |
drawCursor | Specifies whether or not to draw the cursor. |
bounds | Specifies the screen area that you want copied. If bounds is NULL then the entire screen is copied. |
B_OK
if the operation was successful, B_ERROR
otherwise.void BScreen::SetDesktopColor | ( | rgb_color | color, |
bool | stick = true |
||
) |
Set the background color of the current workspace.
color | The 32-bit color to paint the desktop background. |
stick | Whether or not the color will stay after a reboot. |
Set the background color of the specified workspace.
color | The 32-bit color to paint the desktop background. |
workspace | The workspace index to update. |
stick | Whether or not the color will stay after a reboot. |
Sets the VESA Display Power Management Signaling (DPMS) state for the display.
dpmsState | The DPMS state to set, valid values are:
|
B_OK
if the operation was successful, otherwise an error code.status_t BScreen::SetMode | ( | display_mode * | mode, |
bool | makeDefault = false |
||
) |
Sets the screen in the current workspace to the given mode.
mode | A pointer to a display_mode struct. |
makeDefault | Whether or not mode is set as the default. |
B_OK
if the operation was successful, B_ERROR
otherwise.Set the screen in the specified workspace to the given mode.
workspace | The index of the workspace to set the mode of. |
mode | A pointer to a display_mode struct. |
makeDefault | Whether or not the mode is set as the default for the specified workspace. |
B_OK
if the operation was successful, B_ERROR
otherwise.status_t BScreen::SetToNext | ( | ) |
Sets the BScreen object to the next display in the screen list.
B_OK
if successful, otherwise B_ERROR
.status_t BScreen::WaitForRetrace | ( | ) |
Blocks until the monitor has finished its current vertical retrace.
B_OK
or B_ERROR
if the screen object is invalid.Blocks until the monitor has finished its current vertical retrace or until timeout has expired.
timeout | The amount of time to wait before returning. |
B_OK
if the monitor has retraced in the given timeout duration, B_ERROR
otherwise.