Created
November 22, 2020 23:12
-
-
Save ffAudio/5ab032a9e9b98eb7dae52a789fe460a6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include "MainComponent.h" | |
//============================================================================== | |
MainComponent::MainComponent() | |
{ | |
text.append ("Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n", juce::Font (14.0f), juce::Colours::white); | |
text.append ("sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n", juce::Font (20.0f), juce::Colours::white); | |
text.append ("Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi\n", juce::Font (8.0f), juce::Colours::white); | |
text.append ("ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit\n", juce::Font (18.0f), juce::Colours::red); | |
text.append ("in voluptate velit esse cillum dolore eu fugiat nulla pariatur.\n", juce::Colours::blue); | |
text.append ("Excepteur sint occaecat cupidatat non proident, sunt in culpa qui\n", juce::Colours::white); | |
text.append ("officia deserunt mollit anim id est laborum.", juce::Colours::white); | |
setSize (600, 400); | |
} | |
MainComponent::~MainComponent() | |
{ | |
} | |
//============================================================================== | |
void MainComponent::mouseDown (const juce::MouseEvent& event) | |
{ | |
for (int l = 0; l < layout.getNumLines(); ++l) | |
{ | |
auto& line = layout.getLine (l); | |
if (line.getLineBounds().contains (event.position)) | |
{ | |
int r = 0; | |
for (auto& run : line.runs) | |
{ | |
int c = 0; | |
for (auto& g : run->glyphs) | |
{ | |
auto x = line.lineOrigin.x + g.anchor.x; | |
// DBG ("x: " << x << " width: " << g.width << " pos: " << event.position.toString()); | |
if (juce::isPositiveAndBelow (event.position.x - x, g.width)) | |
{ | |
DBG ("Row: " << l << " Run: " << r << " Column: " << c); | |
return; | |
} | |
++c; | |
} | |
++r; | |
} | |
} | |
} | |
DBG ("Nope: " << event.position.toString()); | |
} | |
void MainComponent::paint (juce::Graphics& g) | |
{ | |
g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId)); | |
layout.draw (g, getLocalBounds().toFloat()); | |
} | |
void MainComponent::resized() | |
{ | |
layout.createLayout (text, getWidth(), getHeight()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment