Exemple #1
0
void G2DTestSystemDriver::DrawTextTest ()
{
  // Draw a grid of lines so that transparent text background will be visible
  int w = myG2D->GetWidth ();
  int h = myG2D->GetHeight ();
  int i;
  for (i = 0; i < w; i += 4)
  {
    myG2D->DrawLine (float(i), 0.0f, float(i) + 50.0f, float(h), dsteel);
    myG2D->DrawLine (float(w - i), 0.0f, float(w - i) - 50.0f, float(h), dsteel);
  }

  SetFont (fontItalic);
  WriteCentered (0,-16*7, white, -1, "TEXT DRAWING TEST");

  SetFont (fontLarge);
  WriteCentered (0,-16*5,   blue,    -1, "This is blue text with transparent background");
  WriteCentered (0,-16*4,  green,  blue, "This is green text on blue background");
  WriteCentered (0,-16*3, yellow,  gray, "Yellow text on gray background");
  WriteCentered (0,-16*2,    red, black, "Red text on black background");
  WriteCentered (0,-16*1,  black, white, "Black text on white background");

  SetFont (fontCourier);
  int sx = 0, sy = h / 2 + 48, sw = w, sh = h / 2 - 48;
  myG2D->DrawBox (sx, sy, sw, sh, dsteel);
  const char *text = "Crystal Space rulez";
  int tw, th;
  font->GetDimensions (text, tw, th);
  size_t cc = strlen (text);

  // Test text drawing performance for 1/4 seconds
  int colors [4] = { red, green, blue, yellow };
  sx += 20; sw -= 40 + tw;
  sy += 10; sh -= 20 + th;
  csRandomGen rng (csGetTicks ());
  csTicks start_time = csGetTicks (), delta_time;
  size_t char_count = 0;
  do
  {
    for (i = 0; i < 2000; i++)
    {
      float x = sx + rng.Get () * sw;
      float y = sy + rng.Get () * sh;
      myG2D->Write (font, int(x), int(y), colors [rng.Get (4)], black, text);
      char_count += cc;
    }
    myG2D->PerformExtension ("flush");
    delta_time = csGetTicks () - start_time;
  } while (delta_time < 500);
  float perf = char_count * (1000.0f / delta_time);
  SetFont (fontLarge);
  WriteCentered (0, 16*1, green, black, " Performance: %20.1f characters/second ", perf);
}
Exemple #2
0
void G2DTestSystemDriver::DrawLinePerf ()
{
  SetFont (fontItalic);
  WriteCentered (0,-16*4, white, -1, "LINE SLOPE AND PERFORMANCE TEST");

  int w2 = myG2D->GetWidth () / 2;
  int colors [4] = { red, green, blue, yellow };
  int a;
  for (a = 0; a < 360; a += 5)
  {
    float angle = (a * TWO_PI) / 360.0;
    float x = w2 + 80 * cos (angle);
    float y = 100 + 80 * sin (angle);
    myG2D->DrawLine (w2, 100, x, y, colors [a & 3]);
  }

  // Compute the size for the random lines box
  int sx = 0;
  int sw = myG2D->GetWidth ();
  int sy = myG2D->GetHeight () / 2;
  int sh = sy;
  myG2D->DrawBox (sx, sy + 16, sw, sh - 16, dsteel);

  SetFont (fontLarge);
  WriteCentered (0,-16*2, gray,  -1, "Above this text you should see a uniformly hashed circle,");
  WriteCentered (0,-16*1, gray,  -1, "while below you should see some random lines, and the");
  WriteCentered (0, 16*0, gray,  -1, "measured line drawing performance in pixels per second.");

  // Test line drawing performance for 1/4 seconds
  sx += 20; sw -= 40;
  sy += 30; sh -= 40;
  csRandomGen rng (csGetTicks ());
  csTicks start_time = csGetTicks (), delta_time;
  float pix_count = 0;
  do
  {
    for (a = 0; a < 5000; a++)
    {
      float x1 = sx + rng.Get () * sw;
      float y1 = sy + rng.Get () * sh;
      float x2 = sx + rng.Get () * sw;
      float y2 = sy + rng.Get () * sh;
      myG2D->DrawLine (x1, y1, x2, y2, colors [rng.Get (4)]);
      x2 = csQint (x2 - x1); y2 = csQint (y2 - y1);
      pix_count += csQsqrt (x2 * x2 + y2 * y2);
    }
    myG2D->PerformExtension ("flush");
    delta_time = csGetTicks () - start_time;
  } while (delta_time < 500);
  pix_count = pix_count * (1000.0 / delta_time);
  WriteCentered (0, 16*1, green, black, " Performance: %20.1f pixels/second ", pix_count);
}
Exemple #3
0
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;
  }
}
Exemple #4
0
void G2DTestSystemDriver::DrawClipRect(int sx, int sy, int sw, int sh)
{
  myG2D->DrawLine (sx, sy, sx + sw, sy, green);
  myG2D->DrawLine (sx, sy + sh, sx + sw, sy + sh, green);
  myG2D->DrawLine (sx, sy, sx, sy + sh, green);
  myG2D->DrawLine (sx + sw, sy, sx + sw, sy + sh, green);
  myG2D->DrawLine (sx+1, sy+1, sx + sw-1, sy+1, red);
  myG2D->DrawLine (sx+1, sy + sh-1, sx + sw-1, sy + sh-1, red);
  myG2D->DrawLine (sx+1, sy+1, sx+1, sy + sh-1, red);
  myG2D->DrawLine (sx + sw - 1, sy+1, sx + sw - 1, sy + sh-1, red);
}
Exemple #5
0
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);

} 
Exemple #6
0
void G2DTestSystemDriver::DrawLineTest ()
{
#if 0

  // some tests for some special kinds of lines
  myG2D->DrawLine (0, 0, 200, 200, yellow);
  myG2D->DrawLine (0, 0, 205, 200, red);
  myG2D->DrawLine (0, 0, 195, 200, green);

  int w = myG2D->GetWidth ();
  myG2D->DrawLine (0, 250, w / 3, 250, red);
  myG2D->DrawLine (w / 3, 250.1, w * 2 / 3, 250.1, red);
  myG2D->DrawLine (w * 2 / 3, 250.99, w, 250.99, red);

  myG2D->DrawLine (200, myG2D->GetHeight () - 200, 0, myG2D->GetHeight (), blue);

  myG2D->DrawLine (81, 221, 519, 221, white);

#else

  SetFont (fontItalic);
  WriteCentered (0,-16*5, white, -1, "LINE DRAWING TEST");
  SetFont (fontLarge);
  WriteCentered (0,-16*3, gray,  -1, "At the top of the screen you should see a sinusoid,");
  WriteCentered (0,-16*2, gray,  -1, "each point on sinusoid should be connected with the");
  WriteCentered (0,-16*1, gray,  -1, "top-left corner of the canvas.");

  float py = -1;
  int a;
  for (a = 0; a <= myG2D->GetWidth (); a += 8)
  {
    float angle = float (a) / 30;
    float y = int (80 + sin (angle) * 60);
    if (py > 0)
      myG2D->DrawLine (a - 8, py, a, y, red);
    myG2D->DrawLine (0, 0, a, y, yellow);
    py = y;
  }

  WriteCentered (0, 16*1, gray,  -1, "At the bottom of the screen you should see several");
  WriteCentered (0, 16*2, gray,  -1, "lines interruped by a white pixel in the middle.");

  int w = myG2D->GetWidth ();
  float x = (w / 2) + 0.5;
  float y = myG2D->GetHeight () - 50.5;
  myG2D->DrawPixel (int(x), int(y), white);
  myG2D->DrawLine (0, y - 0.5, x - 0.5, y - 0.5, red);
  myG2D->DrawLine (x + 0.5, y + 0.49, w, y + 0.49, red);

  // Compute the slope for a line that is going through (x,y)
  float y1 = y - 5;
  float y2 = y + 5;
  float dy = float (y2 - y1) / float (w);
  float y11 = y1 + (x - 0.5 ) * dy;
  float y12 = y1 + (x + 0.5) * dy;
  myG2D->DrawLine (0, y1, x - 0.5, y11, blue);
  myG2D->DrawLine (x + 0.5, y12, w, y2, blue);

  myG2D->DrawLine (x, y - 20, x, y - 0.5, gray);
  myG2D->DrawLine (x, y + 0.5, x, y + 20, gray);

  WriteCentered (0, 16*4, gray,  -1, "A little above you should see four adjanced horizontal");
  WriteCentered (0, 16*5, gray,  -1, "lines of blue, green, red and yellow colors.");

  myG2D->DrawLine (0, y - 43 - 0.5,  w - 0.9, y - 43,        blue);
  myG2D->DrawLine (0, y - 42 + 0.49, w + 0.9, y - 42,        green);
  myG2D->DrawLine (0, y - 41,        w,       y - 41 - 0.5,  red);
  myG2D->DrawLine (0, y - 40,        w - 0.5, y - 40 + 0.49, yellow);
#endif
}