void TooltipWindow::updatePosition (const String& tip, Point<int> pos, const Rectangle<int>& parentArea) { int w, h; getLookAndFeel().getTooltipSize (tip, w, h); Rectangle<int> bounds (pos.x > parentArea.getCentreX() ? pos.x - (w + 12) : pos.x + 24, pos.y > parentArea.getCentreY() ? pos.y - (h + 6) : pos.y + 6, w, h); setBounds (bounds.constrainedWithin (parentArea)); setVisible (true); }
TextEditor* Label::createEditorComponent() { TextEditor* const ed = new TextEditor (getName()); ed->applyFontToAllText (getLookAndFeel().getLabelFont (*this)); copyAllExplicitColoursTo (*ed); copyColourIfSpecified (*this, *ed, textWhenEditingColourId, TextEditor::textColourId); copyColourIfSpecified (*this, *ed, backgroundWhenEditingColourId, TextEditor::backgroundColourId); copyColourIfSpecified (*this, *ed, outlineWhenEditingColourId, TextEditor::focusedOutlineColourId); return ed; }
void MenuBarComponent::resized() { xPositions.clear(); int x = 0; xPositions.add (x); for (int i = 0; i < menuNames.size(); ++i) { x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]); xPositions.add (x); } }
Rectangle<int> TabBarButton::getActiveArea() { Rectangle<int> r (getLocalBounds()); const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage(); if (owner.getOrientation() != TabbedButtonBar::TabsAtLeft) r.removeFromRight (spaceAroundImage); if (owner.getOrientation() != TabbedButtonBar::TabsAtRight) r.removeFromLeft (spaceAroundImage); if (owner.getOrientation() != TabbedButtonBar::TabsAtBottom) r.removeFromTop (spaceAroundImage); if (owner.getOrientation() != TabbedButtonBar::TabsAtTop) r.removeFromBottom (spaceAroundImage); return r; }
void CallOutBox::paint (Graphics& g) { if (background.isNull()) { background = Image (Image::ARGB, getWidth(), getHeight(), true); Graphics g (background); getLookAndFeel().drawCallOutBoxBackground (*this, g, outline); } g.setColour (Colours::black); g.drawImageAt (background, 0, 0); }
void ComboBox::showPopup() { PopupMenu menu; menu.setLookAndFeel (&getLookAndFeel()); addItemsToMenu (menu); menu.showMenuAsync (PopupMenu::Options().withTargetComponent (this) .withItemThatMustBeVisible (getSelectedId()) .withMinimumWidth (getWidth()) .withMaximumNumColumns (1) .withStandardItemHeight (label->getHeight()), ModalCallbackFunction::forComponent (comboBoxPopupMenuFinishedCallback, this)); }
void buttonClicked (Button* button) override { if (button == &nativeButton) { getLookAndFeel().setUsingNativeAlertWindows (nativeButton.getToggleState()); return; } for (int i = windowButtons.size(); --i >= 0;) if (button == windowButtons.getUnchecked (i)) return showWindow (*button, static_cast<DialogType> (i)); }
void TooltipWindow::showFor (const String& tip) { jassert (tip.isNotEmpty()); if (tipShowing != tip) repaint(); tipShowing = tip; Point<int> mousePos (Desktop::getMousePosition()); Rectangle<int> parentArea; if (getParentComponent() != nullptr) { mousePos = getParentComponent()->getLocalPoint (nullptr, mousePos); parentArea = getParentComponent()->getLocalBounds(); } else { parentArea = Desktop::getInstance().getMonitorAreaContaining (mousePos); } int w, h; getLookAndFeel().getTooltipSize (tip, w, h); int x = mousePos.x; if (x > parentArea.getCentreX()) x -= (w + 12); else x += 24; int y = mousePos.y; if (y > parentArea.getCentreY()) y -= (h + 6); else y += 6; x = jlimit (parentArea.getX(), parentArea.getRight() - w, x); y = jlimit (parentArea.getY(), parentArea.getBottom() - h, y); setBounds (x, y, w, h); setVisible (true); if (getParentComponent() == nullptr) { addToDesktop (ComponentPeer::windowHasDropShadow | ComponentPeer::windowIsTemporary | ComponentPeer::windowIgnoresKeyPresses); } toFront (false); }
//============================================================================== CodeEditorComponent::CodeEditorComponent (CodeDocument& doc, CodeTokeniser* const tokeniser) : document (doc), firstLineOnScreen (0), spacesPerTab (4), lineHeight (0), linesOnScreen (0), columnsOnScreen (0), scrollbarThickness (16), columnToTryToMaintain (-1), useSpacesForTabs (false), showLineNumbers (false), xOffset (0), caretPos (doc, 0, 0), selectionStart (doc, 0, 0), selectionEnd (doc, 0, 0), verticalScrollBar (true), horizontalScrollBar (false), appCommandManager (nullptr), codeTokeniser (tokeniser) { pimpl = new Pimpl (*this); caretPos.setPositionMaintained (true); selectionStart.setPositionMaintained (true); selectionEnd.setPositionMaintained (true); setOpaque (true); setMouseCursor (MouseCursor::IBeamCursor); setWantsKeyboardFocus (true); addAndMakeVisible (caret = getLookAndFeel().createCaretComponent (this)); addAndMakeVisible (&verticalScrollBar); verticalScrollBar.setSingleStepSize (1.0); addAndMakeVisible (&horizontalScrollBar); horizontalScrollBar.setSingleStepSize (1.0); Font f (12.0f); f.setTypefaceName (Font::getDefaultMonospacedFontName()); setFont (f); if (codeTokeniser != nullptr) setColourScheme (codeTokeniser->getDefaultColourScheme()); setLineNumbersShown (true); verticalScrollBar.addListener (pimpl); horizontalScrollBar.addListener (pimpl); document.addListener (pimpl); }
//============================================================================== void AlertWindow::paint (Graphics& g) { getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout); g.setColour (findColour (textColourId)); g.setFont (getLookAndFeel().getAlertWindowFont()); int i; for (i = textBoxes.size(); --i >= 0;) { const TextEditor* const te = textBoxes.getUnchecked(i); g.drawFittedText (textboxNames[i], te->getX(), te->getY() - 14, te->getWidth(), 14, Justification::centredLeft, 1); } for (i = comboBoxNames.size(); --i >= 0;) { const ComboBox* const cb = comboBoxes.getUnchecked(i); g.drawFittedText (comboBoxNames[i], cb->getX(), cb->getY() - 14, cb->getWidth(), 14, Justification::centredLeft, 1); } for (i = customComps.size(); --i >= 0;) { const Component* const c = customComps.getUnchecked(i); g.drawFittedText (c->getName(), c->getX(), c->getY() - 14, c->getWidth(), 14, Justification::centredLeft, 1); } }
void DrawableButton::paintButton (Graphics& g, const bool isMouseOverButton, const bool isButtonDown) { LookAndFeel& lf = getLookAndFeel(); if (style == ImageOnButtonBackground) lf.drawButtonBackground (g, *this, findColour (getToggleState() ? TextButton::buttonOnColourId : TextButton::buttonColourId), isMouseOverButton, isButtonDown); else lf.drawDrawableButton (g, *this, isMouseOverButton, isButtonDown); }
void TabBarButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown) { const Rectangle<int> area (getActiveArea()); g.setOrigin (area.getX(), area.getY()); getLookAndFeel() .drawTabButton (g, area.getWidth(), area.getHeight(), owner.getTabBackgroundColour (getIndex()), getIndex(), getButtonText(), *this, owner.getOrientation(), isMouseOverButton, isButtonDown, getToggleState()); }
//============================================================================== CodeEditorComponent::CodeEditorComponent (CodeDocument& document_, CodeTokeniser* const codeTokeniser_) : document (document_), firstLineOnScreen (0), gutter (5), spacesPerTab (4), lineHeight (0), linesOnScreen (0), columnsOnScreen (0), scrollbarThickness (16), columnToTryToMaintain (-1), useSpacesForTabs (false), xOffset (0), verticalScrollBar (true), horizontalScrollBar (false), codeTokeniser (codeTokeniser_) { caretPos = CodeDocument::Position (&document_, 0, 0); caretPos.setPositionMaintained (true); selectionStart = CodeDocument::Position (&document_, 0, 0); selectionStart.setPositionMaintained (true); selectionEnd = CodeDocument::Position (&document_, 0, 0); selectionEnd.setPositionMaintained (true); setOpaque (true); setMouseCursor (MouseCursor (MouseCursor::IBeamCursor)); setWantsKeyboardFocus (true); addAndMakeVisible (&verticalScrollBar); verticalScrollBar.setSingleStepSize (1.0); addAndMakeVisible (&horizontalScrollBar); horizontalScrollBar.setSingleStepSize (1.0); addAndMakeVisible (caret = getLookAndFeel().createCaretComponent (this)); Font f (12.0f); f.setTypefaceName (Font::getDefaultMonospacedFontName()); setFont (f); resetToDefaultColours(); verticalScrollBar.addListener (this); horizontalScrollBar.addListener (this); document.addListener (this); }
void TextButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown) { LookAndFeel& lf = getLookAndFeel(); lf.drawButtonBackground (g, *this, findColour (getToggleState() ? buttonOnColourId : buttonColourId), isMouseOverButton, isButtonDown); lf.drawButtonText (g, *this, isMouseOverButton, isButtonDown); }
void paintListBoxItem (int row, Graphics& g, int width, int height, bool rowIsSelected) { if (row < 0 || row >= getNumRows()) return; if (rowIsSelected) g.fillAll (findColour (TextEditor::highlightColourId)); g.setColour (Colours::black); g.setFont (height * 0.6f); g.drawText (returnValues [row] + " " + baseClasses [row] + "::" + methods [row], 30, 0, width - 32, height, Justification::centredLeft, true); getLookAndFeel().drawTickBox (g, *this, 6, 2, 18, 18, document.isOptionalMethodEnabled (methods [row]), true, false, false); }
void TabBarButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown) { int x, y, w, h; getActiveArea (x, y, w, h); g.setOrigin (x, y); getLookAndFeel() .drawTabButton (g, w, h, owner->getTabBackgroundColour (tabIndex), tabIndex, getButtonText(), *this, owner->getOrientation(), isMouseOverButton, isButtonDown, getToggleState()); }
//============================================================================== void ComboBox::paint (Graphics& g) { getLookAndFeel().drawComboBox (g, getWidth(), getHeight(), isButtonDown, label->getRight(), 0, getWidth() - label->getRight(), getHeight(), *this); if (textWhenNothingSelected.isNotEmpty() && label->getText().isEmpty() && ! label->isBeingEdited()) { g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f)); g.setFont (label->getFont()); g.drawFittedText (textWhenNothingSelected, label->getBounds().reduced (2, 1), label->getJustificationType(), jmax (1, (int) (label->getHeight() / label->getFont().getHeight()))); } }
//============================================================================== MainWindow::MainWindow() : DocumentWindow (JUCEApplication::getInstance()->getApplicationName(), Colour::greyLevel (0.6f), DocumentWindow::allButtons, false) { setUsingNativeTitleBar (true); setContentOwned (new ProjectContentComponent(), false); #if ! JUCE_MAC JucerApplication* app = static_cast<JucerApplication*> (JUCEApplication::getInstance()); setMenuBar (app->menuModel); #endif setResizable (true, false); centreWithSize (700, 600); // Register all the app commands.. { commandManager->registerAllCommandsForTarget (this); // use a temporary one of these to harvest its commands.. ProjectContentComponent pcc; commandManager->registerAllCommandsForTarget (&pcc); DocumentEditorComponent dec (nullptr); commandManager->registerAllCommandsForTarget (&dec); } commandManager->getKeyMappings()->resetToDefaultMappings(); ScopedPointer <XmlElement> keys (StoredSettings::getInstance()->getProps().getXmlValue ("keyMappings")); if (keys != nullptr) commandManager->getKeyMappings()->restoreFromXml (*keys); addKeyListener (commandManager->getKeyMappings()); // don't want the window to take focus when the title-bar is clicked.. setWantsKeyboardFocus (false); //getPeer()->setCurrentRenderingEngine (0); getLookAndFeel().setColour (ColourSelector::backgroundColourId, Colours::transparentBlack); }
//============================================================================== MainWindow::MainWindow() : DocumentWindow (ProjucerApplication::getApp().getApplicationName(), ProjucerApplication::getApp().lookAndFeel.getCurrentColourScheme() .getUIColour (LookAndFeel_V4::ColourScheme::UIColour::windowBackground), DocumentWindow::allButtons, false) { setUsingNativeTitleBar (true); #if ! JUCE_MAC setMenuBar (ProjucerApplication::getApp().getMenuModel()); #endif createProjectContentCompIfNeeded(); setResizable (true, false); centreWithSize (800, 600); ApplicationCommandManager& commandManager = ProjucerApplication::getCommandManager(); // Register all the app commands.. commandManager.registerAllCommandsForTarget (this); commandManager.registerAllCommandsForTarget (getProjectContentComponent()); // update key mappings.. { commandManager.getKeyMappings()->resetToDefaultMappings(); ScopedPointer<XmlElement> keys (getGlobalProperties().getXmlValue ("keyMappings")); if (keys != nullptr) commandManager.getKeyMappings()->restoreFromXml (*keys); addKeyListener (commandManager.getKeyMappings()); } // don't want the window to take focus when the title-bar is clicked.. setWantsKeyboardFocus (false); getLookAndFeel().setColour (ColourSelector::backgroundColourId, Colours::transparentBlack); projectNameValue.addListener (this); setResizeLimits (600, 500, 32000, 32000); }
void ProgressBar::paint (Graphics& g) { String text; if (displayPercentage) { if (currentValue >= 0 && currentValue <= 1.0) text << roundToInt (currentValue * 100.0) << '%'; } else { text = displayedMessage; } getLookAndFeel().drawProgressBar (g, *this, getWidth(), getHeight(), currentValue, text); }
//============================================================================== void AlertWindow::addTextEditor (const String& name, const String& initialContents, const String& onScreenLabel, const bool isPasswordBox) { AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox); textBoxes.add (tc); allComps.add (tc); tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId)); tc->setFont (getLookAndFeel().getAlertWindowMessageFont()); tc->setText (initialContents); tc->setCaretPosition (initialContents.length()); addAndMakeVisible (tc); textboxNames.add (onScreenLabel); updateLayout (false); }
void FileChooserDialogBox::ContentComponent::resized() { getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth()); float left, top, right, bottom; text.getBoundingBox (0, text.getNumGlyphs(), left, top, right, bottom, false); const int y = roundToInt (bottom) + 10; const int buttonHeight = 26; const int buttonY = getHeight() - buttonHeight - 8; chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20); okButton->setBounds (proportionOfWidth (0.25f), buttonY, proportionOfWidth (0.2f), buttonHeight); cancelButton->setBounds (proportionOfWidth (0.55f), buttonY, proportionOfWidth (0.2f), buttonHeight); }
//============================================================================== void AlertWindow::setMessage (const String& message) { const String newMessage (message.substring (0, 2048)); if (text != newMessage) { text = newMessage; font = getLookAndFeel().getAlertWindowMessageFont(); AttributedString newText; newText.append (getName() + "\n\n", Font (font.getHeight() * 1.1f, Font::bold)); newText.append (text, font); attributedText = newText; updateLayout (true); repaint(); } }
void Label::componentMovedOrResized (Component& component, bool /*wasMoved*/, bool /*wasResized*/) { const Font f (getLookAndFeel().getLabelFont (*this)); if (leftOfOwnerComp) { setSize (jmin (f.getStringWidth (textValue.toString()) + 8, component.getX()), component.getHeight()); setTopRightPosition (component.getX(), component.getY()); } else { setSize (component.getWidth(), 8 + roundToInt (f.getHeight())); setTopLeftPosition (component.getX(), component.getY() - getHeight()); } }
void TabBarButton::calcAreas (Rectangle<int>& extraComp, Rectangle<int>& text) const { LookAndFeel& lf = getLookAndFeel(); text = getActiveArea(); const int depth = owner.isVertical() ? text.getWidth() : text.getHeight(); const int overlap = lf.getTabButtonOverlap (depth); if (overlap > 0) { if (owner.isVertical()) text.reduce (0, overlap); else text.reduce (overlap, 0); } if (extraComponent != nullptr) extraComp = lf.getTabButtonExtraComponentBounds (*this, text, *extraComponent); }
//============================================================================== void AlertWindow::setMessage (const String& message) { const String newMessage (message.substring (0, 2048)); if (text != newMessage) { text = newMessage; font = getLookAndFeel().getAlertWindowMessageFont(); Font titleFont (font.getHeight() * 1.1f, Font::bold); textLayout.setText (getName() + "\n\n", titleFont); textLayout.appendText (text, font); updateLayout (true); repaint(); } }
//============================================================================== void DocumentWindow::paint (Graphics& g) { ResizableWindow::paint (g); if (resizableBorder == 0) { g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000))); const BorderSize border (getBorderThickness()); g.fillRect (0, 0, getWidth(), border.getTop()); g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom()); g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom()); g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom()); } const Rectangle titleBarArea (getTitleBarArea()); g.setOrigin (titleBarArea.getX(), titleBarArea.getY()); g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight()); int titleSpaceX1 = 6; int titleSpaceX2 = titleBarArea.getWidth() - 6; for (int i = 0; i < 3; ++i) { if (titleBarButtons[i] != 0) { if (positionTitleBarButtonsOnLeft) titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8); else titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8)); } } getLookAndFeel().drawDocumentWindowTitleBar (*this, g, titleBarArea.getWidth(), titleBarArea.getHeight(), titleSpaceX1, jmax (1, titleSpaceX2 - titleSpaceX1), titleBarIcon, ! drawTitleTextCentred); }
//============================================================================== void ComboBox::showPopup() { if (! menuActive) { const int selectedId = getSelectedId(); ComponentDeletionWatcher deletionWatcher (this); PopupMenu menu; menu.setLookAndFeel (&getLookAndFeel()); for (int i = 0; i < items.size(); ++i) { const ItemInfo* const item = items.getUnchecked(i); if (item->isSeparator()) menu.addSeparator(); else if (item->isHeading) menu.addSectionHeader (item->name); else menu.addItem (item->itemId, item->name, item->isEnabled, item->itemId == selectedId); } if (items.size() == 0) menu.addItem (1, noChoicesMessage, false); const int itemHeight = jlimit (12, 24, getHeight()); menuActive = true; const int resultId = menu.showAt (this, selectedId, getWidth(), 1, itemHeight); if (deletionWatcher.hasBeenDeleted()) return; menuActive = false; if (resultId != 0) setSelectedId (resultId); } }
void ComboBox::lookAndFeelChanged() { repaint(); { ScopedPointer<Label> newLabel (getLookAndFeel().createComboBoxTextBox (*this)); jassert (newLabel != nullptr); if (label != nullptr) { newLabel->setEditable (label->isEditable()); newLabel->setJustificationType (label->getJustificationType()); newLabel->setTooltip (label->getTooltip()); newLabel->setText (label->getText(), dontSendNotification); } label = newLabel; } addAndMakeVisible (label); EditableState newEditableState = (label->isEditable() ? labelIsEditable : labelIsNotEditable); if (newEditableState != labelEditableState) { labelEditableState = newEditableState; setWantsKeyboardFocus (labelEditableState == labelIsNotEditable); } label->addListener (this); label->addMouseListener (this, false); label->setColour (Label::backgroundColourId, Colours::transparentBlack); label->setColour (Label::textColourId, findColour (ComboBox::textColourId)); label->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId)); label->setColour (TextEditor::backgroundColourId, Colours::transparentBlack); label->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId)); label->setColour (TextEditor::outlineColourId, Colours::transparentBlack); resized(); }
//============================================================================== void AlertWindow::addButton (const String& name, const int returnValue, const KeyPress& shortcutKey1, const KeyPress& shortcutKey2) { TextButton* const b = new TextButton (name, String::empty); buttons.add (b); b->setWantsKeyboardFocus (true); b->setMouseClickGrabsKeyboardFocus (false); b->setCommandToTrigger (0, returnValue, false); b->addShortcut (shortcutKey1); b->addShortcut (shortcutKey2); b->addListener (this); b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight()); addAndMakeVisible (b, 0); updateLayout (false); }