Newer
Older
invertedlogic / InvertedLogic / iLFramework / toolkit / src / GL / Nodes.cpp
@John Ryland John Ryland on 10 Nov 2019 1 KB rename
#include "GL/Nodes.h"
#include "GL/Font.h"
#include "GL/ImmediateMode.h"
#include "GL/Program.h"


BEGIN_NAMESPACE


NodePanel::NodePanel(int a_x, int a_y, int a_w, int a_h, const char* a_name) : Panel(a_x, a_y, a_w, a_h, a_name)
{
	background = 0x60a0a0a0;
}


void NodePanel::addInput(const char* a_input)
{
	m_inputs.push_back(a_input);
}


void NodePanel::addOutput(const char* a_output)
{
	m_outputs.push_back(a_output);
}


void NodePanel::draw()
{
	drawPanel();

	const int dotSpacing = 28;
	float xf = (float)x, yf = (float)y, wf = (float)w, hf = (float)h;

	for (unsigned i = 0; i < m_inputs.size(); ++i) {
		glDrawDot(xf, yf+h-dotSpacing-dotSpacing*i);
		glDrawShadowText(x+13, y+h-dotSpacing-dotSpacing*i+12, m_inputs[i].data());
	}

	for (unsigned i = 0; i < m_outputs.size(); ++i) {
		glDrawDot(xf+w, yf+10+dotSpacing+dotSpacing*i);
		int tw = (int)textWidth(m_outputs[i].data()) * 17;//fontSize;
		glDrawShadowText(x+w- tw - 15, y+12+dotSpacing+dotSpacing*i+10, m_outputs[i].data());
	}

	//glDrawDot(x, y+h-dotSpacing-dotSpacing);
	//glDrawDot(x+w, y+10+dotSpacing);
}


void NodePanel::GetInputSlotPosition(int slot, int &a_x, int &a_y)
{
	a_x = x;
	a_y = y + h + 2 - 21 - 28*slot;
}


void NodePanel::GetOutputSlotPosition(int slot, int &a_x, int &a_y)
{
	a_x = x + w;
	a_y = y + 17 - 2 + 28 + 28 * slot;
}


Connection::Connection(NodePanel* a_outputPanel, int a_output, NodePanel* a_inputPanel, int a_input)
	: outputPanel(a_outputPanel), output(a_output), inputPanel(a_inputPanel), input(a_input)
{
}


void Connection::draw()
{
	int x1,y1,x2,y2;
	outputPanel->GetOutputSlotPosition(output, x1, y1);
	inputPanel->GetInputSlotPosition(input, x2, y2);
	glDrawStyledCurvedLine((float)x1, (float)y1, (float)x2, (float)y2, g_zoomFactor);
}


END_NAMESPACE