unsigned int CheckBox::drawImages(Form* form, const Rectangle& clip) { if (!_image) return 0; // Left, v-center. // TODO: Set an alignment for icons. const Rectangle& region = _image->getRegion(); const Theme::UVs& uvs = _image->getUVs(); Vector4 color = _image->getColor(); color.w *= _opacity; Vector2 pos(_viewportBounds.x, _viewportBounds.y); SpriteBatch* batch = _style->getTheme()->getSpriteBatch(); startBatch(form, batch); batch->draw(pos.x, pos.y, _viewportBounds.height, _viewportBounds.height, uvs.u1, uvs.v1, uvs.u2, uvs.v2, color, _viewportClipBounds); finishBatch(form, batch); return 1; }
unsigned int Slider::drawImages(Form* form, const Rectangle& clip) { if (!(_minImage && _maxImage && _markerImage && _trackImage)) return 0; // TODO: Vertical slider. // The slider is drawn in the center of the control (perpendicular to orientation). // The track is stretched according to orientation. // Caps and marker are not stretched. const Rectangle& minCapRegion = _minImage->getRegion(); const Rectangle& maxCapRegion = _maxImage->getRegion(); const Rectangle& markerRegion = _markerImage->getRegion(); const Rectangle& trackRegion = _trackImage->getRegion(); const Theme::UVs& minCap = _minImage->getUVs(); const Theme::UVs& maxCap = _maxImage->getUVs(); const Theme::UVs& marker = _markerImage->getUVs(); const Theme::UVs& track = _trackImage->getUVs(); Vector4 minCapColor = _minImage->getColor(); Vector4 maxCapColor = _maxImage->getColor(); Vector4 markerColor = _markerImage->getColor(); Vector4 trackColor = _trackImage->getColor(); Control::State state = getState(); minCapColor.w *= _opacity; maxCapColor.w *= _opacity; markerColor.w *= _opacity; trackColor.w *= _opacity; SpriteBatch* batch = _style->getTheme()->getSpriteBatch(); startBatch(form, batch); // Compute area to draw the slider track unsigned int fontSize = getFontSize(state); float startY, endY; if (_text.length() > 0) { if (_valueTextVisible) { // Both label and value text are visible. // Draw slider in the middle. startY = fontSize; endY = _viewportBounds.height - fontSize; } else { // Only label is visible if (getTextAlignment(state) & ALIGN_BOTTOM) { // Draw slider above label startY = 0; endY = _viewportBounds.height - fontSize; } else { // Draw slider below label startY = fontSize; endY = _viewportBounds.height; } } } else if (_valueTextVisible) { // Only value text is visible. if (_valueTextAlignment & ALIGN_BOTTOM) { // Draw slider above value text startY = 0; endY = _viewportBounds.height - fontSize; } else { // Draw slider below value text startY = fontSize; endY = _viewportBounds.height; } } else { // Only the slider track is visible startY = 0; endY = _viewportBounds.height; } // Compute midpoint of track location float midY = _viewportBounds.y + startY + (endY - startY) * 0.5f; // Draw track below the slider text Vector2 pos(_viewportBounds.x + minCapRegion.width, midY - trackRegion.height * 0.5f); batch->draw(pos.x, pos.y, _viewportBounds.width - minCapRegion.width - maxCapRegion.width, trackRegion.height, track.u1, track.v1, track.u2, track.v2, trackColor, _viewportClipBounds); // Draw min cap to the left of the track pos.y = midY - minCapRegion.height * 0.5f; pos.x = _viewportBounds.x; batch->draw(pos.x, pos.y, minCapRegion.width, minCapRegion.height, minCap.u1, minCap.v1, minCap.u2, minCap.v2, minCapColor, _viewportClipBounds); // Draw max cap to the right of the track pos.x = _viewportBounds.right() - maxCapRegion.width; batch->draw(pos.x, pos.y, maxCapRegion.width, maxCapRegion.height, maxCap.u1, maxCap.v1, maxCap.u2, maxCap.v2, maxCapColor, _viewportClipBounds); // Draw the marker at the correct position float markerPosition = (_value - _min) / (_max - _min); markerPosition *= _viewportBounds.width - markerRegion.width; pos.x = _viewportBounds.x + markerPosition; pos.y = midY - markerRegion.height * 0.5f; batch->draw(pos.x, pos.y, markerRegion.width, markerRegion.height, marker.u1, marker.v1, marker.u2, marker.v2, markerColor, _viewportClipBounds); finishBatch(form, batch); return 4; }