Exemple #1
0
void ALSoftwareGraphicsDriver::ClearRectangle(int x1, int y1, int x2, int y2, RGB *colorToUse)
{
    int color = 0;
    if (colorToUse != NULL)
        color = makecol_depth(this->_colorDepth, colorToUse->r, colorToUse->g, colorToUse->b);
    _filter->ClearRect(x1, y1, x2, y2, color);
}
Exemple #2
0
/* splits bitmaps into sub-sprites, using regions bounded by col #255 */
static void datedit_find_character(BITMAP *bmp, int *x, int *y, int *w, int *h)
{
  int c1;
  int c2;

  if (bitmap_color_depth(bmp) == 8) {
    c1 = 255;
    c2 = 255;
  }
  else {
    c1 = makecol_depth(bitmap_color_depth(bmp), 255, 255, 0);
    c2 = makecol_depth(bitmap_color_depth(bmp), 0, 255, 255);
  }

  /* look for top left corner of character */
  while ((getpixel(bmp, *x, *y) != c1) ||
         (getpixel(bmp, *x+1, *y) != c2) ||
         (getpixel(bmp, *x, *y+1) != c2) ||
         (getpixel(bmp, *x+1, *y+1) == c1) ||
         (getpixel(bmp, *x+1, *y+1) == c2)) {
    (*x)++;
    if (*x >= bmp->w) {
      *x = 0;
      (*y)++;
      if (*y >= bmp->h) {
        *w = 0;
        *h = 0;
        return;
      }
    }
  }

  /* look for right edge of character */
  *w = 0;
  while ((getpixel(bmp, *x+*w+1, *y) == c2) &&
         (getpixel(bmp, *x+*w+1, *y+1) != c2) &&
         (*x+*w+1 <= bmp->w))
    (*w)++;

  /* look for bottom edge of character */
  *h = 0;
  while ((getpixel(bmp, *x, *y+*h+1) == c2) &&
         (getpixel(bmp, *x+1, *y+*h+1) != c2) &&
         (*y+*h+1 <= bmp->h))
    (*h)++;
}
inline int to_allegro(int color_depth, gfx::Color color)
{
  if (color_depth == 32) {
    return makeacol32(
      gfx::getr(color), gfx::getg(color), gfx::getb(color), gfx::geta(color));
  }
  else {
    if (gfx::is_transparent(color))
      return -1;
    else
      return makecol_depth(color_depth, gfx::getr(color), gfx::getg(color), gfx::getb(color));
  }
}
Exemple #4
0
/*
 * Translate a string into a color. Dealing correctly with the number of
 * colors from the GFX mode.
 */
