Beispiel #1
0
/**
 * Creates a dimensioning line (line with one, two or no arrows).
 */
QList<QSharedPointer<RShape> > RDimensionData::getDimensionLineShapes(
    const RVector& p1, const RVector& p2,
    bool arrow1, bool arrow2) const {

    QList<QSharedPointer<RShape> > ret;

    // text height (DIMTXT)
    double dimtxt = getDimtxt();
    // text distance to line (DIMGAP)
    double dimgap = getDimgap();

    // length of dimension line:
    dimLineLength = p1.getDistanceTo(p2);

    // do we have to put the arrows outside of the line?
    bool outsideArrows = (dimLineLength < getDimasz()*2.5);

    // arrow angles:
    double arrowAngle1, arrowAngle2;

    // Create dimension line:
    RLine dimensionLine(p1, p2);

    if (outsideArrows==false) {
        arrowAngle1 = dimensionLine.getDirection2();
        arrowAngle2 = RMath::getNormalizedAngle(arrowAngle1+M_PI);
    } else {
        arrowAngle1 = dimensionLine.getDirection1();
        arrowAngle2 = RMath::getNormalizedAngle(arrowAngle1+M_PI);

        // extend dimension line outside arrows
        RVector dir;
        dir.setPolar(getDimasz()*2, arrowAngle2);
        dimensionLine.setStartPoint(p1 + dir);
        dimensionLine.setEndPoint(p2 - dir);
    }

    ret.append(QSharedPointer<RShape>(new RLine(dimensionLine)));

    if (arrow1) {
        QList<QSharedPointer<RShape> > arrow = getArrow(p1, arrowAngle1);
        ret.append(arrow);
    }

    if (arrow2) {
        QList<QSharedPointer<RShape> > arrow = getArrow(p2, arrowAngle2);
        ret.append(arrow);
    }

    double dimAngle1 = dimensionLine.getDirection1();
    bool corrected=false;
    defaultAngle = RMath::makeAngleReadable(dimAngle1, true, &corrected);

    if (autoTextPos) {
        RVector newTextPos = dimensionLine.getMiddlePoint();
        RVector distV;

        // rotate text so it's readable from the bottom or right (ISO)
        // quadrant 1 & 4
        if (corrected) {
            distV.setPolar(dimgap + dimtxt/2.0, dimAngle1-M_PI/2.0);
        } else {
            distV.setPolar(dimgap + dimtxt/2.0, dimAngle1+M_PI/2.0);
        }

        // move text away from dimension line:
        newTextPos+=distV;

        textPositionCenter = newTextPos;
    }

    return ret;
}
void CWizUserInfoWidgetBase::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    int nAvatarWidth = 32;
    int nArrawWidth = 10;
    int nMargin = 4;

    QStyleOptionToolButton opt;
    initStyleOption(&opt);

    QPainter p(this);
    p.setClipRect(opt.rect);

    // draw user avatar
    QRect rectIcon = opt.rect;
    rectIcon.setLeft(rectIcon.left());
    rectIcon.setRight(rectIcon.left() + nAvatarWidth);

    QPixmap pixmap = getAvatar(nAvatarWidth, nAvatarWidth);
    if (!pixmap.isNull())
    {
        p.drawPixmap(rectIcon, pixmap);
    }
    //if (!opt.icon.isNull()) {
    //    opt.icon.paint(&p, rectIcon);
    //}

    // draw vip indicator
    QRect rectVip = rectIcon;
    rectVip.setLeft(rectVip.right() + nMargin);
    rectVip.setRight(rectVip.left() + fontMetrics().width(opt.text));
    //rectVip.setBottom(rectVip.top() + rectVip.height()/2);
    //if (!m_iconVipIndicator.isNull()) {
    //    m_iconVipIndicator.paint(&p, rectVip, Qt::AlignLeft|Qt::AlignTop);
    //}

    // draw display name
    QRect rectText = rectVip;
    //rectText.setBottom(rectText.bottom() + rectVip.height());
    //rectText.setTop(rectText.bottom() - rectVip.height());
    if (!opt.text.isEmpty()) {
        if (opt.state & QStyle::State_MouseOver) {
            QFont font = p.font();
            font.setUnderline(true);
            p.setFont(font);
        }

        p.setPen("#787878"); // FIXME
        p.drawText(rectText, Qt::AlignLeft|Qt::AlignVCenter, opt.text);
    }

    // draw arraw
    QRect rectArrow = rectText;
    rectArrow.setLeft(rectArrow.right() + nMargin);
    rectArrow.setRight(rectArrow.left() + nArrawWidth);
    QIcon arrow = getArrow();
    if (!arrow.isNull()) {
        arrow.paint(&p, rectArrow, Qt::AlignVCenter, QIcon::Normal);
    }
}
Beispiel #3
0
QList<QSharedPointer<RShape> > RDimAngularData::getShapes(const RBox& queryBox, bool ignoreComplex, bool segment) const {
    Q_UNUSED(queryBox)
    Q_UNUSED(ignoreComplex)
    Q_UNUSED(segment)

    QSharedPointer<RBlockReferenceEntity> dimBlockReference = getDimensionBlockReference();
    if (!dimBlockReference.isNull()) {
        return dimBlockReference->getShapes(queryBox, ignoreComplex);
    }

    QList<QSharedPointer<RShape> > ret;

    double dimexo = getDimexo();
    double dimexe = getDimexe();
    double dimtxt = getDimtxt();
    double dimgap = getDimgap();
    double dimasz = getDimasz();

    // find out center:
    RVector center = getCenter();

    if (!center.isValid()) {
        return ret;
    }

    double ang1 = 0.0;
    double ang2 = 0.0;
    bool reversed = false;
    RVector p1;
    RVector p2;

    getAngles(ang1, ang2, reversed, p1, p2);

    double rad = dimArcPosition.getDistanceTo(center);

    RLine line;
    RVector dir;
    double len;
    double dist;

    // 1st extension line:
    dist = center.getDistanceTo2D(p1);
    len = rad - dist + dimexe;
    dir.setPolar(1.0, ang1);
    line = RLine(center + dir*dist + dir*dimexo, center + dir*dist + dir*len);
    ret.append(QSharedPointer<RShape>(new RLine(line)));

    // 2nd extension line:
    dist = center.getDistanceTo2D(p2);
    len = rad - dist + dimexe;
    dir.setPolar(1.0, ang2);
    line = RLine(center + dir*dist + dir*dimexo, center + dir*dist + dir*len);
    ret.append(QSharedPointer<RShape>(new RLine(line)));

    // Create dimension line (arc):
    RArc arc(center, rad, ang1, ang2, reversed);
    ret.append(QSharedPointer<RShape>(new RArc(arc)));

    // length of dimension arc:
    double distance = arc.getLength();

    // do we have to put the arrows outside of the arc?
    bool outsideArrows = (distance<dimasz*2);

    // arrow angles:
    double arrowAngle1, arrowAngle2;
    double arrowAng;
    if (rad>1.0e-6) {
        arrowAng = getDimasz() / rad;
    }
    else {
        arrowAng = 0.0;
    }

    if (outsideArrows) {
        arrowAngle1 = arc.getDirection1();
        arrowAngle2 = arc.getDirection2();
    }
    else {
        RVector v1, v2;
        if (!arc.isReversed()) {
            v1.setPolar(rad, arc.getStartAngle()+arrowAng);
        } else {
            v1.setPolar(rad, arc.getStartAngle()-arrowAng);
        }
        v1+=arc.getCenter();
        arrowAngle1 = arc.getStartPoint().getAngleTo(v1);


        if (!arc.isReversed()) {
            v2.setPolar(rad, arc.getEndAngle()-arrowAng);
        } else {
            v2.setPolar(rad, arc.getEndAngle()+arrowAng);
        }
        v2+=arc.getCenter();
        arrowAngle2 = arc.getEndPoint().getAngleTo(v2);

        arrowAngle1 = arrowAngle1+M_PI;
        arrowAngle2 = arrowAngle2+M_PI;
    }

    // Arrows:
    //RTriangle arrow = RTriangle::createArrow(arc.getStartPoint(), arrowAngle1, dimasz);
    QList<QSharedPointer<RShape> > arrow = getArrow(arc.getStartPoint(), arrowAngle1);
    ret.append(arrow);
    //arrow = RTriangle::createArrow(arc.getEndPoint(), arrowAngle2, dimasz);
    arrow = getArrow(arc.getEndPoint(), arrowAngle2);
    ret.append(arrow);
    //ret.append(QSharedPointer<RShape>(new RTriangle(arrow)));

    //RVector oldMot = textPosition;
    //textPosition = RVector(0,0);
    //defaultAngle = 0.0;
    //dimLineLength = RNANDOUBLE;
    //getTextData();
    //textPosition = oldMot;

    RVector textPos = arc.getMiddlePoint();
    double dimAngle1 = textPos.getAngleTo(arc.getCenter())-M_PI/2.0;
    if (!autoTextPos) {
        dimAngle1 = textPositionCenter.getAngleTo(arc.getCenter())-M_PI/2.0;
    }

    RVector distV;
    double textAngle;
    // rotate text so it's readable from the bottom or right (ISO)
    // quadrant 1 & 4
    if (dimAngle1>M_PI/2.0*3.0+0.001 ||
        dimAngle1<M_PI/2.0+0.001) {

        distV.setPolar(dimgap + dimtxt/2, dimAngle1+M_PI/2.0);
        textAngle = dimAngle1;
    }
    // quadrant 2 & 3
    else {
        distV.setPolar(dimgap + dimtxt/2, dimAngle1-M_PI/2.0);
        textAngle = dimAngle1+M_PI;
    }

    if (!autoTextPos) {
        textPos = textPositionCenter;
    } else {
        // move text away from dimension line:
        textPos+=distV;

        textPositionCenter = textPos;
    }
    defaultAngle = textAngle;
    //getTextData();
    //textData.rotate(textAngle, RVector(0,0));
    //textData.move(textPos);

    return ret;
}
void PathFinder::printMap()
{
	KeyType agentMap[MAP_WIDTH][MAP_HEIGHT];
	KeyType enemyMap[MAP_WIDTH][MAP_HEIGHT];

	for (int i = 0; i < MAP_WIDTH; i++)
	{
		for (int j = 0; j < MAP_HEIGHT; j++)
		{
			agentMap[i][j] = INVALID_KEY;
		}
	}

	for (int i = 0; i < MAP_WIDTH; i++)
	{
		for (int j = 0; j < MAP_HEIGHT; j++)
		{
			enemyMap[i][j] = INVALID_KEY;
		}
	}

	// Iterate through all the agents and put the key in the local map
	std::map<KeyType, Agent*>* agents = mpAgentHandler->checkOutAllAgents();
	std::map<KeyType, Agent*>::iterator agentIt;
	for (agentIt = agents->begin(); agentIt != agents->end(); ++agentIt)
	{
		Coordinate position = agentIt->second->getPosition();
		agentMap[static_cast<int>(position.x+0.5f)][static_cast<int>(position.y+0.5f)] = agentIt->first;
	}
	mpAgentHandler->checkInAllAgents();

	// Iterate through all the enemies
	std::map<KeyType, Enemy*>* enemies = mpEnemyHandler->checkOutAllEnemies();
	std::map<KeyType, Enemy*>::iterator enemyIt;
	for (enemyIt = enemies->begin(); enemyIt != enemies->end(); ++enemyIt)
	{
		FixedCoordinate position = enemyIt->second->getPosition();
		enemyMap[position.x][position.y] = enemyIt->first;
	}
	mpEnemyHandler->checkInAllEnemies();

	// Print the map
	std::list<std::wostream*>::iterator it;
	for (it = mpOutStreams->begin(); it != mpOutStreams->end(); ++it)
	{
		printLine(**it, true);
		std::wstring text;
		std::wstringstream ss;
		std::wostream& out = **it;

		for (int height = 0; height < MAP_HEIGHT; height++)
		{
			// Print the id
			for (int width = 0; width < MAP_WIDTH; width++)
			{
				ss.clear();
				text = L"";
				// Check the agent and enemy map
				if (agentMap[width][height] != INVALID_KEY)
				{
					ss << agentMap[width][height];
				}
				else if (enemyMap[width][height] != INVALID_KEY)
				{
					ss << enemyMap[width][height];
				}
				ss >> text;

				out << L"|" << std::setw(5) << text;
			}
			out << L"|" << std::endl;

			// Print additional information
			for (int width = 0; width < MAP_WIDTH; width++)
			{
				// Check the agent and enemy map
				if (agentMap[width][height] != INVALID_KEY)
				{
					// get the goal position
					Agent* pAgent = mpAgentHandler->checkOutAgent(agentMap[width][height]);
					FixedCoordinate goal = pAgent->getPotentialInformation().getBestGoalPosition();
					FixedCoordinate nextGoal = pAgent->getPotentialInformation().getBestNextGoalPosition();
					mpAgentHandler->checkInAgent(agentMap[width][height]);

					// current position
					FixedCoordinate curPos;
					curPos.x = width;
					curPos.y = height;

					text = getArrow(curPos, goal);
					text += L" ";
					text += getArrow(goal, nextGoal);
				}
				else if (enemyMap[width][height] != INVALID_KEY)
				{
					text = L"XXXXX";
				}
				else
				{
					text = L"";
				}

				out << L"|" << std::setw(5) << text;
			}
			out << L"|" << std::endl;
			out.setf(std::ios::fixed, std::ios::floatfield);
			out.precision(2);
			
			// Print the potential info
			for (int width = 0; width < MAP_WIDTH; width++)
			{
				out << L"|" << std::setw(5) << mEnemyPotentialMap[width][height] << text;
			}

			
			out << L"|" << std::endl;
			
			if (height < MAP_HEIGHT - 1)
			{
				printLine(**it);
			}
		}

		printLine(**it, false, true);

		out << "\n\n";
	}
}
Beispiel #5
0
static void boardUpdateProc(Layer* this_layer, GContext *ctx) {
  GRect b = layer_get_bounds(this_layer);
  graphics_context_set_antialiased(ctx, 0);

  // Fill grey back (white on BW)
  graphics_context_set_fill_color(ctx, COLOR_FALLBACK(GColorLightGray, GColorWhite));
  graphics_context_set_stroke_color(ctx, GColorBlack);
  graphics_fill_rect(ctx, b, 0, GCornersAll);

  // Frame highlight around currently selected square colours is gray w white highlight, BW is wite w black highight
  graphics_context_set_fill_color(ctx, COLOR_FALLBACK(GColorDarkGray, GColorWhite));
  graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorWhite, GColorBlack));
  GRect highlightR = GRect(s_cursor.x*PIECE_PIXELS, s_cursor.y*PIECE_PIXELS, PIECE_PIXELS+1, PIECE_PIXELS+1);
  graphics_fill_rect(ctx, highlightR, 0, GCornersAll);
  graphics_draw_rect(ctx, highlightR);

  // Draw all board shapes
  for (int x = 0; x < BOARD_PIECES_X; ++x) {
    for (int y = 0; y < BOARD_PIECES_Y; ++y) {
      int xy = XY(x,y);
      if (s_gameState == kFlashRemoved && (s_pieces[xy].match != kUnmatched || s_pieces[XY(x,y)].exploded == true)) {
        // Highlight squares which have just been matched
        GColor highlight = COLOR_FALLBACK(GColorRed, GColorBlack);
        if (s_pieces[xy].match == kMatchedTwice) highlight = COLOR_FALLBACK(GColorDarkCandyAppleRed, GColorBlack);
        graphics_context_set_fill_color(ctx, highlight);
        graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorBlack, GColorLightGray));
        highlightR = GRect((s_pieces[xy].loc.x/SUB_PIXEL), (s_pieces[xy].loc.y/SUB_PIXEL), PIECE_PIXELS+1, PIECE_PIXELS+1);
        graphics_fill_rect(ctx, highlightR, 0, GCornersAll);
        graphics_draw_rect(ctx, highlightR);
      }
      // Draw the shape itself
      graphics_context_set_fill_color(ctx, COLOURS[ s_pieces[xy].colour ]);
      if (getShape( s_pieces[xy].colour ) != NULL) {
        static const bool bw = PBL_IF_BW_ELSE(true,false);
        if (bw == false && s_pieces[xy].colour == kBlack ) {
          graphics_context_set_stroke_color(ctx, GColorWhite);
        } else if (bw == true
          && (s_pieces[xy].match != kUnmatched || s_pieces[XY(x,y)].exploded == true)
          && COLOURS[ s_pieces[xy].colour ].argb != GColorWhite.argb ) {
          graphics_context_set_stroke_color(ctx, GColorWhite);
        } else {
          graphics_context_set_stroke_color(ctx, GColorBlack);
        }
        gpath_move_to(getShape( s_pieces[xy].colour ), GPoint(s_pieces[xy].loc.x/SUB_PIXEL, s_pieces[xy].loc.y/SUB_PIXEL));
        gpath_draw_filled(ctx, getShape( s_pieces[xy].colour ));
        gpath_draw_outline(ctx, getShape( s_pieces[xy].colour ));
      } else {
        // White rectangle of debug - we should not have the case where we render a NULL square
        graphics_fill_rect(ctx, GRect((s_pieces[xy].loc.x/SUB_PIXEL)+2, (s_pieces[xy].loc.y/SUB_PIXEL)+2, PIECE_PIXELS-3, PIECE_PIXELS-3), 2, GCornersAll);
      }
    }
  }

  // Move Arrows
  if (s_flashArrows == true && s_gameState == kAwaitingDirection) {
    graphics_context_set_fill_color(ctx, GColorWhite);
    for (int d = 0; d < N_CARDINAL; ++d) {
      gpath_move_to(getArrow(d), GPoint(s_cursor.x * PIECE_PIXELS, s_cursor.y * PIECE_PIXELS));
      gpath_draw_filled(ctx, getArrow(d));
      gpath_draw_outline(ctx, getArrow(d));
    }
  }

  // Cursor
  if (s_tiltMode > 0) {
    graphics_context_set_fill_color(ctx, GColorWhite);
    graphics_context_set_stroke_color(ctx, GColorBlack);
    graphics_fill_circle(ctx, GPoint(s_motionCursor.x/SUB_PIXEL,s_motionCursor.y/SUB_PIXEL), 3);
    graphics_draw_circle(ctx, GPoint(s_motionCursor.x/SUB_PIXEL,s_motionCursor.y/SUB_PIXEL), 3);
  }

  // Next move
  if (s_hintOn && s_availableMove.x != -1 && s_gameState == kIdle && s_hintStatus == true) {
    graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorDarkCandyAppleRed,GColorBlack) );
    graphics_context_set_stroke_width(ctx, 3);
    graphics_draw_circle(ctx, GPoint(s_availableMove.x*PIECE_PIXELS + PIECE_PIXELS/2, s_availableMove.y*PIECE_PIXELS + PIECE_PIXELS/2), PIECE_PIXELS);
    graphics_context_set_stroke_width(ctx, 1);
  }

  // Redo border
  graphics_context_set_stroke_color(ctx, GColorBlack);
  graphics_draw_rect(ctx, b);

}
Beispiel #6
0
/**
*函数说明:移动触摸,将触摸到的新汉字元素放进已选汉字盒子
*如果是倒退,那么将最后一个汉字元素从已选汉字盒子中删除
*每一次增加/删除汉字元素,都会判断当前已选的汉字是否能消除
*/
void ChrsGrid::onTouchMoved(Touch* pTouch, Event*)
{
	//移动时也可选择
	//将触摸点的坐标转化为模型坐标
	auto pos = this->convertToNodeSpace(pTouch->getLocation());

	//得到阵列坐标
	int x = pos.x / GRID_WIDTH;
	int y = pos.y / GRID_WIDTH;

	//得到汉字原点模型坐标
	auto chr_pos = Vec2(x * GRID_WIDTH, y * GRID_WIDTH);

	//是否按在汉字上
	if (y < m_row && x < m_col && Rect(chr_pos.x + 5, chr_pos.y + 5, CHR_WITDH, CHR_WITDH).containsPoint(pos))
	{
		//得到当前触摸点的汉字元素,以及最后一次选择的汉字
		auto chr = m_ChrsBox[x][y];
		auto last_chr = m_SelectedChrs.back();

		//判断当前触摸点的汉字是否与最后一次选择的相邻
		int dx = abs(chr->getX() - last_chr->getX());
		int dy = abs(chr->getY() - last_chr->getY());
		int d = dx + dy;
		if (dx < 2 && dy < 2 && d <= 2 && d > 0)
		{
			//如果符合情况,那么将其加入临时选择汉字盒子,并设置选中颜色
			//只有当临时选择汉字集合中没有该汉字元素时,才添加
			if (!m_SelectedChrs.contains(chr))
			{
				//判断哪个箭头显示
				last_chr->showArrow(chr);

				m_SelectedChrs.pushBack(chr);
				chr->getBg()->setTexture("char_bg_selected.png");

				//执行按住后动作
				chr->chrAciton();

				//得到能否消除的状态
				m_canCrush = canCrush();
				if (m_canCrush)
				{
					for (auto &chr : m_SelectedChrs)
					{
						chr->chrAciton();
					}
				}
			}
		}

		//如果当前触摸点是已选汉字盒子中倒数第二个汉字,说明是后退操作
		//将倒数第一个元素删除出已选汉字盒子
		if (m_SelectedChrs.size() >= 2)
		{
			//得到倒数第二个元素,判断是否和触摸点的元素一致
			auto secondlast_chr = m_SelectedChrs.at(m_SelectedChrs.size()-2);
			if (secondlast_chr == chr)
			{
				//对最后一个元素执行释放后动作
				m_SelectedChrs.back()->chrAciton();

				//将最后一个元素删除出去
				m_SelectedChrs.back()->getBg()->setTexture(m_SelectedChrs.back()->getNormalBG());
				m_SelectedChrs.popBack();

				//然后将现有最后一个的汉字的箭头隐藏
				auto chr = m_SelectedChrs.back();
				auto arrow = chr->getArrow();
				for (int i = 0; i < 8; i++) { if (arrow[i]->isVisible()) arrow[i]->setVisible(false); }

				m_canCrush = canCrush();
				/*
				if (m_canCrush)
				{
				for (auto &chr : m_SelectedChrs)
				{
				chr->chrAciton();
				}
				}
				*/
			}

			//更改主界面的letter label的显示
			getGameScene()->setLetterLabel(getStringFromChrs(&m_SelectedChrs), m_canCrush);
		}
	}
}