void print(GrayscaleBuffer& buffer)
{
  for(int y = 0; y < buffer.get_height(); ++y)
    {
      for(int x = 0; x < buffer.get_width(); ++x)
      {
        printf("%3d ", int(buffer.at(x,y)));
      }
      putchar('\n');
    }
  putchar('\n');
}
예제 #2
0
void
Controller::update_mouse_cursor()
{ // FIXME: This could need some cleanup/feature enhancements
  if (client_draw_param->generic_brush.radius < 5.0f)
    return ;

  GrayscaleBuffer* brush = client_draw_param->brush_buffer;

  int w     = brush->get_width();
  int pitch = brush->get_width()/8 + 1;
  int h     = brush->get_height();
  int len   = pitch * h;
  Uint8* data = new Uint8[len];
  Uint8* mask = new Uint8[len];

  memset(data, 0, len);
  memset(mask, 0, len);

  for(int y = 1; y < brush->get_height()-1; ++y)
    for(int x = 1; x < brush->get_width()-1; ++x)
      {
        int threshold = 64;

        Uint8 check = 0;
        if (((x / 1) % 2) ^ (y / 1) % 2)
          check = 1;


        if ((brush->at(x-1, y) < threshold &&
             brush->at(x+1, y) > threshold)
            ||
            (brush->at(x-1, y) > threshold &&
             brush->at(x+1, y) < threshold)
            ||
            (brush->at(x, y-1) < threshold &&
             brush->at(x, y+1) > threshold)
            ||
            (brush->at(x, y-1) > threshold &&
             brush->at(x, y+1) < threshold)
            )
          { // black
            data[y * pitch + x/8] |= (check << (7 - (x%8)));
            mask[y * pitch + x/8] |= (0x01 << (7 - (x%8)));
          }
      }

  if (w > 7 && h > 7)
    {
      int y = h / 2;
      int x = 0;
      for(x = w/2 - 3; x <= w/2 + 3; ++x)
        {
          data[y * pitch + x/8] |= (0x01 << (7 - (x%8)));
          mask[y * pitch + x/8] |= (0x01 << (7 - (x%8)));
        }

      x = w / 2;
      for(int y = h/2 - 3; y <= h/2 + 3; ++y)
        {
          data[y * pitch + x/8] |= (0x01 << (7 - (x%8)));
          mask[y * pitch + x/8] |= (0x01 << (7 - (x%8)));
        }


      y = h / 2;
      for(x = w/2 - 1; x <= w/2 + 1; ++x)
        {
          data[y * pitch + x/8] ^= (0x01 << (7 - (x%8)));
          mask[y * pitch + x/8] |= (0x01 << (7 - (x%8)));
        }

      x = w / 2;
      for(int y = h/2 - 1; y <= h/2 + 1; ++y)
        {
          data[y * pitch + x/8] ^= (0x01 << (7 - (x%8)));
          mask[y * pitch + x/8] |= (0x01 << (7 - (x%8)));
        }
    }

  SDL_Cursor* cursor = SDL_CreateCursor(data, mask, pitch*8, h,
                                        w/2, h/2);
  SDL_SetCursor(cursor);

  delete[] mask;
  delete[] data;
}