Esempio n. 1
0
/**
 * Handle eraser event: "Delete Stroke" and "Standard", Whiteout is not handled here
 */
void EraseHandler::erase(double x, double y) {
	XOJ_CHECK_TYPE(EraseHandler);

	ListIterator<Layer*> it = this->page.layerIterator();

	int selected = page.getSelectedLayerId();

	this->halfEraserSize = this->handler->getThickness();
	GdkRectangle eraserRect = { x - halfEraserSize, y - halfEraserSize, halfEraserSize * 2, halfEraserSize * 2 };

	Range * range = new Range(x, y);

	while (it.hasNext() && selected) {
		Layer * l = it.next();

		ListIterator<Element *> eit = l->elementIterator();
		eit.freeze();
		while (eit.hasNext()) {
			Element * e = eit.next();
			if (e->getType() == ELEMENT_STROKE && e->intersectsArea(&eraserRect)) {
				Stroke * s = (Stroke *) e;

				eraseStroke(l, s, x, y, range);
			}
		}

		selected--;
	}

	this->view->rerenderRange(*range);
	delete range;
}
Esempio n. 2
0
bool SearchControl::search(const char * text, int * occures, double * top) {
	XOJ_CHECK_TYPE(SearchControl);

	freeSearchResults();

	if (text == NULL) {
		return true;
	}

	if (this->pdf) {
		this->results = this->pdf->findText(text);
	}

	int selected = this->page.getSelectedLayerId();
	ListIterator<Layer*> it = this->page.layerIterator();

	while (it.hasNext() && selected) {
		Layer * l = it.next();

		ListIterator<Element *> eit = l->elementIterator();
		while (eit.hasNext()) {
			Element * e = eit.next();

			if (e->getType() == ELEMENT_TEXT) {
				Text * t = (Text *) e;

				GList * textResult = TextView::findText(t, text);
				this->results = g_list_concat(this->results, textResult);
			}
		}

		selected--;
	}

	if (occures) {
		*occures = g_list_length(this->results);
	}
	if (top) {
		if (this->results == NULL) {
			*top = 0;
		} else {

			double min = ((XojPopplerRectangle *) this->results->data)->y1;
			for (GList * l = this->results->next; l != NULL; l = l->next) {
				XojPopplerRectangle * rect = (XojPopplerRectangle *) l->data;
				min = MIN(min, rect->y1);
			}

			*top = min;
		}
	}

	return this->results != NULL;
}
Esempio n. 3
0
void PageView::selectObjectAt(double x, double y) {
	XOJ_CHECK_TYPE(PageView);

	int selected = this->page.getSelectedLayerId();
	GdkRectangle matchRect = { x - 10, y - 10, 20, 20 };

	Stroke * strokeMatch = NULL;
	double gap = 1000000000;

	Element * elementMatch = NULL;

	// clear old selection anyway
	this->xournal->getControl()->clearSelection();

	ListIterator<Layer*> it = this->page.layerIterator();
	while (it.hasNext() && selected) {
		Layer * l = it.next();

		ListIterator<Element *> eit = l->elementIterator();
		while (eit.hasNext()) {
			Element * e = eit.next();
			if (e->intersectsArea(&matchRect)) {
				if (e->getType() == ELEMENT_STROKE) {
					Stroke * s = (Stroke *) e;
					double tmpGap = 0;
					if (s->intersects(x, y, 5, &tmpGap)) {
						if (gap > tmpGap) {
							gap = tmpGap;
							strokeMatch = s;
						}
					}
				} else {
					elementMatch = e;
				}
			}
		}

		selected--;
	}

	if (strokeMatch) {
		elementMatch = strokeMatch;
	}

	if (elementMatch) {
		xournal->setSelection(new EditSelection(xournal->getControl()->getUndoRedoHandler(), elementMatch, this, page));

		repaintPage();
	}
}
Esempio n. 4
0
void Scene::render(Pixel* px, Vertex *eyePoint, double attenuation)
{
   //create the zbuffer matrix
   int width = px->getWidth();
   int height = px->getHeight();
   Matrix* zbuffer = new Matrix(height, width);    //rows come first

   //populate zbuffer with -1
   for (int i = 1; i <= height; i++)
   {
      for (int j = 1; j <= width; j++)
      {
         zbuffer->setElement(i, j, -1.0);
      }
   }
   
   //loop over all the Instance instances in the Scene and render them
   ListIterator<TransformNode>* ioIter = transformNodes->iterator();
   while (ioIter->hasNext())
   {
      TransformNode* tn = ioIter->next();
      tn->render(px, sceneTransform, zbuffer, ambientLight, pointLight, eyePoint, attenuation);
   }

   delete ioIter;
   delete zbuffer;
}
Esempio n. 5
0
void ToolbarData::saveToKeyFile(GKeyFile* config)
{
	XOJ_CHECK_TYPE(ToolbarData);

	const char* group = getId().c_str();

	std::vector<ToolbarEntry>::iterator it;
	for (it = this->contents.begin(); it != this->contents.end(); it++)
	{
		ToolbarEntry& e = *it;

		String line = "";

		ListIterator<ToolbarItem*> it = e.iterator();
		while (it.hasNext())
		{
			line += ",";
			line += *it.next();
		}

		if (line.length() > 2)
		{
			g_key_file_set_string(config, group, e.getName().c_str(),
			                      line.substring(1).c_str());
		}
	}

	g_key_file_set_string(config, group, "name", this->name.c_str());
}
Esempio n. 6
0
void SystemTimer::start(void)
{
    updateHiddenDelays();

    ListIterator<TickListener*> iter = tlList.getListIterator();
    iter.reset();
    while (iter.hasNext())
    {
        TickListener *tl = iter.next();
        if (tl != NULL)
            tl->onTick();
    }

    while (time < stoptime)
    {
        time++;

        ListIterator< List<Line*>* > refIter = refLists.getListIterator();
        refIter.reset();
        while (refIter.hasNext())
        {
            List<Line*> *list = refIter.next();

            Line *line = list->first();
            if (line != NULL)
                line->update();
        }

        updateHiddenDelays();

        if (clock != NULL)
            clock->tick();

        updateHiddenDelays();

        ListIterator<TickListener*> iter = tlList.getListIterator();
        iter.reset();

        while (iter.hasNext())
        {
            TickListener *tl = iter.next();
            if (tl != NULL)
                tl->onTick();
        }
    }
}
Esempio n. 7
0
/**
*    render
*    Renders the scene.
*    Preconditions:
*        The pixel object.
*    Postconditions:
*        The scene is rendered when the final render method is reached.
*/
void Scene::render( Pixel* pix )
{
    ListIterator<Node>* iter = scene->iterator();
    while( iter->hasNext() ) {
        iter->next()->render( pix, wnd );
    }
    delete iter;
}
Esempio n. 8
0
/**
*    render
*    Renders the basic object.
*    Preconditions:
*        The windowing transform matrix, the pixel object.
*    Postconditions:
*        Calls the next render method within the hierarchy.
*/
void BasicObject::render( Matrix* wnd, Pixel* pix, Color* material,
    Matrix* zbuffer )
{
    ListIterator<Face>* iter = faces->iterator();
    while( iter->hasNext() ) {
            iter->next()->render( wnd, pix, material, zbuffer );
    }
    delete iter;
}
Esempio n. 9
0
/**
*    addFace
*    Adds a new face to the object.
*    Preconditions:
*        The face to add to the object.
*    Postconditions:
*        A new face is added to the faces list.
*        The vertices from the new face is added to the vertices list.
*/
void BasicObject::addFace( Face* face )
{
    faces->add( face );

    ListIterator<Vertex>* iter = face->getVertices()->iterator();
    while ( iter->hasNext() ) {
        vertices->add( iter->next() );
    }
    delete iter;
}
Esempio n. 10
0
Scene::~Scene()
{
    ListIterator<Node>* iter = scene->iterator();
    while ( iter->hasNext() ) {
        iter->next()->removeRef();
    }
    delete iter;

    delete scene;
    delete wnd;
}
Esempio n. 11
0
void TransformNode::render(Pixel* pix, Matrix* mat)
{
	ListIterator<Node>* iter = nodes->iterator();

	while(iter->hasNext())
	{
		iter->next()->render(pix, mat->multiply(transform));
	}

	delete iter;
}
Esempio n. 12
0
void HiddenModuleManager::destroyModules(void)
{
    ListIterator<Module*> li = modList.getListIterator();

    li.reset();
    while (li.hasNext())
    {
        Module *mod = li.next();
        if (mod != NULL)
            delete mod;
    }
}
Esempio n. 13
0
TransformNode::~TransformNode()
{
   ListIterator<Node>* iter = children->iterator();

   while (iter->hasNext())
   {
      Node* node = iter->next();
      node->removeRef();
   }

   delete children;
   delete iter;
}
Esempio n. 14
0
void BasicObject::render(Pixel* pix, Matrix* transformMatrix)
{
	int count = 1;
	ListIterator<Face>* iter = faces.iterator();

	while(iter->hasNext())
	{
		//printf("\nPrinting face #%d", count);
		count++;
		iter->next()->render(pix, transformMatrix);
	}

	delete iter;
}
Esempio n. 15
0
void PageView::startText(double x, double y) {
	XOJ_CHECK_TYPE(PageView);

	this->xournal->endTextAllPages(this);

	if (this->textEditor == NULL) {
		// Is there already a textfield?
		ListIterator<Element *> eit = this->page.getSelectedLayer()->elementIterator();

		Text * text = NULL;

		while (eit.hasNext()) {
			Element * e = eit.next();

			if (e->getType() == ELEMENT_TEXT) {
				GdkRectangle matchRect = { x - 10, y - 10, 20, 20 };
				if (e->intersectsArea(&matchRect)) {
					text = (Text *) e;
					break;
				}
			}
		}

		bool ownText = false;
		if (text == NULL) {
			ToolHandler * h = xournal->getControl()->getToolHandler();
			ownText = true;
			text = new Text();
			text->setX(x);
			text->setY(y);
			text->setColor(h->getColor());
			text->setFont(settings->getFont());
		}

		this->textEditor = new TextEditor(this, xournal->getWidget(), text, ownText);
		if (!ownText) {
			this->textEditor->mousePressed(x - text->getX(), y - text->getY());
		}

		rerenderPage();
	} else {
		Text * text = this->textEditor->getText();
		GdkRectangle matchRect = { x - 10, y - 10, 20, 20 };
		if (!text->intersectsArea(&matchRect)) {
			endText();
		} else {
			this->textEditor->mousePressed(x - text->getX(), y - text->getY());
		}
	}
}
Esempio n. 16
0
void BasicObject::printFaces()
{
	int count = 0;
	ListIterator<Face>* iter = faces.iterator();

	while(iter->hasNext())
	{
		count++;
		printf("face %d:\n", count);
		iter->next()->printFace();
	}

	delete iter;
}
Esempio n. 17
0
Scene::~Scene()
{
   //clean up all of the basic object heap-allocated memory
   ListIterator<TransformNode>* ioIter = transformNodes->iterator();
   while (ioIter->hasNext())
   {
      TransformNode* tn = ioIter->next();
      tn->removeRef();
   }

   delete ioIter;
   delete transformNodes;
   delete sceneTransform;
}
Esempio n. 18
0
/**
*   ~BasicObject
*   Deconstuctor.
*   Preconditions:
*       None.
*   Postconditions:
*       BasicObject object is destroyed.
*/
BasicObject::~BasicObject()
{


    ListIterator<Face>* iter = faces->iterator();
    while ( iter->hasNext() ) {
            delete iter->next();
    }
    delete iter;
    delete faces;
    
    vertices->removeAll();
    delete vertices;

}
Esempio n. 19
0
TransformNode::~TransformNode()
{
	ListIterator<Node>* iter = nodes->iterator();
	printf("\nDeleting transform node - start");
	while(iter->hasNext())
	{		
		printf("\nin loop temp");
		iter->next()->removeRef();
	}

	delete iter;
	delete nodes;

	printf("\nDeleting transform node - end");
}
Esempio n. 20
0
void Hash::reHashRecords(Bucket* bucket, int bucketNumber, Bucket* newBucket)
{
	List<Record*>* recordList = bucket->getRecordList();
	ListIterator<Record*> it = recordList->getIterator();
	Record* auxRecord = NULL;
	int bucketDestinationNumber = 0;
	while(it.hasNext()){
		auxRecord = it.next();
		bucketDestinationNumber = this->hashTable->getBlock(this->hashKey(auxRecord->getKey()));
		if(bucketDestinationNumber != bucketNumber){
			newBucket->insertRecord(auxRecord->clone());
			bucket->deleteRecord(auxRecord->getKey());
		}
	}
}
Esempio n. 21
0
void TransformNode::render(Pixel* px, Matrix* later, Matrix* zbuffer, Color *ambient, Light *pointLight, Vertex *eye, double attenuation)
{
   //transform passed in from higher in the scene graph
   Matrix* updated = later->multiply(transform);

   ListIterator<Node>* iter = children->iterator();
   while (iter->hasNext())
   {
      Node* node = iter->next();
      node->render(px, updated, zbuffer, ambient, pointLight, eye, attenuation);
   }

   delete iter;
   delete updated;
}
Esempio n. 22
0
/**
*    render
*    Renders the scene.
*    Preconditions:
*        The pixel object.
*    Postconditions:
*        The scene is rendered when the final render method is reached.
*/
void Scene::render( Pixel* pix )
{
    Matrix* zbuffer = new Matrix( pix->getHeight(), pix->getWidth() );
    for ( int i = 0; i < pix->getHeight(); i++ ) {
         for ( int j = 0; j < pix->getWidth(); j++ ) {
             zbuffer->setElement( i, j, -1 );
         }
    }
    
    ListIterator<Node>* iter = scene->iterator();
    while( iter->hasNext() ) {
        iter->next()->render( pix, wnd, zbuffer );
    }
    delete iter;
    delete zbuffer;
}
Esempio n. 23
0
BasicObject::~BasicObject()
{
	ListIterator<Face>* iter2 = faces.iterator();
	while(iter2->hasNext())
	{
		delete iter2->next();
	}

	ListIterator<Vertex>* iter = vertices.iterator();
	while(iter->hasNext())
	{
		delete iter->next();
	}	

	delete iter;
	delete iter2;
	printf("\nDeleting\n");
}
Esempio n. 24
0
void EditSelection::serialize(ObjectOutputStream & out) {
	out.writeObject("EditSelection");

	out.writeDouble(this->x);
	out.writeDouble(this->y);
	out.writeDouble(this->width);
	out.writeDouble(this->height);

	out << this->contents;
	out.endObject();

	ListIterator<Element *> it = this->getElements();
	int count = it.getLength();
	out.writeInt(count);

	while (it.hasNext()) {
		Element * e = it.next();
		out << e;
	}
}
Esempio n. 25
0
void Scene::render(Pixel* px)
{
	//Create zbuffer
	Matrix *zBuffer = new Matrix(px->getHeight(), px->getWidth());
	for(int i=0 ; i<px->getHeight() ; i++)
	{
		for(int j=0 ; j<px->getWidth() ; j++)
		{
			zBuffer->setElement(i, j, -1);
		}
	}
   //loop over all the Instance instances in the Scene and render them
   ListIterator<TransformNode>* ioIter = transformNodes->iterator();
   while (ioIter->hasNext())
   {
      TransformNode* tn = ioIter->next();
      tn->render(px, sceneTransform, zBuffer);
   }
   delete ioIter;
}
Esempio n. 26
0
void XournalView::setSelection(EditSelection* selection)
{
	XOJ_CHECK_TYPE(XournalView);

	clearSelection();
	GTK_XOURNAL(this->widget)->selection = selection;

	control->setClipboardHandlerSelection(getSelection());

	bool canChangeSize = false;
	bool canChangeColor = false;

	ListIterator<Element*> it = selection->getElements();

	while (it.hasNext())
	{
		Element* e = it.next();
		if (e->getType() == ELEMENT_TEXT)
		{
			canChangeColor = true;
		}
		else if (e->getType() == ELEMENT_STROKE)
		{
			Stroke* s = (Stroke*) e;
			if (s->getToolType() != STROKE_TOOL_ERASER)
			{
				canChangeColor = true;
			}
			canChangeSize = true;
		}

		if (canChangeColor && canChangeSize)
		{
			break;
		}
	}

	control->getToolHandler()->setSelectionEditTools(canChangeColor, canChangeSize);

	repaintSelection();
}
Esempio n. 27
0
/**
*    avgNormal
*    Obtain the average normal for a vertex that is within multiply Faces.
*    Preconditions:
*        The vertex that needs to be normalized.
*    Postconditions:
*        Returns a Vector pointer to the averaged normal.
*/
Vector* Face::avgNormal( Vertex* m )
{
    Vector* normal;

    List<Face>* f = m->getFaces();
    List<Vector>* nml = new List<Vector>();

    // Obtain all the normals for each face and add into a list.
    ListIterator<Face>* iter = f->iterator();
    int counter = 0;
    while ( iter->hasNext() ) {
        Face* fac = iter->next();
        nml->add( fac->getNormal( fac->getVertex(1), fac->getVertex(2),
            fac->getVertex(3) ) );
        counter++;
    }
    delete iter;


// MEMORY LEAK---------------------------------------------------------------------
    ListIterator<Vector>* iter2 = nml->iterator();
    Vector* tmp = iter2->next();
    while ( iter2->hasNext() ) {
        Vector* tmp2 = iter2->next();
        normal = tmp->addition( tmp2 );
        delete tmp;
        delete tmp2;
        tmp = normal;
    }
    delete iter2;

    tmp = normal->division( ((double)counter) );
    delete normal;
    normal = tmp;
// END MEMORY Leak=================================================================

    delete nml;
    return normal;
}
Esempio n. 28
0
VerticalToolHandler::VerticalToolHandler(Redrawable * view, PageRef page, double y, double zoom) {
	XOJ_INIT_TYPE(VerticalToolHandler);

	this->startY = y;
	this->endY = y;
	this->view = view;
	this->page = page;
	this->layer = this->page.getSelectedLayer();
	this->elements = NULL;
	this->jumpY = 0;

	ListIterator<Element *> it = this->layer->elementIterator();
	while (it.hasNext()) {
		Element * e = it.next();
		if (e->getY() >= y) {
			this->elements = g_list_append(this->elements, e);
		}
	}

	for (GList * l = this->elements; l != NULL; l = l->next) {
		Element * e = (Element *) l->data;
		this->layer->removeElement(e, false);

		this->jumpY = MAX(this->jumpY, e->getY() + e->getElementHeight());
	}

	this->jumpY = this->page.getHeight() - this->jumpY;

	this->crBuffer = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, this->page.getWidth() * zoom, (this->page.getHeight() - y) * zoom);
	cairo_t * cr = cairo_create(this->crBuffer);
	cairo_scale(cr, zoom, zoom);
	cairo_translate(cr, 0, -y);
	DocumentView v;
	v.drawSelection(cr, this);

	cairo_destroy(cr);

	view->rerenderPage();
}
Esempio n. 29
0
TexImage* PageView::getSelectedTex()
{
	XOJ_CHECK_TYPE(PageView);

	EditSelection* theSelection = this->xournal->getSelection();
	if(!theSelection)
	{
		return NULL;
	}

	TexImage* texMatch = NULL;

	ListIterator<Element*> eit = theSelection->getElements();
	while(eit.hasNext())
	{
		Element* e = eit.next();
		if (e->getType() == ELEMENT_TEXIMAGE)
		{
			texMatch = (TexImage*) e;
		}
	}
	return texMatch;

}
Esempio n. 30
0
BasicObject* Picture::readObject(char* fileName)
{
   BasicObject* obj = new BasicObject();
   FileIO* file = new FileIO(fileName, ' '); //assumed to be a read if a delimiter is specified

   List<Vertex> vertices;
   double x, y, z;
   string* token;
   int index1, index2, index3, temp; 

   //parsing the complex index information for the triangular face
   //could include a vertex index, a vertex normal index, and texture coord information
   string* str1;
   string* str2;
   string* str3;  
   string str11;
   string str22;
   string str33;

   string* v = new string("v");
   string* f = new string("f");

   while (!file->eof())
   {
      ListIterator<string>* iter = file->getTokens();
      token = iter->next();

      //all vertices are held in the vertices list so that the faces can be created
      if (*token == *v)  //vertices
      {
         delete token;

         token = iter->next();
         x = atof((*token).c_str());
         delete token;

         token = iter->next();
         y = atof((*token).c_str());
         delete token;

         token = iter->next();
         z = atof((*token).c_str());
         delete token;

         Vertex* vertex = new Vertex(x, y, z);
         vertices.add(vertex);
         obj->addVertex(vertex);
      }

      else if (*token == *f)  //face definition
      {
         delete token;

         //get the complex index information for the triangle face
         str1 = iter->next();
         str2 = iter->next();
         str3 = iter->next();

         //parse the index information for the vertex index
         temp = str1->find("/");
         str11 = str1->erase(temp, str1->size() - 1);

         temp = str2->find("/");
         str22 = str2->erase(temp, str2->size() - 1);

         temp = str3->find("/");
         str33 = str3->erase(temp, str3->size() - 1);
         char* cp;
         int len;

         cp = new char[10];
         len = str11.length();
         str11.copy(cp, len, 0);
         cp[len] = '\0';
         index1 = atoi(cp);
         delete[] cp;

         cp = new char[10];
         len = str22.length();
         str22.copy(cp, len, 0);
         cp[len] = '\0';
         index2 = atoi(cp);
         delete[] cp;

         cp = new char[10];
         len = str33.length();
         str33.copy(cp, len, 0);
         cp[len] = '\0';
         index3 = atoi(cp);
         delete[] cp;

         Face* face = new Face();

         Vertex* vertex1 = vertices.get(index1);
         Vertex* vertex2 = vertices.get(index2);
         Vertex* vertex3 = vertices.get(index3);

         face->addVertex(vertex1);
         face->addVertex(vertex2);
         face->addVertex(vertex3);

         obj->addFace(face);

         delete str1;
         delete str2;
         delete str3;
      }

      //still need to delete the tokens even if the line is completely disregarded
      else  
      {
         delete token;
         while(iter->hasNext())
         {
            token = iter->next();
            delete token;
         }
      }

      delete iter;
   }

   delete v;
   delete f;
   delete file;
   return obj;
}