Example #1
0
namespace UI
{

void DragDeltaEventArgs::InvokeEventHandler(Object* genericTarget, stub_interface_base* genericHandler)
{
	stub_interface2<void, Object*, DragDeltaEventArgs*>* handler = dynamic_cast<stub_interface2<void, Object*, DragDeltaEventArgs*>*>(genericHandler);
	ASSERT(handler);

	handler->invoke(genericTarget, this);
}

/*
Thumb::Thumb()
{
	Border* pBorder = new Border(new Thickness(1));
	pBorder->set_BorderBrush(new LinearGradientBrush(new Color(255, 255, 255), new Color(0, 0, 0), new Point(0, 0), new Point(0, 1)));
//	pBorder->set_BorderBrush(new SolidColorBrush(new Color(0, 0, 0)));
	pBorder->set_Background(new SolidColorBrush(new Color(80, 114, 158)));

	set_VisualTree(pBorder);
}
*/

DependencyProperty* Thumb::s_IsDraggingProperty = RegisterProperty(WSTR("IsDragging"), typeid(bool), typeid(Thumb), BoolObject::get_False(), PropertyMetaData(None));

RoutedEvent* Thumb::s_DragStartedEvent;
RoutedEvent* Thumb::s_DragCompletedEvent;
RoutedEvent* Thumb::s_DragDeltaEvent = EventManager::RegisterRoutedEvent(WSTR("DragDelta"), RoutingStrategy_Bubble, typeid(stub_interface2<void, Object*, DragDeltaEventArgs*>), typeid(Thumb));

//void ApplyStyle(Style* style, FrameworkElement* element);
//Object* CreateObjectFromElement(Type* pType, Object* parentObject, XmlData::Node* node, Type** pReturnType);

__live_object_ptr<Style> ThumbStyle;

Thumb::Thumb()
{
	m_dragging = false;

	if (ThumbStyle == NULL)
	{
		XmlData::Document* document = new XmlData::Document;

		StringW* filename = MakeFilePath(_Module, L"../../../ThumbStyle.lxui");
		document->load(filename);

		Type* returnType;
		ThumbStyle = dynamic_cast<Style*>(CreateObjectFromElement(NULL, NULL, document->get_documentElement(), &returnType));
	}

	set_Style(ThumbStyle);
/*
	ApplyStyle(get_Style(), this);
	InitScript();
	*/
}

bool Thumb::get_IsDragging()
{
	return static_cast<BoolObject*>(GetValue(get_IsDraggingProperty()))->GetValue();
}

void Thumb::set_IsDragging(bool dragging)
{
	SetValue(get_IsDraggingProperty(), BoolObject::GetObject(dragging));
}

void Thumb::OnMouseDown(MouseButtonEventArgs* args)
{
	if (!m_dragging)
	{
		CaptureMouse();
		set_IsDragging(true);
		m_dragging = true;
		m_oldpoint = args->GetPosition(dynamic_cast<IInputElement*>(GetRParent()));//LDraw::PointD(mouseevt->get_ScreenX(), mouseevt->get_ScreenY());
	}

	args->set_Handled(true);
}

void Thumb::OnMouseUp(MouseButtonEventArgs* args)
{
	if (m_dragging)
	{
		ReleaseMouseCapture();
		set_IsDragging(false);
		m_dragging = false;
	}

	args->set_Handled(true);
}

void Thumb::OnMouseMove(MouseEventArgs* args)
{
//	Point point(mouseevt->get_ScreenX(), mouseevt->get_ScreenY());
	Point point = args->GetPosition(dynamic_cast<IInputElement*>(GetRParent()));//point(mouseevt->get_ScreenX(), mouseevt->get_ScreenY());

	if (m_dragging)
	{
#if 0
		DragDeltaEvent* dragevent = new DragDeltaEvent;
		dragevent->InitEvent(WSTR("DragDelta"), true, true);

		dragevent->m_HorizontalChange = point.X - m_oldpoint.X;
		dragevent->m_VerticalChange = point.Y - m_oldpoint.Y;

		m_oldpoint = point;

		dispatchEvent(dragevent);
#endif

		DragDeltaEventArgs* args = new DragDeltaEventArgs;
		args->set_RoutedEvent(get_DragDeltaEvent());
		args->m_HorizontalChange = point.X - m_oldpoint.X;
		args->m_VerticalChange = point.Y - m_oldpoint.Y;
		m_oldpoint = point;

		RaiseEvent(args);
	}

	args->set_Handled(true);
}

#if 0
void Thumb::handleEvent(Event* evt)
{
	StringW* type = evt->get_type();

	if (evt->get_eventPhase() != CAPTURING_PHASE)
	{
		if (type == MouseEvent::mousedown)
		{
			MouseEvent* mouseevt = static_cast<MouseEvent*>(evt);

			if (!m_dragging)
			{
				CaptureMouse();
				m_dragging = true;
				m_oldpoint = LDraw::PointD(mouseevt->get_ScreenX(), mouseevt->get_ScreenY());
			}

		//	OnLButtonDown(static_cast<MouseEvent*>(evt));
			evt->stopPropagation();
		}
		else if (type == MouseEvent::mouseup)
		{
			if (m_dragging)
			{
				ReleaseMouseCapture();
				m_dragging = false;
			}
		//	OnLButtonUp(static_cast<MouseEvent*>(evt));
			evt->stopPropagation();
		}
		else if (type == MouseEvent::mousemove)
		{
			MouseEvent* mouseevt = static_cast<MouseEvent*>(evt);

			//LDraw::PointD point = ScreenToClient(evt->get_ScreenX(), evt->get_ScreenY());
			LDraw::PointD point(mouseevt->get_ScreenX(), mouseevt->get_ScreenY());

			if (m_dragging)
			{
				DragDeltaEvent* dragevent = new DragDeltaEvent;
				dragevent->InitEvent(WSTR("DragDelta"), true, true);

				dragevent->m_HorizontalChange = point.X - m_oldpoint.X;
				dragevent->m_VerticalChange = point.Y - m_oldpoint.Y;

				m_oldpoint = point;

				dispatchEvent(dragevent);
			}

		//	OnMouseMove(static_cast<MouseEvent*>(evt));
			evt->stopPropagation();
		}
	}
}
#endif

}	// UI
Example #2
0
namespace Media
{

DependencyProperty* TimelineGroup::s_ChildrenProperty = RegisterProperty(WSTR("Children"), typeid(TimelineCollection), typeid(TimelineGroup), NULL, PropertyMetaData(None));

TimelineCollection::TimelineCollection()
{
}

//

TimelineGroup::TimelineGroup()
{
	set_Children(new TimelineCollection());
}

TimelineCollection* TimelineGroup::get_Children()
{
	return static_cast<TimelineCollection*>(GetValue(get_ChildrenProperty()));
}

void TimelineGroup::set_Children(TimelineCollection* children)
{
	SetValue(get_ChildrenProperty(), children);
}

}	// Media
Example #3
0
namespace Media
{

DependencyProperty* Timeline::s_DurationProperty = RegisterProperty(WSTR("Duration"), typeid(double), typeid(Timeline), DoubleObject::GetObject(1), PropertyMetaData(None));
DependencyProperty* Timeline::s_BeginTimeProperty = RegisterProperty(WSTR("BeginTime"), typeid(double), typeid(Timeline), DoubleObject::GetObject(0), PropertyMetaData(None));
DependencyProperty* Timeline::s_AutoReverseProperty = RegisterProperty(WSTR("AutoReverse"), typeid(bool), typeid(Timeline), BoolObject::GetObject(false), PropertyMetaData(None));
DependencyProperty* Timeline::s_FillBehaviorProperty = RegisterProperty(WSTR("FillBehavior"), typeid(FillBehavior), typeid(Timeline), IntObject::GetObject(FillBehavior_HoldEnd), PropertyMetaData(None));
DependencyProperty* Timeline::s_RepeatBehaviorProperty = RegisterProperty(WSTR("RepeatBehavior"), typeid(RepeatBehavior), typeid(Timeline), new RepeatBehavior(1.0), PropertyMetaData(None));
DependencyProperty* Timeline::s_SpeedRatioProperty = RegisterProperty(WSTR("SpeedRatio"), typeid(double), typeid(Timeline), DoubleObject::GetObject(1.0), PropertyMetaData(None));
DependencyProperty* Timeline::s_AccelerationRatioProperty = RegisterProperty(WSTR("Acceleration"), typeid(double), typeid(Timeline), DoubleObject::GetObject(0.0), PropertyMetaData(None));
DependencyProperty* Timeline::s_DecelerationRatioProperty = RegisterProperty(WSTR("Deceleration"), typeid(double), typeid(Timeline), DoubleObject::GetObject(0.0), PropertyMetaData(None));

Timeline::Timeline()
{
//	m_containingElement = NULL;
}

#define REMAINDER(t, d) (t - d*floor(t/d))

double Timeline::ActiveTimeToSimpleTime(double tau, int* iteration)
{
	// m_simpleDur has accounted for autoReverse
	double m_AD = 99999;
	double m_simpleDur = get_Duration();
	double m_dur = get_Duration();

	double AD = m_AD;//m_dur;// ? AD=Active Duration?
	double speed = get_SpeedRatio();//m_speed->m_value->m_value->m_value;

	double acc = get_AccelerationRatio();//m_accelerate->m_value->m_value->m_value;
	double dec = get_DecelerationRatio();//m_decelerate->m_value->m_value->m_value;

	if (acc+dec > 1)	// Ignore both attributes
	{
		acc = 0;
		dec = 0;
	}

	double taf;

	if (speed > 0) // i.e. if the local speed is forwards 
		taf = tau * speed;
	else //  i.e. if the local speed is backwards 
		taf = AD - tau * fabs(speed);

	//Let dur be the value of the simple duration as defined by the Timing and Synchronization model.
	// This is the actual simple duration, and not simply the dur attribute.
	//This value does not account for the effect of any time manipulations.
	double dur = m_dur;
	ASSERT(dur >= 0);
	//if (dur < 0) dur = INDEFINITE;	// indefinite (Is this correct?)

	// m_simpleDur has accounted for autoReverse
	double dur_ = m_simpleDur;

#if 1	// Have something like this
	double tsu = REMAINDER(taf, dur_);
#else
	double tsu = taf;
#endif

	if (iteration)
	{	// ??
		*iteration = (int)(taf/dur_);
	}

// Account for autoReverse behavior.
	double tsu_;

	if (!get_AutoReverse())
	{
		tsu_ = tsu;
	}
	else
	{
		if (tsu < dur)
			tsu_ = tsu;
		else
			//tsu_ = /*dur - (tsu - dur) =*/ 2*dur - tsu;
			tsu_ = 2*dur - tsu;
	}

// Calculate filtered time (tsf)

// Account for acceleration/deceleration
	double tsf;

	double dacc = acc*dur;
	double ddec = dec*dur;

	double r = 1 / (1 - acc/2 - dec/2);

	if (tsu_ >= 0 && tsu_ < dacc)
	{
		double rt = r * (tsu_ / dacc);

		tsf = tsu_ * rt / 2;
	}
	else if (tsu_ > (dur - ddec))
	{
		double rt = r * (dur - tsu_) / ddec;

		double tdec =  tsu_ - (dur - ddec);
		double pd =  tdec / ddec;

		tsf = r * (dur - dacc / 2 - ddec + tdec * (2 - pd) / 2);
	}
	else
	{
		tsf = r * (tsu_ - dacc / 2);
	}

//	tsf = tsf + m_iteration*dur_;	// ???? TODO remove this

	return tsf;
}

/*
Clock* Timeline::AllocateClock()
{
	throw exception("");
	ASSERT(0);
	return NULL;
}
*/

double Timeline::GetNaturalDuration()
{
	return 0;
}

/*
DependencyObject* Timeline::GetDependencyParent()
{
	// ??
	return NULL;
}
*/

/*
void Timeline::AddChild(System::Object* child)
{
	m_animations.push_back(dynamic_cast<Animation*>(child));
}

void Timeline::AddText(System::StringW* text)
{
}
*/

Clock* Timeline::CreateClock(bool controllable)
{
	Clock* clock = AllocateClock();
	VERIFY(clock);
	m_createdClocks.push_back(clock);

	return clock;
}

//double fps = 20;

Nullable<double> Timeline::get_BeginTime()
{
//	return static_cast<DoubleObject*>(GetValue(get_BeginTimeProperty()))->GetValue();
	return unbox_nullable_cast<double>(GetValue(get_BeginTimeProperty()));
}

void Timeline::set_BeginTime(Nullable<double> duration)
{
	SetValue(get_BeginTimeProperty(), box_nullable_cast(duration));
}

double Timeline::get_Duration()
{
	return static_cast<DoubleObject*>(GetValue(get_DurationProperty()))->GetValue();
}

void Timeline::set_Duration(double duration)
{
	SetValue(get_DurationProperty(), DoubleObject::GetObject(duration));
}

bool Timeline::get_AutoReverse()
{
	return static_cast<BoolObject*>(GetValue(get_AutoReverseProperty()))->GetValue();
}

void Timeline::set_AutoReverse(bool autoReverse)
{
	SetValue(get_AutoReverseProperty(), BoolObject::GetObject(autoReverse));
}

RepeatBehavior* Timeline::get_RepeatBehavior()
{
	return static_cast<RepeatBehavior*>(GetValue(get_RepeatBehaviorProperty()));
}

void Timeline::set_RepeatBehavior(RepeatBehavior* repeatBehavior)
{
	SetValue(get_RepeatBehaviorProperty(), repeatBehavior);
}

double Timeline::get_SpeedRatio()
{
	return static_cast<DoubleObject*>(GetValue(get_SpeedRatioProperty()))->GetValue();
}

double Timeline::get_AccelerationRatio()
{
	return static_cast<DoubleObject*>(GetValue(get_AccelerationRatioProperty()))->GetValue();
}

double Timeline::get_DecelerationRatio()
{
	return static_cast<DoubleObject*>(GetValue(get_DecelerationRatioProperty()))->GetValue();
}

/*
void Timeline::Begin(Animatable* containingElement)
{
	m_containingElement = containingElement;
	m_time = 0;
	m_timerID = SetTimer(1000.0 / fps, this);
}
*/

#if 0
void Timeline::dispatchEvent2(Event* evt, bool bCapture, bool* doDefault)
{
	m_time += 1.0 / fps;
//	MessageBeep(-1);

	for (int i = 0; i < m_animations.size(); i++)
	{
		Animation* animation = m_animations[i];

		if (m_time >= animation->get_Duration())
		{
		//	MessageBeep(-1);
			KillTimer(m_timerID);
			return;
		}

		ASSERT(0);
		DependencyProperty* property = NULL;//GetProperty(animation->m_targetProperty);

		animation->m_currentTime = m_time;

		//animation->Do(property, m_time);
		m_containingElement->ApplyAnimation(property, animation);
	}
}
#endif

}	// Media
Example #4
0
namespace UI
{

DependencyProperty* DockPanel::s_DockProperty = RegisterAttached(WSTR("Dock"), typeid(DockEnum), typeid(DockPanel), IntObject::GetObject(Left), PropertyMetaData(None));
DependencyProperty* DockPanel::s_LastChildFillProperty = RegisterProperty(WSTR("LastChildFill"), typeid(bool), typeid(DockPanel), BoolObject::get_True(), PropertyMetaData(None));

DockPanel::DockPanel()
{
}

bool DockPanel::get_LastChildFill()
{
    return static_cast<BoolObject*>(GetValue(get_LastChildFillProperty()))->GetValue();
}

void DockPanel::set_LastChildFill(bool lastChildFill)
{
    SetValue(get_LastChildFillProperty(), BoolObject::GetObject(lastChildFill));
}

// static
DockPanel::DockEnum DockPanel::GetDock(DependencyObject* pObject)
{
    Object* obj = pObject->GetValue(get_DockProperty());
    ASSERT(dynamic_cast<IntObject*>(obj));
    System::IntObject* pInt = static_cast<IntObject*>(obj);

    return (DockEnum)pInt->GetValue();
}

// static
void DockPanel::SetDock(DependencyObject* pObject, DockEnum newVal)
{
    if (newVal != Left &&
            newVal != Top &&
            newVal != Right &&
            newVal != Bottom &&
            newVal != Fill)
    {
        ASSERT(0);
        THROW(std::exception("Invalid Dock enum value"));
    }

    pObject->SetValue(get_DockProperty(), IntObject::GetObject(newVal));
}

// static
void DockPanel::ClearDock(DependencyObject* pObject)
{
    pObject->ClearValue(get_DockProperty());
}

void DockPanel::RemoveChildren()
{
    // ??
    get_Children()->m_items.clear();
//	ASSERT(0);
#if 0
    for (int i = get_rchildList()->get_Size()-1; i >= 0; i--)
    {
        RemoveRChild((*get_rchildList())[i]);
    }
#endif
    InvalidateMeasure();
}

// virtual
LDraw::SizeD DockPanel::MeasureOverride(LDraw::SizeD availSize)
{
    LDraw::BBoxD layoutRect(0, 0, availSize.Width, availSize.Height);

    double minWidth = 0;
    double minHeight = 0;
    double totalWidth = 0;
    double totalHeight = 0;

    unsigned int ncount = get_InternalChildren()->GetCount();

#if 0
    for (unsigned int i = 0; i < ncount; i++)
    {
        UIElement* pVisual = get_InternalChildren()->GetItem(i);//(*get_rchildList())[i];

        // TODO remove this
        //	pVisual->SetRParent(this);
    }
#endif

    for (unsigned int i = 0; i < ncount; i++)
    {
        UIElement* pVisual = get_InternalChildren()->get_Item(i);//(*get_rchildList())[i];

        ASSERT(pVisual->GetRParent() == this);

        if (pVisual->get_Visibility() != Collapsed)
        {
            DockEnum dock = GetDock(pVisual);

            if (dock == Fill || ((i == ncount-1) && get_LastChildFill()))
            {
                pVisual->Measure(LDraw::SizeD(layoutRect.GetWidth(), layoutRect.GetHeight()));
                totalWidth += pVisual->get_DesiredSize().Width;
                totalHeight += pVisual->get_DesiredSize().Height;
                break;
            }
            else if (dock == Left)
            {
                pVisual->Measure(LDraw::SizeD(0, layoutRect.GetHeight()));
                layoutRect.left += pVisual->get_DesiredSize().Width;
                totalWidth += pVisual->get_DesiredSize().Width;
                //	totalHeight = max(totalHeight, pVisual->m_desiredHeight);
                minHeight = MAX(minHeight, pVisual->get_DesiredSize().Height);
            }
            else if (dock == Top)
            {
                pVisual->Measure(LDraw::SizeD(layoutRect.GetWidth(), 0));
                layoutRect.top += pVisual->get_DesiredSize().Height;
                totalHeight += pVisual->get_DesiredSize().Height;
                //	totalWidth = max(totalWidth, pVisual->m_desiredWidth);
                minWidth = MAX(minWidth, pVisual->get_DesiredSize().Width);
            }
            else if (dock == Right)
            {
                pVisual->Measure(LDraw::SizeD(0, layoutRect.GetHeight()));
                layoutRect.right -= pVisual->get_DesiredSize().Width;
                totalWidth += pVisual->get_DesiredSize().Width;
                //	totalHeight = max(totalHeight, pVisual->m_desiredHeight);
                minHeight = MAX(minHeight, pVisual->get_DesiredSize().Height);
            }
            else if (dock == Bottom)
            {
                pVisual->Measure(LDraw::SizeD(layoutRect.GetWidth(), 0));
                layoutRect.bottom -= pVisual->get_DesiredSize().Height;
                totalHeight += pVisual->get_DesiredSize().Height;
                //	totalWidth = max(totalWidth, pVisual->m_desiredWidth);
                minWidth = MAX(minWidth, pVisual->get_DesiredSize().Width);
            }
            else
                ASSERT(0);

            //	pVisual->SetLayoutOffset(fLeft, fTop);
            //	pVisual->Arrange(LDraw::SizeF(pVisual->m_computedWidth, pVisual->m_computedHeight));

            /*
            if (dock == Fill ||

            	layoutRect.GetWidth() <= 0 ||
            	layoutRect.GetHeight() <= 0)
            {
            	break;
            }
            */
        }
    }

    return LDraw::SizeD(MAX(minWidth, totalWidth), MAX(minHeight, totalHeight));
}

// virtual
LDraw::SizeD DockPanel::ArrangeOverride(LDraw::SizeD finalSize)
{
    LDraw::BBoxD layoutRect(0, 0, finalSize.Width, finalSize.Height);

    unsigned int ncount = get_InternalChildren()->GetCount();//get_rchildList()->get_Size();
    for (unsigned int i = 0; i < ncount; i++)
    {
        UIElement* pVisual = get_InternalChildren()->get_Item(i);//(*get_rchildList())[i];

        if (pVisual->get_Visibility() != Collapsed)
        {
            //	long dockValue;
            DockEnum dock = GetDock(pVisual);

            ASSERT(pVisual->get_DesiredSize().Width >= 0 && pVisual->get_DesiredSize().Height >= 0);

            //	double fLeft;
            //	double fTop;

            if (dock == Fill || ((i == ncount-1) && get_LastChildFill()))
            {
                pVisual->Arrange(layoutRect);//LDraw::RectD(layoutRect.GetWidth(), layoutRect.GetHeight()));
                //	fLeft = layoutRect.left;
                //	fTop = layoutRect.top;
            }
            else if (dock == Left)
            {
                pVisual->Arrange(LDraw::RectD(layoutRect.left, layoutRect.top, pVisual->get_DesiredSize().Width, layoutRect.GetHeight()));
                //	fLeft = layoutRect.left;
                //	fTop = layoutRect.top;
                layoutRect.left += pVisual->get_ActualSize().Width;
            }
            else if (dock == Top)
            {
                pVisual->Arrange(LDraw::RectD(layoutRect.left, layoutRect.top, layoutRect.GetWidth(), pVisual->get_DesiredSize().Height));
                //	fLeft = layoutRect.left;
                //	fTop = layoutRect.top;
                layoutRect.top += pVisual->get_ActualSize().Height;
            }
            else if (dock == Right)
            {
                pVisual->Arrange(LDraw::RectD(layoutRect.right - pVisual->get_DesiredSize().Width, layoutRect.top, pVisual->get_DesiredSize().Width, layoutRect.GetHeight()));
                //	fLeft = layoutRect.right - pVisual->get_ActualSize().Width;
                //	fTop = layoutRect.top;
                layoutRect.right -= pVisual->get_ActualSize().Width;
            }
            else if (dock == Bottom)
            {
                pVisual->Arrange(LDraw::RectD(layoutRect.left, layoutRect.bottom - pVisual->get_DesiredSize().Height, layoutRect.GetWidth(), pVisual->get_DesiredSize().Height));
                //	fLeft = layoutRect.left;
                //	fTop = layoutRect.bottom - pVisual->get_ActualSize().Height;
                layoutRect.bottom -= pVisual->get_ActualSize().Height;
            }
            else
                ASSERT(0);

            //	pVisual->SetLayoutOffset(fLeft, fTop);

            if (dock == Fill ||

                    layoutRect.GetWidth() <= 0 ||
                    layoutRect.GetHeight() <= 0)
            {
                break;
            }
        }
    }

    return finalSize;
}

}	// UI
Example #5
0
namespace Shapes
{

DependencyProperty* Rectangle::s_RadiusXProperty = RegisterProperty(WSTR("RadiusX"), typeid(double), typeid(Rectangle), DoubleObject::GetObject(0), PropertyMetaData(AffectsRender));
DependencyProperty* Rectangle::s_RadiusYProperty = RegisterProperty(WSTR("RadiusY"), typeid(double), typeid(Rectangle), DoubleObject::GetObject(0), PropertyMetaData(AffectsRender));

Rectangle::Rectangle()
{
//	m_RadiusX = NULL;
//	m_RadiusY = NULL;

	SetClipMode(false);

	/*
	m_RectangleLeft = NULL;
	m_RectangleTop = NULL;
	m_RectangleWidth = NULL;
	m_RectangleHeight = NULL;
	m_RadiusX = NULL;
	m_RadiusY = NULL;
	*/
}

Rectangle::~Rectangle()
{
}

DependencyProperty* Rectangle::get_RadiusXProperty()
{
	return s_RadiusXProperty;
}

DependencyProperty* Rectangle::get_RadiusYProperty()
{
	return s_RadiusYProperty;
}

#if 0
LDraw::SizeD Rectangle::MeasureOverride(LDraw::SizeD availSize)
{
	if (m_RadiusX != NULL)
	{
		double Value = m_RadiusX->get_Value();
		if (m_RadiusX->get_UnitType() == LengthUnits::Percentage)
		{
			m_computedRadiusX = Value * availSize.Width;
		}
		else
		{
			m_computedRadiusX = Value;
		}
	}
	else
	{
		m_computedRadiusX = 0;
	}

	if (m_RadiusY != NULL)
	{
		double Value = m_RadiusY->get_Value();
		if (m_RadiusY->get_UnitType() == LengthUnits::Percentage)
		{
			m_computedRadiusY = Value * availSize.Height;
		}
		else
		{
			m_computedRadiusY = Value;
		}
	}
	else
	{
		m_computedRadiusY = 0;
	}

	return Shape::MeasureOverride(availSize);

	/*
	if (!m_RectangleLeft.IsNull())
	{
		double Value = m_RectangleLeft.get_Value();
		if (m_RectangleLeft.get_UnitType() == Length::UnitPercentage)
		{
			m_computedRectangleLeft = Value * availSize.Width;
		}
		else
		{
			m_computedRectangleLeft = Value;
		}
	}
	else
	{
		m_computedRectangleLeft = 0;
	}

	if (!m_RectangleTop.IsNull())
	{
		double Value = m_RectangleTop.get_Value();
		if (m_RectangleTop.get_UnitType() == Length::UnitPercentage)
		{
			m_computedRectangleTop = Value * availSize.Height;
		}
		else
		{
			m_computedRectangleTop = Value;
		}
	}
	else
	{
		m_computedRectangleTop = 0;
	}

	if (!m_RectangleWidth.IsNull())
	{
		double Value = m_RectangleWidth.get_Value();
		if (m_RectangleWidth.get_UnitType() == Length::UnitPercentage)
		{
			m_computedRectangleWidth = Value * availSize.Width;
		}
		else
		{
			m_computedRectangleWidth = Value;
		}
	}
	else
	{
		m_computedRectangleWidth = 0;
	}

	if (!m_RectangleHeight.IsNull())
	{
		double Value = m_RectangleHeight.get_Value();
		if (m_RectangleHeight.get_UnitType() == Length::UnitPercentage)
		{
			m_computedRectangleHeight = Value * availSize.Height;
		}
		else
		{
			m_computedRectangleHeight = Value;
		}
	}
	else
	{
		m_computedRectangleHeight = 0;
	}
	*/

/*
	m_RenderBounds.X = m_computedRectangleLeft;
	m_RenderBounds.Y = m_computedRectangleTop;
	m_RenderBounds.Width = m_computedRectangleWidth;
	m_RenderBounds.Height = m_computedRectangleHeight;

	m_expandedBBox = m_RenderBounds;

	return LDraw::SizeD(m_computedRectangleWidth, m_computedRectangleHeight);
	*/
}
#endif

LDraw::SizeD Rectangle::ArrangeOverride(LDraw::SizeD finalSize)
{
	m_computedRadiusX = get_RadiusX();
	m_computedRadiusY = get_RadiusY();

	return finalSize;
//	Shape::OnArrange(finalSize);
	//m_expandedBBox = m_RenderBounds;
}

// virtual
bool Rectangle::HitTest(double x, double y/*, long pointerEvents*/)
{
	// TODO
	return true;
}

// virtual
__release<LDraw::Region> Rectangle::OnGetOpaqueRegion(LDraw::Matrix3f* transform)
{
	LDraw::PointD xpt = transform->Transform(LDraw::PointD(m_expandedBBox.X, m_expandedBBox.Y));

	m_bDrawsOutsideOpaqueRegion = false;
	return new LDraw::Region(LDraw::RectI(xpt.X, xpt.Y, m_expandedBBox.Width, m_expandedBBox.Height));
}

#if 0
// virtual
void Rectangle::Clip(Graphics* pGraphics, LDraw::Region * rgn)
{
	//LDraw::Matrix3f oldTransform = pGraphics->GetTransform();
	pGraphics->PushTransform();//m_transformMatrix);

	{
		LDraw::PointD xpt = pGraphics->GetTransform()->Transform(LDraw::PointD(m_expandedBBox.X, m_expandedBBox.Y));

		ASSERT(0);
#if 0
		rgn->Exclude(LDraw::RectI(xpt.X, xpt.Y, m_expandedBBox.Width, m_expandedBBox.Height));
#endif

		/*
		HRGN rect = CreateRectRgn(xpt[0], xpt[1], xpt[0]+m_expandedBBox.Width, xpt[1]+m_expandedBBox.Height);
		CombineRgn(rgn.m_hRgn, rgn.m_hRgn, rect, RGN_DIFF);
		DeleteObject(rect);
		*/
	}

	pGraphics->PopTransform();//oldTransform);
/*
	// The default is not to clip
	if (m_computedRectangleWidth > 0 && m_computedRectangleHeight > 0)
	{
		HRGN rect = CreateRectRgn(m_computedRectangleLeft, m_computedRectangleTop, m_computedRectangleWidth, m_computedRectangleHeight);
		CombineRgn(hRgn, hRgn, rect, RGN_DIFF);
		DeleteObject(rect);
	}
	*/
}
#endif

// virtual
void Rectangle::OnRender(Graphics* pGraphics)
{
	LDraw::SizeD actualSize = get_ActualSize();

	//if (m_computedRectangleWidth > 0 && m_computedRectangleHeight > 0)
	{
//		LDraw::SmoothingMode oldSmoothingMode = pGraphics->GetSmoothingMode();
	//	pGraphics->SetSmoothingMode(LDraw::SmoothingModeHighQuality);

//		__release<LDraw::GraphicsPathF> path = new LDraw::GraphicsPathF;
//#if _WINDOWS
//		RoundRect(&path, m_computedRectangleLeft, m_computedRectangleTop, m_computedRectangleWidth, m_computedRectangleHeight, m_computedRadiusX, m_computedRadiusY);
//#else
//		path->AddRoundRect(0, 0, actualSize.Width, actualSize.Height, m_computedRadiusX, m_computedRadiusY);
//#endif

//		pGraphics->FillPath(&LDraw::SolidBrush(LDraw::Color(255, 0, 0)), &path);

		Brush* Fill = get_Fill();
		if (Fill)
		{
			__release<LDraw::Brush> brush = Fill->CreateBrush(this, 1, 1);
			if (brush != NULL)
			{
				pGraphics->FillRectangle(brush, 0, 0, actualSize.Width, actualSize.Height);
#if 0
				pGraphics->FillRectangle(pBrush, m_computedRectangleLeft, m_computedRectangleTop, m_computedRectangleWidth, m_computedRectangleHeight);
				pGraphics->Clear(LDraw::Color(255, 0, 0));
				pGraphics->FillPath(brush, path);
#endif
			}
		}

#if 0//_WINDOWS
		double StrokeThickness;
		if (m_StrokeThickness)
			StrokeThickness = m_StrokeThickness->get_Value();
		else
			StrokeThickness = 1;

		if (StrokeThickness > 0)
		{
			CLXUIElementImpl* Stroke = m_Stroke;
			if (Stroke)
			{
				LDraw::Brush* pBrush = Stroke->CreateBrush(this, 1, 1);
				if (pBrush)
				{
					LDraw::Pen pen(pBrush, StrokeThickness);

					pGraphics->DrawPath(pen, &path);
					delete pBrush;
				}
			}
		}
#endif

	//	pGraphics->SetSmoothingMode(oldSmoothingMode);
//#elif AMIGA
//		pGraphics->FillRectangle(&LDraw::SolidBrush(LDraw::Color(255, 0, 0)), m_computedRectangleLeft, m_computedRectangleTop, m_computedRectangleWidth, m_computedRectangleHeight);
//#endif
	}
}

/*
Length Rectangle::get_RectangleLeft()
{
	return m_RectangleLeft;
}

void Rectangle::put_RectangleLeft(Length newVal)
{
	m_RectangleLeft = newVal;
}

Length Rectangle::get_RectangleTop()
{
	return m_RectangleTop;
}

void Rectangle::put_RectangleTop(Length newVal)
{
	m_RectangleTop = newVal;
}

Length Rectangle::get_RectangleWidth()
{
	return m_RectangleWidth;
}

void Rectangle::put_RectangleWidth(Length newVal)
{
	m_RectangleWidth = newVal;
}

Length Rectangle::get_RectangleHeight()
{
	return m_RectangleHeight;
}

void Rectangle::put_RectangleHeight(Length newVal)
{
	m_RectangleHeight = newVal;
}
*/

double Rectangle::get_RadiusX()
{
	return static_cast<DoubleObject*>(GetValue(get_RadiusXProperty()))->GetValue();
}

void Rectangle::set_RadiusX(double newVal)
{
	SetValue(get_RadiusXProperty(), DoubleObject::GetObject(newVal));
}

double Rectangle::get_RadiusY()
{
	return static_cast<DoubleObject*>(GetValue(get_RadiusYProperty()))->GetValue();
}

void Rectangle::set_RadiusY(double newVal)
{
	SetValue(get_RadiusYProperty(), DoubleObject::GetObject(newVal));
}

}	// Shapes
Example #6
0
namespace UI
{