int color_grc_to_al(int color_depth, const char *color_name)
{
    struct color *c = NULL;
    unsigned int i;

    for (i = 0; i < MAX_COLORS; i++)
        if (!strcmp(__colors[i].name, color_name)) {
            c = &__colors[i];
            break;
        }

    if (NULL == c)
        return -1;

    return makecol_depth(color_depth, c->rgb.r, c->rgb.g, c->rgb.b);
}
Exemple #5
0
/**
	fade.c - High Color Fading Routines

	Last Revision: 21 June, 2002

	Author: Matthew Leverton
**/
void ALSoftwareGraphicsDriver::highcolor_fade_in(BITMAP *currentVirtScreen, int speed, int targetColourRed, int targetColourGreen, int targetColourBlue)
{
    BITMAP *bmp_buff;
    BITMAP *bmp_orig = currentVirtScreen;

    if ((_global_y_offset != 0) || (_global_x_offset != 0))
    {
        bmp_orig = create_bitmap(_screenWidth, _screenHeight);
        clear(bmp_orig);
        blit(currentVirtScreen, bmp_orig, 0, 0, _global_x_offset, _global_y_offset, currentVirtScreen->w, currentVirtScreen->h);
    }

    bmp_buff = create_bitmap(bmp_orig->w, bmp_orig->h);
    int clearColor = makecol_depth(bitmap_color_depth(bmp_buff),
                                   targetColourRed, targetColourGreen, targetColourBlue);

    int a;
    if (speed <= 0) speed = 16;

    for (a = 0; a < 256; a+=speed)
    {
        int timerValue = *_loopTimer;
        clear_to_color(bmp_buff, clearColor);
        set_trans_blender(0,0,0,a);
        draw_trans_sprite(bmp_buff, bmp_orig, 0, 0);
        this->Vsync();
        _filter->RenderScreen(bmp_buff, 0, 0);
        do
        {
            if (_callback)
                _callback();
            Sleep(1);
        }
        while (timerValue == *_loopTimer);
    }
    destroy_bitmap(bmp_buff);

    _filter->RenderScreen(currentVirtScreen, _global_x_offset, _global_y_offset);

    if ((_global_y_offset != 0) || (_global_x_offset != 0))
        destroy_bitmap(bmp_orig);
}
Exemple #6
0
void ALSoftwareGraphicsDriver::highcolor_fade_out(int speed, int targetColourRed, int targetColourGreen, int targetColourBlue)
{
    BITMAP *bmp_orig, *bmp_buff;

    int clearColor = makecol_depth(bitmap_color_depth(screen),
                                   targetColourRed, targetColourGreen, targetColourBlue);

    if ((bmp_orig = create_bitmap(_screenWidth, _screenHeight)))
    {
        if ((bmp_buff = create_bitmap(bmp_orig->w, bmp_orig->h)))
        {
            int a;
            _filter->GetCopyOfScreenIntoBitmap(bmp_orig, false);
            if (speed <= 0) speed = 16;

            for (a = 255-speed; a > 0; a-=speed)
            {
                int timerValue = *_loopTimer;
                clear_to_color(bmp_buff, clearColor);
                set_trans_blender(0,0,0,a);
                draw_trans_sprite(bmp_buff, bmp_orig, 0, 0);
                this->Vsync();
                _filter->RenderScreen(bmp_buff, 0, 0);
                do
                {
                    if (_callback)
                        _callback();
                    Sleep(1);
                }
                while (timerValue == *_loopTimer);
            }
            destroy_bitmap(bmp_buff);
        }
        destroy_bitmap(bmp_orig);
    }

    clear_to_color(screen, clearColor);
    _filter->RenderScreen(screen, _global_x_offset, _global_y_offset);
}
Exemple #7
0
int Init_2xSaI(int d)
{

	int minr = 0, ming = 0, minb = 0;
	int i;
	
//	if (d != 15 && d != 16 && d != 24 && d != 32)
//		return -1;

	/* Get lowest color bit */	
	for (i = 0; i < 255; i++) {
		if (!minr)
			minr = makecol(i, 0, 0);
		if (!ming)
			ming = makecol(0, i, 0);
		if (!minb)
			minb = makecol(0, 0, i);
	}

	colorMask = (makecol_depth(d, 255, 0, 0) - minr) | (makecol_depth(d, 0, 255, 0) - ming) | (makecol_depth(d, 0, 0, 255) - minb);
	lowPixelMask = minr | ming | minb;
	qcolorMask = (makecol_depth(d, 255, 0, 0) - 3 * minr) | (makecol_depth(d, 0, 255, 0) - 3 * ming) | (makecol_depth(d, 0, 0, 255) - 3 * minb);
	qlowpixelMask = (minr * 3) | (ming * 3) | (minb * 3);
	redblueMask = makecol_depth(d, 255, 0, 255);
	greenMask = makecol_depth(d, 0, 255, 0);

	PixelsPerMask = (d <= 16) ? 2 : 1;
	
	if (PixelsPerMask == 2) {
		colorMask |= (colorMask << 16);
		qcolorMask |= (qcolorMask << 16);
		lowPixelMask |= (lowPixelMask << 16);
		qlowpixelMask |= (qlowpixelMask << 16);
	}

//	TRACE("Color Mask:       0x%lX\n", colorMask);
//	TRACE("Low Pixel Mask:   0x%lX\n", lowPixelMask);
//	TRACE("QColor Mask:      0x%lX\n", qcolorMask);
//	TRACE("QLow Pixel Mask:  0x%lX\n", qlowpixelMask);
	
	xsai_depth = d;

	return 0;
}
Exemple #8
0
/* makecol:
 *  Converts R, G, and B values (ranging 0-255) to whatever pixel format
 *  is required by the current video mode.
 */
