MCPcopy Create free account
hub / github.com/Tom94/tev / draw

Method draw

src/ImageButton.cpp:148–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146}
147
148void ImageButton::draw(NVGcontext* ctx) {
149 Widget::draw(ctx);
150
151 if (mCaptionTextBox->visible()) {
152 return;
153 }
154
155 if (mIsReference) {
156 nvgBeginPath(ctx);
157 nvgRect(ctx, m_pos.x(), m_pos.y(), m_size.x(), m_size.y());
158 nvgFillColor(ctx, REFERENCE_COLOR);
159 nvgFill(ctx);
160 }
161
162 // Fill the button with color.
163 if (mIsSelected || m_mouse_focus) {
164 nvgBeginPath(ctx);
165
166 if (mIsReference) {
167 nvgRect(ctx, m_pos.x() + 2, m_pos.y() + 2, m_size.x() - 4, m_size.y() - 4);
168 } else {
169 nvgRect(ctx, m_pos.x(), m_pos.y(), m_size.x(), m_size.y());
170 }
171
172 nvgFillColor(ctx, mIsSelected ? IMAGE_COLOR : Color(1.0f, 0.1f));
173 nvgFill(ctx);
174 }
175
176 const string idString = to_string(mId);
177 if (mHighlightBegin == 0 && mHighlightEnd == 0 && m_size.x() >= preferred_size_impl(ctx).x()) {
178 mCutoff = 0;
179 } else if (m_size != mSizeForWhichCutoffWasComputed) {
180 mCutoff = 0;
181
182 nvgFontSize(ctx, m_font_size + 2);
183 nvgFontFace(ctx, "sans-bold");
184 const float idSize = nvgTextBounds(ctx, 0, 0, idString.data(), idString.data() + idString.size(), nullptr);
185
186 vector<size_t> codePointOffsets;
187 for (size_t i = 0; i < mCaption.size(); i += codePointLength(mCaption[i])) {
188 codePointOffsets.push_back(i);
189 }
190
191 const auto boundsView = codePointOffsets | views::transform([&, ctx](size_t offset) { return getCaptionWidth(ctx, offset); });
192
193 const auto it = ranges::lower_bound(boundsView, m_size.x() - 25 - idSize, greater{});
194 if (it != boundsView.end()) {
195 mCutoff = codePointOffsets.at(distance(boundsView.begin(), it));
196 }
197
198 mSizeForWhichCutoffWasComputed = m_size;
199 }
200
201 // Image name
202
203 const Vector2f center = Vector2f{m_pos} + Vector2f{m_size} * 0.5f;
204 const Vector2f bottomRight = Vector2f{m_pos} + Vector2f{m_size};
205 Vector2f textPos{bottomRight.x() - 5, center.y() + 0.5f * (m_font_size + 1)};

Callers

nothing calls this directly

Calls 5

ColorClass · 0.85
codePointLengthFunction · 0.85
dataMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected