MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / draw_hex_code_box

Method draw_hex_code_box

servers/text_server.cpp:765–807  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

763}
764
765void TextServer::draw_hex_code_box(const RID &p_canvas, int64_t p_size, const Vector2 &p_pos, int64_t p_index, const Color &p_color) const {
766 if (p_index == 0) {
767 return;
768 }
769
770 int w = ((p_index <= 0xFF) ? 1 : ((p_index <= 0xFFFF) ? 2 : 3));
771 int sp = MAX(0, w - 1);
772 int sz = MAX(1, Math::round(p_size / 15.f));
773
774 Size2 size = Vector2(4 + 3 * w + sp, 15) * sz;
775 Point2 pos = p_pos - Point2i(0, size.y * 0.85);
776
777 // Draw frame.
778 RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(pos + Point2(0, 0), Size2(sz, size.y)), p_color);
779 RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(pos + Point2(size.x - sz, 0), Size2(sz, size.y)), p_color);
780 RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(pos + Point2(0, 0), Size2(size.x, sz)), p_color);
781 RenderingServer::get_singleton()->canvas_item_add_rect(p_canvas, Rect2(pos + Point2(0, size.y - sz), Size2(size.x, sz)), p_color);
782
783 uint8_t a = p_index & 0x0F;
784 uint8_t b = (p_index >> 4) & 0x0F;
785 uint8_t c = (p_index >> 8) & 0x0F;
786 uint8_t d = (p_index >> 12) & 0x0F;
787 uint8_t e = (p_index >> 16) & 0x0F;
788 uint8_t f = (p_index >> 20) & 0x0F;
789
790 // Draw hex code.
791 if (p_index <= 0xFF) {
792 _draw_hex_code_box_number(p_canvas, sz, pos + Point2(2, 2) * sz, b, p_color);
793 _draw_hex_code_box_number(p_canvas, sz, pos + Point2(2, 8) * sz, a, p_color);
794 } else if (p_index <= 0xFFFF) {
795 _draw_hex_code_box_number(p_canvas, sz, pos + Point2(2, 2) * sz, d, p_color);
796 _draw_hex_code_box_number(p_canvas, sz, pos + Point2(6, 2) * sz, c, p_color);
797 _draw_hex_code_box_number(p_canvas, sz, pos + Point2(2, 8) * sz, b, p_color);
798 _draw_hex_code_box_number(p_canvas, sz, pos + Point2(6, 8) * sz, a, p_color);
799 } else {
800 _draw_hex_code_box_number(p_canvas, sz, pos + Point2(2, 2) * sz, f, p_color);
801 _draw_hex_code_box_number(p_canvas, sz, pos + Point2(6, 2) * sz, e, p_color);
802 _draw_hex_code_box_number(p_canvas, sz, pos + Point2(10, 2) * sz, d, p_color);
803 _draw_hex_code_box_number(p_canvas, sz, pos + Point2(2, 8) * sz, c, p_color);
804 _draw_hex_code_box_number(p_canvas, sz, pos + Point2(6, 8) * sz, b, p_color);
805 _draw_hex_code_box_number(p_canvas, sz, pos + Point2(10, 8) * sz, a, p_color);
806 }
807}
808
809bool TextServer::shaped_text_has_visible_chars(const RID &p_shaped) const {
810 int v_size = shaped_text_get_glyph_count(p_shaped);

Callers 5

_draw_lineMethod · 0.45
_notificationMethod · 0.45
draw_glyphFunction · 0.45
_notificationMethod · 0.45
_draw_spin_sliderMethod · 0.45

Calls 5

MAXFunction · 0.85
roundFunction · 0.85
canvas_item_add_rectMethod · 0.80
Vector2Function · 0.50
Rect2Class · 0.50

Tested by

no test coverage detected