int makecol(int r, int g, int b)
{
   return makecol_depth(_color_depth, r, g, b);
}
Exemple #9
0
bool PaletteView::onProcessMessage(Message* msg)
{
  switch (msg->type) {

    case JM_REQSIZE:
      request_size(&msg->reqsize.w, &msg->reqsize.h);
      return true;

    case JM_DRAW: {
      div_t d = div(Palette::MaxColors, m_columns);
      int cols = m_columns;
      int rows = d.quot + ((d.rem)? 1: 0);
      int x, y, u, v;
      int c, color;
      BITMAP *bmp;
      Palette* palette = get_current_palette();
      int bordercolor = makecol(255, 255, 255);

      bmp = create_bitmap(jrect_w(this->rc), jrect_h(this->rc));
      clear_to_color(bmp, makecol(0 , 0, 0));

      y = this->border_width.t;
      c = 0;

      for (v=0; v<rows; v++) {
        x = this->border_width.l;

        for (u=0; u<cols; u++) {
          if (c >= palette->size())
            break;

          if (bitmap_color_depth(ji_screen) == 8)
            color = c;
          else
            color = makecol_depth
              (bitmap_color_depth(ji_screen),
               _rgba_getr(palette->getEntry(c)),
               _rgba_getg(palette->getEntry(c)),
               _rgba_getb(palette->getEntry(c)));

          rectfill(bmp, x, y, x+m_boxsize-1, y+m_boxsize-1, color);

          if (m_selectedEntries[c]) {
            const int max = Palette::MaxColors;
            bool top    = (c >= m_columns            && c-m_columns >= 0  ? m_selectedEntries[c-m_columns]: false);
            bool bottom = (c < max-m_columns         && c+m_columns < max ? m_selectedEntries[c+m_columns]: false);
            bool left   = ((c%m_columns)>0           && c-1         >= 0  ? m_selectedEntries[c-1]: false);
            bool right  = ((c%m_columns)<m_columns-1 && c+1         < max ? m_selectedEntries[c+1]: false);

            if (!top) hline(bmp, x-1, y-1, x+m_boxsize, bordercolor);
            if (!bottom) hline(bmp, x-1, y+m_boxsize, x+m_boxsize, bordercolor);
            if (!left) vline(bmp, x-1, y-1, y+m_boxsize, bordercolor);
            if (!right) vline(bmp, x+m_boxsize, y-1, y+m_boxsize, bordercolor);
          }

          x += m_boxsize+this->child_spacing;
          c++;
        }

        y += m_boxsize+this->child_spacing;
      }

      blit(bmp, ji_screen,
           0, 0, this->rc->x1, this->rc->y1, bmp->w, bmp->h);
      destroy_bitmap(bmp);
      return true;
    }

    case JM_BUTTONPRESSED:
      captureMouse();
      /* continue... */

    case JM_MOTION: {
      JRect cpos = jwidget_get_child_rect(this);

      int req_w, req_h;
      request_size(&req_w, &req_h);

      int mouse_x = MID(cpos->x1, msg->mouse.x, cpos->x1+req_w-this->border_width.r-1);
      int mouse_y = MID(cpos->y1, msg->mouse.y, cpos->y1+req_h-this->border_width.b-1);

      jrect_free(cpos);

      Color color = getColorByPosition(mouse_x, mouse_y);
      if (color.getType() == Color::IndexType) {
        int idx = color.getIndex();

        app_get_statusbar()->showColor(0, "", color, 255);

        if (hasCapture() && idx != m_currentEntry) {
          if (!(msg->any.shifts & KB_CTRL_FLAG))
            clearSelection();

          if (msg->any.shifts & KB_SHIFT_FLAG)
            selectRange(m_rangeAnchor, idx);
          else
            selectColor(idx);

          // Emit signals
          jwidget_emit_signal(this, SIGNAL_PALETTE_EDITOR_CHANGE);
          IndexChange(idx);
        }
      }

      if (hasCapture())
        return true;

      break;
    }

    case JM_BUTTONRELEASED:
      releaseMouse();
      return true;

    case JM_WHEEL: {
      View* view = View::getView(this);
      if (view) {
        gfx::Point scroll = view->getViewScroll();
        scroll.y += (jmouse_z(1)-jmouse_z(0)) * 3 * m_boxsize;
        view->setViewScroll(scroll);
      }
      break;
    }

    case JM_MOUSELEAVE:
      app_get_statusbar()->clearText();
      break;

  }

  return Widget::onProcessMessage(msg);
}