From b5154bf5790d36e684ec02420ccc9a438b3046a1 Mon Sep 17 00:00:00 2001
From: jsiegle <jsiegle@mit.edu>
Date: Mon, 13 Feb 2012 19:36:01 -0500
Subject: [PATCH] FilterViewport can now be hidden

- Added a FilterViewportButton class to the UIComponent file, which shows/hides
the FilterViewport whenever it's clicked
- Thus, the DataViewport can now fill up almost the entire window
---
 Builds/Linux/build/windowState.xml |   2 +-
 Source/UI/FilterList.cpp           |   4 +-
 Source/UI/FilterViewport.cpp       |   6 +-
 Source/UI/MessageCenter.cpp        |   4 +-
 Source/UI/UIComponent.cpp          | 123 ++++++++++++++++++++++++++---
 Source/UI/UIComponent.h            |  56 ++++++++++++-
 6 files changed, 176 insertions(+), 19 deletions(-)

diff --git a/Builds/Linux/build/windowState.xml b/Builds/Linux/build/windowState.xml
index cddb7cf3d..d2a9ab3cf 100644
--- a/Builds/Linux/build/windowState.xml
+++ b/Builds/Linux/build/windowState.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
 <MAINWINDOW>
-  <BOUNDS x="1870" y="189" w="927" h="718" fullscreen="0"/>
+  <BOUNDS x="1600" y="52" w="1680" h="973" fullscreen="0"/>
 </MAINWINDOW>
diff --git a/Source/UI/FilterList.cpp b/Source/UI/FilterList.cpp
index 3821f257e..4ab3451b8 100644
--- a/Source/UI/FilterList.cpp
+++ b/Source/UI/FilterList.cpp
@@ -393,11 +393,11 @@ void FilterList::mouseDown(const MouseEvent& e)
 		if (fli == baseItem)
 		{
 			if (fli->isOpen()) {
-				UI->filterListOpened();
+				UI->childComponentChanged();
 			}
 			else
 			{
-				UI->filterListClosed();
+				UI->childComponentChanged();
 				//setBounds(0,0,225,itemHeight + 2*yBuffer); 
 				totalHeight = itemHeight + 2*yBuffer;
 			}
diff --git a/Source/UI/FilterViewport.cpp b/Source/UI/FilterViewport.cpp
index 6c7a94e20..ed5440eea 100644
--- a/Source/UI/FilterViewport.cpp
+++ b/Source/UI/FilterViewport.cpp
@@ -47,10 +47,12 @@ void FilterViewport::paint (Graphics& g)
          g.setColour (Colours::magenta);
 
     } else {
-        g.setColour (Colour(127,137,147));
+        g.setColour (Colour(48,48,48));
     }
 
-    g.fillRoundedRectangle (tabSize, 0, getWidth(), getHeight(), 8);
+    g.fillRect (0, 0, getWidth(), getHeight());
+
+    //g.fillRoundedRectangle (tabSize, 0, getWidth(), getHeight(), 8);
 
     g.setColour (Colour(170,178,183));
     g.fillRect (tabSize+borderSize,borderSize,
diff --git a/Source/UI/MessageCenter.cpp b/Source/UI/MessageCenter.cpp
index b51fedced..1e6e5e104 100644
--- a/Source/UI/MessageCenter.cpp
+++ b/Source/UI/MessageCenter.cpp
@@ -30,9 +30,9 @@ MessageCenter::~MessageCenter() {
 void MessageCenter::paint(Graphics& g)
 {
 	
-	g.setColour (Colour(103,116,140));
+	g.setColour (Colour(58,58,58));
 
-	g.fillRoundedRectangle (0, 0, getWidth(), getHeight(), 5);
+	g.fillRect (0, 0, getWidth(), getHeight());
 
 	g.setColour (messageBackground);
    
diff --git a/Source/UI/UIComponent.cpp b/Source/UI/UIComponent.cpp
index 980e8b25b..827e86087 100644
--- a/Source/UI/UIComponent.cpp
+++ b/Source/UI/UIComponent.cpp
@@ -33,6 +33,9 @@ UIComponent::UIComponent (ProcessorGraph* pgraph, AudioComponent* audio_)
 
 	std::cout << "Created filter viewport." << std::endl;
 
+	filterViewportButton = new FilterViewportButton(this);
+	addAndMakeVisible(filterViewportButton);
+
 	controlPanel = new ControlPanel(processorGraph, audio);
 	addAndMakeVisible(controlPanel);
 
@@ -87,14 +90,29 @@ void UIComponent::resized()
 	int h = getHeight();
 	
 	if (dataViewport != 0) {
-		if (filterList->isOpen())
-			dataViewport->setBounds(202,40,w-207,h-230);
-		else 
-			dataViewport->setBounds(6,40,w-11,h-230);
+		if (filterList->isOpen() && filterViewportButton->isOpen())
+			dataViewport->setBounds(202,40,w-207,h-235);
+		else if (!filterList->isOpen() && filterViewportButton->isOpen())
+			dataViewport->setBounds(6,40,w-11,h-235);
+		else if (filterList->isOpen() && !filterViewportButton->isOpen())
+			dataViewport->setBounds(202,40,w-207,h-85);
+		else	
+			dataViewport->setBounds(6,40,w-11,h-85);
+	}
+
+	if (filterViewportButton != 0)
+	{
+		filterViewportButton->setBounds(w-230, h-40, 225, 35);
 	}
 	
-	if (filterViewport != 0)
-		filterViewport->setBounds(10,h-175,w-20,125);
+	if (filterViewport != 0) {
+		if (filterViewportButton->isOpen() && !filterViewport->isVisible())
+			filterViewport->setVisible(true);
+		else if (!filterViewportButton->isOpen() && filterViewport->isVisible())
+			filterViewport->setVisible(false);
+
+		filterViewport->setBounds(6,h-190,w-11,150);
+	}
 
 	if (controlPanel != 0)
 		controlPanel->setBounds(201,6,w-210,32);
@@ -107,7 +125,7 @@ void UIComponent::resized()
 	}
 
 	if (messageCenter != 0)
-		messageCenter->setBounds(40,h-40,w-160,30);
+		messageCenter->setBounds(6,h-35,w-241,30);
 
 }
 
@@ -117,13 +135,98 @@ void UIComponent::disableCallbacks()
 	controlPanel->disableCallbacks();
 }
 
