-
-
Save sudara/ea997bdc7c2ff6c9fb32b75cb915d30c to your computer and use it in GitHub Desktop.
TextEditor, Cursor, and setOpaque
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "juce_gui_extra/juce_gui_extra.h" | |
class Modal : public juce::Component | |
{ | |
public: | |
Modal() | |
{ | |
addAndMakeVisible (editor); | |
editor.setFont (editor.getFont().withPointHeight (50)); | |
editor.setBorder (juce::BorderSize (5)); | |
editor.setOpaque (true); | |
} | |
void paint (juce::Graphics& g) override | |
{ | |
g.setColour (juce::Colours::darkblue.withAlpha (0.8f)); | |
g.fillAll(); | |
} | |
void resized() override | |
{ | |
auto area = getLocalBounds(); | |
editor.setBounds (area.reduced (50).removeFromTop (100)); | |
} | |
private: | |
juce::TextEditor editor; | |
}; | |
class Main : public juce::Component | |
{ | |
public: | |
void mouseDown (const MouseEvent& event) override | |
{ | |
repaint(); | |
} | |
void paint (juce::Graphics& g) override | |
{ | |
g.setColour ({ (uint8) rng.nextInt (255), | |
(uint8) rng.nextInt (255), | |
(uint8) rng.nextInt (255) }); | |
g.fillRect (getLocalBounds()); | |
} | |
private: | |
Random rng; | |
}; | |
class TextEditorPlayground : public juce::Component | |
{ | |
public: | |
TextEditorPlayground() | |
{ | |
addAndMakeVisible (main); | |
addAndMakeVisible (modal); | |
} | |
void paint (juce::Graphics& g) override | |
{ | |
g.fillAll (juce::Colours::grey); | |
} | |
void resized() override | |
{ | |
auto area = getLocalBounds(); | |
main.setBounds (area); | |
modal.setBounds (getLocalBounds().reduced (100)); | |
} | |
private: | |
Main main; | |
Modal modal; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment