Пример #1
0
void
MFCInstanceView::Draw(Graphics &dc, CRect &clipBox)
{
// !!!??? need to clip properly for short instances with long names
	Pen			blackPen(AlphaColor(250, rgb_black), 1);
	Pen			redPen(AlphaColor(250, rgb_red), 1);
	SolidBrush	blueBrush(AlphaColor(100, rgb_blue));
	SolidBrush	blackBrush(AlphaColor(100, rgb_black));

	CRect		clipBounds = bounds;
	if (clipBox.left > bounds.left) clipBounds.left = clipBox.left-1;
	if (clipBox.right < bounds.right) clipBounds.right = clipBox.right+1;

	cerr << "ondraw instance view " << clipBox.left << ", " << clipBox.right << endl;
	dc.FillRectangle(&blueBrush,
			bounds.left, bounds.top, bounds.right-bounds.left, bounds.bottom-bounds.top);
	dc.DrawRectangle(selected?&redPen:&blackPen,
			bounds.left, bounds.top, clipBounds.right-bounds.left, bounds.bottom-bounds.top);
	Font	labelFont(L"Arial", 8.0, FontStyleRegular, UnitPoint, NULL);
	wstring nm;
	const char *cp = instance->sym->uniqueName();
	while (*cp) { nm.push_back(*cp++); }
	float lbx = bounds.left+2;
#define LBLSEP 200
	if (clipBox.left > lbx) {
		int nld = clipBox.left - lbx;
		nld = nld/LBLSEP;
//		if (nld > 2) lbx += (nld-2)*LBLSEP;
	}
	PointF	p(lbx, clipBounds.top);
	do {
		dc.DrawString(nm.c_str(), -1, &labelFont, p, &blackBrush);
		p.X += LBLSEP;
	} while (p.X < clipBounds.right);
}
/**
 * Event: OnPaint
 *
 * Render the Notification Window
 */
LRESULT NotificationWindow::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
  PAINTSTRUCT ps;
  BeginPaint(&ps);
  {
    MyGdiplusHelper gdi_plus_autostart;
    {
      // get draw area
      RECT clientRect;
      ::GetClientRect(m_hWnd, &clientRect);
      // create Gdiplus Graphics object
      Gdiplus::Graphics graphics(m_hWnd, FALSE);
      graphics.SetClip(Gdiplus::Rect(clientRect.left, clientRect.top, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top));

      // draw a background
      Gdiplus::SolidBrush backgroundBrush(Gdiplus::Color(DEFAULT_ALPHA, 255, 255, 255));
      graphics.FillRectangle(&backgroundBrush, clientRect.left, clientRect.top, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top);

      // shrink draw area 
      int inset = 4;
      clientRect.left += inset;
      clientRect.top += inset;
      clientRect.right -= inset;
      clientRect.bottom -= inset;

      // whack a logo TODO
      //Bitmap* bitmap = new Bitmap(m_icon.c_str(), FALSE);
      int bitmapWidth = 0;//bitmap->GetWidth(); 
      int bitmapHeight = 15;//bitmap->GetHeight(); 
      //graphics->DrawImage(bitmap, clientRect.left, clientRect.top, 
      //bitmapWidth, bitmapHeight); 

      // draw a separator
      Gdiplus::Pen blackPen(Gdiplus::Color(0, 0, 0), 1.0f);
      graphics.DrawLine(&blackPen, clientRect.left, clientRect.top + bitmapHeight + inset, clientRect.right, clientRect.top + bitmapHeight + inset);

      // setup text properties
      Gdiplus::Font titleFont(L"Verdana", 10, Gdiplus::FontStyleBold);
      Gdiplus::Font textFont(L"Verdana", 10, Gdiplus::FontStyleRegular);
      Gdiplus::RectF titleRect((float)clientRect.left + inset + bitmapWidth, (float)clientRect.top, (float)clientRect.right, 20.0f);
      Gdiplus::RectF textRect((float)clientRect.left,
        (float)clientRect.top + bitmapHeight + (inset * 2),
        (float)clientRect.right,
        (float)clientRect.bottom - bitmapHeight - (inset * 2));
      Gdiplus::StringFormat format;
      format.SetTrimming(Gdiplus::StringTrimmingEllipsisCharacter);
      format.SetFormatFlags(Gdiplus::StringFormatFlagsLineLimit);
      Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0));

      // draw the message
      graphics.DrawString(m_title.c_str(), (int)m_title.length(), &titleFont, titleRect, &format, &blackBrush);
      graphics.DrawString(m_message.c_str(), (int)m_message.length(), &textFont, textRect, &format, &blackBrush);
    }
  }

  EndPaint(&ps);
  bHandled = TRUE;

  return 0;
}
Пример #3
0
GameOver::GameOver(MainWindow* parent)
{
    parent_ = parent;

    scene_ = new QGraphicsScene();
    setScene(scene_);

    QBrush silverBrush(QColor(227,228,229));
    gameOverText = new QGraphicsSimpleTextItem("GAME OVER");
    QFont myFont("Helvetica [Cronyx]",70,QFont::Bold);
    gameOverText->setFont(myFont);
    gameOverText->setBrush(silverBrush);
    scene_->addItem(gameOverText);
    gameOverText->setPos(300,170);

    QBrush blackBrush(QColor(0,0,0));
    clickText = new QGraphicsSimpleTextItem("Click File->New Game to play again!");
    QFont bFont("Helvetica [Cronyx]",30,QFont::Bold);
    clickText->setFont(bFont);
    clickText->setBrush(blackBrush);
    scene_->addItem(clickText);
    clickText->setPos(250,300);

    counter = 0;
    timer_ = new QTimer(this);
    timer_->setInterval(1000);
    connect(timer_,SIGNAL(timeout()),this,SLOT(handleTimer()));
    timer_->start();
}
Пример #4
0
void draw_ARM(HDC hdc)
{

	Graphics graphics(hdc);
	Pen pen(Color(255, 0, 0, 255));

	graphics.DrawLine(&pen, floorx1, floory1, floorx2, floory2);



	if (choose_arm == 1)
	{
		armx1 += steering*((M_PI)* cos(b0ss / 180.0 * M_PI));
		army1 += steering*((M_PI)* sin(b0ss / 180.0 * M_PI));
		graphics.DrawLine(&pen, startx, starty, armx1, army1);


		armx2 += steering*((M_PI)* cos(b0ss / 180.0 * M_PI));
		army2 += steering*((M_PI)* sin(b0ss / 180.0 * M_PI));
		graphics.DrawLine(&pen, armx1, army1, armx2, army2);
	}
	if (choose_arm == 2)
	{

		graphics.DrawLine(&pen, startx, starty, armx1, army1);

		armx2 += steering*((M_PI)* cos(8 * b0ss / 180.0 * M_PI));
		army2 += steering*((M_PI)* sin(8 * b0ss / 180.0 * M_PI));
		graphics.DrawLine(&pen, armx1, army1, armx2, army2);
	}



	if (armx2 > kulax1 && armx2 <kulax1 + R && army2>kulay1  && army2 < kulay1 + R)
	{
		kulax1 = armx2 - R / 2;
		kulay1 = army2 - R / 2;
	}
	if (armx2 > kulax2 && armx2 <kulax2 + R && army2>kulay2  && army2 < kulay2 + R)
	{
		kulax2 = armx2 - R / 2;
		kulay2 = army2 - R / 2;
	}
	if (time == 25 && kulay1 - R<400 && kulay1 - R>=kulay2-R)
		kulay1 = kulay1 + 2;

	if (time == 25 && kulay2 - R<400 )
		kulay1 = kulay1 + 2;
	SolidBrush blackBrush(Color(255, 0, 0, 0));
	graphics.FillEllipse(&blackBrush, kulax1, kulay1, R, R);
	graphics.FillEllipse(&blackBrush, kulax2, kulay2, R, R);


}
Пример #5
0
void
MFCEditorItemView::Draw(Graphics &dc, CRect &clipBox)
{
// !!!??? need to clip properly for short instances with long names
	Pen			blackPen(Color(250, 0,0,0), 1);
	Pen			redPen(Color(250, 160, 10, 10), 1);
	SolidBrush	blueBrush(Color(100, 10, 10, 160));
	SolidBrush	blackBrush(Color(100, 0,0,0));

//	fprintf(stderr, "drawing instance view %d\n", bounds.right-bounds.left);
	dc.FillRectangle(&blueBrush, bounds.left, bounds.top, bounds.right-bounds.left, bounds.bottom-bounds.top);
	dc.DrawRectangle(selected?&redPen:&blackPen, bounds.left, bounds.top, bounds.right-bounds.left, bounds.bottom-bounds.top);
}
Пример #6
0
void CStartupView::DrawTitleText(Gdiplus::Graphics &graphics)
{
   Gdiplus::Rect gdipRcLeftButtons;
   CalculateLeftButtonsRegion(gdipRcLeftButtons);

   Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0));

   Gdiplus::Font titleFont(m_csFontFamily, m_iTitleFontSize, 
      Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
   Gdiplus::Font subTitleFont(m_csFontFamily, m_iNormalFontSize, 
      Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
   CString csRecord1;
   csRecord1.LoadString(IDS_RECORD);
   INT x = gdipRcLeftButtons.X;
   INT y = gdipRcLeftButtons.Y + 2*BUTTON_TITLE_HEIGHT;
   Gdiplus::PointF textOrigin(x/*gdipRcLeftButtons.X*/, y/*(gdipRcLeftButtons.Y + gdipRcLeftButtons.Height)*/ );
   graphics.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAliasGridFit);
   graphics.DrawString(csRecord1, csRecord1.GetLength(), &titleFont, textOrigin, &blackBrush);
   
   x = gdipRcLeftButtons.X;
   y = gdipRcLeftButtons.Y + BUTTON_TITLE_HEIGHT + 2*BUTTON_SUBTITLE_HEIGHT + 2*(BUTTON_HEIGHT1 + 10) + SEPARATOR_HEIGHT + 5;
   //Gdiplus::PointF textOrigin(x/*gdipRcLeftButtons.X*/, y/*(gdipRcLeftButtons.Y + gdipRcLeftButtons.Height)*/ );
   textOrigin.X = x;
   textOrigin.Y = y;

   CString csWelcome;
   //csWelcome.LoadStringW(IDS_WELCOME);
   csWelcome.LoadStringW(ID_MENU_NEW);
   graphics.DrawString(csWelcome, csWelcome.GetLength(), &titleFont, textOrigin, &blackBrush); 

   textOrigin.Y += BUTTON_TITLE_HEIGHT;
   

   Gdiplus::Rect gdipRcRightButtons;
   CalculateRightButtonsRegion(gdipRcRightButtons);

   textOrigin.X = gdipRcRightButtons.X ;
   textOrigin.Y = gdipRcRightButtons.Y + BUTTON_TITLE_HEIGHT + BUTTON_HEIGHT;;
   CString csRecord;
   //csRecord.LoadStringW(IDS_RECORD);
   csRecord.LoadStringW(ID_MENU_OPEN);
   graphics.DrawString(csRecord, csRecord.GetLength(), &titleFont, textOrigin, &blackBrush); 

   /*textOrigin.X = gdipRcRightButtons.X ;
   textOrigin.Y += 3*BUTTON_HEIGHT;

   CString csRecent;
   csRecent.LoadStringW(IDS_RECENTLY_OPENED_PROJECTS);
   graphics.DrawString(csRecent, csRecent.GetLength(), &titleFont, textOrigin, &blackBrush); */

}
	void treeVisualiserFrame::highlightPosition(double x, double y)
	{
		if(highlightItem)
		{
			graphicsScene->removeItem(highlightItem);
			delete highlightItem;
		}
		QPen blackPen(QColor("black"));
		blackPen.setStyle(Qt::NoPen);
		QBrush blackBrush(QColor("black"));
		highlightItem = graphicsScene->addEllipse(x - pointSize/2, y - pointSize/2, pointSize, pointSize, blackPen, blackBrush);
		highlightItem->setFlag(QGraphicsItem::ItemIsSelectable, false);
		highlightItem->setZValue(1);
	}
void subObservationVisualiserBase::constructStandardPoints(const observation& subObs)
{
    assert(standardPointsItem);
    std::size_t nVertices = boost::num_vertices(contextObj.getGraph());
    const std::vector<context::vertexPosition>& vertexPositions = contextObj.getVertexPositions();
    const vertexState* state = subObs.getState();

    QPen blackPen(QColor("black"));
    QBrush blackBrush(QColor("black"));

    QPen redPen(QColor("red"));
    QBrush redBrush(QColor("red"));

    QBrush noBrush;
    noBrush.setStyle(Qt::NoBrush);

    for(std::size_t vertexCounter = 0; vertexCounter < nVertices; vertexCounter++)
    {
        context::vertexPosition currentPosition = vertexPositions[vertexCounter];
        float x = currentPosition.first;
        float y = currentPosition.second;
        QGraphicsEllipseItem* newItem = new QGraphicsEllipseItem(x - pointSize/2, y - pointSize/2, pointSize, pointSize, standardPointsItem);
        if(state[vertexCounter].state == FIXED_OFF)
        {
            newItem->setBrush(noBrush);
            newItem->setPen(blackPen);
        }
        else if(state[vertexCounter].state == FIXED_ON)
        {
            newItem->setBrush(blackBrush);
            newItem->setPen(blackPen);
        }
        else if(state[vertexCounter].state == UNFIXED_OFF)
        {
            newItem->setBrush(noBrush);
            newItem->setPen(redPen);
        }
        else if(state[vertexCounter].state == UNFIXED_ON)
        {
            newItem->setBrush(redBrush);
            newItem->setPen(redPen);
        }
        else
        {
            throw std::runtime_error("Internal error");
        }
    }
}
Пример #9
0
void Canvas::initialize() {

    painter->resize(width(), height());
    painter->move(-width()/2, 0);
    painter->setXOffset(width()/2);
    addWidget(painter);

    QBrush blackBrush(Qt::black);
    QPen blackPen(Qt::black);
    blackPen.setWidth(1);

    Axis* axis;
    vector<double> heights;
    for(int i=0; i< NUM_LINKS+1; i++) {

        if (i==0) {
            axis = new Axis(0, 0);
            heights.push_back(0);
        } else if(i==1) {
            axis = new Axis(0, 150);
            heights.push_back(150);
        } else if (i==2) {
            axis = new Axis(0, 250);
            heights.push_back(250);
        } else if (i==3) {
            axis = new Axis(0, 325);
            heights.push_back(325);
        }
        axes.push_back(axis);
    }

    setUpAxes();


    for(int i=0; i< NUM_LINKS; i++) {
        Link* link = new Link();
        link->length = heights[i+1] - heights[i];

        link->ellipse = this->addEllipse(-WIDTH/2,heights[i],WIDTH,link->length,blackPen,blackBrush);
        link->ellipse->setTransformOriginPoint(0,heights[i]);

        link->frontAxis = axes[i+1];
        link->backAxis = axes[i];
        link->orientation = 0;

        links.push_back(link);
    }
}
Пример #10
0
void Location::CutsceneView::CameraManipulatable::DrawCore(QGraphicsScene * pScene, QList<QGraphicsItem *> & addedItems)
{
    QBrush blackBrush(qRgba(0, 0, 0, 255));
    QPen blackPen(blackBrush, 4);
    QPen whitePen(QBrush(qRgba(255, 255, 255, 255)), 2);

    pOutsideCameraPathItem = new QGraphicsPathItem();
    pOutsideCameraPathItem->setBrush(blackBrush);

    QGraphicsOpacityEffect *pOutsideCameraOpacityEffect = new QGraphicsOpacityEffect();
    pOutsideCameraOpacityEffect->setOpacity(0.5);

    pOutsideCameraPathItem->setGraphicsEffect(pOutsideCameraOpacityEffect);

    pScene->addItem(pOutsideCameraPathItem);
    addedItems.append(pOutsideCameraPathItem);

    pCameraCenterHorizontalOuterLineItem = new QGraphicsLineItem();
    pCameraCenterVerticalOuterLineItem = new QGraphicsLineItem();
    pCameraCenterHorizontalInnerLineItem = new QGraphicsLineItem();
    pCameraCenterVerticalInnerLineItem = new QGraphicsLineItem();

    pCameraCenterHorizontalOuterLineItem->setPen(blackPen);
    pCameraCenterVerticalOuterLineItem->setPen(blackPen);
    pCameraCenterHorizontalInnerLineItem->setPen(whitePen);
    pCameraCenterVerticalInnerLineItem->setPen(whitePen);

    pCameraCenterGraphicsItemGroup = new QGraphicsItemGroup();
    pCameraCenterGraphicsItemGroup->addToGroup(pCameraCenterHorizontalOuterLineItem);
    pCameraCenterGraphicsItemGroup->addToGroup(pCameraCenterVerticalOuterLineItem);
    pCameraCenterGraphicsItemGroup->addToGroup(pCameraCenterHorizontalInnerLineItem);
    pCameraCenterGraphicsItemGroup->addToGroup(pCameraCenterVerticalInnerLineItem);

    pCameraCenterOpacityEffect = new QGraphicsOpacityEffect();
    pCameraCenterOpacityEffect->setOpacity(1.0);

    pCameraCenterGraphicsItemGroup->setGraphicsEffect(pCameraCenterOpacityEffect);

    pScene->addItem(pCameraCenterGraphicsItemGroup);
    addedItems.append(pCameraCenterGraphicsItemGroup);
}
Пример #11
0
void MyOnPaint(HDC hdc)
{
	Graphics graphics(hdc);
	Pen pen(Color(255, 0, 0, 255));


	graphics.DrawLine(&pen, startx, starty, armx1, army1);
	graphics.DrawLine(&pen, armx1, army1, armx2, army2);


	graphics.DrawLine(&pen, floorx1, floory1, floorx2, floory2);


	SolidBrush blackBrush(Color(255, 0, 0, 0));
	graphics.FillEllipse(&blackBrush, kulax1, kulay1, R, R);

	if (time > 0)
	{
		kulay1 = kulay1 + 2;
	}
}
void CHSBControlText::Paint(Gdiplus::Graphics *pGraphics)
{
	PointF origin(m_Left, m_Top);
	SolidBrush blackBrush(Color(255, 0, 0, 0));
	pGraphics->DrawString(m_pText, -1, g_pFont, origin, &blackBrush);
}
Пример #13
0
void CTextToolView::DoFontSavefontfiles(CString szPathName)
{
  CString	szPNGName = szPathName + ".png";
  CString	szMetricFileName = szPathName + ".fmt";

  CDC	*pDC = GetDC();
  CDC	*pDrawDC = pDC;//new CDC;

  Invalidate(true);
  // pDrawDC->CreateCompatibleDC(pDC);

  if (!pDrawDC)
    return;

  int iImageY = m_iMaxY;

  int iPictureY = iImageY;

  int y2 = 4;

  // find next greater power of two
  while (iPictureY > y2) {
    y2 <<= 1;
  }
  iPictureY = y2;

  // fill the DC with black
  CRect	rect;
  CBrush	blackBrush(RGB(0,0,0));

  COLORREF      rPixel = RGB(0,0,0);

  rect.SetRect(0,0,m_iMaxTextureWidth,iImageY);

  pDrawDC->FillRect(&rect,&blackBrush);
  OnDraw(pDrawDC);

  std::ofstream* f = new std::ofstream(szPNGName, std::ios::out | std::ios::binary);

  int temp = 0; //temporary values for binary file writing
  char tempByte = 0;
  int crc = 0;  //used for running CRC values

  int w = 512, h = iPictureY;
  unsigned long blength = (w + 1) * h * 4;
  char* b = new char[blength];

  // Write PNG headers
  (*f) << "\211PNG\r\n\032\n";
#define	  PNGTAG(t_) ((((int)t_[0]) << 24) | \
		      (((int)t_[1]) << 16) | \
		      (((int)t_[2]) <<  8) | \
			(int)t_[3])

  // IHDR chunk
  temp = htonl((int) 13);       //(length) IHDR is always 13 bytes long
  f->write((char*) &temp, 4);
  temp = htonl(PNGTAG("IHDR")); //(tag) IHDR
  f->write((char*) &temp, 4);
  crc = crc32(crc, (unsigned char*) &temp, 4);
  temp = htonl(w);	      //(data) Image width
  f->write((char*) &temp, 4);
  crc = crc32(crc, (unsigned char*) &temp, 4);
  temp = htonl(h);		//(data) Image height
  f->write((char*) &temp, 4);
  crc = crc32(crc, (unsigned char*) &temp, 4);
  tempByte = 8;		 //(data) Image bitdepth (8 bits/sample = 24 bits/pixel)
  f->write(&tempByte, 1);
  crc = crc32(crc, (unsigned char*) &tempByte, 1);
  tempByte = 6;		 //(data) Color type: RGBA = 6
  f->write(&tempByte, 1);
  crc = crc32(crc, (unsigned char*) &tempByte, 1);
  tempByte = 0;
  int i;
  for (i = 0; i < 3; i++) { //(data) Last three tags are compression (only 0 allowed), filtering (only 0 allowed), and interlacing (we don't use it, so it's 0)
    f->write(&tempByte, 1);
    crc = crc32(crc, (unsigned char*) &tempByte, 1);
  }
  crc = htonl(crc);
  f->write((char*) &crc, 4);    //(crc) write crc

  // IDAT chunk

  // fill buffer with black
  for (i = 0; i < (long)blength; i++)
    b[i] = 0;
  // write image data over buffer
  for (int y = 0; y <= m_iMaxY - 1; y++) {
    const unsigned long line = y * (w * 4 + 1); //beginning of this line
    b[line] = 0;  //filter type byte at the beginning of each scanline (0 = no filter, 1 = sub filter)
    for (int x = 0; x < m_iMaxTextureWidth; x++) {
      // Grab a reference to the current pixel
      rPixel = pDrawDC->GetPixel(x, y);
      // Pixel color values
      b[line + x * 4 + 1] = GetRValue(rPixel);
      b[line + x * 4 + 2] = GetGValue(rPixel);
      b[line + x * 4 + 3] = GetBValue(rPixel);
      // Write Alpha channel as average of RGB, since it's grayscale anyhow
      b[line + x * 4 + 4] =(GetBValue(rPixel) + GetGValue(rPixel) + GetRValue(rPixel)) / 3;
    }
  }

  unsigned long zlength = blength + 15;	    //length of bz[], will be changed by zlib to the length of the compressed string contained therein
  unsigned char* bz = new unsigned char[zlength]; //just like b, but compressed; might get bigger, so give it room
  // compress b into bz
  compress2(bz, &zlength, reinterpret_cast<const unsigned char*>(b), blength, 5);
  temp = htonl(zlength);			  //(length) IDAT length after compression
  f->write((char*) &temp, 4);
  temp = htonl(PNGTAG("IDAT"));		   //(tag) IDAT
  f->write((char*) &temp, 4);
  crc = crc32(crc = 0, (unsigned char*) &temp, 4);
  f->write(reinterpret_cast<char*>(bz), zlength);  //(data) This line of pixels, compressed
  crc = htonl(crc32(crc, bz, zlength));
  f->write((char*) &crc, 4);		       //(crc) write crc

  // tEXt chunk containing bzflag build/version
  temp = htonl(28);//(length) tEXt is "Software\0BZFlag TextTool-W32"
  f->write((char*) &temp, 4);
  temp = htonl(PNGTAG("tEXt"));		   //(tag) tEXt
  f->write((char*) &temp, 4);
  crc = crc32(crc = 0, (unsigned char*) &temp, 4);
  strcpy(b, "Software"); //(data) Keyword
  f->write(reinterpret_cast<char*>(b), strlen(reinterpret_cast<const char*>(b)));
  crc = crc32(crc, reinterpret_cast<const unsigned char*>(b), strlen(b));
  tempByte = 0;					  //(data) Null character separator
  f->write(&tempByte, 1);
  crc = crc32(crc, (unsigned char*) &tempByte, 1);
  strcpy((char*) b, "BZFlag TextTool-W32");       //(data) Text contents (build/version)
  f->write(reinterpret_cast<char*>(b), strlen(reinterpret_cast<const char*>(b)));
  crc = htonl(crc32(crc, reinterpret_cast<const unsigned char*>(b), strlen(b)));
  f->write((char*) &crc, 4);		       //(crc) write crc

  // IEND chunk
  temp = htonl((int) 0);	//(length) IEND is always 0 bytes long
  f->write((char*) &temp, 4);
  temp = htonl(PNGTAG("IEND")); //(tag) IEND
  f->write((char*) &temp, 4);
  crc = htonl(crc32(crc = 0, (unsigned char*) &temp, 4));
  //(data) IEND has no data field
  f->write((char*) &crc, 4);     //(crc) write crc
  delete [] bz;
  delete [] b;
  delete f;

  // pDrawDC->DeleteDC();
  // delete(pDrawDC);
  ReleaseDC(pDC);

  FILE *fp = fopen(szMetricFileName,"wt");
  if (!fp)
    return;

  struct {
    int iInitalDist;
    int iCharWidth;
    int iWhiteSpaceDist;
    int iStartX;
    int iEndX;
    int iStartY;
    int iEndY;
  } rFontMetrics;

  int iNumChars = '~' - ' ';

  fprintf(fp,"NumChars: %d\nTextureWidth: %d\nTextureHeight: %d\nTextZStep: %d\n\n",iNumChars+1,m_iMaxTextureWidth,iPictureY,m_iTextureZStep);

  for (int iChar = 0; iChar <= iNumChars; iChar++) {
    rFontMetrics.iInitalDist = m_aWidths[iChar].abcA;
    rFontMetrics.iCharWidth = m_aWidths[iChar].abcB;
    rFontMetrics.iWhiteSpaceDist = m_aWidths[iChar].abcC;

    rFontMetrics.iStartX = m_arGlyphExtents[iChar].iStartX;
    rFontMetrics.iEndX = m_arGlyphExtents[iChar].iEndX;
    rFontMetrics.iStartY = m_arGlyphExtents[iChar].iStartY;
    rFontMetrics.iEndY = m_arGlyphExtents[iChar].iEndY;

    fprintf(fp,"Char: \"%c\"\nInitialDist: %d\nWidth: %d\nWhitespace: %d\n",iChar+32,rFontMetrics.iInitalDist,rFontMetrics.iCharWidth,rFontMetrics.iWhiteSpaceDist);
    fprintf(fp,"StartX: %d\nEndX: %d\nStartY: %d\nEndY: %d\n\n",rFontMetrics.iStartX,rFontMetrics.iEndX,rFontMetrics.iStartY,rFontMetrics.iEndY);
  }
  fclose(fp);

  Invalidate(true);
}
Пример #14
0
void ImageEditor::paintEvent(QPaintEvent *event)
{
	if (!_image_loaded)
		return;
	
 	QPainter painter(this);
 	QPixmap pixmaptoshow;
	if(!_flag_mask)
 		pixmaptoshow=QPixmap::fromImage(_image_layer.scaled(this->size(),Qt::KeepAspectRatio));
	else
		pixmaptoshow=QPixmap::fromImage(_image_mask.scaled(this->size(),Qt::KeepAspectRatio));
	
 	painter.drawPixmap(0,0, pixmaptoshow);
 	_real_size=pixmaptoshow.size();
 
	
 	//draw point
	if(_scissor)
	{
		QBrush blackBrush(qRgba(0, 0, 0, 255));
		painter.setBrush(blackBrush);
		for (int i=0;i<_contourList.size();i++)
			for(int j=0;j<_contourList[i].size();j+=3)
		{
			QPoint ConP;						
			ConP=QPoint(_contourList[i][j].x()*_real_size.width(),_contourList[i][j].y()*_real_size.height());
			painter.drawEllipse(ConP,1,1);
		}
		for(int i=0;i<_segList.size();i+=3)
		{
			QPoint ConP;						
			ConP=QPoint(_segList[i].x()*_real_size.width(),_segList[i].y()*_real_size.height());
			painter.drawEllipse(ConP,1,1);
		}

		QBrush redBrush(qRgba(255, 0, 0, 255));
		painter.setBrush(redBrush);

		for(int i=0;i<_fixedSeedList.size();i++)
		{
			
			QPoint ConP;						
			ConP=QPoint(_fixedSeedList[i].x()*_real_size.width(),_fixedSeedList[i].y()*_real_size.height());
		
			painter.drawEllipse(ConP,3,3);
		}

	}
	else
	{
		if(parameters)
		{
			for(int i=0;i<parameters->ui_points.size();i++)
			{
				if(i==parameters->ActIndex)
				{
					QBrush redBrush(qRgba(255, 0, 0, 255));
					painter.setBrush(redBrush);
				}
				else
				{
					QBrush yellowBrush(qRgba(255, 255, 0, 255));
					painter.setBrush(yellowBrush);
				}

				QPoint ConP;
				switch(_name)
				{
				case 'L':
				case 'l':				
					ConP=QPoint(parameters->ui_points[i].lp.x*_real_size.width(),parameters->ui_points[i].lp.y*_real_size.height());
					break;

				case 'R':
				case 'r':
					ConP=QPoint(parameters->ui_points[i].rp.x*_real_size.width(),parameters->ui_points[i].rp.y*_real_size.height());

				}
				painter.drawEllipse(ConP,3,3);
			}

		}
	}	
	
}
Пример #15
0
// Maybe i just need the final 3 points
// TODO get the points correctly
//void Canvas::update(vector<QPoint>* points) {
void Canvas::updateLinks(Link* _link, double _angle) {

    // There is four positions to keep track of:
    // targetBackJointPos
    // targetFrontJointPos
    // currentBackJointPos
    // currentFrontJointPos
    // BackJoint = i
    // FrontJoint = i+1
    // i = link number

    rotate_axis(_link->backAxis, _link->frontAxis, _angle, _link);

    QPointF targetBackJointPos;
    QPointF targetFrontJointPos;
    vector<QPointF> targetPoints;

    for(int i=0;i<axes.size() - 1;i++)
    {
        Axis* axis = axes[i];
        QPointF point (axis->loc_x, axis->loc_y);
        qDebug() << "Next X: " << axis->loc_x << "Next Y: " << axis->loc_y;
        targetPoints.push_back(point);
    }



    QBrush blackBrush(Qt::black);
    QPen blackPen(Qt::black);
    blackPen.setWidth(1);

    for(int i=0; i< NUM_LINKS; i++) {

        Link* link = links[i];
        Axis* front = link->frontAxis;
        Axis* back  = link->backAxis;
        double angleX = front->loc_x - back->loc_x;
        double angleY = front->loc_y - back->loc_y;
        double angle = atan2(angleY,angleX) * RAD_TO_DEG - 90; // to degrees
        qDebug() << "Front:  "<< front->loc_x << "," << front->loc_y;
        qDebug() << "Back:   "<< back->loc_x << "," << back->loc_y;


        qDebug() << "AngleX: "<< angle;

        delete link->ellipse;
        link->ellipse = this->addEllipse(-1*WIDTH/2,0, WIDTH,link->length,blackPen,blackBrush);
        link->ellipse->setRotation(angle);
        link->ellipse->setX(targetPoints[i].x());
        link->ellipse->setY(targetPoints[i].y());
        //link->ellipse->setTransformOriginPoint(targetPoints[i].x(), targetPoints[i].y());

       // link->ellipse->setPos(targetFrontJointPos.x(),targetFrontJointPos.y());
    }




    /****
     *Almost working
     *
     *
     * QBrush blackBrush(Qt::black);
    QPen blackPen(Qt::black);
    blackPen.setWidth(1);

    for(int i=0; i< NUM_LINKS; i++) {

        Link* link = links[i];

        double angleX = link->frontAxis->loc_x - link->backAxis->loc_x;
        double angleY = link->frontAxis->loc_y - link->backAxis->loc_y;
        double angle = atan2(angleY,angleX) * RAD_TO_DEG - 90; // to degrees


        delete link->ellipse;
        link->ellipse = this->addEllipse(-1*WIDTH/2,0, WIDTH,link->length,blackPen,blackBrush);
        link->ellipse->setRotation(angle);
        link->ellipse->setX(targetPoints[i].x());
        link->ellipse->setY(targetPoints[i].y());
        //link->ellipse->setTransformOriginPoint(targetPoints[i].x(), targetPoints[i].y());

       // link->ellipse->setPos(targetFrontJointPos.x(),targetFrontJointPos.y());
    }*/





    /*

    Link* link;
    for(size_t i=0; i<links.size(); i++) {
        targetFrontJointPos = targetPoints[i+1];
        link = links[i];

        currentBackJointPos = link->ellipse->mapToScene(link->ellipse->pos());
        double angleX = targetFrontJointPos.x() - targetBackJointPos.x();
        double angleY = targetFrontJointPos.y() - targetBackJointPos.y();
        double angle = atan2(angleY,angleX) * RAD_TO_DEG - 90; // to degrees

        currentFrontJointPos = QPointF(link->length * sin(link->ellipse->rotation() * DEG_TO_RAD) + currentFrontJointPos.x(),
                                       link->length * cos(link->ellipse->rotation() * DEG_TO_RAD) + currentFrontJointPos.y());
        // Absolute in scene

        qDebug() << "CurrentFront: " << currentFrontJointPos << "CurrentBack: " <<  currentBackJointPos << "angle: " << angle;
        qDebug() << "TargetFront: " << targetFrontJointPos << "TargetBack: " <<  targetBackJointPos << '\n';

        // This works because of reasons
        //link->ellipse->setPos(shiftPoint);
        link->ellipse->moveBy(shiftPoint.x(), shiftPoint.y());
        link->ellipse->setRotation( angle);


        double shitfX = targetFrontJointPos.x() + -1*currentFrontJointPos.x()  ;
        double shitfY = targetFrontJointPos.y() + -1*currentFrontJointPos.y()  ;

        shiftPoint = QPointF(shitfX, shitfY);
        qDebug() << "Shift: " << shiftPoint << " FROM: " << link->ellipse->mapToScene(shiftPoint) << "\n\n";

        targetBackJointPos = targetFrontJointPos;
    }

*/

}
Пример #16
0
// EFW - Various changes to make it draw cells better when using alternate
// color schemes.  Also removed printing references as that's now done
// by PrintCell() and fixed the sort marker so that it doesn't draw out
// of bounds.
BOOL CGridCellBase::Draw(CDC* pDC, int nRow, int nCol, CRect rect,  BOOL bEraseBkgnd /*=TRUE*/)
{
    // Note - all through this function we totally brutalise 'rect'. Do not
    // depend on it's value being that which was passed in.

    CGridCtrl* pGrid = GetGrid();
    ASSERT(pGrid);

    if (!pGrid || !pDC)
        return FALSE;

    if( rect.Width() <= 0 || rect.Height() <= 0)  // prevents imagelist item from drawing even
        return FALSE;                             //  though cell is hidden

    //TRACE3("Drawing %scell %d, %d\n", IsFixed()? _T("Fixed ") : _T(""), nRow, nCol);

    int nSavedDC = pDC->SaveDC();
    pDC->SetBkMode(TRANSPARENT);

    // Get the default cell implementation for this kind of cell. We use it if this cell
    // has anything marked as "default"
    CGridDefaultCell *pDefaultCell = (CGridDefaultCell*) GetDefaultCell();
    if (!pDefaultCell)
        return FALSE;

    // Set up text and background colours
    COLORREF TextClr, TextBkClr;

    TextClr = (GetTextClr() == CLR_DEFAULT)? pDefaultCell->GetTextClr() : GetTextClr();
    if (GetBackClr() == CLR_DEFAULT)
        TextBkClr = pDefaultCell->GetBackClr();
    else
    {
        bEraseBkgnd = TRUE;
        TextBkClr = GetBackClr();
    }

	if (pGrid->m_BackColorSettingEnble == TRUE)
	{
		 // Draw cell background and highlighting (if necessary)
		if ( IsFocused() || IsDropHighlighted() )
		{
			// Always draw even in list mode so that we can tell where the
			// cursor is at.  Use the highlight colors though.
			if(GetState() & GVIS_SELECTED)
			{
				TextBkClr = RGB(min(GetRValue(TextBkClr)+100,255), min(GetGValue(TextBkClr)+100,255) , min(GetBValue(TextBkClr)+100,255));		//	::GetSysColor(COLOR_HIGHLIGHT);
				TextClr = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
				
				bEraseBkgnd = TRUE;
			}

			rect.right++; rect.bottom++;    // FillRect doesn't draw RHS or bottom
			if (bEraseBkgnd)
			{
				TRY 
				{
					CBrush brush(TextBkClr);
					pDC->FillRect(rect, &brush);

					if(GetState() & GVIS_SELECTED)
					{
						CBrush blackBrush(RGB(0,0,0));
						pDC->FrameRect(rect, &blackBrush);
					}
				} 
				CATCH(CResourceException, e)
				{
					//e->ReportError();
				}
				END_CATCH
			}

			// Don't adjust frame rect if no grid lines so that the
			// whole cell is enclosed.
			if(pGrid->GetGridLines() != GVL_NONE)
			{
				rect.right--;
				rect.bottom--;
			}

			if (pGrid->GetFrameFocusCell())
			{
				//// Use same color as text to outline the cell so that it shows
				//// up if the background is black.
				//TRY 
				//{
				//	CBrush brush(TextClr);
				//	pDC->FrameRect(rect, &brush);
				//}
				//CATCH(CResourceException, e)
				//{
				//	//e->ReportError();
				//}
				//END_CATCH
			}
			pDC->SetTextColor(TextClr);

			// Adjust rect after frame draw if no grid lines
			if(pGrid->GetGridLines() == GVL_NONE)
			{
				rect.right--;
				rect.bottom--;
			}

			//rect.DeflateRect(0,1,1,1);  - Removed by Yogurt
		}
		else if ((GetState() & GVIS_SELECTED))
		{
			COLORREF textBkColor = RGB(min(GetRValue(TextBkClr)+100,255), min(GetGValue(TextBkClr)+100,255) , min(GetBValue(TextBkClr)+100,255));
			rect.right++; rect.bottom++;    // FillRect doesn't draw RHS or bottom
			pDC->FillSolidRect(rect, textBkColor );			//	::GetSysColor(COLOR_HIGHLIGHT));

			CBrush blackBrush(RGB(0,0,0));
			pDC->FrameRect(rect, &blackBrush);

			rect.right--; rect.bottom--;
			pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
		}
		else
		{
			if (bEraseBkgnd)
			{
				rect.right++; rect.bottom++;    // FillRect doesn't draw RHS or bottom
				CBrush brush(TextBkClr);
				pDC->FillRect(rect, &brush);
				rect.right--; rect.bottom--;
			}
			pDC->SetTextColor(TextClr);
		}
	}
Пример #17
0
static void __fastcall SaveBitmap2Tiff(Gdiplus::Bitmap *bm, int npage) {
//-------------------------------------------------------------------------------
//                  Выводит очередную страницу в файл *.tif                     |
// Если npage == 0, то не выводит номер страницы                                |
// Полагает, что если это многостраничный файл, то страница уже выбрана         |
//-------------------------------------------------------------------------------
    if (SaveBitmap2TiffState == 0) return;


    // ------------------ для начала строим образ в SaveBitmap2TiffBitmap32 (SaveBitmap2TiffGraphics)
    int x, y, w, h;

    h = bm->GetHeight();
    w = bm->GetWidth();

    Gdiplus::SolidBrush whiteBrush(Gdiplus::Color(255, 255, 255, 255));
    SaveBitmap2TiffGraphics->FillRectangle(&whiteBrush, Gdiplus::Rect(0, 0, SaveBitmapW, SaveBitmapH));

    //Gdiplus::Matrix matr;
    Gdiplus::Rect r;
    //if (w > h) {                            // Если изображение шире, чем выше
    //    matr.Rotate(270.0f);                // поворачиваем его на 270 градусов
    //    SaveBitmap2TiffGraphics->SetTransform(&matr);
    //    r.X = -SaveBitmapH;
    //    r.Y = -30;
    //    r.Width = SaveBitmapH - 30;
    //    r.Height = SaveBitmapW - 30;
    //} else {
    //    r.X = 30;
    //    r.Y = 0;
    //    r.Width = SaveBitmapW - 30;
    //    r.Height = SaveBitmapH - 30;
    //}
    r.X = 0;
    r.Y = 0;
    r.Width = SaveBitmapW;
    r.Height = SaveBitmapH;

    SaveBitmap2TiffGraphics->DrawImage(bm, r, 0, 0, w, h, Gdiplus::UnitPixel, 0, 0, 0);

    // matr.Reset();
    // SaveBitmap2TiffGraphics->SetTransform(&matr);

    if (npage != 0) {            // Здесь выводим номер страницы
        AnsiString snum;
        wchar_t wnum[20];
        Gdiplus::Pen whitePen40(Gdiplus::Color(255, 255, 255, 255), 45);
        snum.printf("%d", npage);
        snum.WideChar(wnum, 20);
        Gdiplus::Font myFont(L"Arial", 40, Gdiplus::FontStyleBold);
        Gdiplus::PointF origin(SaveBitmapW - 160, 20.0f);
        Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0));
        SaveBitmap2TiffGraphics->DrawLine(&whitePen40, SaveBitmapW - 200, 50, SaveBitmapW, 50);
        if (npage > 0) {
            SaveBitmap2TiffGraphics->DrawString(wnum, -1, &myFont, origin, &blackBrush);
        }
    }


    // ------- строим SaveBitmap2TiffBitmap1
    UINT *pix;
    unsigned char byte, bit, *pix1;

    w = SaveBitmapW; h = SaveBitmapH;
    Gdiplus::Rect BitsRect(0, 0, SaveBitmapW, SaveBitmapH);
    Gdiplus::BitmapData *bits = new Gdiplus::BitmapData;
    Gdiplus::BitmapData *bits1 = new Gdiplus::BitmapData;
    sres = SaveBitmap2TiffBitmap32->LockBits(&BitsRect, Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, bits);
    sres = SaveBitmap2TiffBitmap1->LockBits(&BitsRect, Gdiplus::ImageLockModeWrite, PixelFormat1bppIndexed, bits1);

    for (y = 0; y < SaveBitmapH; y++) {
        pix = (UINT *)((int)bits->Scan0 + bits->Stride * y);
        pix1 = (unsigned char *)((int)bits1->Scan0 + bits1->Stride * y);
        byte = 0;
        for (x = 0; x < SaveBitmapW; x++, pix++) {
            if ((*pix & 0xFF) > 0xD8) {
                bit = 1;
            }
            else bit = 0;
            byte <<= 1; byte |= bit;
            if ((x & 7) == 7) {
                *pix1++ = byte;
                byte = 0;
            }
        }
    }

    SaveBitmap2TiffBitmap32->UnlockBits(bits); delete bits;
    SaveBitmap2TiffBitmap1->UnlockBits(bits1); delete bits1;


    // ------- и наконец выводим очередную страницу SaveBitmap2TiffBitmap1
    Gdiplus::EncoderParameters encoderParameters;
    ULONG parameterValue;

    // An EncoderParameters object has an array of
    // EncoderParameter objects. In this case, there is only
    // one EncoderParameter object in the array.
    encoderParameters.Count = 1;
    // Initialize the one EncoderParameter object.
    // encoderParameters.Parameter[0].Guid = Gdiplus::EncoderSaveFlag;
    encoderParameters.Parameter[0].Guid = aEncoderSaveFlag;
    encoderParameters.Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong;
    encoderParameters.Parameter[0].NumberOfValues = 1;
    encoderParameters.Parameter[0].Value = &parameterValue;

    // Get the CLSID of the TIFF encoder.
    CLSID encoderClsid;
    GetEncoderClsid(L"image/tiff", &encoderClsid);

    if (SaveBitmap2TiffState == 1) {                    // Требуется вывести первую страницу
        parameterValue = Gdiplus::EncoderValueMultiFrame;
        sres = SaveBitmap2TiffBitmap1->Save(SaveBitmap2TiffFiln, &encoderClsid, &encoderParameters);
    } else {
        parameterValue = Gdiplus::EncoderValueFrameDimensionPage;
        sres = SaveBitmap2TiffBitmap1->SaveAdd(&encoderParameters);
    }

    SaveBitmap2TiffState = 2;
}
Пример #18
0
void __fastcall TTiffImage::DrawCenter(TCanvas *c, int xc, int yc, int w1, int h1, int PageNumber) {
//-------------------------------------------------------------------------------
//                  Рисует текущую страницу с центром (xc, yc)                  |
// Масштабирует пропроционально, в итоге будет заполнено либо w, либо h         |
//-------------------------------------------------------------------------------
    if (fbm == NULL) return;

    Gdiplus::Graphics *gra, *g32;
    Gdiplus::Bitmap *b32;
    Gdiplus::Rect r;
    int w = fbm->GetWidth(), h = fbm->GetHeight();

    b32 = new Gdiplus::Bitmap(w, h, PixelFormat32bppARGB);
    g32 = new Gdiplus::Graphics(b32);

    r.X = 0;
    r.Y = 0;
    r.Width = w;
    r.Height = h;

    sres = g32->DrawImage(fbm, r, 0, 0, w, h, Gdiplus::UnitPixel, 0, 0, 0);

    if (PageNumber != 0) {                      // Надо выводить номер страницы?
        AnsiString snum;
        wchar_t wnum[20];
        Gdiplus::Pen whitePen40(Gdiplus::Color(255, 255, 255, 255), 45);
        snum.printf("%d", PageNumber);
        snum.WideChar(wnum, 20);
        Gdiplus::Font myFont(L"Arial", 40, Gdiplus::FontStyleBold);
        Gdiplus::PointF origin(w - 160, 20.0f);
        Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0));
        g32->DrawLine(&whitePen40, w - 200, 50, w, 50);
        if (PageNumber > 0) {
            sres = g32->DrawString(wnum, -1, &myFont, origin, &blackBrush);
        }
    }


    w = w1; h = h1;
    gra = new Gdiplus::Graphics(c->Handle);

    //if (CanvasHandle != c->Handle) {
    //    if (CanvasHandle != NULL) delete gra;
    //    CanvasHandle = c->Handle;
    //    gra = new Gdiplus::Graphics(CanvasHandle);
    //}


    double scalex = (double)w / GetWidth();
    double scaley = (double)h / GetHeight();
    double scale = scalex < scaley ? scalex : scaley;
    w = round(GetWidth() * scale);
    h = round(GetHeight() * scale);
    xc -= w / 2;
    yc -= h / 2;

    Gdiplus::Rect dst(xc, yc, w, h);

    // gra->DrawImage(fbm, dst, 0, 0, GetWidth(), GetHeight(), Gdiplus::UnitPixel, 0, 0, 0);
    gra->DrawImage(b32, dst, 0, 0, GetWidth(), GetHeight(), Gdiplus::UnitPixel, 0, 0, 0);

    delete gra;
    delete g32;
    delete b32;

}
Пример #19
0
void CSkinDialog::DrawFrame(Graphics & graphics)
{
    CRect rcWindow;
    GetWindowRect(&rcWindow);

    Rect rc, rc1;

    // Title Left
    rc = m_bActive?m_mapRect["TitleLeftActive"]:m_mapRect["TitleLeft"];
    rc1.X = 0;
    rc1.Y = 0;
    rc1.Width = rc.Width;
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Title Center
    rc = m_bActive?m_mapRect["TitleCenterActive"]:m_mapRect["TitleCenter"];
    rc1.X = m_mapRect["TitleLeftActive"].Width;
    rc1.Y = 0;
    rc1.Width = rcWindow.Width()-m_mapRect["TitleLeftActive"].Width-m_mapRect["TitleRightActive"].Width;
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Title Right
    rc = m_bActive?m_mapRect["TitleRightActive"]:m_mapRect["TitleRight"];
    rc1.X = rc1.GetRight();
    rc1.Y = 0;
    rc1.Width = rc.Width;
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Border Left
    rc = m_bActive?m_mapRect["BorderLeftActive"]:m_mapRect["BorderLeft"];
    rc1.X = 0;
    rc1.Y = m_mapRect["TitleLeft"].Height;
    rc1.Width = rc.Width;
    rc1.Height = rcWindow.Height()-m_mapRect["TitleLeftActive"].Height-m_mapRect["BorderBotActive"].Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Border Bottom
    rc = m_bActive?m_mapRect["BorderBotActive"]:m_mapRect["BorderBot"];
    rc1.X = 0;
    rc1.Y = rcWindow.Height()-rc.Height-1;
    rc1.Width = rcWindow.Width();
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Border Right
    rc = m_bActive?m_mapRect["BorderRightActive"]:m_mapRect["BorderRight"];
    rc1.X = rcWindow.Width()-rc.Width-1;
    rc1.Y = m_mapRect["TitleLeftActive"].Height;
    rc1.Width = rc.Width;
    rc1.Height = rcWindow.Height()-m_mapRect["TitleLeftActive"].Height-m_mapRect["BorderBotActive"].Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Close Button
    rc = m_nButtonDown==HT_CLOSE?m_mapRect["NcBtnCloseDown"]:m_mapRect["NcBtnClose"];
    rc1.X = rcWindow.Width()-m_mapRect["NcBtnClosePos"].X;
    rc1.Y = m_mapRect["NcBtnClosePos"].Y;
    rc1.Width = rc.Width;
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Max Button
    if(GetStyle()&WS_MAXIMIZEBOX)
    {
        rc = IsZoomed()?(m_nButtonDown==HT_MAX?m_mapRect["NcBtnResDown"]:m_mapRect["NcBtnRes"]):(m_nButtonDown==HT_MAX?m_mapRect["NcBtnMaxDown"]:m_mapRect["NcBtnMax"]);
        rc1.X = rcWindow.Width()-m_mapRect["NcBtnMaxPos"].X;
        rc1.Y = m_mapRect["NcBtnMaxPos"].Y;
        rc1.Width = rc.Width;
        rc1.Height = rc.Height;
        graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);
    }

    // Min Button
    if(GetStyle()&WS_MINIMIZEBOX)
    {
        rc = m_nButtonDown==HT_MIN?m_mapRect["NcBtnMinDown"]:m_mapRect["NcBtnMin"];
        rc1.X = rcWindow.Width()-m_mapRect["NcBtnMinPos"].X;
        rc1.Y = m_mapRect["NcBtnMinPos"].Y;
        rc1.Width = rc.Width;
        rc1.Height = rc.Height;
        graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);
    }

    Font myFont(L"宋体", 9);
    Color col(255,0,0,0);
    col.SetFromCOLORREF(m_mapColor["Caption"]);
    SolidBrush blackBrush(col);

    StringFormat format;
    format.SetAlignment(StringAlignmentNear);

    RectF layoutRect(::GetSystemMetrics(SM_CYICON)+m_mapRect["TitleTextStart"].X, m_mapRect["TitleTextStart"].Y, rcWindow.Width(), rcWindow.Height());

    WCHAR string[MAX_PATH] = {0};
    CString str;
    GetWindowText(str);

    MultiByteToWideChar( CP_ACP, 0, str, -1, string, MAX_PATH) ;

    graphics.DrawString(string,	-1, &myFont, layoutRect, &format, &blackBrush);
}
Пример #20
0
void CSkinDialog::OnNcPaint()
{
    // TODO: Add your message handler code here

    if(!CImgSkin::IsLoaded())
    {
        CXTPDialog::OnNcPaint();
        return;
    }

    if(HasStyle(WS_CHILD))
    {
        return;
    }

    /*
    RECT ClientRect;
    GetClientRect(&ClientRect);
    OffsetRect(&ClientRect, 100, 100);
    ExcludeClipRect(GetWindowDC()->GetSafeHdc(), ClientRect.left, ClientRect.top,
    	ClientRect.right, ClientRect.bottom);
    */

    CRect rcWindow;
    GetWindowRect(&rcWindow);

    Bitmap bmpBuf(rcWindow.Width(), rcWindow.Height());
    Graphics graphics(&bmpBuf);
    Graphics g(GetWindowDC()->GetSafeHdc());

    Rect rc, rc1;

    // Title Left
    rc = m_bActive?m_mapRect["TitleLeftActive"]:m_mapRect["TitleLeft"];
    rc1.X = 0;
    rc1.Y = 0;
    rc1.Width = rc.Width;
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Title Center
    rc = m_bActive?m_mapRect["TitleCenterActive"]:m_mapRect["TitleCenter"];
    rc1.X = m_mapRect["TitleLeftActive"].Width;
    rc1.Y = 0;
    rc1.Width = rcWindow.Width()-m_mapRect["TitleLeftActive"].Width-m_mapRect["TitleRightActive"].Width;
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Title Right
    rc = m_bActive?m_mapRect["TitleRightActive"]:m_mapRect["TitleRight"];
    rc1.X = rc1.GetRight();
    rc1.Y = 0;
    rc1.Width = rc.Width;
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Border Left
    rc = m_bActive?m_mapRect["BorderLeftActive"]:m_mapRect["BorderLeft"];
    rc1.X = 0;
    rc1.Y = m_mapRect["TitleLeftActive"].Height;
    rc1.Width = rc.Width;
    rc1.Height = rcWindow.Height()-m_mapRect["TitleLeftActive"].Height-m_mapRect["BorderBotActive"].Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Border Bottom
    rc = m_bActive?m_mapRect["BorderBotActive"]:m_mapRect["BorderBot"];
    rc1.X = 0;
    rc1.Y = rcWindow.Height()-rc.Height-1;
    rc1.Width = rcWindow.Width();
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Border Right
    rc = m_bActive?m_mapRect["BorderRightActive"]:m_mapRect["BorderRight"];
    rc1.X = rcWindow.Width()-rc.Width-1;
    rc1.Y = m_mapRect["TitleLeftActive"].Height;
    rc1.Width = rc.Width;
    rc1.Height = rcWindow.Height()-m_mapRect["TitleLeftActive"].Height-m_mapRect["BorderBotActive"].Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Close Button
    rc = m_nButtonDown==HT_CLOSE?m_mapRect["NcBtnCloseDown"]:m_mapRect["NcBtnClose"];
    rc1.X = rcWindow.Width()-m_mapRect["NcBtnClosePos"].X;
    rc1.Y = m_mapRect["NcBtnClosePos"].Y;
    rc1.Width = rc.Width;
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Max Button
    if(GetStyle()&WS_MAXIMIZEBOX)
    {
        rc = IsZoomed()?(m_nButtonDown==HT_MAX?m_mapRect["NcBtnResDown"]:m_mapRect["NcBtnRes"]):(m_nButtonDown==HT_MAX?m_mapRect["NcBtnMaxDown"]:m_mapRect["NcBtnMax"]);
        rc1.X = rcWindow.Width()-m_mapRect["NcBtnMaxPos"].X;
        rc1.Y = m_mapRect["NcBtnMaxPos"].Y;
        rc1.Width = rc.Width;
        rc1.Height = rc.Height;
        graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);
    }

    // Min Button
    if(GetStyle()&WS_MINIMIZEBOX)
    {
        rc = m_nButtonDown==HT_MIN?m_mapRect["NcBtnMinDown"]:m_mapRect["NcBtnMin"];
        rc1.X = rcWindow.Width()-m_mapRect["NcBtnMinPos"].X;
        rc1.Y = m_mapRect["NcBtnMinPos"].Y;
        rc1.Width = rc.Width;
        rc1.Height = rc.Height;
        graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);
    }

    Font myFont(L"宋体", 9);
    Color col(255,0,0,0);
    col.SetFromCOLORREF(m_mapColor["Caption"]);
    SolidBrush blackBrush(col);

    StringFormat format;
    format.SetAlignment(StringAlignmentNear);

    RectF layoutRect(::GetSystemMetrics(SM_CYICON)+m_mapRect["TitleTextStart"].X, m_mapRect["TitleTextStart"].Y, rcWindow.Width(), rcWindow.Height());

    WCHAR string[MAX_PATH] = {0};
    CString str;
    GetWindowText(str);

    MultiByteToWideChar( CP_ACP, 0, str, -1, string, MAX_PATH) ;

    graphics.DrawString(string,	-1, &myFont, layoutRect, &format, &blackBrush);

    g.DrawImage(&bmpBuf, 0, 0);

    // Do not call CXTPDialog::OnNcPaint() for painting messages
}
Пример #21
0
void __fastcall TTiffBook::FlipCurPage(int n) {
//-------------------------------------------------------------------------------
//               Переворачивает текущую страницу вверх ногами                   |
// n - номер страницы, который надо нанести. <= 0 - только убрать ном стр       |
//-------------------------------------------------------------------------------
    stop++;
    Gdiplus::Graphics *g32;
    TTiffImage *img = GetImagePage(GetPage());
    Gdiplus::Bitmap *fbm = img->fbm;
    Gdiplus::Rect r;
    int w = fbm->GetWidth(), h = fbm->GetHeight();

    // g = new Gdiplus::Graphics(fbm);

    Gdiplus::Bitmap *b32 = new Gdiplus::Bitmap(w, h, PixelFormat32bppARGB);
    g32 = new Gdiplus::Graphics(b32);

    Gdiplus::Matrix matr;
    matr.Rotate(180.0f);                // поворачиваем его на 270 градусов
    g32->SetTransform(&matr);

    //r.X = 0;
    //r.Y = 0;
    //r.Width = w;
    //r.Height = h;

    //r.X = -SaveBitmapH;
    //r.Y = -30;
    //r.Width = SaveBitmapH - 30;
    //r.Height = SaveBitmapW - 30;

    r.X = -w;
    r.Y = -h;
    r.Width = w;
    r.Height = h;

    sres = g32->DrawImage(fbm, r, 0, 0, w, h, Gdiplus::UnitPixel, 0, 0, 0);

    matr.Reset();
    g32->SetTransform(&matr);

    // Удаляем черные полосы сверху и снизу
    Gdiplus::Pen whitePen2(Gdiplus::Color(255, 255, 255, 255), 2);
    g32->DrawLine(&whitePen2, 0, 0, w, 0);
    g32->DrawLine(&whitePen2, 0, h-1, w, h-1);

    // Удаляем старый номер страницы - он теперь внизу
    // Gdiplus::Pen whitePen40(Gdiplus::Color(255, 0, 0, 0), 45);   // ??? Пока черный - для отладки!
    Gdiplus::Pen whitePen40(Gdiplus::Color(255, 255, 255, 255), 45);
    g32->DrawLine(&whitePen40, 0, h - 50, 200, h - 50);

    if (n > 0) {                        // Здесь выводим номер страницы
        AnsiString snum;
        wchar_t wnum[20];
        snum.printf("%d", n);
        snum.WideChar(wnum, 20);
        Gdiplus::Font myFont(L"Arial", 40, Gdiplus::FontStyleBold);
        Gdiplus::PointF origin(w - 160, 20.0f);
        Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0));
        g32->DrawLine(&whitePen40, w - 200, 50, w, 50);
        sres = g32->DrawString(wnum, -1, &myFont, origin, &blackBrush);
    }

    //if (npage > 0) {            // Здесь выводим номер страницы
    //    AnsiString snum;
    //    wchar_t wnum[20];
    //    snum.printf("%d", npage);
    //    snum.WideChar(wnum, 20);
    //    Gdiplus::Font myFont(L"Arial", 40, Gdiplus::FontStyleBold);
    //    Gdiplus::PointF origin(SaveBitmapW - 160, 20.0f);
    //    Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0));
    //    SaveBitmap2TiffGraphics->DrawString(wnum, -1, &myFont, origin, &blackBrush);
    //}

    // ------- строим SaveBitmap2TiffBitmap1
    UINT *pix;
    unsigned char byte, bit, *pix1;

    Gdiplus::Bitmap *b1 = new Gdiplus::Bitmap(w, h, PixelFormat1bppIndexed);
    Gdiplus::Rect BitsRect(0, 0, w, h);
    Gdiplus::BitmapData *bits = new Gdiplus::BitmapData;
    Gdiplus::BitmapData *bits1 = new Gdiplus::BitmapData;
    sres = b32->LockBits(&BitsRect, Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, bits);
    sres = b1->LockBits(&BitsRect, Gdiplus::ImageLockModeWrite, PixelFormat1bppIndexed, bits1);

    for (int y = 0; y < h; y++) {
        pix = (UINT *)((int)bits->Scan0 + bits->Stride * y);
        pix1 = (unsigned char *)((int)bits1->Scan0 + bits1->Stride * y);
        byte = 0;
        for (int x = 0; x < w; x++, pix++) {
            if ((*pix & 0xFF) > 0xD8) {
                bit = 1;
            }
            else bit = 0;
            byte <<= 1; byte |= bit;
            if ((x & 7) == 7) {
                *pix1++ = byte;
                byte = 0;
            }
        }
    }

    b32->UnlockBits(bits); delete bits;
    b1->UnlockBits(bits1); delete bits1;

    delete g32;
    delete b32;

    TTiffPageInfo *pi = GetPageInfo(GetPage());
    if (img->Filn.Length() == 0) {                  // Это уже временный файл!
        delete img->fbm;
        img->fbm = b1;
    } else {                                        // Надо будет заменить страницу на временный файл
        img = new TTiffImage(b1);
        pi->ImageIndex = AppendImage(img);
        pi->PageIndex = 0;
    }

    changed = true;
}
twoChessBoard::twoChessBoard(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::twoChessBoard)
{

	// There are issues with this right now. Hardcoded integers are only used for testing on simulator, not actual phone.
    this->parent = parent;
    ui->setupUi(this);
    ui->widget->setGeometry(QRect(10,130,480,480));
    graphicsView = new QGraphicsView(ui->widget);
    scene = new QGraphicsScene(QRect(-240,-180,480,480));
    graphicsView->setGeometry(QRect(0,0,490,490));
    graphicsView->setScene(scene);
    select = 0;//used to check whether a piece is selected or not
    turn = 1;//used to check which players turn it is
    //the following are to check how many different kind of pieces are left in the board
    blackPawnsLeft = 8;
    whitePawnsLeft = 8;
    blackRooksLeft = 2;
    whiteRooksLeft = 2;
    blackKnightsLeft = 2;
    whiteKnightsLeft = 2;
    blackBishopsLeft = 2;
    whiteBishopsLeft = 2;
    blackQueenLeft = 1;
    whiteQueenLeft = 1;
    blackKingLeft = 1;
    whiteKingLeft = 1;

    // colors for pieces
    QBrush blackBrush(Qt::black);
    QBrush whiteBrush(Qt::white);
    QBrush greenBrush(Qt::green);
    QBrush redBrush(Qt::red);
    QBrush yellowBrush(Qt::yellow);
    QBrush blueBrush(Qt::blue);
    QBrush magentaBrush(Qt::magenta);
    QBrush grayBrush(Qt::gray);

    QBrush darkGreenBrush(Qt::darkGreen);
    QBrush darkRedBrush(Qt::darkRed);
    QBrush darkYellowBrush(Qt::darkYellow);
    QBrush darkBlueBrush(Qt::darkBlue);
    QBrush darkMagentaBrush(Qt::darkMagenta);
    QBrush darkGrayBrush(Qt::darkGray);

    QPen pen(Qt::transparent);
    pen.setWidth(0);


    // This loop generates the chessboard. Code was written by TA.
    for(int i=0;i<CHESSBOARD_SIZE;i++){

        chessboard[i].resize(CHESSBOARD_SIZE);
        for(int j = 0 ; j<CHESSBOARD_SIZE;j++){
            chessboard[i][j] = new QGraphicsRectItem(CHESSBOARD_GRID_SIZE*(j-CHESSBOARD_SIZE/2) , CHESSBOARD_GRID_SIZE*( -i+CHESSBOARD_SIZE/2) ,
                            CHESSBOARD_GRID_SIZE ,CHESSBOARD_GRID_SIZE);
            scene->addItem(chessboard[i][j]);
            chessboard[i][j]->setPen(pen);

            chessboard[i][j]->setBrush(((i+j)%2==0)?blackBrush:whiteBrush);

        }
    }

    graphicsView->show();
    qDebug("Initialized chessboard...");


    for(int i =0; i<8;i++)
    {
        for(int j=0;j<8;j++)
        {
            boardvalues[i][j] = 0;
        }
    }


    //initialising the board values
    for(int i = 0;i<8;i++)
    {
        //pawns
        boardvalues[1][i] = 1;
        boardvalues[6][i] = 7;
    }

    //rooks
    boardvalues[0][0] = 2;
    boardvalues[0][7] = 2;
    boardvalues[7][0] = 8;
    boardvalues[7][7] = 8;

    //knights
    boardvalues[0][1] = 3;
    boardvalues[0][6] = 3;
    boardvalues[7][1] =9;
    boardvalues[7][6] =9;

    //bishops
    boardvalues[0][2] = 4;
    boardvalues[0][5] = 4;
    boardvalues[7][2] =10;
    boardvalues[7][5] =10;

    //queen
    boardvalues[0][3] = 6;
    boardvalues[7][3] =12;

    //king
    boardvalues[0][4] = 5;
    boardvalues[7][4] =11;

    // white pawns
    for (int i = 0; i < 8; i++)
    {
        whitePawns.resize(8);
        whitePawns[i] = new QGraphicsRectItem(-225+60*i, -105, 30, 30 );
        whitePawns[i]->setBrush(greenBrush);
        scene->addItem(whitePawns[i]);
    }
    //black pawns
    for (int i = 0; i < 8; i++)
    {
        blackPawns.resize(8);
        blackPawns[i] = new QGraphicsRectItem(-225+60*i, 195, 30, 30 );
        blackPawns[i]->setBrush(darkGreenBrush);
        scene->addItem(blackPawns[i]);
    }

    // white and black pieces
    for (int i = 0; i < 2; i++)
    {
        whiteRooks.resize(2);
        whiteRooks[i] = new QGraphicsRectItem(-225+420*i,-165,30,30);
        whiteRooks[i]->setBrush(redBrush);
        scene->addItem(whiteRooks[i]);

        blackRooks.resize(2);
        blackRooks[i] = new QGraphicsRectItem(-225+420*i,255,30,30);
        blackRooks[i]->setBrush(darkRedBrush);
        scene->addItem(blackRooks[i]);

        whiteKnights.resize(2);
        whiteKnights[i] = new QGraphicsRectItem(-165+300*i,-165,30,30);
        whiteKnights[i]->setBrush(yellowBrush);
        scene->addItem(whiteKnights[i]);

        blackKnights.resize(2);
        blackKnights[i] = new QGraphicsRectItem(-165+300*i,255,30,30);
        blackKnights[i]->setBrush(darkYellowBrush);
        scene->addItem(blackKnights[i]);

        whiteBishops.resize(2);
        whiteBishops[i] = new QGraphicsRectItem(-105+180*i,-165,30,30);
        whiteBishops[i]->setBrush(blueBrush);
        scene->addItem(whiteBishops[i]);

        blackBishops.resize(2);
        blackBishops[i] = new QGraphicsRectItem(-105+180*i,255,30,30);
        blackBishops[i]->setBrush(darkBlueBrush);
        scene->addItem(blackBishops[i]);
    }


    whiteQueen = new QGraphicsRectItem(-45,-165,30,30);
    whiteQueen->setBrush(magentaBrush);
    scene->addItem(whiteQueen);

    blackQueen = new QGraphicsRectItem(-45,255,30,30);
    blackQueen->setBrush(darkMagentaBrush);
    scene->addItem(blackQueen);

    whiteKing = new QGraphicsRectItem(15,-165,30,30);
    whiteKing->setBrush(grayBrush);
    scene->addItem(whiteKing);

    blackKing = new QGraphicsRectItem(15,255,30,30);
    blackKing->setBrush(darkGrayBrush);
    scene->addItem(blackKing);

}
Пример #23
0
void
MFCClipItemView::Draw(Graphics &dc, CRect &clipBox)
{
// !!!??? need to clip properly for short instances with long names
	cerr << "clip item draw " << item->sym->name << endl;
	Pen blackPen(Color(250, 0, 0, 0), 1);
	Pen redPen(Color(250, 238, 100, 100), 1);
	Pen orangePen(Color(200, 250, 150, 10), 1);
	SolidBrush blueBrush(Color(100, 100, 100, 238));
	SolidBrush blackBrush(Color(200, 0, 0, 0));
	SolidBrush orangeBrush(Color(190, 250, 150, 10));

	dc.DrawLine( &orangePen, bounds.left, 0, bounds.left, bounds.bottom);
	bool	isMarker = false;
	if (item != NULL && item->duration.ticks <= 0) {
		isMarker = true;
	}
	if (!isMarker) {
		dc.DrawLine( &orangePen, bounds.right, 0, bounds.right, bounds.bottom);
	}

	PointF	tri[3];

	Font	labelFont(L"Arial", 8.0, FontStyleRegular, UnitPoint, NULL);
	wstring nm;
	const char *cp = item->sym->uniqueName();
	while (*cp) {
		nm.push_back(*cp++);
	}
	PointF	p;
	UINT py = 0;
	do {
		if (!isMarker) {
			// a triangle bit
			tri[0].X = bounds.left; tri[0].Y = py;
			tri[1].X = bounds.left+6; tri[1].Y = py+3;
			tri[2].X = bounds.left; tri[2].Y = py+6;
			dc.FillPolygon(&orangeBrush, tri, 3);
		}

		p.X = bounds.left-1;
		p.Y = py+5;
		RectF	box;
		StringFormat	sff = StringFormatFlagsDirectionVertical;
		dc.MeasureString(nm.c_str(), -1, &labelFont, p, &sff, &box);
		dc.DrawString(nm.c_str(), -1, &labelFont, box,	&sff, &blackBrush);

		if (!isMarker) {
			// a nother triangle bit
			tri[0].X = bounds.right;
			tri[1].X = bounds.right-6;
			tri[2].X = bounds.right;
			dc.FillPolygon(&orangeBrush, tri, 3);

			p.X = bounds.right-10;
			p.Y = py+5;
			dc.MeasureString(nm.c_str(), -1, &labelFont, p, &sff, &box);
			dc.DrawString(nm.c_str(), -1, &labelFont, box,	&sff, &blackBrush);
		}
		py += editor->bounds.bottom;
	} while (py < bounds.bottom);

}