#include "GUIShaderNodeIO.h" #include GUIShaderNodeIO::GUIShaderNodeIO(GUIShaderNode* _parent) :mode_input(true), can_drag(false) { Owner = _parent; skip_mouse = true; arrow = new GUINodePort(); arrow->SetWidth(14); arrow->SetHeight(10); arrow->SetBackColor(Vec4f(0,0,1,1)); arrow->user_data = this; arrow->SetMode(mode_input); AddChild(arrow); caption = new GUIText(); caption->SetAutoSize(true); caption->SetText("UV"); caption->SetBackColor(Vec4f(1,1,1,0.1f)); caption->SetForeColor(Vec4f(0,0,0,1.0f)); AddChild(caption); arrow->Event_MouseDown += NewDelegate(this, &GUIShaderNodeIO::OnArrowPress); arrow->Event_MouseClick += NewDelegate(this, &GUIShaderNodeIO::OnArrowClick); arrow->Event_Link += NewDelegate(this, &GUIShaderNodeIO::AcceptLink); } Vec2i GUIShaderNodeIO::GetAttachPoint() { Vec2i pos = arrow->GetPositionAbs(); pos.Y += arrow->GetHeight() / 2; if(IsInput()) { pos.X += arrow->GetWidth(); } return pos; } GUIShaderNodeIO::~GUIShaderNodeIO() { } void GUIShaderNodeIO::AcceptLink(GUINodePort* me, GUINodePort* other) { Event_Link.Invoke(this, reinterpret_cast(other->user_data)); } void GUIShaderNodeIO::SetCaption(const String& _caption) { caption->SetText(_caption); } void GUIShaderNodeIO::SetMode(bool input) { mode_input = input; arrow->SetMode(mode_input); } void GUIShaderNodeIO::Update(float dt) { } void GUIShaderNodeIO::RenderSelf() { int caption_offset = 3; if(this->GetWidth() != (caption->GetWidth() + arrow->GetWidth() + caption_offset)) { this->SetWidth(caption->GetWidth() + arrow->GetWidth() + caption_offset); } int h = 0; if(caption->GetHeight() > arrow->GetHeight()) h = caption->GetHeight(); else h = arrow->GetHeight(); if(this->GetHeight() != h) this->SetHeight(h); if(mode_input) { arrow->SetPosition(Vec2i(0,(caption->GetHeight() - arrow->GetHeight()) / 2 )); caption->SetPosition(Vec2i(arrow->GetWidth() + caption_offset, 0)); } else { caption->SetPosition(Vec2i(0,0)); arrow->SetPosition(Vec2i(caption->GetWidth() + caption_offset, (caption->GetHeight() - arrow->GetHeight()) / 2 )); } } void GUIShaderNodeIO::SetBackColor(const Vec4f& color) { } void GUIShaderNodeIO::OnArrowPress(GUIWindow* w, int arg) { if(arg == KEY_MOUSE_LEFT) can_drag = true; } void GUIShaderNodeIO::OnArrowClick(GUIWindow* w, int arg) { Event_PortClick.Invoke(this, arg); }