Exemplo n.º 1
0
//--------------------------------------------------------------
void ofApp::draw(){
    ofBackground(255);
    ofSetColor(255, 0, 0);
    //ofDrawBitmapString("hello world", ofGetWidth()/2, ofGetHeight()/2);
    ofDrawBitmapString(phrase, position.x, position.y);
    drawWord(phrase);

}
Exemplo n.º 2
0
void PaintArea::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::RightButton)
        _right = true;
    else
        _right = false;
    if (_tool != 0)
    {
        _redo.clear();
        emit noRedo();
    }
    if (_isselect)
    {
        Undo();
        _isselect = false;
        emit noCopy();
    }
    lastPoint = event->pos();
    if (_tool == 7)
    {
        _history.push_back(image);
        emit enableUndo();
        drawWord(lastPoint);
    }
    else if (_tool == 6)
    {
        _history.push_back(image);
        emit enableUndo();
        drawBucket(event->pos());
    }
    else if (_tool == 10)
    {
        _history.push_back(image);
        emit enableUndo();
        Paste(event->pos());
    }
    else if (_tool == 12)
    {
        if (event->button() == Qt::LeftButton)
            zoomIn();
        else
            zoomOut();
    }
    else
    {
        _history.push_back(image);
        emit enableUndo();
        _scroll = image;
        scribbling = true;
        if (_tool == 1)
            drawLineTo(event->pos());
        else if (_tool == 2)
            drawEraser(event->pos());
        else if (_tool == 11)
            drawSpray(event->pos());
    }
}
Exemplo n.º 3
0
void ZLTextView::drawTextLine(const ZLTextLineInfo &info, int y, size_t from, size_t to) {
	const ZLTextParagraphCursor &paragraph = info.RealStart.paragraphCursor();

	const ZLTextElementIterator fromIt = myTextElementMap.begin() + from;
	const ZLTextElementIterator toIt = myTextElementMap.begin() + to;

	if (!mySelectionModel.isEmpty() && (from != to)) {
		const std::vector<ZLTextSelectionModel::Range> &ranges = mySelectionModel.ranges();

		if (!ranges.empty()) {
			RangeVector::const_iterator rt = ranges.end();
			const int top = y + 1;
			int bottom = y + info.Height + info.Descent;
			if (strongFindRange(ranges, info.End) != ranges.end()) {
				bottom += info.VSpaceAfter;
			}
			int left = viewWidth() + lineStartMargin() - 1;
			int right = lineStartMargin();
			const int baseRTL = myStyle.baseBidiLevel() % 2;

			for (ZLTextElementIterator it = fromIt; it < toIt; ++it) {
				const ZLTextElementArea &area = *it;
				RangeVector::const_iterator rt2 = findRange(ranges, area);
				if (rt2 == rt) {
					if (rt != ranges.end()) {
						const bool mainDir = area.BidiLevel % 2 == baseRTL;
						int r = area.XEnd;
						const ZLTextSelectionModel::BoundElement &bound =
							mainDir ? rt->second : rt->first;
						if (bound.ElementIndex == area.ElementIndex) {
							const ZLTextElement &element = paragraph[area.ElementIndex];
							if (element.kind() == ZLTextElement::WORD_ELEMENT) {
								r = areaBound(paragraph, area, bound.CharIndex, mainDir);
							}
						}
						right = std::max(right, r);
					}
				} else {
					if (rt != ranges.end()) {
						drawSelectionRectangle(left, top, right, bottom);
						left = viewWidth() + lineStartMargin() - 1;
						right = lineStartMargin();
					}
					rt = rt2;
					if (rt != ranges.end()) {
						if ((it == fromIt) &&
								(info.StartBidiLevel % 2 == baseRTL) &&
								strongContains(*rt, info.Start)) {
							left = lineStartMargin();
						}

						const bool mainDir = area.BidiLevel % 2 == baseRTL;

						int l = area.XStart - 1;
						int r = area.XEnd;

						const ZLTextSelectionModel::BoundElement &rightBound =
							mainDir ? rt->second : rt->first;
						const ZLTextSelectionModel::BoundElement &leftBound =
							mainDir ? rt->first : rt->second;
						if (paragraph[area.ElementIndex].kind() == ZLTextElement::WORD_ELEMENT) {
							if (rightBound.ElementIndex == area.ElementIndex) {
								r = areaBound(paragraph, area, rightBound.CharIndex, mainDir);
							}
							if (leftBound.ElementIndex == area.ElementIndex) {
								l = areaBound(paragraph, area, leftBound.CharIndex, mainDir);
							}
						}

						left = std::min(left, l);
						right = std::max(right, r);
					}
				}
			}
			if (rt != ranges.end()) {
				if ((paragraph.index() < (size_t)rt->second.ParagraphIndex) &&
						strongContains(*rt, info.End)) {
					right = viewWidth() + lineStartMargin() - 1;
				}
				drawSelectionRectangle(left, top, right, bottom);
			}
		}
	}

	y = std::min(y + info.Height, topMargin() + textAreaHeight());
	int x = lineStartMargin();
	if (!info.NodeInfo.isNull()) {
		drawTreeLines(*info.NodeInfo, x, y, info.Height, info.Descent + info.VSpaceAfter);
	}
	ZLTextElementIterator it = fromIt;
	const int endElementIndex = info.End.elementIndex();
	for (; (it != toIt) && (it->ElementIndex != endElementIndex); ++it) {
		const ZLTextElement &element = paragraph[it->ElementIndex];
		ZLTextElement::Kind kind = element.kind();
	
		if ((kind == ZLTextElement::WORD_ELEMENT) || (kind == ZLTextElement::IMAGE_ELEMENT)) {
			myStyle.setTextStyle(it->Style, it->BidiLevel);
			const int wx = myStyle.baseIsRtl() ? context().width() - it->XEnd : it->XStart;
			const int wy = it->YEnd - myStyle.elementDescent(element) - myStyle.textStyle()->verticalShift();
			if (kind == ZLTextElement::WORD_ELEMENT) {
				drawWord(wx, wy, (const ZLTextWord&)element, it->StartCharIndex, -1, false);
			} else {
				context().drawImage(wx, wy, *((const ZLTextImageElement&)element).image());
			}
		}
	}
	if (it != toIt) {
		myStyle.setTextStyle(it->Style, it->BidiLevel);
		int start = 0;
		if (info.Start.equalElementIndex(info.End)) {
			start = info.Start.charIndex();
		}
		int len = info.End.charIndex() - start;
		const ZLTextWord &word = (const ZLTextWord&)info.End.element();
		context().setColor(myStyle.textStyle()->color());
		const int x = myStyle.baseIsRtl() ? context().width() - it->XEnd : it->XStart;
		const int y = it->YEnd - myStyle.elementDescent(word) - myStyle.textStyle()->verticalShift();
		drawWord(x, y, word, start, len, it->AddHyphenationSign);
	}
}
Exemplo n.º 4
0
void drawBox (KinoWidget w, Element *box, int x, int y, LargeRegion r)
{
  Node *p;
  Region regExpose, regBox, empty, intersect;
  XRectangle re, rb;

  if (box != NULL && box->display != DISPLAY_NONE &&
    (box->display == DISPLAY_INLINE ||
    !(x + box->x + box->width < r.x || x + box->x > r.x + r.width ||
      y + box->y + box->height < r.y || y + box->y > r.y + r.height)))
  {
    x = x + box->x;
    y = y + box->y;

    if (box->display == DISPLAY_BLOCK)
    {
      if (box->background_color.alpha == 0)
      {
	changeGC (w, ((XFontStruct *) box->font)->fid,
	  box->background_color, box->background_color, 0);

	rb.x = x + ElementTotalLeft (box);
	rb.y = y + ElementTotalTop (box);
	rb.width = box->width -
	  ElementTotalLeft (box) - ElementTotalRight (box);
	rb.height = box->height -
	  ElementTotalTop (box) - ElementTotalBottom (box);

	re.x = r.x; re.y = r.y; re.width = r.width; re.height = r.height;

	empty = XCreateRegion ();
	regBox = XCreateRegion ();
	XUnionRectWithRegion (&rb, empty, regBox);
	regExpose = XCreateRegion ();
	XUnionRectWithRegion (&re, empty, regExpose);
	intersect = XCreateRegion ();
	XIntersectRegion (regBox, regExpose, intersect);

	XSetRegion (XtDisplay (w), w->kino.painter->gc, intersect);
	XFillRectangle (XtDisplay (w), XtWindow (w), w->kino.painter->gc,
	  r.x, r.y, r.width, r.height); 
	
	XDestroyRegion (regBox);
	XDestroyRegion (regExpose);
	XDestroyRegion (empty);
	XDestroyRegion (intersect);
      }

      if (box->border_top_color.alpha == 0 &&
	box->border_top_width.effective > 0)
      {
	changeGC (w, ((XFontStruct *) box->font)->fid,
	  box->border_top_color, box->background_color,
	  box->border_top_width.effective);
	XDrawLine (XtDisplay (w), XtWindow (w), w->kino.painter->gc,
	  x + box->margin_left.effective, 
	  y + box->margin_top.effective,
	  x + box->width - box->margin_right.effective,
	  y + box->margin_top.effective);
      }

      if (box->border_bottom_color.alpha == 0 &&
	box->border_bottom_width.effective > 0)
      {
	changeGC (w, ((XFontStruct *) box->font)->fid,
	  box->border_bottom_color, box->background_color,
	  box->border_bottom_width.effective);
	XDrawLine (XtDisplay (w), XtWindow (w), w->kino.painter->gc,
	  x + box->margin_left.effective, 
	  y + box->height - box->margin_bottom.effective,
	  x + box->width - box->margin_right.effective,
	  y + box->height - box->margin_bottom.effective);
      }

      if (box->border_left_color.alpha == 0 &&
	box->border_left_width.effective > 0)
      {
	changeGC (w, ((XFontStruct *) box->font)->fid,
	  box->border_left_color, box->background_color,
	  box->border_left_width.effective);
	XDrawLine (XtDisplay (w), XtWindow (w), w->kino.painter->gc,
	  x + box->margin_left.effective, 
	  y + box->margin_top.effective,
	  x + box->margin_left.effective, 
	  y + box->height - box->margin_bottom.effective);
      }

      if (box->border_right_color.alpha == 0 &&
	box->border_right_width.effective > 0)
      {
	changeGC (w, ((XFontStruct *) box->font)->fid,
	  box->border_right_color, box->background_color,
	  box->border_right_width.effective);
	XDrawLine (XtDisplay (w), XtWindow (w), w->kino.painter->gc,
	  x + box->width - box->margin_right.effective, 
	  y + box->margin_top.effective,
	  x + box->width - box->margin_right.effective, 
	  y + box->height - box->margin_bottom.effective);
      }
    }

    changeGC (w, ((XFontStruct *) box->font)->fid,
      box->color, box->background_color, 1);

    p = box->contents;
    while (p != NULL)
    {
      switch (p->type)
      {
	case TEXT_NODE:
	  drawWord (w, box, (Text *) p, x, y, r);
	  break;
	case ELEMENT_NODE:
	  drawBox (w, (Element *) p, x, y, r);
	  changeGC (w, ((XFontStruct *) box->font)->fid,
	    box->color, box->background_color, 1);
	  break;
	default: 
	  break;
      }
      p = p->next;
    }
  }
}