Пример #1
0
IBitmap IGraphicsLice::LoadIBitmap(int ID, const char* name, int nStates)
{
  LICE_IBitmap* lb = s_bitmapCache.Find(ID); 
  if (!lb)
  {
    lb = OSLoadBitmap(ID, name);
    bool imgResourceFound = (lb);
    assert(imgResourceFound); // Protect against typos in resource.h and .rc files.
    s_bitmapCache.Add(lb, ID);
  }
  return IBitmap(lb, lb->getWidth(), lb->getHeight(), nStates);
}
Пример #2
0
IBitmap IGraphics::LoadIBitmap(int ID, const char* name, int nStates, bool framesAreHoriztonal)
{
  LICE_IBitmap* lb = s_bitmapCache.Find(ID);
  if (!lb)
  {
    lb = OSLoadBitmap(ID, name);
    #ifndef NDEBUG
    bool imgResourceFound = lb;
    #endif
    assert(imgResourceFound); // Protect against typos in resource.h and .rc files.
    s_bitmapCache.Add(lb, ID);
  }
  return IBitmap(lb, lb->getWidth(), lb->getHeight(), nStates, framesAreHoriztonal);
}
Пример #3
0
void WDL_VirtualIconButton_PreprocessSkinConfig(WDL_VirtualIconButton_SkinConfig *a)
{
  if (a && a->image)
  {
    a->image_ltrb_used.flags=0;
    int wi;
    for(wi=0;wi<2;wi++)
    {
      LICE_IBitmap *srcimg = wi ? a->image : a->olimage;
      if (!srcimg) continue;
      int w=srcimg->getWidth();
      int h=srcimg->getHeight();

      if (LICE_GetPixel(srcimg,0,0)==LICE_RGBA(255,0,255,255)&&
          LICE_GetPixel(srcimg,w-1,h-1)==LICE_RGBA(255,0,255,255))
      {
        int lext=0,rext=0,bext=0,text=0;
        int x;
        for (x = 1; x < w/3 && LICE_GetPixel(srcimg,x,0)==LICE_RGBA(255,0,255,255); x ++);
        lext=x-1;
        for (x = 1; x < h && LICE_GetPixel(srcimg,0,x)==LICE_RGBA(255,0,255,255); x ++);
        text=x-1;

        for (x = w-2; x >= (w*2/3) && LICE_GetPixel(srcimg,x,h-1)==LICE_RGBA(255,0,255,255); x --);
        rext=w-2-x;
        for (x = h-2; x >= text && LICE_GetPixel(srcimg,w-1,x)==LICE_RGBA(255,0,255,255); x --);
        bext=h-2-x;
        if (lext||text||rext||bext)
        {
          a->image_ltrb_used.flags |= 1 << wi;
          short *buf = wi ? a->image_ltrb_main : a->image_ltrb_ol;
          buf[0]=lext;
          buf[1]=text;
          buf[2]=rext;
          buf[3]=bext;
        }
      }
    }
  }
}
Пример #4
0
bool SNM_AddLogo(LICE_IBitmap* _bm, const RECT* _r, int _x, int _h)
{
	LICE_IBitmap* logo = SNM_GetThemeLogo();
	if (_bm && logo && _r)
	{
		// top right display (if no overlap with left controls)
		if (_x>=0 && _h>=0)
		{
			if ((_x+logo->getWidth()) < (_r->right+SNM_GUI_X_MARGIN_LOGO))
			{
				int y = _r->top + int(_h/2 - logo->getHeight()/2 + 0.5);
				LICE_Blit(_bm,logo,_r->right-(logo->getWidth()+SNM_GUI_X_MARGIN_LOGO),y,NULL,0.125f,LICE_BLIT_MODE_ADD|LICE_BLIT_USE_ALPHA);
				return true;
			}
		}
		// bottom right display
		else if (((_r->right-_r->left)-SNM_GUI_X_MARGIN_LOGO) > logo->getWidth() && (_r->bottom-_r->top-SNM_GUI_Y_MARGIN_LOGO) > logo->getHeight()) {
			LICE_Blit(_bm,logo,_r->right-(logo->getWidth()+SNM_GUI_X_MARGIN_LOGO),_r->bottom-_r->top-logo->getHeight()-SNM_GUI_Y_MARGIN_LOGO,NULL,0.125f,LICE_BLIT_MODE_ADD|LICE_BLIT_USE_ALPHA);
			return true;
		}
	}
	return false;
}
Пример #5
0
LICE_IBitmap *LICE_LoadPCX(const char *filename, LICE_IBitmap *_bmp)
{
  FILE *fp = fopen(filename,"rb");
  if(!fp) return 0;

  fgetc(fp);
  if (fgetc(fp) != 5) { fclose(fp); return NULL; }
  if (fgetc(fp) != 1) { fclose(fp); return NULL; }
  if (fgetc(fp) != 8) { fclose(fp); return NULL; }

  int sx = fgetc(fp); sx += fgetc(fp)<<8;
  int sy = fgetc(fp); sy += fgetc(fp)<<8;
  int ex = fgetc(fp); ex += fgetc(fp)<<8;
  int ey = fgetc(fp); ey += fgetc(fp)<<8;


  unsigned char pal[768];
  fseek(fp,-769,SEEK_END);
  if (fgetc(fp) != 12) { fclose(fp); return NULL; }
  fread(pal,1,768,fp);
  if (feof(fp)) { fclose(fp); return NULL; }


  LICE_IBitmap *usebmp = NULL;
  if (_bmp) (usebmp=_bmp)->resize(ex-sx+1,ey-sy+1);
  else usebmp = new LICE_MemBitmap(ex-sx+1,ey-sy+1);

  fseek(fp,128,SEEK_SET);

  LICE_Clear(usebmp,0);
  int y = usebmp->getHeight();
  int w = usebmp->getWidth();
  int rowspan = usebmp->getRowSpan();
  LICE_pixel *pout = usebmp->getBits();
  if (usebmp->isFlipped())
  {
    pout += rowspan*(y-1);
    rowspan=-rowspan;
  }
  while (y--)
  {
    int xpos = 0;
    while (xpos < w)
    {
      int c = fgetc(fp);
      if (c&~255) break;
      if ((c & 192) == 192) 
      {
        int oc = (fgetc(fp))&255;
        LICE_pixel t=LICE_RGBA(pal[oc*3],pal[oc*3+1],pal[oc*3+2],255);

        c&=63;
        while (c-- && xpos<w) pout[xpos++] =  t;
      } 
      else pout[xpos++] = LICE_RGBA(pal[c*3],pal[c*3+1],pal[c*3+2],255);
    } 
    pout+=rowspan;
  }

  return usebmp;
}
Пример #6
0
int DrawText(HDC ctx, const char *buf, int buflen, RECT *r, int align)
{
  const char *obuf=buf;
  HDC__ *ct=(HDC__ *)ctx;
  if (!r) return 0;

  int lineh = 8;
  int charw = 8;

  HGDIOBJ__  *font  = NULL;
#ifdef SWELL_FREETYPE
  int ascent=0;
  font  = HDC_VALID(ct) && HGDIOBJ_VALID(ct->curfont,TYPE_FONT) ? ct->curfont : SWELL_GetDefaultFont();
  FT_Face face = NULL;
  if (font && font->fontface) 
  {
    face=(FT_Face)font->fontface;
    lineh = face->size->metrics.height/64;
    ascent = face->size->metrics.ascender/64;
    charw = face->size->metrics.max_advance/64;
  }
#endif

  if (align&DT_CALCRECT)
  {
    if (!font && (align&DT_SINGLELINE))
    {
      r->right = r->left + ( buflen < 0 ? strlen(buf) : buflen ) * charw;
      int h = r->right ? lineh:0;
      r->bottom = r->top+h;
      return h;
    }

    int xpos=0;
    int ypos=0;

    r->bottom=r->top;
    bool in_prefix=false;
    while (buflen && *buf) // if buflen<0, go forever
    {
      unsigned short c=0;
      int charlen = utf8char(buf,&c);
      buf+=charlen;
      if (buflen > 0) 
      {
        buflen -= charlen;
        if (buflen < 0) buflen=0;
      }
      if (!c) break;

      if (c=='&' && !in_prefix && !(align&DT_NOPREFIX)) 
      {
        in_prefix = true;
        continue;
      }
      in_prefix=false;
 
      if (c == '\n') { ypos += lineh; xpos=0; }
      else if (c != '\r')
      {
        if (font)
        {
#ifdef SWELL_FREETYPE
          if (!FT_Load_Char(face, c, FT_LOAD_DEFAULT) && face->glyph)
          {
            // measure character
            FT_GlyphSlot g = face->glyph;
            int rext = xpos + (g->metrics.width + g->metrics.horiBearingX)/64;
            if (rext<=xpos) rext=xpos + g->metrics.horiAdvance/64;
            if (r->left+rext > r->right) r->right = r->left+rext;
            xpos += g->metrics.horiAdvance/64;

            int bext = r->top + ypos + lineh; // ascent + (g->metrics.height - g->metrics.horiBearingY)/64;
            if (bext > r->bottom) r->bottom = bext;
            continue;
          }
        }
#endif
        xpos += c=='\t' ? charw*5 : charw;
        if (r->top + ypos + lineh > r->bottom) r->bottom = r->top+ypos+lineh;
        if (r->left+xpos>r->right) r->right=r->left+xpos;
      }
    }
    return r->bottom-r->top;
  }
  if (!HDC_VALID(ct)) return 0;

  RECT use_r = *r;
  use_r.left += ct->surface_offs.x;
  use_r.right += ct->surface_offs.x;
  use_r.top += ct->surface_offs.y;
  use_r.bottom += ct->surface_offs.y;

  int xpos = use_r.left;
  int ypos = use_r.top;
  if (align&(DT_CENTER|DT_VCENTER|DT_RIGHT|DT_BOTTOM))
  {
    RECT tr={0,};
    DrawText(ctx,buf,buflen,&tr,align|DT_CALCRECT);

    if (align&DT_CENTER)
      xpos -= ((tr.right-tr.left) - (use_r.right-use_r.left))/2;
    else if (align&DT_RIGHT)
      xpos = use_r.right - (tr.right-tr.left);

    if (align&DT_VCENTER)
      ypos -= ((tr.bottom-tr.top) - (use_r.bottom-use_r.top))/2;
    else if (align&DT_BOTTOM)
      ypos = use_r.bottom - (tr.bottom-tr.top);
  }
  LICE_IBitmap *surface = ct->surface;
  int fgcol = ct->cur_text_color_int;
  int bgcol = ct->curbkcol;
  int bgmode = ct->curbkmode;


  int clip_x1=wdl_max(use_r.left,0), clip_y1 = wdl_max(use_r.top,0);
  int clip_w=0, clip_h=0;
  if (surface)
  {
    clip_w = wdl_min(use_r.right,surface->getWidth())-clip_x1;
    clip_h = wdl_min(use_r.bottom,surface->getHeight())-clip_y1;
    if (clip_w<0)clip_w=0;
    if (clip_h<0)clip_h=0;
  }

  LICE_SubBitmap clipbm(surface,clip_x1,clip_y1,clip_w,clip_h);
  if (surface && !(align&DT_NOCLIP)) { surface = &clipbm; xpos-=clip_x1; ypos-=clip_y1; }

  int left_xpos = xpos,ysize=0,max_xpos=0;
  int start_ypos = ypos;
  bool in_prefix=false;

  while (buflen && *buf)
  {
    unsigned short c=0;
    int  charlen = utf8char(buf,&c);
    if (buflen>0)
    {
      buflen -= charlen;
      if (buflen<0) buflen=0;
    }
    buf+=charlen;

    bool doUl=in_prefix;

    if (c=='&' && !in_prefix && !(align&DT_NOPREFIX)) 
    {
      in_prefix = true;
      continue;
    }
    in_prefix=false;

    if (c=='\n' && !(align&DT_SINGLELINE)) { xpos=left_xpos; ypos+=lineh; }
    else if (c=='\r')  {} 
    else 
    {
      bool needr=true;
      if (font)
      {
#ifdef SWELL_FREETYPE
        if (!FT_Load_Char(face, c, FT_LOAD_RENDER) && face->glyph)
        {
          FT_GlyphSlot g = face->glyph;
          if (bgmode==OPAQUE) LICE_FillRect(surface,xpos,ypos,g->metrics.horiAdvance/64,lineh,bgcol,1.0f,LICE_BLIT_MODE_COPY);
  
          LICE_DrawGlyphEx(surface,xpos+g->bitmap_left,ypos+ascent-g->bitmap_top,fgcol,(LICE_pixel_chan *)g->bitmap.buffer,g->bitmap.width,g->bitmap.pitch,g->bitmap.rows,1.0f,LICE_BLIT_MODE_COPY);
  
          int rext = xpos + (g->metrics.width + g->metrics.horiBearingX)/64;
          if (rext<=xpos) rext=xpos + g->metrics.horiAdvance/64;
          if (rext > max_xpos) max_xpos=rext;
          xpos += g->metrics.horiAdvance/64;
          int bext = ypos + lineh; // +  (g->metrics.height - g->metrics.horiBearingY)/64;
          if (ysize < bext) ysize=bext;
          needr=false;
        }
#endif
      }

      if (needr)
      {
        if (c=='\t') 
        {
          if (bgmode==OPAQUE) LICE_FillRect(surface,xpos,ypos,charw*5,lineh,bgcol,1.0f,LICE_BLIT_MODE_COPY);
          xpos+=charw*5;
          if (ysize < ypos+lineh) ysize=ypos+lineh;
        }
        else 
        {
          if (bgmode==OPAQUE) LICE_FillRect(surface,xpos,ypos,charw,lineh,bgcol,1.0f,LICE_BLIT_MODE_COPY);
          LICE_DrawChar(surface,xpos,ypos,c,fgcol,1.0f,LICE_BLIT_MODE_COPY);
          if (doUl) LICE_Line(surface,xpos,ypos+lineh+1,xpos+charw,ypos+lineh+1,fgcol,1.0f,LICE_BLIT_MODE_COPY,false);
  
          if (ysize < ypos+lineh+(doUl ? 2:1)) ysize=ypos+lineh+(doUl ? 2:1);
          xpos+=charw;
        }
      }
    }
    if(xpos>max_xpos)max_xpos=xpos;
  }
  if (surface==&clipbm)
    swell_DirtyContext(ct,clip_x1+left_xpos,clip_y1+start_ypos,clip_x1+max_xpos,clip_y1+start_ypos+ysize);
  else
    swell_DirtyContext(ct,left_xpos,start_ypos,max_xpos,start_ypos+ysize);
  return ysize;
}