Class: Nuklear::Style::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/nuklear/style/color.rb,
ext/nuklear/nkrb_style_color.c

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r, g, b, a = 1) ⇒ Color

defined in C attr_accessor :red, :green, :blue, :alpha attr_accessor :hue, :saturation, :value



8
9
10
11
12
13
# File 'lib/nuklear/style/color.rb', line 8

def initialize(r, g, b, a = 1)
  self.red   = r
  self.green = g
  self.blue  = b
  self.alpha = a
end

Class Method Details

.from_bytes(r, g, b, a = 255) ⇒ Object



15
16
17
# File 'lib/nuklear/style/color.rb', line 15

def self.from_bytes(r, g, b, a = 255)
  new(r / 255.0, g / 255.0, b / 255.0, a / 255.0)
end

Instance Method Details

#alphaObject



56
57
58
59
# File 'ext/nuklear/nkrb_style_color.c', line 56

VALUE nkrb_style_color_get_alpha(VALUE self) {
  NK_UNPACK(self, style);
  return DBL2NUM(style->data.color.a / 255.0);
}

#alpha=(a) ⇒ Object



50
51
52
53
54
# File 'ext/nuklear/nkrb_style_color.c', line 50

VALUE nkrb_style_color_set_alpha(VALUE self, VALUE a) {
  NK_UNPACK(self, style);
  style->data.color.a = (nk_byte) (NK_SATURATE((float) NUM2DBL(a)) * 255.0f);
  return a;
}

#blueObject



45
46
47
48
# File 'ext/nuklear/nkrb_style_color.c', line 45

VALUE nkrb_style_color_get_blue(VALUE self) {
  NK_UNPACK(self, style);
  return DBL2NUM(style->data.color.b / 255.0);
}

#blue=(b) ⇒ Object



39
40
41
42
43
# File 'ext/nuklear/nkrb_style_color.c', line 39

VALUE nkrb_style_color_set_blue(VALUE self, VALUE b) {
  NK_UNPACK(self, style);
  style->data.color.b = (nk_byte) (NK_SATURATE((float) NUM2DBL(b)) * 255.0f);
  return b;
}

#greenObject



34
35
36
37
# File 'ext/nuklear/nkrb_style_color.c', line 34

VALUE nkrb_style_color_get_green(VALUE self) {
  NK_UNPACK(self, style);
  return DBL2NUM(style->data.color.g / 255.0);
}

#green=(g) ⇒ Object



28
29
30
31
32
# File 'ext/nuklear/nkrb_style_color.c', line 28

VALUE nkrb_style_color_set_green(VALUE self, VALUE g) {
  NK_UNPACK(self, style);
  style->data.color.g = (nk_byte) (NK_SATURATE((float) NUM2DBL(g)) * 255.0f);
  return g;
}

#hueObject



70
71
72
73
74
75
# File 'ext/nuklear/nkrb_style_color.c', line 70

VALUE nkrb_style_color_get_hue(VALUE self) {
  NK_UNPACK(self, style);
  nk_byte tmp[4];
  nk_color_hsva_bv(tmp, style->data.color);
  return DBL2NUM(tmp[0] / 255.0);
}

#hue=(a) ⇒ Object



61
62
63
64
65
66
67
68
# File 'ext/nuklear/nkrb_style_color.c', line 61

VALUE nkrb_style_color_set_hue(VALUE self, VALUE a) {
  NK_UNPACK(self, style);
  nk_byte tmp[4];
  nk_color_hsva_bv(tmp, style->data.color);
  tmp[0] = (nk_byte) (NK_SATURATE((float) NUM2DBL(a)) * 255.0f);
  style->data.color = nk_hsva_bv(tmp);
  return a;
}

#inspectObject



19
20
21
# File 'lib/nuklear/style/color.rb', line 19

def inspect
  "#<#{self.class.name} red=#{red} green=#{green} blue=#{blue} alpha=#{alpha}>"
end

#redObject



23
24
25
26
# File 'ext/nuklear/nkrb_style_color.c', line 23

VALUE nkrb_style_color_get_red(VALUE self) {
  NK_UNPACK(self, style);
  return DBL2NUM(style->data.color.r / 255.0);
}

#red=(r) ⇒ Object



17
18
19
20
21
# File 'ext/nuklear/nkrb_style_color.c', line 17

VALUE nkrb_style_color_set_red(VALUE self, VALUE r) {
  NK_UNPACK(self, style);
  style->data.color.r = (nk_byte) (NK_SATURATE((float) NUM2DBL(r)) * 255.0f);
  return r;
}

#saturationObject



86
87
88
89
90
91
# File 'ext/nuklear/nkrb_style_color.c', line 86

VALUE nkrb_style_color_get_saturation(VALUE self) {
  NK_UNPACK(self, style);
  nk_byte tmp[4];
  nk_color_hsva_bv(tmp, style->data.color);
  return DBL2NUM(tmp[1] / 255.0);
}

#saturation=(a) ⇒ Object



77
78
79
80
81
82
83
84
# File 'ext/nuklear/nkrb_style_color.c', line 77

VALUE nkrb_style_color_set_saturation(VALUE self, VALUE a) {
  NK_UNPACK(self, style);
  nk_byte tmp[4];
  nk_color_hsva_bv(tmp, style->data.color);
  tmp[1] = (nk_byte) (NK_SATURATE((float) NUM2DBL(a)) * 255.0f);
  style->data.color = nk_hsva_bv(tmp);
  return a;
}

#valueObject



102
103
104
105
106
107
# File 'ext/nuklear/nkrb_style_color.c', line 102

VALUE nkrb_style_color_get_value(VALUE self) {
  NK_UNPACK(self, style);
  nk_byte tmp[4];
  nk_color_hsva_bv(tmp, style->data.color);
  return DBL2NUM(tmp[3] / 255.0);
}

#value=(a) ⇒ Object



93
94
95
96
97
98
99
100
# File 'ext/nuklear/nkrb_style_color.c', line 93

VALUE nkrb_style_color_set_value(VALUE self, VALUE a) {
  NK_UNPACK(self, style);
  nk_byte tmp[4];
  nk_color_hsva_bv(tmp, style->data.color);
  tmp[3] = (nk_byte) (NK_SATURATE((float) NUM2DBL(a)) * 255.0f);
  style->data.color = nk_hsva_bv(tmp);
  return a;
}