kopia lustrzana https://github.com/jameshball/osci-render
Save and load fonts and styles
rodzic
7c0043edf6
commit
665e7b806e
|
@ -124,6 +124,18 @@ void OscirenderAudioProcessor::openLegacyProject(const juce::XmlElement* xml) {
|
|||
juce::Base64::convertFromBase64(stream, perspectiveFunction->getAllSubText());
|
||||
perspectiveEffect->updateCode(stream.toString());
|
||||
}
|
||||
|
||||
auto fontFamilyXml = xml->getChildByName("fontFamily");
|
||||
if (fontFamilyXml != nullptr) {
|
||||
font.setTypefaceName(fontFamilyXml->getAllSubText());
|
||||
}
|
||||
auto fontStyleXml = xml->getChildByName("fontStyle");
|
||||
if (fontStyleXml != nullptr) {
|
||||
int style = fontStyleXml->getAllSubText().getIntValue();
|
||||
font.setBold(style == 1);
|
||||
font.setItalic(style == 2);
|
||||
}
|
||||
|
||||
// close all files
|
||||
auto numFiles = fileBlocks.size();
|
||||
for (int i = 0; i < numFiles; i++) {
|
||||
|
|
|
@ -69,8 +69,8 @@ OscirenderAudioProcessorEditor::~OscirenderAudioProcessorEditor() {
|
|||
|
||||
// parsersLock must be held
|
||||
void OscirenderAudioProcessorEditor::initialiseCodeEditors() {
|
||||
codeDocuments.clear();
|
||||
codeEditors.clear();
|
||||
codeDocuments.clear();
|
||||
// -1 is the perspective function
|
||||
addCodeEditor(-1);
|
||||
for (int i = 0; i < audioProcessor.numFiles(); i++) {
|
||||
|
@ -237,6 +237,7 @@ void OscirenderAudioProcessorEditor::handleAsyncUpdate() {
|
|||
void OscirenderAudioProcessorEditor::changeListenerCallback(juce::ChangeBroadcaster* source) {
|
||||
juce::SpinLock::ScopedLockType lock(audioProcessor.parsersLock);
|
||||
initialiseCodeEditors();
|
||||
txt.update();
|
||||
}
|
||||
|
||||
void OscirenderAudioProcessorEditor::editPerspectiveFunction(bool enable) {
|
||||
|
|
|
@ -622,6 +622,12 @@ void OscirenderAudioProcessor::getStateInformation(juce::MemoryBlock& destData)
|
|||
|
||||
auto perspectiveFunction = xml->createNewChildElement("perspectiveFunction");
|
||||
perspectiveFunction->addTextElement(juce::Base64::toBase64(perspectiveEffect->getCode()));
|
||||
|
||||
auto fontXml = xml->createNewChildElement("font");
|
||||
fontXml->setAttribute("family", font.getTypefaceName());
|
||||
fontXml->setAttribute("bold", font.isBold());
|
||||
fontXml->setAttribute("italic", font.isItalic());
|
||||
|
||||
auto filesXml = xml->createNewChildElement("files");
|
||||
|
||||
for (int i = 0; i < fileBlocks.size(); i++) {
|
||||
|
@ -631,6 +637,7 @@ void OscirenderAudioProcessor::getStateInformation(juce::MemoryBlock& destData)
|
|||
fileXml->addTextElement(juce::Base64::toBase64(fileString));
|
||||
}
|
||||
xml->setAttribute("currentFile", currentFile);
|
||||
|
||||
copyXmlToBinary(*xml, destData);
|
||||
}
|
||||
|
||||
|
@ -683,6 +690,16 @@ void OscirenderAudioProcessor::setStateInformation(const void* data, int sizeInB
|
|||
juce::Base64::convertFromBase64(stream, perspectiveFunction->getAllSubText());
|
||||
perspectiveEffect->updateCode(stream.toString());
|
||||
}
|
||||
|
||||
auto fontXml = xml->getChildByName("font");
|
||||
if (fontXml != nullptr) {
|
||||
auto family = fontXml->getStringAttribute("family");
|
||||
auto bold = fontXml->getBoolAttribute("bold");
|
||||
auto italic = fontXml->getBoolAttribute("italic");
|
||||
juce::SpinLock::ScopedLockType lock(fontLock);
|
||||
font = juce::Font(family, 1.0, (bold ? juce::Font::bold : 0) | (italic ? juce::Font::italic : 0));
|
||||
}
|
||||
|
||||
// close all files
|
||||
auto numFiles = fileBlocks.size();
|
||||
for (int i = 0; i < numFiles; i++) {
|
||||
|
|
|
@ -12,17 +12,7 @@ TxtComponent::TxtComponent(OscirenderAudioProcessor& p, OscirenderAudioProcessor
|
|||
font.addItem(installedFonts[i], i + 1);
|
||||
}
|
||||
|
||||
{
|
||||
juce::SpinLock::ScopedLockType lock(audioProcessor.fontLock);
|
||||
juce::String defaultFont = audioProcessor.font.getTypefaceName();
|
||||
int index = installedFonts.indexOf(defaultFont);
|
||||
if (index == -1) {
|
||||
index = 0;
|
||||
}
|
||||
font.setSelectedItemIndex(index);
|
||||
bold.setToggleState(audioProcessor.font.isBold(), juce::dontSendNotification);
|
||||
italic.setToggleState(audioProcessor.font.isItalic(), juce::dontSendNotification);
|
||||
}
|
||||
update();
|
||||
|
||||
auto updateFont = [this]() {
|
||||
juce::SpinLock::ScopedLockType lock1(audioProcessor.parsersLock);
|
||||
|
@ -49,3 +39,15 @@ void TxtComponent::resized() {
|
|||
bold.setBounds(area.removeFromTop(rowHeight));
|
||||
italic.setBounds(area.removeFromTop(rowHeight));
|
||||
}
|
||||
|
||||
void TxtComponent::update() {
|
||||
juce::SpinLock::ScopedLockType lock(audioProcessor.fontLock);
|
||||
juce::String defaultFont = audioProcessor.font.getTypefaceName();
|
||||
int index = installedFonts.indexOf(defaultFont);
|
||||
if (index == -1) {
|
||||
index = 0;
|
||||
}
|
||||
font.setSelectedItemIndex(index);
|
||||
bold.setToggleState(audioProcessor.font.isBold(), juce::dontSendNotification);
|
||||
italic.setToggleState(audioProcessor.font.isItalic(), juce::dontSendNotification);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ public:
|
|||
TxtComponent(OscirenderAudioProcessor&, OscirenderAudioProcessorEditor&);
|
||||
|
||||
void resized() override;
|
||||
void update();
|
||||
private:
|
||||
OscirenderAudioProcessor& audioProcessor;
|
||||
OscirenderAudioProcessorEditor& pluginEditor;
|
||||
|
|
Ładowanie…
Reference in New Issue