public void FillRectMultiColor(RectangleF rect, Color left, Color top, Color right, Color bottom) { var col_left = new Colorf(); var col_top = new Colorf(); var col_right = new Colorf(); var col_bottom = new Colorf(); ushort index; Color_fv(&col_left.R, left); Color_fv(&col_right.R, right); Color_fv(&col_top.R, top); Color_fv(&col_bottom.R, bottom); PushImage(_config._null_.texture); index = (ushort)_vertices.Count; var vtxStart = _vertices.Count; _vertices.addToEnd(4); var idxStart = AddElements(6); fixed(Vertex *vtx2 = _vertices.Data) { var vtx = vtx2 + vtxStart; fixed(short *ids2 = _elements.Data) { var idx = ids2 + idxStart; if (vtx == null || idx == null) { return; } idx[0] = (short)(index + 0); idx[1] = (short)(index + 1); idx[2] = (short)(index + 2); idx[3] = (short)(index + 0); idx[4] = (short)(index + 2); idx[5] = (short)(index + 3); vtx = nk_draw_vertex(vtx, new Vector2(rect.X, rect.Y), _config._null_.uv, col_left); vtx = nk_draw_vertex(vtx, new Vector2(rect.X + rect.Width, rect.Y), _config._null_.uv, col_top); vtx = nk_draw_vertex(vtx, new Vector2(rect.X + rect.Width, rect.Y + rect.Height), _config._null_.uv, col_right); vtx = nk_draw_vertex(vtx, new Vector2(rect.X, rect.Y + rect.Height), _config._null_.uv, col_bottom); } } }
public void PushRectUV(Vector2 a, Vector2 c, Vector2 uva, Vector2 uvc, Color color) { var uvb = new Vector2(); var uvd = new Vector2(); var b = new Vector2(); var d = new Vector2(); var col = new Colorf(); ushort index; Color_fv(&col.R, color); uvb = new Vector2(uvc.X, uva.Y); uvd = new Vector2(uva.X, uvc.Y); b = new Vector2(c.X, a.Y); d = new Vector2(a.X, c.Y); index = (ushort)_vertices.Count; var vtxStart = _vertices.Count; _vertices.addToEnd(4); var idxStart = AddElements(6); fixed(Vertex *vtx2 = _vertices.Data) { var vtx = vtx2 + vtxStart; fixed(short *ids2 = _elements.Data) { var idx = ids2 + idxStart; if (vtx == null || idx == null) { return; } idx[0] = (short)(index + 0); idx[1] = (short)(index + 1); idx[2] = (short)(index + 2); idx[3] = (short)(index + 0); idx[4] = (short)(index + 2); idx[5] = (short)(index + 3); vtx = nk_draw_vertex(vtx, a, uva, col); vtx = nk_draw_vertex(vtx, b, uvb, col); vtx = nk_draw_vertex(vtx, c, uvc, col); vtx = nk_draw_vertex(vtx, d, uvd, col); } } }
public static Color ToColor(this Colorf c) { return(new Color(c.R, c.G, c.B, c.A)); }
public static void Colorf_hsva_fv(float *hsva, Colorf _in_) { Colorf_hsva_f(&hsva[0], &hsva[1], &hsva[2], &hsva[3], (Colorf)(_in_)); }
public static void Colorf_hsva_f(float *out_h, float *out_s, float *out_v, float *out_a, Colorf _in_) { float chroma; float K = (float)(0.0f); if ((_in_.G) < (_in_.B)) { float t = (float)(_in_.G); _in_.G = (float)(_in_.B); _in_.B = (float)(t); K = (float)(-1.0f); } if ((_in_.R) < (_in_.G)) { float t = (float)(_in_.R); _in_.R = (float)(_in_.G); _in_.G = (float)(t); K = (float)(-2.0f / 6.0f - K); } chroma = (float)(_in_.R - (((_in_.G) < (_in_.B)) ? _in_.G : _in_.B)); *out_h = (float) (((K + (_in_.G - _in_.B) / (6.0f * chroma + 1e-20f)) < (0)) ? -(K + (_in_.G - _in_.B) / (6.0f * chroma + 1e-20f)) : (K + (_in_.G - _in_.B) / (6.0f * chroma + 1e-20f))); *out_s = (float)(chroma / (_in_.R + 1e-20f)); *out_v = (float)(_in_.R); *out_a = (float)(_in_.A); }
public static Color nk_hsva_f(float h, float s, float v, float a) { Colorf c = (Colorf)(nk_hsva_colorf((float)(h), (float)(s), (float)(v), (float)(a))); return((Color)(new Color((float)(c.R), (float)(c.G), (float)(c.B), (float)(c.A)))); }
public static Colorf nk_hsva_colorf(float h, float s, float v, float a) { int i; float p; float q; float t; float f; Colorf _out_ = new Colorf(); if (s <= 0.0f) { _out_.R = (float)(v); _out_.G = (float)(v); _out_.B = (float)(v); _out_.A = (float)(a); return((Colorf)(_out_)); } h = (float)(h / (60.0f / 360.0f)); i = ((int)(h)); f = (float)(h - (float)(i)); p = (float)(v * (1.0f - s)); q = (float)(v * (1.0f - (s * f))); t = (float)(v * (1.0f - s * (1.0f - f))); switch (i) { case 0: default: _out_.R = (float)(v); _out_.G = (float)(t); _out_.B = (float)(p); break; case 1: _out_.R = (float)(q); _out_.G = (float)(v); _out_.B = (float)(p); break; case 2: _out_.R = (float)(p); _out_.G = (float)(v); _out_.B = (float)(t); break; case 3: _out_.R = (float)(p); _out_.G = (float)(q); _out_.B = (float)(v); break; case 4: _out_.R = (float)(t); _out_.G = (float)(p); _out_.B = (float)(v); break; case 5: _out_.R = (float)(v); _out_.G = (float)(p); _out_.B = (float)(q); break; } _out_.A = (float)(a); return((Colorf)(_out_)); }
public static Colorf ColorPicker(this NuklearContext ctx, Colorf color, int fmt) { ColorPick(ctx, &color, fmt); return(color); }
public void FillPolyConvex(Color color, int aliasing) { var col = new Colorf(); var col_trans = new Colorf(); var points_count = (ulong)_points.Count; if (_points.Count < 3) { return; } color.A = (byte)(color.A * _config.global_alpha); Color_fv(&col.R, color); col_trans = col; col_trans.A = 0; if (aliasing == NK_ANTI_ALIASING_ON) { var i = (ulong)0; var i0 = (ulong)0; var i1 = (ulong)0; var AA_SIZE = 1.0f; var index = (ulong)_vertices.Count; var idx_count = (points_count - 2) * 3 + points_count * 6; var vtx_count = points_count * 2; var vtxStart = _vertices.Count; _vertices.addToEnd((int)vtx_count); var idxStart = AddElements((int)idx_count); fixed(Vertex *vtx2 = _vertices.Data) { var vtx = vtx2 + vtxStart; fixed(short *ids2 = _elements.Data) { var ids = ids2 + idxStart; var vtx_inner_idx = (uint)(index + 0); var vtx_outer_idx = (uint)(index + 1); if (vtx == null || ids == null) { return; } var normalsStart = _normals.Count; _normals.addToEnd((int)points_count); fixed(Vector2 *normals2 = _normals.Data) { var normals = normals2 + normalsStart; for (i = (ulong)2; i < points_count; i++) { ids[0] = (short)vtx_inner_idx; ids[1] = (short)(vtx_inner_idx + ((i - 1) << 1)); ids[2] = (short)(vtx_inner_idx + (i << 1)); ids += 3; } for (i0 = points_count - 1, i1 = (ulong)0; i1 < points_count; i0 = i1++) { var p0 = _points[i0]; var p1 = _points[i1]; var diff = new Vector2(p1.X - p0.X, p1.Y - p0.Y); var len = diff.X * diff.X + diff.Y * diff.Y; if (len != 0.0f) { len = nk_inv_sqrt(len); } else { len = 1.0f; } diff = new Vector2(diff.X * len, diff.Y * len); normals[i0].X = diff.Y; normals[i0].Y = -diff.X; } for (i0 = points_count - 1, i1 = (ulong)0; i1 < points_count; i0 = i1++) { var uv = _config._null_.uv; var n0 = normals[i0]; var n1 = normals[i1]; var dm = new Vector2(new Vector2(n0.X + n1.X, n0.Y + n1.Y).X * 0.5f, new Vector2(n0.X + n1.X, n0.Y + n1.Y).Y * 0.5f); var dmr2 = dm.X * dm.X + dm.Y * dm.Y; if (dmr2 > 0.000001f) { var scale = 1.0f / dmr2; scale = scale < 100.0f ? scale : 100.0f; dm = new Vector2(dm.X * scale, dm.Y * scale); } dm = new Vector2(dm.X * (AA_SIZE * 0.5f), dm.Y * (AA_SIZE * 0.5f)); vtx = nk_draw_vertex(vtx, new Vector2(_points[i1].X - dm.X, _points[i1].Y - dm.Y), uv, col); vtx = nk_draw_vertex(vtx, new Vector2(_points[i1].X + dm.X, _points[i1].Y + dm.Y), uv, col_trans); ids[0] = (short)(vtx_inner_idx + (i1 << 1)); ids[1] = (short)(vtx_inner_idx + (i0 << 1)); ids[2] = (short)(vtx_outer_idx + (i0 << 1)); ids[3] = (short)(vtx_outer_idx + (i0 << 1)); ids[4] = (short)(vtx_outer_idx + (i1 << 1)); ids[5] = (short)(vtx_inner_idx + (i1 << 1)); ids += 6; } } } } _normals.reset(); } else { var i = (ulong)0; var index = (ulong)_vertices.Count; var idx_count = (points_count - 2) * 3; var vtx_count = points_count; var vtxStart = _vertices.Count; _vertices.addToEnd((int)vtx_count); var idxStart = AddElements((int)idx_count); fixed(Vertex *vtx2 = _vertices.Data) { var vtx = vtx2 + vtxStart; fixed(short *ids2 = _elements.Data) { var ids = ids2 + idxStart; if (vtx == null || ids == null) { return; } for (i = (ulong)0; i < vtx_count; ++i) { vtx = nk_draw_vertex(vtx, _points[i], _config._null_.uv, col); } for (i = (ulong)2; i < points_count; ++i) { ids[0] = (short)index; ids[1] = (short)(index + i - 1); ids[2] = (short)(index + i); ids += 3; } } } } }
public void StrokePolyLine(Color color, int closed, float thickness, int aliasing) { ulong count; int thick_line; var points_count = (ulong)_points.Count; var col = new Colorf(); var col_trans = new Colorf(); if (points_count < 2) { return; } color.A = (byte)(color.A * _config.global_alpha); count = points_count; if (closed == 0) { count = points_count - 1; } thick_line = thickness > 1.0f ? 1 : 0; color.A = (byte)(color.A * _config.global_alpha); Color_fv(&col.R, color); col_trans = col; col_trans.A = 0; if (aliasing == NK_ANTI_ALIASING_ON) { var AA_SIZE = 1.0f; var i1 = (ulong)0; var index = (ulong)_vertices.Count; var idx_count = thick_line != 0 ? count * 18 : count * 12; var vtx_count = thick_line != 0 ? points_count * 4 : points_count * 3; var vtxStart = _vertices.Count; _vertices.addToEnd((int)vtx_count); var idxStart = AddElements((int)idx_count); Vector2 *temp; var points_total = (thick_line != 0 ? 5 : 3) * (int)points_count; var normalsStart = _normals.Count; _normals.addToEnd(points_total); fixed(Vector2 *normals2 = _normals.Data) { var normals = normals2 + normalsStart; fixed(Vertex *vtx2 = _vertices.Data) { var vtx = vtx2 + vtxStart; fixed(short *ids2 = _elements.Data) { var ids = ids2 + idxStart; if (normals == null) { return; } temp = normals + points_count; for (i1 = (ulong)0; i1 < count; ++i1) { var i2 = i1 + 1 == points_count ? 0 : i1 + 1; var diff = new Vector2(_points[i2].X - _points[i1].X, _points[i2].Y - _points[i1].Y); float len; len = diff.X * diff.X + diff.Y * diff.Y; if (len != 0.0f) { len = nk_inv_sqrt(len); } else { len = 1.0f; } diff = new Vector2(diff.X * len, diff.Y * len); normals[i1].X = diff.Y; normals[i1].Y = -diff.X; } if (closed == 0) { normals[points_count - 1] = normals[points_count - 2]; } if (thick_line == 0) { ulong idx1; ulong i; if (closed == 0) { var d = new Vector2(); temp[0] = new Vector2( _points[0].X + new Vector2(normals[0].X * AA_SIZE, normals[0].Y * AA_SIZE) .X, _points[0].Y + new Vector2(normals[0].X * AA_SIZE, normals[0].Y * AA_SIZE) .Y); temp[1] = new Vector2( _points[0].X - new Vector2(normals[0].X * AA_SIZE, normals[0].Y * AA_SIZE) .X, _points[0].Y - new Vector2(normals[0].X * AA_SIZE, normals[0].Y * AA_SIZE) .Y); d = new Vector2(normals[points_count - 1].X * AA_SIZE, normals[points_count - 1].Y * AA_SIZE); temp[(points_count - 1) * 2 + 0] = new Vector2(_points[points_count - 1].X + d.X, _points[points_count - 1].Y + d.Y); temp[(points_count - 1) * 2 + 1] = new Vector2(_points[points_count - 1].X - d.X, _points[points_count - 1].Y - d.Y); } idx1 = index; for (i1 = (ulong)0; i1 < count; i1++) { var dm = new Vector2(); float dmr2; var i2 = i1 + 1 == points_count ? 0 : i1 + 1; var idx2 = i1 + 1 == points_count ? index : idx1 + 3; dm = new Vector2( new Vector2(normals[i1].X + normals[i2].X, normals[i1].Y + normals[i2].Y).X * 0.5f, new Vector2(normals[i1].X + normals[i2].X, normals[i1].Y + normals[i2].Y).Y * 0.5f); dmr2 = dm.X * dm.X + dm.Y * dm.Y; if (dmr2 > 0.000001f) { var scale = 1.0f / dmr2; scale = 100.0f < scale ? 100.0f : scale; dm = new Vector2(dm.X * scale, dm.Y * scale); } dm = new Vector2(dm.X * AA_SIZE, dm.Y * AA_SIZE); temp[i2 * 2 + 0] = new Vector2(_points[i2].X + dm.X, _points[i2].Y + dm.Y); temp[i2 * 2 + 1] = new Vector2(_points[i2].X - dm.X, _points[i2].Y - dm.Y); ids[0] = (short)(idx2 + 0); ids[1] = (short)(idx1 + 0); ids[2] = (short)(idx1 + 2); ids[3] = (short)(idx1 + 2); ids[4] = (short)(idx2 + 2); ids[5] = (short)(idx2 + 0); ids[6] = (short)(idx2 + 1); ids[7] = (short)(idx1 + 1); ids[8] = (short)(idx1 + 0); ids[9] = (short)(idx1 + 0); ids[10] = (short)(idx2 + 0); ids[11] = (short)(idx2 + 1); ids += 12; idx1 = idx2; } for (i = (ulong)0; i < points_count; ++i) { var uv = _config._null_.uv; vtx = nk_draw_vertex(vtx, _points[i], uv, col); vtx = nk_draw_vertex(vtx, temp[i * 2 + 0], uv, col_trans); vtx = nk_draw_vertex(vtx, temp[i * 2 + 1], uv, col_trans); } } else { ulong idx1; ulong i; var half_inner_thickness = (thickness - AA_SIZE) * 0.5f; if (closed == 0) { var d1 = new Vector2(normals[0].X * (half_inner_thickness + AA_SIZE), normals[0].Y * (half_inner_thickness + AA_SIZE)); var d2 = new Vector2(normals[0].X * half_inner_thickness, normals[0].Y * half_inner_thickness); temp[0] = new Vector2(_points[0].X + d1.X, _points[0].Y + d1.Y); temp[1] = new Vector2(_points[0].X + d2.X, _points[0].Y + d2.Y); temp[2] = new Vector2(_points[0].X - d2.X, _points[0].Y - d2.Y); temp[3] = new Vector2(_points[0].X - d1.X, _points[0].Y - d1.Y); d1 = new Vector2(normals[points_count - 1].X * (half_inner_thickness + AA_SIZE), normals[points_count - 1].Y * (half_inner_thickness + AA_SIZE)); d2 = new Vector2(normals[points_count - 1].X * half_inner_thickness, normals[points_count - 1].Y * half_inner_thickness); temp[(points_count - 1) * 4 + 0] = new Vector2(_points[points_count - 1].X + d1.X, _points[points_count - 1].Y + d1.Y); temp[(points_count - 1) * 4 + 1] = new Vector2(_points[points_count - 1].X + d2.X, _points[points_count - 1].Y + d2.Y); temp[(points_count - 1) * 4 + 2] = new Vector2(_points[points_count - 1].X - d2.X, _points[points_count - 1].Y - d2.Y); temp[(points_count - 1) * 4 + 3] = new Vector2(_points[points_count - 1].X - d1.X, _points[points_count - 1].Y - d1.Y); } idx1 = index; for (i1 = (ulong)0; i1 < count; ++i1) { var dm_out = new Vector2(); var dm_in = new Vector2(); var i2 = i1 + 1 == points_count ? 0 : i1 + 1; var idx2 = i1 + 1 == points_count ? index : idx1 + 4; var dm = new Vector2( new Vector2(normals[i1].X + normals[i2].X, normals[i1].Y + normals[i2].Y).X * 0.5f, new Vector2(normals[i1].X + normals[i2].X, normals[i1].Y + normals[i2].Y).Y * 0.5f); var dmr2 = dm.X * dm.X + dm.Y * dm.Y; if (dmr2 > 0.000001f) { var scale = 1.0f / dmr2; scale = 100.0f < scale ? 100.0f : scale; dm = new Vector2(dm.X * scale, dm.Y * scale); } dm_out = new Vector2(dm.X * (half_inner_thickness + AA_SIZE), dm.Y * (half_inner_thickness + AA_SIZE)); dm_in = new Vector2(dm.X * half_inner_thickness, dm.Y * half_inner_thickness); temp[i2 * 4 + 0] = new Vector2(_points[i2].X + dm_out.X, _points[i2].Y + dm_out.Y); temp[i2 * 4 + 1] = new Vector2(_points[i2].X + dm_in.X, _points[i2].Y + dm_in.Y); temp[i2 * 4 + 2] = new Vector2(_points[i2].X - dm_in.X, _points[i2].Y - dm_in.Y); temp[i2 * 4 + 3] = new Vector2(_points[i2].X - dm_out.X, _points[i2].Y - dm_out.Y); ids[0] = (short)(idx2 + 1); ids[1] = (short)(idx1 + 1); ids[2] = (short)(idx1 + 2); ids[3] = (short)(idx1 + 2); ids[4] = (short)(idx2 + 2); ids[5] = (short)(idx2 + 1); ids[6] = (short)(idx2 + 1); ids[7] = (short)(idx1 + 1); ids[8] = (short)(idx1 + 0); ids[9] = (short)(idx1 + 0); ids[10] = (short)(idx2 + 0); ids[11] = (short)(idx2 + 1); ids[12] = (short)(idx2 + 2); ids[13] = (short)(idx1 + 2); ids[14] = (short)(idx1 + 3); ids[15] = (short)(idx1 + 3); ids[16] = (short)(idx2 + 3); ids[17] = (short)(idx2 + 2); ids += 18; idx1 = idx2; } for (i = (ulong)0; i < points_count; ++i) { var uv = _config._null_.uv; vtx = nk_draw_vertex(vtx, temp[i * 4 + 0], uv, col_trans); vtx = nk_draw_vertex(vtx, temp[i * 4 + 1], uv, col); vtx = nk_draw_vertex(vtx, temp[i * 4 + 2], uv, col); vtx = nk_draw_vertex(vtx, temp[i * 4 + 3], uv, col_trans); } } _normals.reset(); } } } } else { var i1 = (ulong)0; var idx = (ulong)_vertices.Count; var idx_count = count * 6; var vtx_count = count * 4; var vtxStart = _vertices.Count; _vertices.addToEnd((int)vtx_count); var idxStart = AddElements((int)idx_count); fixed(Vertex *vtx2 = _vertices.Data) { var vtx = vtx2 + vtxStart; fixed(short *ids2 = _elements.Data) { var ids = ids2 + idxStart; for (i1 = (ulong)0; i1 < count; ++i1) { float dx; float dy; var uv = _config._null_.uv; var i2 = i1 + 1 == points_count ? 0 : i1 + 1; var p1 = _points[i1]; var p2 = _points[i2]; var diff = new Vector2(p2.X - p1.X, p2.Y - p1.Y); float len; len = diff.X * diff.X + diff.Y * diff.Y; if (len != 0.0f) { len = nk_inv_sqrt(len); } else { len = 1.0f; } diff = new Vector2(diff.X * len, diff.Y * len); dx = diff.X * (thickness * 0.5f); dy = diff.Y * (thickness * 0.5f); vtx = nk_draw_vertex(vtx, new Vector2(p1.X + dy, p1.Y - dx), uv, col); vtx = nk_draw_vertex(vtx, new Vector2(p2.X + dy, p2.Y - dx), uv, col); vtx = nk_draw_vertex(vtx, new Vector2(p2.X - dy, p2.Y + dx), uv, col); vtx = nk_draw_vertex(vtx, new Vector2(p1.X - dy, p1.Y + dx), uv, col); ids[0] = (short)(idx + 0); ids[1] = (short)(idx + 1); ids[2] = (short)(idx + 2); ids[3] = (short)(idx + 0); ids[4] = (short)(idx + 2); ids[5] = (short)(idx + 3); ids += 6; idx += 4; } } } } }