Skip to content

Commit

Permalink
add clock
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Aug 21, 2024
1 parent c5c0d98 commit dc5ddb3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "JUCE"]
path = JUCE
url = https://github.com/juce-framework/JUCE/
branch = master
branch = develop
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ include(PamplejuceVersion)
# This is the internal name of the project and the name of JUCE's shared code "target"
# Note: This cannot have spaces (it may be 2023, but you can't have it all!)
# Worry not, JUCE's PRODUCT_NAME can have spaces (and is DAWs display)
set(PROJECT_NAME "ZLTemplate")
set(PLUGIN_CODE "Temp")
set(PROJECT_NAME "ZLTest")
set(PLUGIN_CODE "Test")

# Change me!
# Worry not, JUCE's PRODUCT_NAME can have spaces (and is what DAWs will display)
Expand All @@ -21,7 +21,7 @@ set(PLUGIN_CODE "Temp")
# # set(PROJECT_NAME "MyPlugin_v${MAJOR_VERSION}")
# Doing so enables major versions to show up in IDEs and DAWs as separate plugins
# allowing you to change parameters and behavior without breaking existing user projects
set(PRODUCT_NAME "ZL Template")
set(PRODUCT_NAME "ZL Test")

# Change me! Used for the MacOS bundle name and Installers
set(COMPANY_NAME "ZL")
Expand Down
45 changes: 27 additions & 18 deletions source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,40 @@ PluginEditor::PluginEditor(PluginProcessor &p)
: AudioProcessorEditor(&p), processorRef(p) {
juce::ignoreUnused(processorRef);

addAndMakeVisible(inspectButton);

// Make sure that before the constructor has finished, you've set the
// editor's size to whatever you need it to be.
setSize(400, 300);
setSize(400, 150);
getConstrainer()->setFixedAspectRatio(400.f / 150.f);
setResizable(true, p.wrapperType != PluginProcessor::wrapperType_AudioUnitv3);
startTimerHz(60);
}

PluginEditor::~PluginEditor() {
stopTimer();
}

void PluginEditor::paint(juce::Graphics &g) {
// (Our component is opaque, so we must completely fill the background with a solid colour)
g.fillAll(getLookAndFeel().findColour(juce::ResizableWindow::backgroundColourId));

auto area = getLocalBounds();
g.setColour(juce::Colours::white);
g.setFont(16.0f);
auto helloWorld = juce::String("Hello from ") + PRODUCT_NAME_WITHOUT_VERSION + " v"
VERSION + " running in " + CMAKE_BUILD_TYPE;
g.drawText(helloWorld, area.removeFromTop(150), juce::Justification::centred, false);
const auto time = juce::Time::getCurrentTime();
const auto timeString = time.toString(false, true, true, true);
g.setFont(getLocalBounds().toFloat().getHeight() * .5f);

if (colourFlag == 0) {
g.fillAll(juce::Colours::white);
g.setColour(juce::Colours::black);
g.drawText(timeString, getLocalBounds(), juce::Justification::centred);
} else {
g.fillAll(juce::Colours::black);
g.setColour(juce::Colours::white);
g.drawText(timeString, getLocalBounds(), juce::Justification::centred);
}
}

void PluginEditor::mouseDown(const juce::MouseEvent &event) {
juce::ignoreUnused(event);
colourFlag = 1 - colourFlag;
}

void PluginEditor::resized() {
// layout the positions of your child components here
auto area = getLocalBounds();
area.removeFromBottom(50);
inspectButton.setBounds(getLocalBounds().withSizeKeepingCentre(100, 50));
}

void PluginEditor::timerCallback() {
repaint();
}
13 changes: 9 additions & 4 deletions source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include "BinaryData.h"

//==============================================================================
class PluginEditor : public juce::AudioProcessorEditor {
class PluginEditor : public juce::AudioProcessorEditor,
juce::Timer {
public:
explicit PluginEditor(PluginProcessor &);

Expand All @@ -15,10 +16,14 @@ class PluginEditor : public juce::AudioProcessorEditor {

void resized() override;

void mouseDown(const juce::MouseEvent &event) override;

private:
// This reference is provided as a quick way for your editor to
// access the processor object that created it.
PluginProcessor &processorRef;
juce::TextButton inspectButton{"Inspect the UI"};

int colourFlag = 0;

void timerCallback() override;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginEditor)
};

0 comments on commit dc5ddb3

Please sign in to comment.