コード例 #1
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;
  }
}
コード例 #2
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");
}
コード例 #3
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");
}
コード例 #4
0
ファイル: g2dtest.cpp プロジェクト: crystalspace/CS
void G2DTestSystemDriver::WriteCenteredWrapped (int mode, int dy, int &h, 
						int fg, int bg, 
						const char *format, ...)
{
  if (!font) return;

  csString text;
  va_list arg;

  va_start (arg, format);
  text.FormatV (format, arg);
  va_end (arg);

  int y = 0, w = myG2D->GetWidth ();
  int fW, fH;
  font->GetMaxSize (fW, fH);

  switch (mode)
  {
    case 0: // centered by Y
      y = dy + myG2D->GetHeight () / 2;
      break;
    case 1: // from top
      y = dy;
      break;
    case 2: // from bottom
      y = dy + (myG2D->GetHeight () - 1 - fH);
      break;
  }

  h = 0;

  int sW, sH;
  font->GetDimensions (" ", sW, sH);

  // break text so that it completely fits onto the screen.
  int lw = -sW;
  int maxLH = fH;
  char* line = csStrNew (text);
  char* p = line;
  csString drawLine;

  while (p && *p)
  {
    char* space = strchr (p, ' ');
    if (space != 0)
      *space = 0;
    int tW, tH;
    font->GetDimensions (p, tW, tH);
    if (lw + tW + sW >= w)
    {
      WriteCentered (1, y + h, fg, bg, (drawLine.GetData ()) + 1);
      drawLine.Clear ();
      drawLine << ' ' << p;
      //p = space + 1;
      lw = 0;
      h += maxLH;
      maxLH = MAX(fH, tH);
    }
    else
    {
      lw += tW + sW;
      drawLine << ' ' << p;
      maxLH = MAX(maxLH, tH);
    }
    if (space != 0) p = space + 1; else p = 0;
  }
  WriteCentered (1, y + h, fg, bg, (drawLine.GetData ()) + 1);
  h += maxLH;
  delete[] line;
}