tbx  0.7.3
scalefactors.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 /*
26  * scalefactors.h
27  *
28  * Created on: 2 Nov 2010
29  * Author: alanb
30  */
31 
32 #ifndef TBX_SCALEFACTORS_H_
33 #define TBX_SCALEFACTORS_H_
34 
35 namespace tbx
36 {
46 {
47  int _xmult;
48  int _ymult;
49  int _xdiv;
50  int _ydiv;
51 public:
56  ScaleFactors() {_xmult=_ymult=_xdiv=_ydiv=1;}
65  ScaleFactors(int xm, int ym, int xd, int yd) {_xmult = xm; _ymult = ym; _xdiv = xd; _ydiv = yd;}
72  ScaleFactors(int mult, int div = 1) {_xmult = _ymult = mult; _xdiv = _ydiv = div;}
73 
77  bool is_unit() const {return (_xmult == _xdiv && _ymult == _ydiv);};
78 
82  int xmult() const {return _xmult;}
83 
90  ScaleFactors &xmult(int x) {_xmult=x;return *this;}
94  int ymult() const {return _ymult;}
101  ScaleFactors &ymult(int y) {_ymult=y;return *this;}
105  int xdiv() const {return _xdiv;}
112  ScaleFactors &xdiv(int x) {_xdiv=x;return *this;}
116  int ydiv() const {return _ydiv;}
123  ScaleFactors &ydiv(int y) {_ydiv=y;return *this;}
124 
128  int *as_array() {return &_xmult;}
132  const int *as_array() const {return &_xmult;}
133 
134 };
135 
136 }
137 
138 #endif /* TBX_SCALEFACTORS_H_ */
ScaleFactors & xmult(int x)
Set the x direction multiplier.
Definition: scalefactors.h:90
const int * as_array() const
Return 4 integer array of scale factors.
Definition: scalefactors.h:132
ScaleFactors & ymult(int y)
Set the y direction multiplier.
Definition: scalefactors.h:101
int ymult() const
Return the y direction multiplier.
Definition: scalefactors.h:94
bool is_unit() const
Returns true if scale factors do not change a value.
Definition: scalefactors.h:77
ScaleFactors(int mult, int div=1)
Constructor for common multiplier/divider in x and y directions.
Definition: scalefactors.h:72
int xmult() const
Return the x direction multiplier.
Definition: scalefactors.h:82
ScaleFactors & ydiv(int y)
Set the y direction divider.
Definition: scalefactors.h:123
int xdiv() const
Return the x direction divider.
Definition: scalefactors.h:105
ScaleFactors & xdiv(int x)
Set the x direction divider.
Definition: scalefactors.h:112
ScaleFactors(int xm, int ym, int xd, int yd)
Constructor allowing the multipliers and dividers to be specified.
Definition: scalefactors.h:65
Class for sprite ScaleFactors.
Definition: scalefactors.h:45
int ydiv() const
Return the y direction divider.
Definition: scalefactors.h:116
ScaleFactors()
Constructor that creates the unit scale factors.
Definition: scalefactors.h:56
int * as_array()
Return 4 integer array of scale factors.
Definition: scalefactors.h:128