void Screen::print(const Common::Point &pt, uint color, const char *formatStr, ...) { // Create the string to display va_list args; va_start(args, formatStr); Common::String str = Common::String::vformat(formatStr, args); va_end(args); // Figure out area to draw text in Common::Point pos = pt; int width_ = stringWidth(str); pos.y--; // Font is always drawing one line higher if (!pos.x) // Center text horizontally pos.x = (this->width() - width_) / 2; Common::Rect textBounds(pos.x, pos.y, pos.x + width_, pos.y + _fontHeight); if (textBounds.right > this->width()) textBounds.moveTo(this->width() - width_, textBounds.top); if (textBounds.bottom > this->height()) textBounds.moveTo(textBounds.left, this->height() - _fontHeight); // Write out the string at the given position writeString(str, Common::Point(textBounds.left, textBounds.top), color); // Copy the affected area to the screen slamRect(textBounds); }
//----------------------------------------------------------------------------- void MadShiftaVerticalFillSlider::draw(DGGraphicsContext * inContext) { // draw background inContext->setFillColor(kControlBackgroundColor); inContext->fillRect( getBounds() ); // calculate coordinates of "on" portion inContext->setFillColor(kControlFillColor); SInt32 min = GetControl32BitMinimum(carbonControl); SInt32 max = GetControl32BitMaximum(carbonControl); SInt32 val = GetControl32BitValue(carbonControl); float valNorm = ((max-min) == 0) ? 0.0f : (float)(val-min) / (float)(max-min); DGRect onRect( getBounds() ); long onBottom; if (valNorm > axis) { onRect.y = (long) (getBounds()->h * valNorm); onBottom = (long) (getBounds()->h * axis); } else { onRect.y = (long) (getBounds()->h * axis); onBottom = (long) (getBounds()->h * valNorm); } onRect.y = getBounds()->h - onRect.y; onBottom = getBounds()->h - onBottom; onRect.h = onBottom - onRect.y; if (onRect.h < 1) { onRect.h = 1; inContext->setFillColor(kControlFillColor_alt); } onRect.y += getBounds()->y; // draw "on" portion inContext->fillRect(&onRect); // draw the text display if (textProc != NULL) { char text[kDGTextDisplay_stringSize]; text[0] = 0; textProc(getAUVP().GetValue(), text, NULL); DGRect textBounds( getBounds() ); textBounds.y += textY; textBounds.h = textHeight; inContext->setFont(kValueDisplayTextFont, kSliderTextSize); inContext->setColor(kValueDisplayTextColor); inContext->drawText(&textBounds, text, kDGTextAlign_center); } }
void Choice::Draw(UIContext &dc) { if (!IsSticky()) { ClickableItem::Draw(dc); } else { Style style = dc.theme->itemStyle; if (highlighted_) { style = dc.theme->itemHighlightedStyle; } if (down_) { style = dc.theme->itemDownStyle; } if (HasFocus()) { style = dc.theme->itemFocusedStyle; } dc.FillRect(style.background, bounds_); } Style style = dc.theme->itemStyle; if (!IsEnabled()) { style = dc.theme->itemDisabledStyle; } if (atlasImage_ != -1) { dc.Draw()->DrawImage(atlasImage_, bounds_.centerX(), bounds_.centerY(), 1.0f, style.fgColor, ALIGN_CENTER); } else { dc.SetFontStyle(dc.theme->uiFont); const int paddingX = 12; const float availWidth = bounds_.w - paddingX * 2 - textPadding_.horiz(); float scale = CalculateTextScale(dc, availWidth); dc.SetFontScale(scale, scale); if (centered_) { dc.DrawTextRect(text_.c_str(), bounds_, style.fgColor, ALIGN_CENTER | FLAG_WRAP_TEXT); } else { if (iconImage_ != -1) { dc.Draw()->DrawImage(iconImage_, bounds_.x2() - 32 - paddingX, bounds_.centerY(), 0.5f, style.fgColor, ALIGN_CENTER); } Bounds textBounds(bounds_.x + paddingX + textPadding_.left, bounds_.y, availWidth, bounds_.h); dc.DrawTextRect(text_.c_str(), textBounds, style.fgColor, ALIGN_VCENTER | FLAG_WRAP_TEXT); } dc.SetFontScale(1.0f, 1.0f); } if (selected_) { dc.Draw()->DrawImage(dc.theme->checkOn, bounds_.x2() - 40, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_CENTER); } }
BTextControl::BTextControl(BRect frame, const char *name, const char *label, const char *text, BMessage *message, uint32 mask, uint32 flags) : BControl(frame, name, label, message, mask, flags | B_FRAME_EVENTS) { InitData(label, text); BRect bounds(Bounds()); font_height fh; GetFontHeight(&fh); float height = (float)ceil(fh.ascent + fh.descent + fh.leading); float lineHeight = fText->LineHeight(0); ResizeTo(bounds.Width(), height + 8); BRect textBounds(fText->Bounds()); fText->ResizeTo(textBounds.Width(), lineHeight + 4); fText->MoveBy(0, (bounds.Height() - height) / 2.0f); }
void CheckBox::Draw(UIContext &dc) { Style style = dc.theme->itemStyle; if (!IsEnabled()) style = dc.theme->itemDisabledStyle; dc.SetFontStyle(dc.theme->uiFont); ClickableItem::Draw(dc); int image = *toggle_ ? dc.theme->checkOn : dc.theme->checkOff; float imageW, imageH; dc.Draw()->MeasureImage(image, &imageW, &imageH); const int paddingX = 12; // Padding right of the checkbox image too. const float availWidth = bounds_.w - paddingX * 2 - imageW - paddingX; float scale = CalculateTextScale(dc, availWidth); dc.SetFontScale(scale, scale); Bounds textBounds(bounds_.x + paddingX, bounds_.y, availWidth, bounds_.h); dc.DrawTextRect(text_.c_str(), textBounds, style.fgColor, ALIGN_VCENTER | FLAG_WRAP_TEXT); dc.Draw()->DrawImage(image, bounds_.x2() - paddingX, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_RIGHT | ALIGN_VCENTER); dc.SetFontScale(1.0f, 1.0f); }
void ArpTextControl::FrameResized(float new_width, float new_height) { ArpD(cdb << ADH << "ArpTextControl: FrameResized(" << new_width << ", " << new_height << ")" << endl); BTextView* text = dynamic_cast<BTextView*>(ChildAt(0)); if( !text ) ArpD(cdb << ADH << "!!! No BTextView !!!" << endl); if( text ) { ArpD(cdb << ADH << "BTextView: Initial Bounds=" << text->Bounds() << ", TextRect=" << text->TextRect() << endl); } BTextControl::FrameResized(new_width, new_height); BRect textBounds(text->Bounds()); BRect textRect(text->TextRect()); textRect.right = textRect.left + text->LineWidth(0)-1; if( textRect.Width() < textBounds.Width() ) { textRect.right = textRect.left + textBounds.Width()-1; } text->SetTextRect(textRect); if( text ) { ArpD(cdb << ADH << "BTextView: Finish Bounds=" << text->Bounds() << ", TextRect=" << text->TextRect() << endl); } }
bool AuthenticationPanel::getAuthentication(const BString& text, const BString& previousUser, const BString& previousPass, bool previousRememberCredentials, bool badPassword, BString& user, BString& pass, bool* rememberCredentials) { // Configure panel and layout controls. rgb_color infoColor = ui_color(B_PANEL_TEXT_COLOR); BRect textBounds(0, 0, 250, 200); BTextView* textView = new BTextView(textBounds, "text", textBounds, be_plain_font, &infoColor, B_FOLLOW_NONE, B_WILL_DRAW | B_SUPPORTS_LAYOUT); textView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); textView->SetText(text.String()); textView->MakeEditable(false); textView->MakeSelectable(false); m_usernameTextControl->SetText(previousUser.String()); m_passwordTextControl->TextView()->HideTyping(true); // Ignore the previous password, if it didn't work. if (!badPassword) m_passwordTextControl->SetText(previousPass.String()); m_hidePasswordCheckBox->SetValue(B_CONTROL_ON); m_rememberCredentialsCheckBox->SetValue(previousRememberCredentials); // create layout SetLayout(new BGroupLayout(B_VERTICAL, 0.0)); float spacing = be_control_look->DefaultItemSpacing(); AddChild(BGroupLayoutBuilder(B_VERTICAL, 0.0) .Add(BGridLayoutBuilder(0, spacing) .Add(textView, 0, 0, 2) .Add(m_usernameTextControl->CreateLabelLayoutItem(), 0, 1) .Add(m_usernameTextControl->CreateTextViewLayoutItem(), 1, 1) .Add(m_passwordTextControl->CreateLabelLayoutItem(), 0, 2) .Add(m_passwordTextControl->CreateTextViewLayoutItem(), 1, 2) .Add(BSpaceLayoutItem::CreateGlue(), 0, 3) .Add(m_hidePasswordCheckBox, 1, 3) .Add(m_rememberCredentialsCheckBox, 0, 4, 2) .SetInsets(spacing, spacing, spacing, spacing) ) .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) .Add(BGroupLayoutBuilder(B_HORIZONTAL, spacing) .AddGlue() .Add(m_cancelButton) .Add(m_okButton) .SetInsets(spacing, spacing, spacing, spacing) ) ); float textHeight = textView->LineHeight(0) * textView->CountLines(); textView->SetExplicitMinSize(BSize(B_SIZE_UNSET, textHeight)); SetDefaultButton(m_okButton); if (badPassword && previousUser.Length()) m_passwordTextControl->MakeFocus(true); else m_usernameTextControl->MakeFocus(true); if (m_parentWindowFrame.IsValid()) CenterIn(m_parentWindowFrame); else CenterOnScreen(); // Start AuthenticationPanel window thread Show(); // Let the window jitter, if the previous password was invalid if (badPassword) PostMessage(kMsgJitter); // Block calling thread // Get the originating window, if it exists, to let it redraw itself. BWindow* window = dynamic_cast<BWindow*>(BLooper::LooperForThread(find_thread(NULL))); if (window) { status_t err; for (;;) { do { err = acquire_sem_etc(m_exitSemaphore, 1, B_RELATIVE_TIMEOUT, 10000); // We've (probably) had our time slice taken away from us } while (err == B_INTERRUPTED); if (err != B_TIMED_OUT) { // Semaphore was finally released or nuked. break; } window->UpdateIfNeeded(); } } else { // No window to update, so just hang out until we're done. while (acquire_sem(m_exitSemaphore) == B_INTERRUPTED) { } } // AuthenticationPanel wants to quit. Lock(); user = m_usernameTextControl->Text(); pass = m_passwordTextControl->Text(); if (rememberCredentials) *rememberCredentials = m_rememberCredentialsCheckBox->Value() == B_CONTROL_ON; bool canceled = m_cancelled; Quit(); // AuthenticationPanel object is TOAST here. return !canceled; }
void UILabel::CalculateTextDimensions() { size_t len; int const MAX_LINES = 16; float lineWidths[MAX_LINES]; int numLines = 0; float w; float h; float ascent; float descent; float fontHeight; GuiSys.GetDefaultFont().CalcTextMetrics( GetText().ToCStr(), len, w, h, ascent, descent, fontHeight, lineWidths, MAX_LINES, numLines ); // NOTE: despite being 3 scalars, text scaling only uses the x component since // DrawText3D doesn't take separate x and y scales right now. Vector3f const textLocalScale = GetMenuObject()->GetTextLocalScale(); float const scale = textLocalScale.x * FontParms.Scale; // this seems overly complex because font characters are rendered so that their origin // is on their baseline and not on one of the corners of the glyph. Because of this // we must treat the initial ascent (amount the font goes above the first baseline) and // final descent (amount the font goes below the final baseline) independently from the // lines in between when centering. Bounds3f textBounds( Vector3f( 0.0f, ( h - ascent ) * -1.0f, 0.0f ) * scale, Vector3f( w, ascent, 0.0f ) * scale ); Vector3f trans = Vector3f::ZERO; switch( FontParms.AlignVert ) { case VERTICAL_BASELINE : trans.y = 0.0f; break; case VERTICAL_CENTER : { trans.y = ( h * 0.5f ) - ascent; break; } case VERTICAL_CENTER_FIXEDHEIGHT : { trans.y = ( fontHeight * 0.5f ); break; } case VERTICAL_TOP : { trans.y = h - ascent; break; } } switch( FontParms.AlignHoriz ) { case HORIZONTAL_LEFT : trans.x = 0.0f; break; case HORIZONTAL_CENTER : { trans.x = w * -0.5f; break; } case HORIZONTAL_RIGHT : { trans.x = w; break; } } textBounds.Translate( trans * scale ); LOG( "textBounds: %f, %f", textBounds.GetSize().x, textBounds.GetSize().y ); SetDimensions( Vector2f( textBounds.GetSize().x * TEXELS_PER_METER, textBounds.GetSize().y * TEXELS_PER_METER ) ); CalculateTextOffset(); }