예제 #1
0
파일: g2dtest.cpp 프로젝트: crystalspace/CS
void G2DTestSystemDriver::PixelClipTest ()
{
  int w = myG2D->GetWidth ();
  int h = myG2D->GetHeight ();
  int sx = w/4, sy = h / 2 + 60, sw = w/2, sh = h / 4 - 60;
  myG2D->SetClipRect(0,0,w,h);
  myG2D->DrawBox(0,0,w,h, dsteel);
  


  SetFont (fontItalic);
  WriteCentered (0,16*-12, white, -1, "PIXEL CLIP TEST");

  SetFont (fontLarge);
  WriteCentered (0,16*-10,  black, dsteel, "This will test if pixel clipping is being done properly");
  
  WriteCentered (0,16*-8,   black, dsteel, "For each of the following clip tests we will be drawing");
  WriteCentered (0,16*-7,   black, dsteel, "a 1 pixel wide green rectangle with a 1 pixel wide red rectangle");
  WriteCentered (0,16*-6,   black, dsteel, "inside of it.");

  WriteCentered (0,16*-4,   black, dsteel, "The clipping rectangle has been set so the red rectangle is");
  WriteCentered (0,16*-3,   black, dsteel, "inside the clipping region. If any of the lines of the red rectangle");
  WriteCentered (0,16*-2,   black, dsteel, "are solid (not drawn over) then the clipping region is cutting off too much");
  
  WriteCentered (0,16*0,   black, dsteel, "The green rectangle is outside the clipping region. If any of the lines");
  WriteCentered (0,16*1,   black, dsteel, "of the green rectangle are being drawn over then the clipping region is");
  WriteCentered (0,16*2,   black, dsteel, "not clipping enough.");
  

  SetFont (fontCourier);

  DrawClipRect(sx, sy, sw, sh);

  myG2D->SetClipRect(sx + 1, sy + 1, sx + sw, sy + sh);
  

  // Test random pixel drawing
  csRandomGen rng (csGetTicks ());
  csTicks start_time = csGetTicks (), delta_time;


  // widen the range where we try to draw pixels
  sx -= 10;
  sy -= 10;
  sw += 20;
  sh += 20;

  do
  {
	int i;
    for (i = 0; i < 1000; i++)
    {
      int x = int(sx + rng.Get () * sw);
      int y = int(sy + rng.Get () * sh);
      myG2D->DrawPixel(x,y,black);
    }
    delta_time = csGetTicks () - start_time;
  } while (delta_time < 100);
}
예제 #2
0
파일: g2dtest.cpp 프로젝트: crystalspace/CS
void G2DTestSystemDriver::BoxClipTest()
{
  int w = myG2D->GetWidth ();
  int h = myG2D->GetHeight ();
  int sx = w/4, sy = h / 2 + 60, sw = w/2, sh = h / 4 - 60;
  myG2D->SetClipRect(0,0,w,h);
  myG2D->DrawBox(0,0,w,h, dsteel);
  
  SetFont (fontItalic);
  WriteCentered (0,-16*4, white, -1, "BOX CLIP TEST");

  SetFont (fontLarge);
  WriteCentered (0,-16*3,  black, dsteel, "This will test if box clipping is being done properly");
  WriteCentered (0,-16*2,  black, dsteel, "You should see a thin green rectangle below");

  WriteCentered (0,16*0,   black, dsteel, "Again all the black should be contained inside the green");
  WriteCentered (0,16*1,   black, dsteel, "rectangle. The red rectangle should not be visible.");
  

  SetFont (fontCourier);

  DrawClipRect(sx, sy, sw, sh);

  myG2D->SetClipRect(sx + 1, sy + 1, sx + sw, sy + sh);
  

  // Test random box drawing
  csRandomGen rng (csGetTicks ());
  csTicks start_time = csGetTicks (), delta_time;


  // widen the range where we try to draw
  sx -= 10;
  sy -= 10;
  sw += 20;
  sh += 20;

  do
  {
	int i;
    for (i = 0; i < 1000; i++)
    {
      int x = int(sx + rng.Get () * sw);
      int y = int(sy + rng.Get () * sh);
      int width = int(rng.Get () * sw);
      int height = int(rng.Get () * sh);
      myG2D->DrawBox(x,y,width,height,black);
    }
    delta_time = csGetTicks () - start_time;
  } while (delta_time < 100);

}
예제 #3
0
파일: g2dtest.cpp 프로젝트: crystalspace/CS
void G2DTestSystemDriver::BlitTest ()
{
  int w = myG2D->GetWidth ();
  int h = myG2D->GetHeight ();
  myG2D->SetClipRect(0,0,w,h);
  myG2D->DrawBox(0,0,w,h, dsteel);
  
  SetFont (fontItalic);
  WriteCentered (0,-16*8, white, -1, "BLIT() TEST");

  SetFont (fontLarge);
  WriteCentered (0,-16*7, black, dsteel, "This will test whether iGraphics2D->Blit() works correctly");
  WriteCentered (0,-16*6, black, dsteel, "on this canvas.");

  WriteCentered (0,-16*4, black, dsteel, "You should see an image of an arrow and the word %s.",
		 CS::Quote::Double ("up"));
  WriteCentered (0,-16*3, black, dsteel, "It is surrounded by a green rectangle, and the image");
  WriteCentered (0,-16*2, black, dsteel, "itself has a black border. No red should be visible");
  WriteCentered (0,-16*1, black, dsteel, "and the border has to be complete, too.");

  if (blitTestImage.IsValid ())
  {
    const int imW = blitTestImage->GetWidth ();
    const int imH = blitTestImage->GetHeight ();
    const int bx = (w - imW) / 2;
    const int by = h / 2;
    DrawClipRect (bx, by, imW + 1, imH + 1);
    myG2D->Blit (bx + 1, by + 1, imW, imH, 
      (unsigned char*)blitTestImage->GetImageData ());
  }
}
예제 #4
0
파일: g2dtest.cpp 프로젝트: crystalspace/CS
void G2DTestSystemDriver::DrawFreetypeTest ()
{
  const char* fontFaces[] = {"DejaVuSans", "DejaVuSansBoldOblique", 
    "DejaVuSansMono", "DejaVuSerif", 0};
  const int fontSizes[] = {4, 8, 12, 24, 0};

  int w = myG2D->GetWidth ();
  int h = myG2D->GetHeight ();
  myG2D->SetClipRect(0,0,w,h);
  myG2D->DrawBox(0,0,w,h, dsteel);

  SetFont (fontItalic);
  int tpos = -h / 2;
  WriteCentered (0, tpos, white, -1, "FREETYPE2 PLUGIN TEST");

  SetFont (fontLarge);
  WriteCentered (0, tpos + 16*2, black,  -1, 
    "If the FreeType2 plugin was built and activated in the");
  WriteCentered (0, tpos + 16*3, black,  -1, 
    "g2dtest.cfg file (it is by default), you should see text");
  WriteCentered (0, tpos + 16*4, black,  -1, 
    "in various faces and sizes below.");

  csRefArray<iFont> fonts;
  // The used fonts are all kept until the end of this function, to provide
  // some more "stress" on the font cache.

  int y = tpos + 16*7;
  int i = 0;
  while (fontFaces[i] != 0)
  {
    csString str;
    int j = 0;
    while (fontSizes[j] != 0)
    {
      int fW, fH;
      csRef<iFont> font = GetFont (fontFaces[i], fontSizes[j]);
      if (font)
      {
	fonts.Push (font);
	SetFont (font);
	str.Clear ();
        str << fontFaces[i] << ", Size " << fontSizes[j];
        WriteCentered (0, y, yellow, -1, str.GetData ());
        font->GetDimensions (str.GetData (), fW, fH);
        y += fH + 4;
      }
      j++;
    }
    i++;
  }

  SetFont (fontCourier);
  WriteCentered (2, 0, green, -1, "press any key to continue");
}
예제 #5
0
파일: g2dtest.cpp 프로젝트: crystalspace/CS
void G2DTestSystemDriver::DrawAlphaTestScreen ()
{
  int w = myG2D->GetWidth ();
  int h = myG2D->GetHeight ();
  myG2D->SetClipRect(0,0,w,h);
  myG2D->DrawBox(0,0,w,h, dsteel);

  SetFont (fontItalic);
  WriteCentered (1, 1, white, -1, "ALPHA COLOR TEST");

  SetFont (fontLarge);
  WriteCentered (1, 16*2, black, -1, "If your current canvas is in 32-bit mode, you should");
  WriteCentered (1, 16*3, black, -1, "see various text and geometry at various transparencies.");

  myG2D->DrawBox (190, 80, 50, 100, black);
  myG2D->DrawBox (20, 100, 150, 75, myG2D->FindRGB (205, 0, 125, 200));
  myG2D->DrawBox (120, 100, 100, 50, myG2D->FindRGB (120, 50, 50, 100));
  myG2D->DrawLine (30, 110, 120, 60, myG2D->FindRGB (255, 128, 128, 128));
  myG2D->DrawLine (120, 60, 70, 120, myG2D->FindRGB (128, 255, 128, 128));
  myG2D->DrawLine (70, 120, 30, 110, myG2D->FindRGB (128, 128, 255, 128));

  if (alphaBlitImage.IsValid ())
  {
    myG2D->Blit (20, 160, alphaBlitImage->GetWidth (), alphaBlitImage->GetHeight (), 
      (unsigned char*)alphaBlitImage->GetImageData ());
  }

  myG2D->Write (font, 50, 140, myG2D->FindRGB (255, 255, 255, 100), -1,
    L"Here is some partially transparent text");
  myG2D->Write (font, 50, 150, myG2D->FindRGB (0, 0, 255, 150), -1,
    L"overlaying partially transparent boxes.");

  csString str;
  int i;
  int y = 140;
  int tw, th;
  font->GetMaxSize (tw, th);
  for (i = 0; i < 6; i++)
  {
    const uint8 alpha = (i * 51);
    str.Format ("FG has alpha %" PRIu8 , alpha);
    myG2D->Write (font, 320, y, MakeColor (255, 255, 255, alpha), 
      black, str);
    y += th;
    str.Format ("BG has alpha %" PRIu8, alpha);
    myG2D->Write (font, 320, y, white, MakeColor (0, 0, 0, alpha), 
      str);
    y += th;
  }
}
예제 #6
0
파일: g2dtest.cpp 프로젝트: crystalspace/CS
void G2DTestSystemDriver::DrawCustomCursorScreen ()
{
  int w = myG2D->GetWidth ();
  int h = myG2D->GetHeight ();
  myG2D->SetClipRect(0,0,w,h);
  myG2D->DrawBox(0,0,w,h, dsteel);

  SetFont (fontItalic);
  int tpos = -h / 2;
  WriteCentered (0, tpos, white, -1, "CUSTOM MOUSE CURSOR");

  SetFont (fontLarge);
  WriteCentered (0, tpos + 16*2, black,  -1, "If your current canvas supports custom mouse cursors");
  WriteCentered (0, tpos + 16*3, black,  -1, "you shouldn't see your systems default cursor now.");
}
예제 #7
0
파일: g2dtest.cpp 프로젝트: crystalspace/CS
void G2DTestSystemDriver::DrawCustomIconScreen ()
{
  int w = myG2D->GetWidth ();
  int h = myG2D->GetHeight ();
  myG2D->SetClipRect(0,0,w,h);
  myG2D->DrawBox(0,0,w,h, dsteel);

  SetFont (fontItalic);
  int tpos = -h / 2;
  WriteCentered (0, tpos, white, -1, "CUSTOM WINDOW ICON");

  SetFont (fontLarge);
  WriteCentered (0, tpos + 16*2, black,  -1, "If your current canvas supports custom window icons");
  WriteCentered (0, tpos + 16*3, black,  -1, "the window icon should have changed.");
  WriteCentered (0, tpos + 16*4, black,  -1, "It should look like a %s of the Crystal Space logo.",
		 CS::Quote::Double ("shard"));
}
예제 #8
0
파일: g2dtest.cpp 프로젝트: crystalspace/CS
void G2DTestSystemDriver::DrawUnicodeTest1 ()
{
  int w = myG2D->GetWidth ();
  int h = myG2D->GetHeight ();
  myG2D->SetClipRect(0,0,w,h);
  myG2D->DrawBox(0,0,w,h, dsteel);

  SetFont (fontItalic);
  int tpos = -h / 2;
  WriteCentered (0, tpos, white, -1, "UNICODE TEST 1");

  SetFont (fontLarge);
  WriteCentered (0, tpos + 16*2, black,  -1, "Below you see the equivalent of %s",
		 CS::Quote::Double ("Quick brown fox"));
  WriteCentered (0, tpos + 16*3, black,  -1, "in several languages.");
  WriteCentered (0, tpos + 16*4, black,  -1, "In the ideal case, all characters should be displayed.");
  WriteCentered (0, tpos + 16*5, black,  -1, "If you see a box in some places, a particular");
  WriteCentered (0, tpos + 16*6, black,  -1, "character is not available in the font.");

  int y = tpos + 16*8;
  int i = 0;
  while (quickBrownFox[i] != 0)
  {
    int fW, fH;
    SetFont (fontCourier);
    WriteCentered (0, y, yellow, -1, quickBrownFox[i + 1]);
    font->GetDimensions (quickBrownFox[i + 1], fW, fH);
    y += fH;

    SetFont (fontLarge);
    font->GetMaxSize (fW, fH);
    int h;
    WriteCenteredWrapped (0, y, h, white, -1, quickBrownFox[i]);
    y += h + fH;
    i += 2;
  }

  SetFont (fontCourier);
  WriteCentered (2, 0, green, -1, "press any key to continue");
}
예제 #9
0
파일: g2dtest.cpp 프로젝트: crystalspace/CS
void G2DTestSystemDriver::DrawUnicodeTest2 ()
{
  int w = myG2D->GetWidth ();
  int h = myG2D->GetHeight ();
  myG2D->SetClipRect(0,0,w,h);
  myG2D->DrawBox(0,0,w,h, dsteel);

  SetFont (fontItalic);
  int tpos = -h / 2;
  WriteCentered (0, tpos, white, -1, "UNICODE TEST 2");

  SetFont (fontLarge);
  WriteCentered (0, tpos + 16*2, black,  -1, "Below you see some translations for %s.",
		 CS::Quote::Double ("I can eat glass"));
  WriteCentered (0, tpos + 16*3, black,  -1, "In the ideal case, all characters should be displayed.");
  WriteCentered (0, tpos + 16*4, black,  -1, "If you see a box in some places, a particular");
  WriteCentered (0, tpos + 16*5, black,  -1, "character is not available in the font.");

  int y = tpos + 16*7;
  int i = 0;
  while (iCanEatGlass[i] != 0)
  {
    int fW, fH;
    SetFont (fontCourier);
    WriteCentered (0, y, yellow, -1, iCanEatGlass[i + 1]);
    font->GetDimensions (iCanEatGlass[i + 1], fW, fH);
    y += fH;

    SetFont (fontLarge);
    font->GetMaxSize (fW, fH);
    int h;
    WriteCenteredWrapped (0, y, h, white, -1, iCanEatGlass[i]);
    y += h + fH;
    i += 2;
  }

  SetFont (fontCourier);
  WriteCentered (2, 0, green, -1, "press any key to continue");
}
예제 #10
0
파일: g2dtest.cpp 프로젝트: crystalspace/CS
void G2DTestSystemDriver::SetupFrame ()
{
  if (state_sptr == 0)
  {
    EventOutlet->Broadcast (csevQuit (object_reg));
    return;
  }

  appState curstate = state [state_sptr - 1];
  switch (curstate)
  {
    case stInit:
    case stStartup:
    case stContextInfo:
    case stWindowFixed:
    case stWindowResize:
    case stCustomCursor:
    case stCustomIcon:
    case stAlphaTest:
    case stTestUnicode1:
    case stTestUnicode2:
    case stTestFreetype:
    case stTestLineDraw:
    case stTestLinePerf:
    case stTestTextDraw:
    case stTestTextDraw2:
    case stPixelClipTest:
    case stLineClipTest:
    case stBoxClipTest:
    case stFontClipTest:
    case stBlitTest:
    {
      if (!myG3D->BeginDraw (CSDRAW_2DGRAPHICS))
        break;

      myG2D->Clear (black);
      LeaveState ();
      switch (curstate)
      {
        case stInit:
	  fontLarge = GetFont (CSFONT_LARGE);
	  fontItalic = GetFont (CSFONT_ITALIC);
	  fontCourier = GetFont (CSFONT_COURIER);
	  fontSmall = GetFont (CSFONT_SMALL);
	  {
	    csRef<iVFS> vfs = csQueryRegistry<iVFS> (object_reg);
	    csRef<iImageIO> iio = 
	      csQueryRegistry<iImageIO> (object_reg);
	    if (vfs.IsValid () && iio.IsValid ())
	    {
	      csRef<iFile> testFile = vfs->Open ("/lib/g2dtest/up.png", 
		VFS_FILE_READ);
	      if (testFile.IsValid ())
	      {
		csRef<iDataBuffer> fileData = testFile->GetAllData ();
		blitTestImage = iio->Load (fileData, CS_IMGFMT_TRUECOLOR 
		  | CS_IMGFMT_ALPHA);
	      }
	      testFile = vfs->Open ("/lib/std/cslogo2.png", VFS_FILE_READ);
	      if (testFile.IsValid ())
	      {
		csRef<iDataBuffer> fileData = testFile->GetAllData ();
		alphaBlitImage = iio->Load (fileData, CS_IMGFMT_TRUECOLOR |
		  CS_IMGFMT_ALPHA);
	      }
	    }
	  }
	  EnterState (stStartup);
	  break;
        case stStartup:
          DrawStartupScreen ();
	  EnterState (stContextInfo);
          EnterState (stPause, 5000);
          break;
        case stContextInfo:
          DrawContextInfoScreen ();
          EnterState (stWindowFixed);
          EnterState (stWaitKey);
          break;
        case stWindowFixed:
          DrawWindowScreen ();
          EnterState (stWindowResize);
          EnterState (stWaitKey);
          break;
        case stWindowResize:
          DrawWindowResizeScreen ();
          EnterState (stCustomCursor);
          EnterState (stWaitKey);
          break;
	case stCustomCursor:
          DrawCustomCursorScreen ();
	  SetCustomCursor ();
	  if (lastkey9)
            EnterState (stCustomIcon);
	  else
            EnterState (stCustomCursor);
          break;
	case stCustomIcon:
          SetNormalCursor ();
	  SetCustomIcon ();
          DrawCustomIconScreen ();
	  EnterState (stAlphaTest);
          EnterState (stWaitKey);
          break;
	case stAlphaTest:
          DrawAlphaTestScreen ();
          EnterState (stTestUnicode1);
          EnterState (stWaitKey);
          break;
	case stTestUnicode1:
	  DrawUnicodeTest1 ();
          EnterState (stTestUnicode2);
          EnterState (stWaitKey);
          break;
	case stTestUnicode2:
	  DrawUnicodeTest2 ();
          EnterState (stTestFreetype);
          EnterState (stWaitKey);
          break;
	case stTestFreetype:
	  DrawFreetypeTest ();
          EnterState (stTestLineDraw);
          EnterState (stWaitKey);
          break;
        case stTestLineDraw:
          DrawLineTest ();
          EnterState (stTestLinePerf);
          EnterState (stWaitKey);
          break;
        case stTestLinePerf:
          DrawLinePerf ();
          if (lastkey2)
            EnterState (stTestTextDraw);
          else
            EnterState (stTestLinePerf);
          break;
        case stTestTextDraw:
          DrawTextTest ();
          if (lastkey3)
            EnterState (stTestTextDraw2);
          else
            EnterState (stTestTextDraw);
          break;
        case stTestTextDraw2:
          DrawTextTest2 ();
          if (lastkey4)
            EnterState (stPixelClipTest);
          else
            EnterState (stTestTextDraw2);
          break;
        case stPixelClipTest:
          PixelClipTest ();
          if (lastkey5)
          {
            myG2D->SetClipRect(0,0,myG2D->GetWidth(), myG2D->GetHeight());
            EnterState (stLineClipTest);
          }
          else
            EnterState (stPixelClipTest);
          break;
        case stLineClipTest:
          LineClipTest ();
          if (lastkey6)
          {
            myG2D->SetClipRect(0,0,myG2D->GetWidth(), myG2D->GetHeight());
            EnterState (stBoxClipTest);
          }
          else
            EnterState (stLineClipTest);
          break;
        case stBoxClipTest:
          BoxClipTest ();
          if (lastkey7)
          {
            myG2D->SetClipRect(0,0,myG2D->GetWidth(), myG2D->GetHeight());
	    EnterState (stFontClipTest);
          }
          else
            EnterState (stBoxClipTest);
          break;
        case stFontClipTest:
          FontClipTest ();
          if (lastkey8)
	    EnterState (stBlitTest);
          else
            EnterState (stFontClipTest);
          break;
	case stBlitTest:
	  BlitTest ();
          EnterState (stWaitKey);
          break;
        default:
          break;
      }
      break;
    }
    case stPause:
      if (int (csGetTicks () - timer) > 0)
        LeaveState ();
      else
        csSleep (1);
      break;
    case stWaitKey:
      if (lastkey)
      {
        LeaveState ();
        SwitchBB = false;
      }
      else
      {
        if (SwitchBB)
        {
          myG2D->Print (0);
          csSleep (200);
        }
        else
          csSleep (1);
      }
      break;
  }
}
예제 #11
0
파일: g2dtest.cpp 프로젝트: crystalspace/CS
void G2DTestSystemDriver::FontClipTest()
{
  int w = myG2D->GetWidth ();
  int h = myG2D->GetHeight ();
  int sx = w/10, sy = h / 2 + 60, sw = sx * 2, sh = h / 6 - 60;
  int sx1 = sx * 1, sx2 = sx * 4, sx3 = sx * 7;
  myG2D->SetClipRect(0,0,w,h);
  myG2D->DrawBox(0,0,w,h, dsteel);
  
  SetFont (fontItalic);
  WriteCentered (0,-16*8, white, -1, "FONT CLIP TEST");

  SetFont (fontLarge);
  WriteCentered (0,-16*7, black, dsteel, "This will test if font clipping is being done properly");
  WriteCentered (0,-16*6, black, dsteel, "You should see three thin green rectangles below");

  WriteCentered (0,-16*4, black, dsteel, "Again all the black should be contained inside the first");
  WriteCentered (0,-16*3, black, dsteel, "green rectangle. The red rectangle should not be visible.");
  
  WriteCentered (0,-16*1, black, dsteel, "The second and third green rectangles shouldn't be crossed as well,");
  WriteCentered (0, 16*0, black, dsteel, "the text should only overdraw the red rectangle. Additionally,");
  WriteCentered (0, 16*1, black, dsteel, "all the text should look the same (well, except for the parts cut off.)");

  SetFont (fontCourier);

  const char* testText = "CrystalSpace";
  int fW, fH;

  font->GetDimensions (testText, fW, fH);

  int fX = -fW /2, fY = -fH / 2;

  DrawClipRect(sx2, sy, sw, sh);
  myG2D->SetClipRect(sx2 + 1, sy + 1, sx2 + sw, sy + sh);

  myG2D->Write (font, sx2 + fX,          sy + fY,          black, -1, testText);
  myG2D->Write (font, sx2 + sw / 2 + fX, sy + fY,          black, -1, testText);
  myG2D->Write (font, sx2 + sw + fX,     sy + fY,          black, -1, testText);

  myG2D->Write (font, sx2 + fX,          sy + sh / 2 + fY, black, -1, testText);
  myG2D->Write (font, sx2 + sw / 2 + fX, sy + sh / 2 + fY, black, -1, testText);
  myG2D->Write (font, sx2 + sw + fX,     sy + sh / 2 + fY, black, -1, testText);

  myG2D->Write (font, sx2 + fX,          sy + sh + fY,     black, -1, testText);
  myG2D->Write (font, sx2 + sw / 2 + fX, sy + sh + fY,     black, -1, testText);
  myG2D->Write (font, sx2 + sw + fX,     sy + sh + fY,     black, -1, testText);

  myG2D->SetClipRect(0,0,w,h);
  DrawClipRect(sx3, sy, sw, sh);
  myG2D->SetClipRect(sx3 + 1, sy + 1, sx3 + sw, sy + sh);

  myG2D->Write (font, sx3 + fX,          sy + fY,          black, blue, testText);
  myG2D->Write (font, sx3 + sw / 2 + fX, sy + fY,          black, blue, testText);
  myG2D->Write (font, sx3 + sw + fX,     sy + fY,          black, blue, testText);

  myG2D->Write (font, sx3 + fX,          sy + sh / 2 + fY, black, blue, testText);
  myG2D->Write (font, sx3 + sw / 2 + fX, sy + sh / 2 + fY, black, blue, testText);
  myG2D->Write (font, sx3 + sw + fX,     sy + sh / 2 + fY, black, blue, testText);

  myG2D->Write (font, sx3 + fX,          sy + sh + fY,     black, blue, testText);
  myG2D->Write (font, sx3 + sw / 2 + fX, sy + sh + fY,     black, blue, testText);
  myG2D->Write (font, sx3 + sw + fX,     sy + sh + fY,     black, blue, testText);

  myG2D->SetClipRect(0,0,w,h);
  DrawClipRect(sx1, sy, sw, sh);
  myG2D->SetClipRect(sx1 + 1, sy + 1, sx1 + sw, sy + sh);

  // Test random text drawing
  csRandomGen rng (csGetTicks ());
  csTicks start_time = csGetTicks (), delta_time;

  // widen the range where we try to draw
  sx -= fW;
  sy -= fH;
  sw += fW * 2;
  sh += fH * 2;

  do
  {
    int i;
    for (i = 0; i < 1000; i++)
    {
      int x = int(sx + rng.Get () * sw);
      int y = int(sy + rng.Get () * sh);
      myG2D->Write (font, x, y, black, blue, testText);
    }
    delta_time = csGetTicks () - start_time;
  } while (delta_time < 100);
}
예제 #12
0
파일: g2dtest.cpp 프로젝트: crystalspace/CS
void G2DTestSystemDriver::LineClipTest ()
{
  int w = myG2D->GetWidth ();
  int h = myG2D->GetHeight ();
    myG2D->SetClipRect(0,0,w,h);
  myG2D->DrawBox(0,0,w,h, dsteel);


  SetFont (fontItalic);
  WriteCentered (0,-16*4, white, -1, "LINE CLIP TEST");

  SetFont (fontLarge);
  WriteCentered (0,-16*1,  black, dsteel, "This will test if line clipping is being done properly");
  WriteCentered (0,0,   black, dsteel, "You should see 3 thin green rectangles below with black");
  WriteCentered (0,16*1,   black, dsteel, "inside each. Like before we want no black on the green while the");
  WriteCentered (0,16*2,   black, dsteel, "red should be covered. The first box is drawing horizontal lines, ");
  WriteCentered (0,16*3,   black, dsteel, "the second, vertical lines, and the third, random diagonal lines.");
  

  SetFont (fontCourier);
  int sx1 = w/7, sx2 = 3*sx1, sx3 = 5*sx1, sy = h / 2 + 60, sw = w/7, sh = h / 4 - 60;
  DrawClipRect(sx1, sy, sw, sh);
  DrawClipRect(sx2, sy, sw, sh);
  DrawClipRect(sx3, sy, sw, sh);



  // Test random pixel drawing
  csRandomGen rng (csGetTicks ());
  csTicks start_time = csGetTicks (), delta_time;


  // widen the range where we try to draw pixels
  int sx1_big = sx1 - 10;
  int sx2_big = sx2 - 10;
  int sx3_big = sx3 - 10;
  int sy_big = sy - 10;
  int sw_big = sw + 20;
  int sh_big = sh + 20;

  do
  {
	int i;

    myG2D->SetClipRect(sx1 + 1, sy + 1, sx1 + sw, sy + sh);
    for (i = 0; i < 10; i++)
    {
      float x1 = sx1_big + rng.Get () * sw_big;
      float x2 = sx1_big + rng.Get () * sw_big;
      float y = sy_big + rng.Get () * sh_big;
      myG2D->DrawLine(x1,y,x2,y,black);
    }

    myG2D->SetClipRect(sx2 + 1, sy + 1, sx2 + sw, sy + sh);
    for (i = 0; i < 100; i++)
    {
      float x = sx2_big + rng.Get () * sw_big;
      float y1 = sy_big + rng.Get () * sh_big;
      float y2 = sy_big + rng.Get () * sh_big;
      myG2D->DrawLine(x,y1,x,y2,black);
    }

    myG2D->SetClipRect(sx3 + 1, sy + 1, sx3 + sw, sy + sh);
    for (i = 0; i < 100; i++)
    {
      float x1 = sx3_big + rng.Get () * sw_big;
      float y1 = sy_big + rng.Get () * sh_big;
      float x2 = sx3_big + rng.Get () * sw_big;
      float y2 = sy_big + rng.Get () * sh_big;
      myG2D->DrawLine(x1,y1,x2,y2,black);
    }
    delta_time = csGetTicks () - start_time;
  } while (delta_time < 100);

}