/**
 *  Test if we have a circle; inertia has been precomputed by caller
 */
double CircleRecognizer::scoreCircle(Stroke* s, Inertia& inertia)
{
	if (inertia.getMass() == 0.0)
	{
		return 0;
	}

	double sum = 0.0;
	double x0 = inertia.centerX();
	double y0 = inertia.centerY();
	double r0 = inertia.rad();

	ArrayIterator<Point> it = s->pointIterator();

	if (!it.hasNext())
	{
		return 0;
	}

	Point p1 = it.next();

	while (it.hasNext())
	{
		Point p2 = it.next();

		double dm = hypot(p2.x - p1.x, p2.y - p1.y);
		double deltar = hypot(p1.x - x0, p1.y - y0) - r0;
		sum += dm * fabs(deltar);

		p1 = p2;
	}

	return sum / (inertia.getMass() * r0);
}
void VisualDebugger::draw()
{
 
 ArrayIterator<Scene*> iterator = mWorld->getScenes();
 mMeshData->mLines.clear();
 mMeshData->mColours.clear();
 mMeshData->mNbLines = 0;

 for (Scene* scene = iterator.begin(); scene = iterator.next();)
 {
  const NxDebugRenderable* renderable = scene->getScene()->getDebugRenderable();
  
  if (renderable == 0)
   continue;
  
  unsigned int nbLines = renderable->getNbLines();
  const NxDebugLine* lines = renderable->getLines();
  while(nbLines--)
  {
   mMeshData->mLines.append(lines->p0.x);
   mMeshData->mLines.append(lines->p0.y);
   mMeshData->mLines.append(lines->p0.z);
   mMeshData->mLines.append(lines->p1.x);
   mMeshData->mLines.append(lines->p1.y);
   mMeshData->mLines.append(lines->p1.z);
   mMeshData->mColours.append(lines->color);
   mMeshData->mColours.append(lines->color);
   lines++;
  }
  mMeshData->mNbLines += renderable->getNbLines();
 }

 
 mRenderable->drawVisualDebugger(mMeshData);
}
Archive* ResourceSystem::openArchive(const String& name, const UniformResourceIdentifier& uri)
{
 ResourceProtocol* requestedProtocol = 0;
 ArrayIterator<ResourceProtocol*> iterator = mProtocols.getIterator();
 for (ResourceProtocol* protocol = iterator.begin(); protocol = iterator.next();)
 {
  if (protocol->getProtocolHash() == uri.getProtocolHash())
  {
   requestedProtocol = protocol;
   break;
  }
 }
  
 if (requestedProtocol == 0)
 {
  SharedStringStream ss(200);
  ss << "Could not open archive '" << uri.getLocation() << ":" << uri.getLocation() << "\n"
     << "Reason: Protocol could not be found.";
  NxOgre_ThrowError(ss.get());
  return 0;
 }
  
 Archive* archive = requestedProtocol->openArchive(name, uri);
  
 if (archive == 0)
 {
  SharedStringStream ss(200);
  ss << "Could not open archive '" << uri.getLocation() << ":" << uri.getLocation() << "\n"
     << "Reason: Protocol could not open archive.";
  NxOgre_ThrowError(ss.get());
  return 0;
 }
 
 mArchives.insert(archive);
 return archive;
}
Exemple #4
0
static gboolean gtk_xournal_expose(GtkWidget* widget, GdkEventExpose* event)
{
	g_return_val_if_fail(widget != NULL, FALSE);
	g_return_val_if_fail(GTK_IS_XOURNAL(widget), FALSE);
	g_return_val_if_fail(event != NULL, FALSE);

	GtkXournal* xournal = GTK_XOURNAL(widget);

	gdk_threads_enter();
	cairo_t* cr = gdk_cairo_create(GTK_WIDGET(widget)->window);

	ArrayIterator<PageView*> it = xournal->view->pageViewIterator();

	GtkAllocation alloc = { 0 };
	gtk_widget_get_allocation(widget, &alloc);
	int lastVisibleX = alloc.width + xournal->x + 10;
	int lastVisibleY = alloc.height + xournal->y + 10; //+10 fix to draw the shadow

	int firstVisibleX = xournal->x - 10;
	int firstVisibleY = xournal->y - 10;

	while (it.hasNext())
	{
		PageView* pv = it.next();

		int px = pv->getX();
		int py = pv->getY();
		int pw = pv->getDisplayWidth();
		int ph = pv->getDisplayHeight();

		// not visible, its on the right side of the visible area
		if (px > lastVisibleX)
		{
			continue;
		}
		// not visible, its on the left side of the visible area
		if (px + pw < firstVisibleX)
		{
			continue;
		}
		// not visible, its on the bottom side of the visible area
		if (py > lastVisibleY)
		{
			continue;
		}
		// not visible, its on the top side of the visible area
		if (py + ph < firstVisibleY)
		{
			continue;
		}

		int x = px - xournal->x;
		int y = py - xournal->y;

		gtk_xournal_draw_shadow(xournal, cr, x, y, pw, ph, pv->isSelected());
		cairo_save(cr);
		cairo_translate(cr, x, y);

		GdkRectangle rect = event->area;
		rect.x -= x;
		rect.y -= y;

		pv->paintPage(cr, &rect);
		cairo_restore(cr);
	}

	if (xournal->selection)
	{
		double zoom = xournal->view->getZoom();

		int px = xournal->selection->getXOnView() * zoom;
		int py = xournal->selection->getYOnView() * zoom;
		//		int pw = xournal->selection->getWidth() * zoom;
		//		int ph = xournal->selection->getHeight() * zoom;

		// not visible, its on the right side of the visible area
		if (px > lastVisibleX)
		{
			printf("Warning: object on right side of visible area.\n");
		}
		else
			// not visible, its on the left side of the visible area

			// TODO LOW PRIO this is not working correct if the zoom is small, xournal->x is never smaller than 0
			//		if (px + pw < firstVisibleX) {
			//			printf("test2\n");
			//		} else
			// not visible, its on the bottom side of the visible area
			if (py > lastVisibleY)
			{
				printf("Warning: object below visible area.\n");
				//		} else
				//		// not visible, its on the top side of the visible area
				//		if (py + ph < firstVisibleY) {
				//			printf("test4 %i:: %i\n", py + ph, firstVisibleY);
			}
			else
			{
				Redrawable* red = xournal->selection->getView();
				cairo_translate(cr, red->getX() - xournal->x, red->getY() - xournal->y);

				xournal->selection->paint(cr, zoom);
			}
	}

	cairo_destroy(cr);
	gdk_threads_leave();

	return true;
}
void ToolHandler::loadSettings()
{
	XOJ_CHECK_TYPE(ToolHandler);

	SElement& s = settings->getCustomElement("tools");

	string selectedTool;
	if (s.getString("current", selectedTool))
	{
		ArrayIterator<Tool*> it = iterator();

		for (; it.hasNext();)
		{
			Tool* t = it.next();
			SElement& st = s.child(t->getName());

			if (selectedTool == t->getName())
			{
				this->current = t;
			}

			int color = 0;
			if (t->isEnableColor() && st.getInt("color", color))
			{
				t->setColor(color);
			}

			bool enabled = false;
			if (t->isEnableRuler() && st.getBool("ruler", enabled))
			{
				t->setRuler(enabled);
			}
			if (t->isEnableRectangle() && st.getBool("rectangle", enabled))
			{
				t->setRectangle(enabled);
			}
			if (t->isEnableCircle() && st.getBool("circle", enabled))
			{
				t->setCircle(enabled);
			}
			if (t->isEnableArrow() && st.getBool("arrow", enabled))
			{
				t->setArrow(enabled);
			}
			if (t->isEnableShapeRecognizer() && st.getBool("shapeRecognizer", enabled))
			{
				t->setShapeRecognizer(enabled);
			}

			string value;

			if (t->isEnableSize() && st.getString("size", value))
			{
				if (value == "VERY_THIN")	  t->setSize(TOOL_SIZE_VERY_FINE);
				else if (value == "THIN")	  t->setSize(TOOL_SIZE_FINE);
				else if (value == "MEDIUM")	  t->setSize(TOOL_SIZE_MEDIUM);
				else if (value == "BIG")	  t->setSize(TOOL_SIZE_THICK);
				else if (value == "VERY_BIG") t->setSize(TOOL_SIZE_VERY_THICK);
				else g_warning("Settings::Unknown tool size: %s\n", value.c_str());
			}

			if (t->type == TOOL_ERASER)
			{
				string type;

				if (st.getString("type", type))
				{
					if (type == "deleteStroke")	 setEraserType(ERASER_TYPE_DELETE_STROKE);
					else if (type == "whiteout") setEraserType(ERASER_TYPE_WHITEOUT);
					else						 setEraserType(ERASER_TYPE_DEFAULT);
					eraserTypeChanged();
				}
			}
		}
	}
}
void ToolHandler::saveSettings()
{
	XOJ_CHECK_TYPE(ToolHandler);

	SElement& s = settings->getCustomElement("tools");
	s.clear();

	s.setString("current", this->current->getName());

	ArrayIterator<Tool*> it = iterator();

	for (; it.hasNext();)
	{
		Tool* t = it.next();
		SElement& st = s.child(t->getName());
		if (t->isEnableColor())
		{
			st.setIntHex("color", t->getColor());
		}
		if (t->isEnableRuler())
		{
			st.setBool("ruler", t->isRuler());
		}
		if (t->isEnableRectangle())
		{
			st.setBool("rectangle", t->isRectangle());
		}
		if (t->isEnableCircle())
		{
			st.setBool("circle", t->isCircle());
		}
		if (t->isEnableArrow())
		{
			st.setBool("arrow", t->isArrow());
		}
		if (t->isEnableShapeRecognizer())
		{
			st.setBool("shapeRecognizer", t->isShapeRecognizer());
		}

		if (t->isEnableSize())
		{
			string value;
			switch (t->getSize())
			{
			case TOOL_SIZE_VERY_FINE:
				value = "VERY_THIN";
				break;
			case TOOL_SIZE_FINE:
				value = "THIN";
				break;
			case TOOL_SIZE_MEDIUM:
				value = "MEDIUM";
				break;
			case TOOL_SIZE_THICK:
				value = "BIG";
				break;
			case TOOL_SIZE_VERY_THICK:
				value = "VERY_BIG";
				break;
			default:
				value = "";
			}

			st.setString("size", value);
		}

		if (t->type == TOOL_ERASER)
		{
			if (this->eraserType == ERASER_TYPE_DELETE_STROKE)
			{
				st.setString("type", "deleteStroke");
			}
			else if (this->eraserType == ERASER_TYPE_WHITEOUT)
			{
				st.setString("type", "whiteout");
			}
			else //ERASER_TYPE_DEFAULT
			{
				st.setString("type", "default");
			}
		}
	}

	settings->customSettingsChanged();
}
Exemple #7
0
void InputHandler::onButtonReleaseEvent(GdkEventButton * event, PageRef page) {
	XOJ_CHECK_TYPE(InputHandler);

	if (!this->tmpStroke) {
		return;
	}

	// Backward compatibility and also easier to handle for me;-)
	// I cannot draw a line with one point, to draw a visible line I need two points,
	// twice the same Point is also OK
	if (this->tmpStroke->getPointCount() == 1) {
		ArrayIterator<Point> it = this->tmpStroke->pointIterator();
		if (it.hasNext()) {
			this->tmpStroke->addPoint(it.next());
		}
		// No pressure sensitivity
		this->tmpStroke->clearPressure();
	}

	this->tmpStroke->freeUnusedPointItems();

	if (page.getSelectedLayerId() < 1) {
		// This creates a layer if none exists
		page.getSelectedLayer();
		page.setSelectedLayerId(1);
		xournal->getControl()->getWindow()->updateLayerCombobox();
	}

	Layer * layer = page.getSelectedLayer();

	UndoRedoHandler * undo = xournal->getControl()->getUndoRedoHandler();

	undo->addUndoAction(new InsertUndoAction(page, layer, this->tmpStroke, this->redrawable));

	ToolHandler * h = xournal->getControl()->getToolHandler();
	if (h->isShapeRecognizer()) {
		if (this->reco == NULL) {
			this->reco = new ShapeRecognizer();
		}
		ShapeRecognizerResult * result = this->reco->recognizePatterns(this->tmpStroke);

		if (result != NULL) {
			UndoRedoHandler * undo = xournal->getControl()->getUndoRedoHandler();

			Stroke * recognized = result->getRecognized();

			RecognizerUndoAction * recognizerUndo = new RecognizerUndoAction(page, this->redrawable, layer, this->tmpStroke, recognized);
			undo->addUndoAction(recognizerUndo);
			layer->addElement(result->getRecognized());

			Range range(recognized->getX(), recognized->getY());
			range.addPoint(recognized->getX() + recognized->getElementWidth(), recognized->getY() + recognized->getElementHeight());

			range.addPoint(this->tmpStroke->getX(), this->tmpStroke->getY());
			range.addPoint(this->tmpStroke->getX() + this->tmpStroke->getElementWidth(), this->tmpStroke->getY() + this->tmpStroke->getElementHeight());

			ListIterator<Stroke *> l = result->getSources();
			while (l.hasNext()) {
				Stroke * s = l.next();

				layer->removeElement(s, false);

				recognizerUndo->addSourceElement(s);

				range.addPoint(s->getX(), s->getY());
				range.addPoint(s->getX() + s->getElementWidth(), s->getY() + s->getElementHeight());
			}

			this->redrawable->rerenderRange(range);

			// delete the result object, this is not needed anymore, the stroke are not deleted with this
			delete result;
		} else {
			layer->addElement(this->tmpStroke);
			this->redrawable->rerenderElement(this->tmpStroke);
		}

	} else {
		layer->addElement(this->tmpStroke);
		this->redrawable->rerenderElement(this->tmpStroke);
	}

	this->tmpStroke = NULL;

	if (currentInputDevice == event->device) {
		currentInputDevice = NULL;
		INPUTDBG("currentInputDevice = NULL\n", 0);
	}

	this->tmpStrokeDrawElem = 0;
}