-void UIComponent::filterListOpened()
+void UIComponent::childComponentChanged()
 {
 	resized();
 }
 
-void UIComponent::filterListClosed()
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+FilterViewportButton::FilterViewportButton(UIComponent* ui) : UI(ui)
 {
+	open = true;
+
+	const unsigned char* buffer = reinterpret_cast<const unsigned char*>(BinaryData::cpmono_light_otf);
+	size_t bufferSize = BinaryData::cpmono_light_otfSize;
+
+	font = new FTPixmapFont(buffer, bufferSize);
 	
-	resized();
+}
+
+FilterViewportButton::~FilterViewportButton()
+{
+	
+}
+
+void FilterViewportButton::newOpenGLContextCreated()
+{
+	
+	glMatrixMode (GL_PROJECTION);
+
+	glLoadIdentity();
+	glOrtho (0, 1, 1, 0, 0, 1);
+	glMatrixMode (GL_MODELVIEW);
+	
+	glEnable(GL_TEXTURE_2D);
+
+	glClearColor(0.23f, 0.23f, 0.23f, 1.0f); 
+
+	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
+	glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
+	glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
+
+	glEnable(GL_LINE_SMOOTH);
+	glEnable(GL_POINT_SMOOTH);
+	glEnable(GL_POLYGON_SMOOTH);
+
+	glEnable(GL_BLEND);
+	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+}
+
+
+void FilterViewportButton::renderOpenGL()
+{
+	glClear(GL_COLOR_BUFFER_BIT);
+	drawName();
+	drawButton();
+}
+
+void FilterViewportButton::drawName()
+{
+	glColor4f(1.0f,1.0f,1.0f,1.0f);
+	glRasterPos2f(5.0/getWidth(),0.75f);
+	font->FaceSize(23);
+	font->Render("SIGNAL CHAIN");
+	
+
+	
+}
+
+void FilterViewportButton::drawButton()
+{
+	glColor4f(1.0f,1.0f,1.0f,1.0f);
+	glLineWidth(1.0f);
+
+	glBegin(GL_LINE_LOOP);
+
+	if (open)
+	{
+		glVertex2f(0.90,0.65);
+		glVertex2f(0.925,0.35);
+	} else {
+		glVertex2f(0.95,0.35);
+		glVertex2f(0.90,0.5);
+	}
+	glVertex2f(0.95,0.65);
+	glEnd();
+
+}
+
+void FilterViewportButton::mouseDown(const MouseEvent& e)
+{
+	open = !open;
+	UI->childComponentChanged();
+	repaint();
+
 }
\ No newline at end of file
diff --git a/Source/UI/UIComponent.h b/Source/UI/UIComponent.h
index 87010e04a..999d5cccc 100644
--- a/Source/UI/UIComponent.h
+++ b/Source/UI/UIComponent.h
@@ -23,6 +23,31 @@
 #include "../Processors/ProcessorGraph.h"
 #include "../Audio/AudioComponent.h"
 
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
+#if JUCE_WINDOWS
+#include <gl/gl.h>
+#include <gl/glu.h>
+#elif JUCE_LINUX
+#include <GL/gl.h>
+#include <GL/glut.h>
+#undef KeyPress
+#elif JUCE_IPHONE
+#include <OpenGLES/ES1/gl.h>
+#include <OpenGLES/ES1/glext.h>
+#elif JUCE_MAC
+#include <GLUT/glut.h>
+#endif
+
+#ifndef GL_BGRA_EXT
+#define GL_BGRA_EXT 0x80e1
+#endif
+
+#include <FTGL/ftgl.h>
+
+class FilterViewportButton;
 
 class UIComponent : public Component,
 				    public ActionBroadcaster,
@@ -42,13 +67,13 @@ public:
 	//void transmitMessage(const String& message);
 	void disableCallbacks();
 
-	void filterListOpened();
-	void filterListClosed();
+	void childComponentChanged();
 
 private:
 
 	DataViewport* dataViewport;
 	FilterViewport* filterViewport;
+	FilterViewportButton* filterViewportButton;
 	FilterList* filterList;
 	ControlPanel* controlPanel;
 	MessageCenter* messageCenter;
@@ -64,4 +89,31 @@ private:
 	
 };
 
+
+
+class FilterViewportButton : public OpenGLComponent
+{
+public:
+	FilterViewportButton(UIComponent* ui);
+	~FilterViewportButton();
+
+	bool isOpen() {return open;}
+
+	void newOpenGLContextCreated();
+	void renderOpenGL();
+
+	void drawName();
+	void drawButton();
+
+	void mouseDown(const MouseEvent& e);
+
+private:	
+
+	UIComponent* UI;
+	bool open;
+
+	FTPixmapFont* font;
+
+};
+
 #endif  // __UICOMPONENT_H_D97C73CF__
-- 
GitLab