void TBScrollBar::UpdateHandle() { // Calculate the mover size and position bool horizontal = m_axis == AXIS_X; int available_pixels = horizontal ? GetRect().w : GetRect().h; int min_thickness_pixels = MIN(GetRect().h, GetRect().w); int visible_pixels = available_pixels; if (m_max - m_min > 0 && m_visible > 0) { double visible_proportion = m_visible / (m_visible + m_max - m_min); visible_pixels = (int)(visible_proportion * available_pixels); // Limit the size of the indicator to the slider thickness so that it doesn't // become too tiny when the visible proportion is very small. visible_pixels = MAX(visible_pixels, min_thickness_pixels); m_to_pixel_factor = (double)(available_pixels - visible_pixels) / (m_max - m_min)/*+ 0.5*/; } else { m_to_pixel_factor = 0; // If we can't scroll anything, make the handle invisible visible_pixels = 0; } int pixel_pos = (int)(m_value * m_to_pixel_factor); TBRect rect; if (horizontal) rect.Set(pixel_pos, 0, visible_pixels, GetRect().h); else rect.Set(0, pixel_pos, GetRect().w, visible_pixels); m_handle.SetRect(rect); }
bool TBMessageWindow::Show(const char *title, const char *message, TBMessageWindowSettings *settings) { TBWidget *target = m_target.Get(); if (!target) return false; TBMessageWindowSettings default_settings; if (!settings) settings = &default_settings; TBWidget *root = target->GetParentRoot(); const char *source = "TBLayout: axis: y, distribution: available\n" " TBLayout: distribution: available, size: available\n" " TBSkinImage: id: 2\n" " TBEditField: multiline: 1, readonly: 1, id: 1\n" " TBLayout: distribution-position: right bottom, id: 3\n"; if (!g_widgets_reader->LoadData(GetContentRoot(), source)) return false; SetText(title); GetWidgetByIDAndType<TBSkinImage>(2)->SetSkinBg(settings->icon_skin); TBEditField *editfield = GetWidgetByIDAndType<TBEditField>(1); editfield->SetStyling(settings->styling); editfield->SetText(message); editfield->SetSkinBg(""); // Create buttons if (settings->msg == TB_MSG_OK) { AddButton("TBMessageWindow.ok", true); } else if (settings->msg == TB_MSG_OK_CANCEL) { AddButton("TBMessageWindow.ok", true); AddButton("TBMessageWindow.cancel", false); } else if (settings->msg == TB_MSG_YES_NO) { AddButton("TBMessageWindow.yes", true); AddButton("TBMessageWindow.no", false); } // Size to fit content. This will use the default size of the textfield. ResizeToFitContent(); TBRect rect = GetRect(); // Get how much we overflow the textfield has given the current width, and grow our height to show all we can. // FIX: It would be better to use adapt-to-content on the editfield to achieve the most optimal size. // At least when we do full blown multi pass size checking. rect.h += editfield->GetStyleEdit()->GetOverflowY(); // Create background dimmer if (settings->dimmer) { if (TBDimmer *dimmer = new TBDimmer) { root->AddChild(dimmer); m_dimmer.Set(dimmer); } } // Center and size to the new height TBRect bounds(0, 0, root->GetRect().w, root->GetRect().h); SetRect(rect.CenterIn(bounds).MoveIn(bounds).Clip(bounds)); root->AddChild(this); return true; }
void TBRendererBatcher::DrawBitmapTile(const TBRect &dst_rect, TBBitmap *bitmap) { AddQuadInternal(dst_rect.Offset(m_translation_x, m_translation_y), TBRect(0, 0, dst_rect.w, dst_rect.h), VER_COL_OPACITY(m_opacity), bitmap, nullptr); }
void TBRendererBatcher::DrawBitmapColored(const TBRect &dst_rect, const TBRect &src_rect, const TBColor &color, TBBitmap *bitmap) { uint32 a = (color.a * m_opacity) / 255; AddQuadInternal(dst_rect.Offset(m_translation_x, m_translation_y), src_rect, VER_COL(color.r, color.g, color.b, a), bitmap, nullptr); }