	/*
class CreateIfNull
{
public:
	CreateIfNull();
};

CreateIfNull createifnull;

CreateIfNull::CreateIfNull()
{
	if (SolidColorBrush::ColorProperty == NULL)
	{
		SolidColorBrush::ColorProperty = RegisterProperty(WSTR("Color"), typeid(Color), typeid(SolidColorBrush), NULL, PropertyMetaData(None));
	}
}
*/

DependencyProperty* SolidColorBrush::s_ColorProperty = RegisterProperty(WSTR("Color"), typeid(Color), typeid(SolidColorBrush), new Color(), PropertyMetaData(None));

SolidColorBrush::SolidColorBrush()
{
	/*
	if (ColorProperty == NULL)
	{
		ColorProperty = RegisterProperty(WSTR("Color"), typeid(Color), typeid(SolidColorBrush), NULL, PropertyMetaData(None));
	}
	*/

//	m_Color = NULL;
//	m_Opacity = 1.0;
}

SolidColorBrush::SolidColorBrush(Color color)
{
	/*
	if (ColorProperty == NULL)
	{
		ColorProperty = RegisterProperty(WSTR("Color"), typeid(Color), typeid(SolidColorBrush), NULL, PropertyMetaData(None));
	}
*/
	set_Color(color);
}

SolidColorBrush::SolidColorBrush(Color color, double opacity)
{
	/*
	if (ColorProperty == NULL)
	{
		ColorProperty = RegisterProperty(WSTR("Color"), typeid(Color), typeid(SolidColorBrush), NULL, PropertyMetaData(None));
	}
	*/

	set_Color(color);
	set_Opacity(opacity);
}

// virtual
__release<LDraw::Brush> SolidColorBrush::CreateBrush(UIElement* pReferencingElement, double scaleX, double scaleY)
{
	int opacity = get_Opacity()*255;
	if (opacity < 0) opacity = 0;
	else if (opacity > 255) opacity = 255;

	Color color = get_Color();
//	if (color != NULL)
	{
		LDraw::Color dcolor = LDraw::Color(color.get_A()*opacity/255, color.get_R(), color.get_G(), color.get_B());
		return new LDraw::SolidBrush(dcolor);
	}
/*	else
	{
		return NULL;
	}
	*/
}

Color SolidColorBrush::get_Color()
{
	return *static_cast<Color*>(GetValue(get_ColorProperty()));
}

void SolidColorBrush::set_Color(Color newVal)
{
	SetValue(get_ColorProperty(), new Color(newVal));
}

}	// UI
Example #7
0
namespace UI
{

DependencyProperty* RangeBase::s_MinimumProperty = RegisterProperty(WSTR("Minimum"), typeid(double), typeid(RangeBase), DoubleObject::GetObject(0.0), PropertyMetaData(None));
DependencyProperty* RangeBase::s_MaximumProperty = RegisterProperty(WSTR("Maximum"), typeid(double), typeid(RangeBase), DoubleObject::GetObject(1.0), PropertyMetaData(None));
DependencyProperty* RangeBase::s_ValueProperty = RegisterProperty(WSTR("Value"), typeid(double), typeid(RangeBase), DoubleObject::GetObject(0.0), PropertyMetaData(None));

RoutedEvent* RangeBase::s_ValueChangedEvent = EventManager::RegisterRoutedEvent(WSTR("ValueChanged"), RoutingStrategy_Bubble, typeid(stub_interface2<void, Object*, RoutedPropertyChangedEventArgs<double>*>), typeid(RangeBase));

template class UIEXT RoutedPropertyChangedEventArgs<double>;
template class UIEXT signal2<Object*, RoutedPropertyChangedEventArgs<double>*>;

RangeBase::RangeBase()
{
}

double RangeBase::get_Value()
{
	return static_cast<DoubleObject*>(GetValue(get_ValueProperty()))->GetValue();
}

void RangeBase::set_Value(double value)
{
	SetValue(get_ValueProperty(), DoubleObject::GetObject(value));
}

double RangeBase::get_Minimum()
{
	return static_cast<DoubleObject*>(GetValue(get_MinimumProperty()))->GetValue();
}

void RangeBase::set_Minimum(double minimum)
{
	SetValue(get_MinimumProperty(), DoubleObject::GetObject(minimum));
}

double RangeBase::get_Maximum()
{
	return static_cast<DoubleObject*>(GetValue(get_MaximumProperty()))->GetValue();
}

void RangeBase::set_Maximum(double maximum)
{
	SetValue(get_MaximumProperty(), DoubleObject::GetObject(maximum));
}

signal2<Object*, RoutedPropertyChangedEventArgs<double>*>& RangeBase::get_ValueChanged()
{
	RoutedEvent* routedEvent = get_ValueChangedEvent();
	int index = routedEvent->GetIndex();

	if (m_handlers[index] == NULL)
	{
		VERIFY(routedEvent->get_HandlerType()->GetClass());
		ClassType* pSigType = dynamic_cast<ClassType*>(routedEvent->get_HandlerType()->GetClass()->LookupType(ASTR("signal_type"))->GetStripped());
		VERIFY(pSigType);
		m_handlers[index] = (signal_base*)newobj(pSigType);
	}

	return *dynamic_cast<signal2<Object*, RoutedPropertyChangedEventArgs<double>*>*>(m_handlers[index]);
}

}	// UI
Example #8
0
namespace UI
{

namespace Data
{

CollectionView::CollectionView()
{
}

CollectionView::CollectionView(IObjectCollection* sourceCollection)
{
	m_sourceCollection = sourceCollection;
}

unsigned int CollectionView::GetCount()
{
	return m_items.size();
}

Object* CollectionView::GetItemAt(unsigned int index)
{
	return m_items[index];
}

bool CollectionView::Contains(Object* object)
{
	ASSERT(0);
	return false;
}

int CollectionView::IndexOf(Object* item)
{
	ASSERT(0);
	return -1;
}

bool CollectionView::PassesFilter(Object* object)
{
	// TODO
	return true;
}

IObjectCollection* CollectionView::get_SourceCollection()
{
	return m_sourceCollection;
}

}	// Data

ItemCollection::ItemCollection()
{
	m_sourceCollection = new Vector<Object*>;
}

void ItemCollection::Add(Object* item)
{
	m_sourceCollection->AddObject(item);

	// TODO, improve
	m_owner->SetValue(m_owner->get_HasItemsProperty(), BoolObject::get_True());
	m_owner->AddItem(item);
}

DependencyObject* ItemContainerGenerator::ContainerFromIndex(unsigned int index)
{
	return m_panel->get_Children()->get_Item(index);
//	return m_containers[index];
}

DependencyObject* ItemContainerGenerator::ContainerFromItem(Object* object)
{
	ASSERT(0);
	return NULL;
}

Object* ItemContainerGenerator::ItemFromContainer(DependencyObject* object)
{
	return dynamic_cast<ContentControl*>(object)->get_Content();
}

DependencyProperty* ItemsControl::s_ItemsPanelProperty = RegisterProperty(WSTR("ItemsPanel"), typeid(ItemsPanelTemplate), typeid(ItemsControl), NULL, PropertyMetaData(None));
DependencyProperty* ItemsControl::s_HasItemsProperty = RegisterProperty(WSTR("HasItems"), typeid(bool), typeid(ItemsControl), BoolObject::get_False(), PropertyMetaData(None));

ItemsControl::ItemsControl()
{
	m_items = new ItemCollection;
	m_items->m_owner = this;
}

bool ItemsControl::get_HasItems()
{
	return static_cast<BoolObject*>(GetValue(get_HasItemsProperty()))->GetValue();
}

void ItemsControl::OnApplyTemplate()
{
	Control::OnApplyTemplate();

	m_itemsPresenter = dynamic_cast<ItemsPresenter*>(get_VisualTree()->FindByType((ClassType*)typeid(ItemsPresenter).GetType()));

//	if (m_itemsPresenter == NULL)
//	m_itemsPresenter = dynamic_cast<ItemsPresenter*>(get_VisualTree()->FindByType((ClassType*)typeid(ItemsPresenter).GetType()));

	if (m_itemsPresenter)
	{
		ItemsPanelTemplate* itemsPanelTemplate = get_ItemsPanel();

		ASSERT(m_objectpropertymap.size() == 0);
		Type* pRealType;
		Object* obj = itemsPanelTemplate->get_VisualTree()->Create4(NULL, &pRealType, this/*???*/, m_objectpropertymap);
		m_itemsPresenter->m_panel = dynamic_cast<Panel*>(obj);

		m_itemContainerGenerator = new ItemContainerGenerator;	// hm..
		m_itemContainerGenerator->m_panel = m_itemsPresenter->m_panel;

		m_itemsPresenter->set_VisualTree(m_itemsPresenter->m_panel);
	}
}

ItemCollection* ItemsControl::get_Items()
{
	return m_items;
}

ItemsPanelTemplate* ItemsControl::get_ItemsPanel()
{
	return static_cast<ItemsPanelTemplate*>(GetValue(get_ItemsPanelProperty()));
}

void ItemsControl::set_ItemsPanel(ItemsPanelTemplate* itemsPanel)
{
	SetValue(get_ItemsPanelProperty(), itemsPanel);
}

// Default implementation, override if this isn't what you want
void ItemsControl::AddItem(Object* item)
{
	ContentControl* contentItem = dynamic_cast<ContentControl*>(item);
	if (contentItem == NULL)
	{
		contentItem = new ContentControl;
		contentItem->set_Content(item);
	}

//	m_owner->m_itemContainerGenerator->m_containers.push_back(listboxitem);

	if (m_itemsPresenter)
	{
		m_itemsPresenter->m_panel->AddChild(contentItem);
	}
}

}	// UI
Example #9
0
namespace Shapes
{

DependencyProperty* Polyline::s_PointsProperty = RegisterProperty(WSTR("Points"), typeid(PointCollection), typeid(Polyline), NULL, PropertyMetaData(AffectsMeasure));

Polyline::Polyline()
{
//	SetClipMode(false);
}

Polyline::~Polyline()
{
}

LDraw::SizeD Polyline::MeasureOverride(LDraw::SizeD availSize)
{
	PointCollection* points = get_Points();

	if (points)
	{
		int count = points->GetCount();

		if (count > 0)
		{
			__release<LDraw::GraphicsPathF> path = new LDraw::GraphicsPathF;

			//CLXUIPoint* pOldPoint = static_cast<CLXUIPoint*>(points->m_items[0]);

			Point point = points->get_Item(0);
			path->AddMove(point.X, point.Y);

			for (int i = 1; i < count; i++)
			{
				point = points->get_Item(i);
				path->AddLine(point.X, point.Y);

			//	CLXUIPoint* pPoint = static_cast<CLXUIPoint*>(points->m_items[i]);
			//	path.AddLine(float(pOldPoint->m_X), float(pOldPoint->m_Y), float(pPoint->m_X), float(pPoint->m_Y));
			//	pOldPoint = pPoint;
			}

			LDraw::RectF rect;
			path->GetBounds(&rect, NULL, NULL);

			return LDraw::SizeD(rect.Width, rect.Height);
		}
	}

	return LDraw::SizeD(0, 0);
}

// virtual
void Polyline::OnRender(Graphics* pGraphics)
{
	PointCollection* points = get_Points();

	if (points)
	{
		unsigned int count = points->GetCount();
		if (count > 0)
		{
			__release<LDraw::GraphicsPathF> path = new LDraw::GraphicsPathF;

			Point point = points->get_Item(0);
			path->AddMove(point.X, point.Y);

			for (unsigned int i = 1; i < count; i++)
			{
				point = points->get_Item(i);
				path->AddLine(point.X, point.Y);
			}

			Brush* Fill = get_Fill();
			if (Fill)
			{
				__release<LDraw::Brush> brush = Fill->CreateBrush(this, 1, 1);
				if (brush != NULL)
				{
					pGraphics->FillPath(brush, path);
				}
			}

#if 0
			double StrokeThickness;
			if (m_StrokeThickness)
				m_StrokeThickness->get_Value(&StrokeThickness);
			else
				StrokeThickness = 1;

			if (StrokeThickness > 0)
			{
				CComQIPtr<CLXUIElementImplImpl> Stroke(m_Stroke);
				if (Stroke)
				{
					Gdiplus::Brush* pBrush = Stroke->CreateBrush(this, 1, 1);
					if (pBrush)
					{
						Gdiplus::Pen pen(pBrush, StrokeThickness);

						pGraphics->DrawPath(pen, &path);
						delete pBrush;
					}
				}
			}
#endif
		}

	}
}

PointCollection* Polyline::get_Points()
{
	return static_cast<PointCollection*>(GetValue(get_PointsProperty()));
}

void Polyline::set_Points(PointCollection* newVal)
{
	SetValue(get_PointsProperty(), newVal);
}

}	// Shapes