| 61 | } |
| 62 | |
| 63 | void draw_window(Window* window, |
| 64 | const FontMgrRef& fontMgr, |
| 65 | const FontRef& font, |
| 66 | const gfx::Point& mousePos) |
| 67 | { |
| 68 | Surface* surface = window->surface(); |
| 69 | SurfaceLock lock(surface); |
| 70 | const gfx::Rect rc = surface->bounds(); |
| 71 | |
| 72 | Paint p; |
| 73 | p.color(gfx::rgba(0, 0, 0)); |
| 74 | p.style(Paint::Fill); |
| 75 | surface->drawRect(rc, p); |
| 76 | |
| 77 | p.color(gfx::rgba(255, 255, 255)); |
| 78 | |
| 79 | // Create the text blobs just one time, and we cache them in textBlobs array |
| 80 | if (textBlobs.empty()) { |
| 81 | textBlobs.resize(N); |
| 82 | for (size_t i = 0; i < N; ++i) { |
| 83 | textBlobs[i] = TextBlob::MakeWithShaper(fontMgr, font, kLines[i]); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | gfx::RectF focusedGlyph; |
| 88 | base::codepoint_t focusedCodepoint = 0; |
| 89 | |
| 90 | gfx::PointF pos(rc.w / 2, 0); |
| 91 | for (size_t i = 0; i < N; ++i) { |
| 92 | auto& blob = textBlobs[i]; |
| 93 | gfx::PointF textPos(pos.x - blob->bounds().w / 2, pos.y); |
| 94 | |
| 95 | draw_text(surface, blob, textPos, &p); |
| 96 | |
| 97 | // Check if the mouse is over one glyph of this text blob. |
| 98 | if (!focusedCodepoint) { |
| 99 | focusedCodepoint = |
| 100 | inside_glyph_bounds(blob.get(), kLines[i], mousePos - textPos, focusedGlyph); |
| 101 | if (focusedCodepoint) |
| 102 | focusedGlyph.offset(textPos); |
| 103 | } |
| 104 | |
| 105 | pos.y += font->lineHeight() + 4; |
| 106 | } |
| 107 | |
| 108 | // Show Unicode code point of the hover char in the title bar. |
| 109 | if (focusedCodepoint) { |
| 110 | char buf[256]; |
| 111 | snprintf(buf, sizeof(buf), "%s - U+%04X", kTitle, focusedCodepoint); |
| 112 | window->setTitle(buf); |
| 113 | |
| 114 | focusedGlyph.enlarge(1.0f); |
| 115 | p.style(Paint::Style::Stroke); |
| 116 | surface->drawRect(focusedGlyph, p); |
| 117 | } |
| 118 | else { |
| 119 | window->setTitle(kTitle); |
| 120 | } |
no test coverage detected