tbx  0.7.6
modeinfo.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #ifndef tbx_MODEINFO_H_
26 #define tbx_MODEINFO_H_
27 
28 #include "kernel.h"
29 #include "swis.h"
30 #include "point.h"
31 #include "size.h"
32 
33 namespace tbx
34 {
35 
43 class ModeInfo
44 {
45  public:
49  ModeInfo() {_mode = -1;};
55  ModeInfo(int mode) {_mode = mode;};
56 
62  void mode(int mode = -1) {_mode = mode;};
63 
74  static int screen_mode();
75 
79  int mode() const {return _mode;};
80 
86  inline int colours() const;
87 
98  inline Point eig() const;
99 
105  inline Size screen_unit() const;
106 
112  inline Size pixel_size() const;
118  inline Size screen_size() const;
119 
120  protected:
124  int _mode;
125 };
126 
127 inline int ModeInfo::colours() const
128 {
129  int colours;
130  _swix(OS_ReadModeVariable,_IN(0) | _IN(1) | _OUT(2), _mode, 3, &colours);
131  if (colours == 63) colours = 255;
132  return (colours+1);
133 }
134 
135 inline Point ModeInfo::eig() const
136 {
137  int x,y;
138  _swix(OS_ReadModeVariable,_IN(0) | _IN(1) | _OUT(2), _mode, 4, &x);
139  _swix(OS_ReadModeVariable,_IN(0) | _IN(1) | _OUT(2), _mode, 5, &y);
140  return Point(x,y);
141 }
142 
144 {
145  int x,y;
146  _swix(OS_ReadModeVariable,_IN(0) | _IN(1) | _OUT(2), _mode, 4, &x);
147  _swix(OS_ReadModeVariable,_IN(0) | _IN(1) | _OUT(2), _mode, 5, &y);
148  return Size((1<<x),(1<<y));
149 }
150 
152 {
153  int x,y;
154  _swix(OS_ReadModeVariable,_IN(0) | _IN(1) | _OUT(2), _mode, 11, &x);
155  _swix(OS_ReadModeVariable,_IN(0) | _IN(1) | _OUT(2), _mode, 12, &y);
156  return Size(x+1,y+1);
157 }
158 
160 {
161  int eig, x,y;
162  _swix(OS_ReadModeVariable,_IN(0) | _IN(1) | _OUT(2), _mode, 4, &eig);
163  _swix(OS_ReadModeVariable,_IN(0) | _IN(1) | _OUT(2), _mode, 11, &x);
164  x = (x + 1) << eig;
165  _swix(OS_ReadModeVariable,_IN(0) | _IN(1) | _OUT(2), _mode, 5, &eig);
166  _swix(OS_ReadModeVariable,_IN(0) | _IN(1) | _OUT(2), _mode, 12, &y);
167  y = (y + 1) << eig;
168 
169  return Size(x,y);
170 }
171 
173 {
174  int mode = 0;
175  _swix(OS_ScreenMode, _IN(0)|_OUT(1), 1, &mode);
176  return mode;
177 }
178 
179 };
180 
181 #endif
tbx::ModeInfo::ModeInfo
ModeInfo()
Constructor to retrieve information about the current screen mode.
Definition: modeinfo.h:49
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::ModeInfo::pixel_size
Size pixel_size() const
Get the screen size in pixels.
Definition: modeinfo.h:151
tbx::ModeInfo::eig
Point eig() const
Return the eigen factors for the mode.
Definition: modeinfo.h:135
tbx::Size
Class to represent a two-dimensional size.
Definition: size.h:35
tbx::ModeInfo::mode
void mode(int mode=-1)
Set the mode to return information about.
Definition: modeinfo.h:62
tbx::ModeInfo::screen_size
Size screen_size() const
Get the screen size in OS units.
Definition: modeinfo.h:159
tbx::ModeInfo::mode
int mode() const
Get the mode number information will be returned about.
Definition: modeinfo.h:79
tbx::Point
Class to represent a position in two dimensional space.
Definition: point.h:37
tbx::ModeInfo::screen_unit
Size screen_unit() const
Get the size of one pixel in OS units.
Definition: modeinfo.h:143
tbx::ModeInfo::_mode
int _mode
Screen mode number interrogated for details.
Definition: modeinfo.h:124
tbx::ModeInfo
Class to return information on a screen mode.
Definition: modeinfo.h:44
tbx::ModeInfo::colours
int colours() const
Return the number of colours for the mode.
Definition: modeinfo.h:127
tbx::ModeInfo::ModeInfo
ModeInfo(int mode)
Constructor to retrieve information about the given screen mode.
Definition: modeinfo.h:55
tbx::ModeInfo::screen_mode
static int screen_mode()
Get to current sreen mode.
Definition: modeinfo.h:172