Example #1
0
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);
}
Example #2
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
}