-
Notifications
You must be signed in to change notification settings - Fork 12
Basic Data Types
These types defines most basic types with which API operates. By default most of types are derivatives from c_util
and c_geometry
types.
typedef float kScalar;
typedef c_util::pointT<kScalar> kPoint;
typedef c_util::sizeT<kScalar> kSize;
typedef c_util::rectT<kScalar> kRect;
typedef c_util::rectT<int> kRectInt;
typedef c_geometry::mat3x2<kScalar> kTransform;
kScalar
defines basic type for storing units. By default it maps to 32-bit IEEE float.
kSize
defines structure for describing dimensions (width
and height
). By default it's derived from c_util::sizeT
type template.
kRect
defines structure for describing rectangular area (left
, top
, right
and bottom
). By default it's derived from c_util::rectT
type template.
kRectInt
defines structure for describing rectangular area with integer coordinates. Typicaly it's used for describing part of image data.
kTransform
represents generic 2D transformation as 3x2 matrix (3 rows by 2 columns). By default it's derived from c_geometry::mat3x2
type template.
enum class kExtendType
{
Clamp = 0,
Wrap = 1
};
kExtendType
enum defines behaviour for gradients and bitmaps outside their bounds.
Clamp
Wrap
enum class kStrokeStyle
{
Clear = 0,
Solid = 1,
Dot = 2,
Dash = 3,
DashDot = 4,
DashDotDot = 5,
Custom = 6
};
kStrokeStyle
enum defines stroke pattern style for kStroke
object.
-
Clear
- stroke operation will not be performed. -
Solid
- stroke operation will be done using solid line. -
Dot
- stroke operation will use dot pattern (1, 1). -
Dash
- stroke operation will use dash pattern (3, 1). -
DashDot
- stroke operation will use dash-dot pattern (3, 1, 1, 1). -
DashDotDot
- stroke operation will use dash-dot-dot pattern (3, 1, 1, 1, 1, 1). -
Custom
- stroke operation will use custom pattern.
Result of applying different stroke styles can be seen in stroke styles and pens example.
enum class kCapStyle
{
Flat = 0,
Square = 1,
Round = 2
};
kCapStyle
enum defines cap style for line ends or dashes within line stroke pattern.
-
Flat
- flat cap. -
Square
- square cap. -
Round
- round cap.
Result of applying different cap styles can be seen in stroke styles and pens example.
enum class kLineJoin
{
Miter = 0,
Bevel = 1,
Round = 2
};
kLineJoin
enum defines style of line join between multiple line segments.
-
Miter
- miter join. -
Bevel
- bevel join. -
Round
- round join.
Result of applying different line joins can be seen in stroke styles and pens example.
enum class kBrushStyle
{
Clear = 0,
Solid = 1,
LinearGradient = 2,
RadialGradient = 3,
Bitmap = 4
};
kBrushStyle
enum defines brush style and affects behaviour of fill operation. It's not explicitly used to construct brush objects.
-
Clear
- fill operation will not be performed by brush of that type. -
Solid
- fill operation will be performed using solid color. -
LinearGradient
- fill operation will be performed using linear gradient. Gradient colors are defined bykGradient
object. -
RadialGradient
- fill operation will be performed using radial gradient. Gradient colors are defined bykGradient
object. -
Bitmap
- fill operation will be performed using bitmap iamge (pattern).
Result of applying solid color brush can be seen in basic filled shapes example. Result of applying different gradient brushes can be seen in gradients and gradient brushes example. Result of applyign bitmap brush can be seen in bitmaps example.
struct kFontStyle
{
enum Style {
Bold = 0x01,
Italic = 0x02,
Underline = 0x04,
Strikethrough = 0x08
};
};
kFontStyle
flags set defines style flags for font object.
-
Bold
- font will be bold. -
Italic
- font will be italic. -
Underline
- underlined font. -
Strikethrough
- striked out font.
Result of applying different flags to font can be seen in text and fonts example.
enum class kTextOrigin
{
Top = 0,
BaseLine = 1
};
kTextOrigin
enum defines origin point for single line text output.
-
Top
- origin point treated as top (top-left corner of the first glyph will be located at origin). -
BaseLine
- origin point treated as point at font baseline.
enum class kBitmapFormat
{
Color32BitAlphaPremultiplied = 1,
Mask8Bit = 2
};
kBitmapFormat
enum defines format and color components layout for bitmap data.
-
Color32BitAlphaPremultiplied
- BGRA 32 bit color (8 bit per component) with colors premultiplied by alpha value. -
Mask8Bit
- single channel 8 bit mask (alpha channel only).
struct kTextFlags
{
enum Flags
{
Multiline = 0x01,
IgnoreLineBreaks = 0x02,
MergeSpaces = 0x04,
UseTabs = 0x08,
StrictBounds = 0x10,
ClipToBounds = 0x20,
Ellipses = 0x40
};
};
kTextFlags
flags set defines possible flags for text measurement and output functions.
-
Multiline
- text might wrap to multiple lines. When this flag is not set text always treated as single line. -
IgnoreLineBreaks
- ignore line break sequences in text. This flag has effect only with multiline text, when it's set line breaks inside source string are ignored. -
MergeSpaces
- treat consecutive white space characters as single white space. -
UseTabs
- account for TAB (0x9) character and use tabulation. When this flag is not set TAB character treated as usual space character. -
StrictBounds
- indicates that bounds passed to text measurment functions are strict and can not be exceeded. -
ClipToBounds
- text measurement/output will be clipped to given bounds. -
Ellipses
- ellipses will be shown at the end of text if it doesn't fit into provided bounds.
enum class kTextHorizontalAlignment
{
Left = 0,
Center = 1,
Right = 2,
Justify = 3
};
kTextHorizontalAlignment
enum defines horizontal alignment for multiline text output.
-
Left
- text will be aligned to left side of bounding rectangle. -
Center
- text will be centered inside bounding rectangle. -
Right
- text will be aligned to right side of bounding rectangle. -
Justify
- text will be aligned to both left and right sides of bounding rectangle. This type of alignment affects size of spaces between individual words.
enum class kTextVerticalAlignment
{
Top = 0,
Middle = 1,
Bottom = 2
};
kTextVerticalAlignment
enum defines vertical alignment for multiline text output.
-
Top
- text will be aligned to top side of bounding rectangle. -
Middle
- text will be vertically centered inside bounding rectangle. -
Bottom
- text will be aligned to bottom side of bounding rectangle.
struct kColor
{
uint8_t r, g, b, a;
inline kColor();
inline kColor(const kColor source, uint8_t _a);
inline kColor(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a = 255);
inline kColor inverse() const;
inline bool operator==(const kColor color) const;
inline bool operator!=(const kColor color) const;
inline bool operator<(const kColor color) const;
static inline kColor fromHSL(int hue, int saturation, int lightness);
static kColor fromHSL(kScalar hue, kScalar saturation, kScalar lightness);
static const kColor Pink; // 255 192 203
static const kColor LightPink; // 255 182 193
static const kColor HotPink; // 255 105 180
static const kColor DeepPink; // 255 20 147
static const kColor PaleVioletRed; // 219 112 147
static const kColor MediumVioletRed; // 199 21 133
static const kColor LightSalmon; // 255 160 122
static const kColor Salmon; // 250 128 114
static const kColor DarkSalmon; // 233 150 122
static const kColor LightCoral; // 240 128 128
static const kColor IndianRed; // 205 92 92
static const kColor Crimson; // 220 20 60
static const kColor FireBrick; // 178 34 34
static const kColor DarkRed; // 139 0 0
static const kColor Red; // 255 0 0
static const kColor OrangeRed; // 255 69 0
static const kColor Tomato; // 255 99 71
static const kColor Coral; // 255 127 80
static const kColor DarkOrange; // 255 140 0
static const kColor Orange; // 255 165 0
static const kColor Yellow; // 255 255 0
static const kColor LightYellow; // 255 255 224
static const kColor LemonChiffon; // 255 250 205
static const kColor LightGoldenrodYellow; // 250 250 210
static const kColor PapayaWhip; // 255 239 213
static const kColor Moccasin; // 255 228 181
static const kColor PeachPuff; // 255 218 185
static const kColor PaleGoldenrod; // 238 232 170
static const kColor Khaki; // 240 230 140
static const kColor DarkKhaki; // 189 183 107
static const kColor Gold; // 255 215 0
static const kColor Cornsilk; // 255 248 220
static const kColor BlanchedAlmond; // 255 235 205
static const kColor Bisque; // 255 228 196
static const kColor NavajoWhite; // 255 222 173
static const kColor Wheat; // 245 222 179
static const kColor BurlyWood; // 222 184 135
static const kColor Tan; // 210 180 140
static const kColor RosyBrown; // 188 143 143
static const kColor SandyBrown; // 244 164 96
static const kColor Goldenrod; // 218 165 32
static const kColor DarkGoldenrod; // 184 134 11
static const kColor Peru; // 205 133 63
static const kColor Chocolate; // 210 105 30
static const kColor SaddleBrown; // 139 69 19
static const kColor Sienna; // 160 82 45
static const kColor Brown; // 165 42 42
static const kColor Maroon; // 128 0 0
static const kColor DarkOliveGreen; // 85 107 47
static const kColor Olive; // 128 128 0
static const kColor OliveDrab; // 107 142 35
static const kColor YellowGreen; // 154 205 50
static const kColor LimeGreen; // 50 205 50
static const kColor Lime; // 0 255 0
static const kColor LawnGreen; // 124 252 0
static const kColor Chartreuse; // 127 255 0
static const kColor GreenYellow; // 173 255 47
static const kColor SpringGreen; // 0 255 127
static const kColor MediumSpringGreen; // 0 250 154
static const kColor LightGreen; // 144 238 144
static const kColor PaleGreen; // 152 251 152
static const kColor DarkSeaGreen; // 143 188 143
static const kColor MediumSeaGreen; // 60 179 113
static const kColor SeaGreen; // 46 139 87
static const kColor ForestGreen; // 34 139 34
static const kColor Green; // 0 128 0
static const kColor DarkGreen; // 0 100 0
static const kColor MediumAquamarine; // 102 205 170
static const kColor Aqua; // 0 255 255
static const kColor Cyan; // 0 255 255
static const kColor LightCyan; // 224 255 255
static const kColor PaleTurquoise; // 175 238 238
static const kColor Aquamarine; // 127 255 212
static const kColor Turquoise; // 64 224 208
static const kColor MediumTurquoise; // 72 209 204
static const kColor DarkTurquoise; // 0 206 209
static const kColor LightSeaGreen; // 32 178 170
static const kColor CadetBlue; // 95 158 160
static const kColor DarkCyan; // 0 139 139
static const kColor Teal; // 0 128 128
static const kColor LightSteelBlue; // 176 196 222
static const kColor PowderBlue; // 176 224 230
static const kColor LightBlue; // 173 216 230
static const kColor SkyBlue; // 135 206 235
static const kColor LightSkyBlue; // 135 206 250
static const kColor DeepSkyBlue; // 0 191 255
static const kColor DodgerBlue; // 30 144 255
static const kColor CornflowerBlue; // 100 149 237
static const kColor SteelBlue; // 70 130 180
static const kColor RoyalBlue; // 65 105 225
static const kColor Blue; // 0 0 255
static const kColor MediumBlue; // 0 0 205
static const kColor DarkBlue; // 0 0 139
static const kColor Navy; // 0 0 128
static const kColor MidnightBlue; // 25 25 112
static const kColor Lavender; // 230 230 250
static const kColor Thistle; // 216 191 216
static const kColor Plum; // 221 160 221
static const kColor Violet; // 238 130 238
static const kColor Orchid; // 218 112 214
static const kColor Fuchsia; // 255 0 255
static const kColor Magenta; // 255 0 255
static const kColor MediumOrchid; // 186 85 211
static const kColor MediumPurple; // 147 112 219
static const kColor BlueViolet; // 138 43 226
static const kColor DarkViolet; // 148 0 211
static const kColor DarkOrchid; // 153 50 204
static const kColor DarkMagenta; // 139 0 139
static const kColor Purple; // 128 0 128
static const kColor Indigo; // 75 0 130
static const kColor DarkSlateBlue; // 72 61 139
static const kColor RebeccaPurple; // 102 51 153
static const kColor SlateBlue; // 106 90 205
static const kColor MediumSlateBlue; // 123 104 238
static const kColor White; // 255 255 255
static const kColor Snow; // 255 250 250
static const kColor Honeydew; // 240 255 240
static const kColor MintCream; // 245 255 250
static const kColor Azure; // 240 255 255
static const kColor AliceBlue; // 240 248 255
static const kColor GhostWhite; // 248 248 255
static const kColor WhiteSmoke; // 245 245 245
static const kColor Seashell; // 255 245 238
static const kColor Beige; // 245 245 220
static const kColor OldLace; // 253 245 230
static const kColor FloralWhite; // 255 250 240
static const kColor Ivory; // 255 255 240
static const kColor AntiqueWhite; // 250 235 215
static const kColor Linen; // 250 240 230
static const kColor LavenderBlush; // 255 240 245
static const kColor MistyRose; // 255 228 225
static const kColor Gainsboro; // 220 220 220
static const kColor LightGrey; // 211 211 211
static const kColor Silver; // 192 192 192
static const kColor DarkGray; // 169 169 169
static const kColor Gray; // 128 128 128
static const kColor DimGray; // 105 105 105
static const kColor LightSlateGray; // 119 136 153
static const kColor SlateGray; // 112 128 144
static const kColor DarkSlateGray; // 47 79 79
static const kColor Black; // 0 0 0
};
kColor
structure is used to specify RGBA color values with 8 bits per each color component. This is primary type for passing color information to kcanvas API.
Fields
-
r
- red component value. -
g
- green component value. -
b
- blue component value. -
a
- alpha value.
Built in constant values
There are several built-in named constant color values. These are standard CSS3 X11 colors.
Methods
kColor()
Construct opaque black color (0, 0, 0, 255).
kColor(const kColor source, uint8_t _a)
Construct color from existing one with different alpha value.
kColor(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a = 255)
Construct color by specifying individual components values as _r
, _g
, _b
and _a
parameters.
kColor inverse() const
Returns inverse color.
kColor fromHSL(int hue, int saturation, int lightness)
Returns color baseed on hue
, saturation
and lightness
values. Hue value should be in range 0 - 360. Saturation and lightness values should be in range 0 - 100.
kColor fromHSL(kScalar hue, kScalar saturation, kScalar lightness)
Floating point version of previos fromHSL
function. All values should be in range 0 - 1.
struct kColorReal
{
kScalar r, g, b, a;
inline kColorReal();
inline kColorReal(const kColor color);
inline kColorReal(float _r, float _g, float _b, float _a = 1.0f);
inline operator kColor() const;
};
kColorReal
is a helper struct, it is used to specify RGBA color values with 32 bit float components in 0 - 1 range. Purpose of this structure is to make conversion between integer and float color representations easier.
struct kGradientStop
{
kColor color;
kScalar position;
kGradientStop(const kColor _color, kScalar _position);
};
kGradientStop
structure is used to specify gradient stop points for kGradient
object.
Fields
-
color
- color value at given gradient stop position. -
position
- gradient stop position, must be within 0 - 1 range.
Methods
kGradientStop(const kColor _color, kScalar _position)
Construct gradient stop with specified values.
struct kFontMetrics
{
kScalar ascent;
kScalar descent;
kScalar height;
kScalar linegap;
kScalar underlinepos;
kScalar underlinewidth;
kScalar strikethroughpos;
kScalar strikethroughwidth;
kScalar capheight;
kScalar xheight;
};
kFontMetrics
structure is used to retrieve information about different font metrics.
Fields
-
ascent
- font size above base line. -
descent
- font size below base line. -
height
- total font height (equals to ascent + descent). -
linegap
- extra distance between lines of text (usually this is 0). -
underlinepos
- line position for underlined text. -
underlinewidth
- width of underline line. -
strikethroughpos
- position of strikethrough line for strikethough text. -
strikethroughwidth
- width of strikethrough line. -
capheight
- height of typical capital letter above base line (H for example). -
xheight
- height of typical lowercase letter above base line (x for example).
struct kGlyphMetrics
{
kScalar leftbearing;
kScalar advance;
kScalar rightbearing;
};
kGlyphMetrics
structure is used to retrieve information about single glyph metrics.
Fields
-
leftbearing
- distance from origin to left side of glyph's black box. -
advance
- distance from current origin to next glyph's origin. -
rightbearing
- distance from next glyph's origin to right side of current glyph's black box.
struct kTextPropertiesBase
{
kTextFlags flags;
kScalar interval;
kScalar indent;
kScalar defaulttabwidth;
};
kTextPropertiesBase
structure holds common parameters for text measurement and rendering.
Fields
-
flags
- set ofkTextFlags
. -
interval
- additional distance between lines of text (applies to multiline text rendering/measurement). -
indent
- paragraph indentation. -
defaulttabwidth
- default tabulation width (applies for text with TAB characters).
struct kTextSizeProperties : public kTextPropertiesBase
{
kSize bounds;
};
kTextSizeProperties
structure holds parameters for text measurement. It extends kTextPropertiesBase
structure.
Fields
-
bounds
- requested dimensions for measured text.
struct kTextOutProperties : public kTextPropertiesBase
{
kTextHorizontalAlignment horzalign;
kTextVerticalAlignment vertalign;
};
kTextOutProperties
structure holds parameters for paragrpah-like text rendering. It extends kTextPropertiesBase
structure.
Fields
-
horzalign
- text horizontal alignment. -
vertalign
- text vertical alignment.