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 ()); } }
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); }
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); }
//draws the box on the screen void drawBox(WIN_RECT box, char value){ DrawClipRect(&box,ScrRect,A_NORMAL); if(value == 17) FontSetSys(F_4x6);//Make Text even more smaller for even more bigger numbers else if(value>13) FontSetSys(F_6x8);//Make text smaller for bigger numbers /*This game does not support going over 2^17 = 131072 and you can't exceed that value in a normal game anyways. this check prevents accessing bad memory*/ DrawStr((box.x0)+2, (box.y0)+5, strConv[value], A_NORMAL); FontSetSys(F_8x10); }
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); }
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); }