mousestate uielement::sendmouse(vector2d pos, mousestate state)
	{
		if (active)
		{
			mousestate ret = state;
			bool iteminfo = false;

			for (vector<dragicon>::iterator dgit = dragicons.begin(); dgit != dragicons.end(); ++dgit)
			{
				if (dgit->bounds(position).contains(pos))
				{
					if (!dgit->dragged())
					{
						switch (state)
						{
						case MST_IDLE:
						case MST_CANCLICK:
						case MST_CANCLICK2:
						case MST_CANGRAB:
							ret = MST_CANGRAB;
							if (dgit->gettype() == DIT_ITEM || dgit->gettype() == DIT_ITEMKEY)
							{
								oniteminfo(dgit._Ptr);
								iteminfo = true;
							}
							break;
						case MST_CLICKING:
							dgit->setdrag(pos, position);
							app.getui()->seticon(dgit._Ptr);
							ret = MST_GRABBING;
							break;
						}
					}

					return ret;
				}
			}

			if (!iteminfo && state != MST_IDLE)
			{
				oniteminfo(0);
			}

			bool anycoll = false;
			for (map<short, button>::iterator itbt = buttons.begin(); itbt != buttons.end(); ++itbt)
			{
				string btst = itbt->second.getstate();
				if (itbt->second.bounds(position).contains(pos) && itbt->second.isactive())
				{
					anycoll = true;
					switch (state)
					{
					case MST_IDLE:
					case MST_CANCLICK:
						if (btst == "normal")
						{
							itbt->second.setstate("mouseOver");
							ret = MST_CANCLICK;
						}
						break;
					case MST_CLICKING:
						if (btst == "normal" || btst == "mouseOver")
						{
							if (buttoncd <= 0)
							{
								itbt->second.setstate("pressed");
								buttonpressed(itbt->first);
								buttoncd = 60;
							}
							ret = MST_CANCLICK;
						}
					}
				}
				else
				{
					switch (state)
					{
					case MST_IDLE:
					case MST_CANCLICK:
						if (btst == "mouseOver")
						{
							itbt->second.setstate("normal");
						}
						break;
					}
				}
			}

			bool anytext = false;
			for (map<textid, textfield>::iterator txtit = textfields.begin(); txtit != textfields.end(); txtit++)
			{
				if (txtit->second.isactive())
				{
					if (txtit->second.bounds(position).contains(pos))
					{
						switch (state)
						{
						case MST_CLICKING:
							txtit->second.setfocus(true);
							app.getui()->settextfield(&txtit->second);
							anytext = true;
							break;
						}
					}
					else
					{
						switch (state)
						{
						case MST_CLICKING:
							txtit->second.setfocus(false);
							if (!anytext)
							{
								app.getui()->settextfield(0);
							}
							break;
						}
					}
				}
			}

			if (!anycoll)
			{
				if (dragged)
				{
					if (state == MST_CLICKING)
					{
						position = pos + cursorrel;
					}
					else
					{
						dragged = false;
					}
				}
				else
				{
					switch (state)
					{
					case MST_CANCLICK:
					case MST_CANGRAB:
						ret = MST_IDLE;
						break;
					case MST_CLICKING:
						if (dragarea().contains(pos))
						{
							cursorrel = position - pos;
							dragged = true;
						}
						break;
					}
				}
			}

			return ret;
		}
		else
		{
			return state;
		}
	}
Esempio n. 2
0
	mousestate uielement::sendmouse(vector2d pos, mousestate state)
	{
		if (active)
		{
			mousestate ret = state;
			bool drag = false;

			for (vector<dragicon>::iterator dgit = dragicons.begin(); dgit != dragicons.end(); ++dgit)
			{
				if (colliding(pos, dgit->bounds(), position))
				{
					drag = true;

					if (!dgit->dragged())
					{
						switch (state)
						{
						case MST_IDLE:
						case MST_CANCLICK:
						case MST_CANCLICK2:
							ret = MST_CANGRAB;
							break;
						case MST_CLICKING:
							dgit->setdrag(pos, position);
							app.getui()->seticon(dgit._Ptr);
							ret = MST_GRABBING;
							break;
						}
					}
				}

				if (drag)
				{
					return ret;
				}
			}

			bool anycoll = false;
			for (map<short, button>::iterator itbt = buttons.begin(); itbt != buttons.end(); ++itbt)
			{
				string btst = itbt->second.getstate();
				if (util::colliding(pos, itbt->second.bounds(), position) && itbt->second.isactive())
				{
					anycoll = true;
					switch (state)
					{
					case MST_IDLE:
					case MST_CANCLICK:
						if (btst == "normal")
						{
							itbt->second.setstate("mouseOver");
							ret = MST_CANCLICK;
						}
						break;
					case MST_CLICKING:
						if (btst == "normal" || btst == "mouseOver")
						{
							itbt->second.setstate("pressed");
							buttonpressed(itbt->first);
							ret = MST_CANCLICK;
						}
					}
				}
				else
				{
					switch (state)
					{
					case MST_IDLE:
					case MST_CANCLICK:
						if (btst == "mouseOver")
						{
							itbt->second.setstate("normal");
						}
						break;
					}
				}
			}

			bool anytext = false;
			for (map<short, textfield>::iterator txtit = textfields.begin(); txtit != textfields.end(); txtit++)
			{
				if (util::colliding(pos, txtit->second.bounds(), position))
				{
					switch (state)
					{
					case MST_CLICKING:
						txtit->second.setstate("active");
						app.getui()->settextfield(&txtit->second);
						anytext = true;
						break;
					}
				}
				else
				{
					switch (state)
					{
					case MST_CLICKING:
						txtit->second.setstate("inactive");
						if (!anytext)
						{
							app.getui()->settextfield(0);
						}
						break;
					}
				}
			}

			if (!anycoll)
			{
				switch (state)
				{
				case MST_CANCLICK:
				case MST_CANGRAB:
					ret = MST_IDLE;
					break;
				}
			}

			return ret;
		}
		else
		{
			return state;
		}
	}