コード例 #1
0
void SWELL_FillRect(HDC ctx, const RECT *r, HBRUSH br)
{
  HDC__ *c=(HDC__ *)ctx;
  HGDIOBJ__ *b=(HGDIOBJ__ *) br;
  if (!HDC_VALID(c) || !HGDIOBJ_VALID(b,TYPE_BRUSH)) return;
  if (!c->surface) return;

  if (b->wid<0) return;
  LICE_FillRect(c->surface,
      r->left+c->surface_offs.x,
      r->top+c->surface_offs.y,
      r->right-r->left,r->bottom-r->top,b->color,b->alpha,LICE_BLIT_MODE_COPY);
  swell_DirtyContext(ctx,r->left,r->top,r->right,r->bottom);
}
コード例 #2
0
ファイル: SnM_VWnd.cpp プロジェクト: Breeder/sws
void SNM_TinyTickBox::OnPaint(LICE_IBitmap *drawbm, int origin_x, int origin_y, RECT *cliprect)
{
	RECT r = m_position;
	r.left += origin_x;
	r.right += origin_x;
	r.top += origin_y;
	r.bottom += origin_y;

	ColorTheme* ct = SNM_GetColorTheme();
	int col = ct ? LICE_RGBA_FROMNATIVE(ct->main_text,255) : LICE_RGBA(255,255,255,255);
	float alpha = m_en ? 0.8f : 0.4f;

	// border
	LICE_Line(drawbm,r.left,r.bottom-1,r.left,r.top,col,alpha,0,false);
	LICE_Line(drawbm,r.left,r.top,r.right-1,r.top,col,alpha,0,false);
	LICE_Line(drawbm,r.right-1,r.top,r.right-1,r.bottom-1,col,alpha,0,false);
	LICE_Line(drawbm,r.left,r.bottom-1,r.right-1,r.bottom-1,col,alpha,0,false);

	if (m_checkstate)
		LICE_FillRect(drawbm, r.left+2, r.top+2, r.right-r.left-4, r.bottom-r.top-4, col, alpha);
}
コード例 #3
0
void Rectangle(HDC ctx, int l, int t, int r, int b)
{
  HDC__ *c=(HDC__ *)ctx;
  if (!HDC_VALID(c)) return;
  
  //CGRect rect=CGRectMake(l,t,r-l,b-t);

  swell_DirtyContext(ctx,l,t,r,b);
  
  l += c->surface_offs.x;
  t += c->surface_offs.y;
  r += c->surface_offs.x;
  b += c->surface_offs.y;

  if (HGDIOBJ_VALID(c->curbrush,TYPE_BRUSH) && c->curbrush->wid >= 0)
  {
    LICE_FillRect(c->surface,l,t,r-l,b-t,c->curbrush->color,c->curbrush->alpha,LICE_BLIT_MODE_COPY);
  }
  if (HGDIOBJ_VALID(c->curpen,TYPE_PEN) && c->curpen->wid >= 0)
  {
    LICE_DrawRect(c->surface,l,t,r-l,b-t,c->curpen->color,c->curpen->alpha,LICE_BLIT_MODE_COPY);
  }
}
コード例 #4
0
ファイル: virtwnd-iconbutton.cpp プロジェクト: Artogn/licecap
void WDL_VirtualStaticText::OnPaint(LICE_IBitmap *drawbm, int origin_x, int origin_y, RECT *cliprect)
{
  RECT r=m_position;
  r.left+=origin_x;
  r.right+=origin_x;
  r.top += origin_y;
  r.bottom += origin_y;

  if (m_bkbm && m_bkbm->bgimage)
  {
    WDL_VirtualWnd_ScaledBlitBG(drawbm,m_bkbm,
      r.left,r.top,r.right-r.left,r.bottom-r.top,
      r.left,r.top,r.right-r.left,r.bottom-r.top,
      1.0,LICE_BLIT_MODE_COPY|LICE_BLIT_FILTER_BILINEAR|LICE_BLIT_USE_ALPHA);

    if (m_dotint && LICE_GETA(m_bg)) 
    {
        float amt = LICE_GETA(m_bg)/255.0f;

        // todo: apply amt

        float rv=LICE_GETR(m_bg)/255.0f;
        float gv=LICE_GETG(m_bg)/255.0f;
        float bv=LICE_GETB(m_bg)/255.0f;

        float avg=(rv+gv+bv)*0.33333f;
        if (avg<0.05f)avg=0.05f;

        float sc=0.5f*amt;
        float sc2 = (amt-sc)/avg;

        float sc3=32.0f * amt;
        float sc4=64.0f*(avg-0.5f) * amt;

        // tint
        LICE_MultiplyAddRect(drawbm,
          r.left,r.top,
            r.right-r.left,
            r.bottom-r.top,
            sc+rv*sc2 + (1.0f-amt),
            sc+gv*sc2 + (1.0f-amt),
            sc+bv*sc2 + (1.0f-amt),
            1.0f,
            (rv-avg)*sc3+sc4,
            (gv-avg)*sc3+sc4,
            (bv-avg)*sc3+sc4,
            0.0f);
    }
  }
  else 
  {
    if (LICE_GETA(m_bg))
    {
      LICE_FillRect(drawbm,r.left,r.top,r.right-r.left,r.bottom-r.top,m_bg,LICE_GETA(m_bg)/255.0f,LICE_BLIT_MODE_COPY);
    }

    if (m_wantborder)
    {    
      int cidx=COLOR_3DSHADOW;

      int pencol = GSC(cidx);
      pencol = LICE_RGBA_FROMNATIVE(pencol,255);

      LICE_Line(drawbm,r.left,r.bottom-1,r.left,r.top,pencol,1.0f,LICE_BLIT_MODE_COPY,false);
      LICE_Line(drawbm,r.left,r.top,r.right-1,r.top,pencol,1.0f,LICE_BLIT_MODE_COPY,false);
      cidx=COLOR_3DHILIGHT;
      pencol = GSC(cidx);
      pencol = LICE_RGBA_FROMNATIVE(pencol,255);
      LICE_Line(drawbm,r.right-1,r.top,r.right-1,r.bottom-1,pencol,1.0f,LICE_BLIT_MODE_COPY,false);
      LICE_Line(drawbm,r.right-1,r.bottom-1,r.left,r.bottom-1,pencol,1.0f,LICE_BLIT_MODE_COPY,false);

      r.left++;
      r.bottom--;
      r.top++;
      r.right--;

    }
  }

  if (m_text.Get()[0])
  {
    r.left += m_margin_l;
    r.right -= m_margin_r;
    r.top += m_margin_t;
    r.bottom -= m_margin_b;

    m_didvert=m_vfont && (r.right-r.left)<(r.bottom-r.top)/2;
    LICE_IFont *font = m_didvert ? m_vfont : m_font;

    if (font)
    {
      font->SetBkMode(TRANSPARENT);    

      m_didalign=m_align;
      if (m_didalign==0)
      {
        RECT r2={0,0,0,0};
        font->DrawText(drawbm,m_text.Get(),-1,&r2,DT_SINGLELINE|DT_NOPREFIX|DT_CALCRECT);
        if (m_didvert)
        {
         if (r2.bottom > r.bottom-r.top) m_didalign=-1;
        }
        else
        {
          if (r2.right > r.right-r.left) m_didalign=-1;
        }
      }

      int dtflags=DT_SINGLELINE|DT_NOPREFIX;

      if (m_didvert)
      {
        dtflags |= DT_CENTER;
        if (m_didalign < 0) dtflags |= DT_TOP;
        else if (m_didalign > 0) dtflags |= DT_BOTTOM;
        else dtflags |= DT_VCENTER;
      }
      else
      {
        dtflags|=DT_VCENTER;

        if (m_didalign < 0) dtflags |= DT_LEFT;
        else if (m_didalign > 0) dtflags |= DT_RIGHT;
        else dtflags |= DT_CENTER;
      }
      const char* txt=m_text.Get();
      const int len = m_text.GetLength();

      int abbrx=0;
      char abbrbuf[64];
      abbrbuf[0]=0;

      if (m_wantabbr)
      {
        if (len && isdigit(txt[len-1]))
        {
          RECT tr = { 0, 0, 0, 0 };
          font->DrawText(drawbm, txt, -1, &tr, DT_SINGLELINE|DT_NOPREFIX|DT_CALCRECT);
          if (m_didvert ? (tr.bottom > r.bottom-r.top) : (tr.right > r.right-r.left))
          {
            strcpy(abbrbuf, "..");
            int i;
            for (i=len-1; i >= 0; --i)
            {
              if (!isdigit(txt[i]) || len-i > 4) break;
            }
            strcat(abbrbuf, txt+i+1);

            int f=dtflags&~(DT_TOP|DT_VCENTER|DT_BOTTOM|DT_LEFT|DT_CENTER|DT_RIGHT);
            RECT tr2 = { 0, 0, 0, 0 };
            if (m_didvert)
            {
              font->DrawText(drawbm, abbrbuf, -1, &tr2, f|DT_CALCRECT);
              abbrx=tr2.bottom;
            }
            else
            {
              font->DrawText(drawbm, abbrbuf, -1, &tr2, f|DT_CALCRECT);
              abbrx=tr2.right;
            }
          }
        }
      }

      int tcol=m_fg ? m_fg : LICE_RGBA_FROMNATIVE(GSC(COLOR_BTNTEXT));
      font->SetTextColor(tcol);
      if (m_fg && LICE_GETA(m_fg) != 0xff) font->SetCombineMode(LICE_BLIT_MODE_COPY,LICE_GETA(m_fg)/255.0f);

      if (abbrx && abbrbuf[0])
      {
        if (m_didvert)
        {
          int f=dtflags&~(DT_TOP|DT_VCENTER|DT_BOTTOM);
          RECT r1 = { r.left, r.top, r.right, r.bottom-abbrx };
          font->DrawText(drawbm, txt, -1, &r1, f|DT_TOP);
          RECT r2 = { r.left, r.bottom-abbrx, r.right, r.bottom };
          font->DrawText(drawbm, abbrbuf, -1, &r2, f|DT_BOTTOM);
        }
        else
        {
          int f=dtflags&~(DT_LEFT|DT_CENTER|DT_RIGHT);
          RECT r1 = { r.left, r.top, r.right-abbrx, r.bottom };
          font->DrawText(drawbm, txt, -1, &r1, f|DT_LEFT);
          RECT r2 = { r.right-abbrx, r.top, r.right, r.bottom };
          font->DrawText(drawbm, abbrbuf, -1, &r2, f|DT_RIGHT);
        }
      }
      else
      {
        font->DrawText(drawbm,txt,-1,&r,dtflags);
      }

      if (m_fg && LICE_GETA(m_fg) != 0xff) font->SetCombineMode(LICE_BLIT_MODE_COPY,1.0f);
    }


  }
  WDL_VWnd::OnPaint(drawbm,origin_x,origin_y,cliprect);
}
コード例 #5
0
ファイル: virtwnd-iconbutton.cpp プロジェクト: Artogn/licecap
void WDL_VirtualComboBox::OnPaint(LICE_IBitmap *drawbm, int origin_x, int origin_y, RECT *cliprect)
{
  {
    if (m_font) m_font->SetBkMode(TRANSPARENT);

    RECT r=m_position;
    r.left+=origin_x;
    r.right+=origin_x;
    r.top+=origin_y;
    r.bottom+=origin_y;

    int col=GSC(COLOR_WINDOW);
    col = LICE_RGBA_FROMNATIVE(col,255);
    LICE_FillRect(drawbm,r.left,r.top,r.right-r.left,r.bottom-r.top,col,1.0f,LICE_BLIT_MODE_COPY);

    {
      RECT tr=r;
      tr.left=tr.right-(tr.bottom-tr.top);
      //int col2=GSC(COLOR_BTNFACE);
    //  col2 = LICE_RGBA_FROMNATIVE(col2,255);

      LICE_FillRect(drawbm,tr.left,tr.top,tr.right-tr.left,tr.bottom-tr.top,col,1.0f,LICE_BLIT_MODE_COPY);
    }
    

    int tcol=GSC(COLOR_BTNTEXT);
    tcol=LICE_RGBA_FROMNATIVE(tcol,255);
    if (m_font && m_items.Get(m_curitem)&&m_items.Get(m_curitem)[0])
    {
      RECT tr=r;
      tr.left+=2;
      tr.right-=16;
      m_font->SetTextColor(tcol);
      if (m_align == 0)
      {
        RECT r2={0,};
        m_font->DrawText(drawbm,m_items.Get(m_curitem),-1,&tr,DT_SINGLELINE|DT_CALCRECT|DT_NOPREFIX);
        m_font->DrawText(drawbm,m_items.Get(m_curitem),-1,&tr,DT_SINGLELINE|DT_VCENTER|(r2.right < tr.right-tr.left ? DT_CENTER : DT_LEFT)|DT_NOPREFIX);
      }
      else
        m_font->DrawText(drawbm,m_items.Get(m_curitem),-1,&tr,DT_SINGLELINE|DT_VCENTER|(m_align<0?DT_LEFT:DT_RIGHT)|DT_NOPREFIX);
    }


    // pen3=tcol
    int pencol = GSC(COLOR_3DSHADOW);
    pencol = LICE_RGBA_FROMNATIVE(pencol,255);
    int pencol2 = GSC(COLOR_3DHILIGHT);
    pencol2 = LICE_RGBA_FROMNATIVE(pencol2,255);

    // draw the down arrow button
    {
      int bs=(r.bottom-r.top);
      int l=r.right-bs;

      int a=(bs/4)&~1;

      LICE_Line(drawbm,l,r.top,l,r.bottom-1,pencol,1.0f,LICE_BLIT_MODE_COPY,false);
      LICE_Line(drawbm,l-1,r.top,l-1,r.bottom-1,pencol2,1.0f,LICE_BLIT_MODE_COPY,false);

      LICE_Line(drawbm,l+bs/2-a,r.top+bs/2-a/2,
                       l+bs/2,r.top+bs/2+a/2,tcol,1.0f,LICE_BLIT_MODE_COPY,true);
      LICE_Line(drawbm,l+bs/2,r.top+bs/2+a/2,
                       l+bs/2+a,r.top+bs/2-a/2, tcol,1.0f,LICE_BLIT_MODE_COPY,true);
    }

   

    // draw the border
    LICE_Line(drawbm,r.left,r.bottom-1,r.left,r.top,pencol,1.0f,0,false);
    LICE_Line(drawbm,r.left,r.top,r.right-1,r.top,pencol,1.0f,0,false);
    LICE_Line(drawbm,r.right-1,r.top,r.right-1,r.bottom-1,pencol2,1.0f,0,false);
    LICE_Line(drawbm,r.left,r.bottom-1,r.right-1,r.bottom-1,pencol2,1.0f,0,false);

  }
}
コード例 #6
0
ファイル: virtwnd-iconbutton.cpp プロジェクト: Artogn/licecap
void WDL_VirtualIconButton::OnPaint(LICE_IBitmap *drawbm, int origin_x, int origin_y, RECT *cliprect) 
{ 
  int col;

  float alpha = (m_grayed ? 0.25f : 1.0f) * m_alpha;

  bool isdown = !!(m_pressed&1);
  bool ishover = !!(m_pressed&2);

  if (m_iconCfg && m_iconCfg->image && !m_iconCfg->image_issingle)
  {
    bool swapupdown = (m_checkstate > 0);
    bool isdownimg = (swapupdown != isdown);
    
    RECT r=m_position;

    int sx=0;
    int sy=0;
    int w=m_iconCfg->image->getWidth();
    int h=m_iconCfg->image->getHeight();

    if (w>0 && (m_iconCfg->image_ltrb_used.flags&2))
      w-=2;

    w/=3;
    if (w>0 && h > 0)
    {
      if (m_is_button)
      {
        if (isdownimg) sx += w*2;
        else if (ishover) sx += w;
      }


      if (m_iconCfg->image_ltrb_used.flags&2)
      {
        WDL_VirtualWnd_BGCfg cfg={0,};
        LICE_SubBitmap sb(m_iconCfg->image,sx+1,sy+1,w,h-2);
        cfg.bgimage = &sb;
        cfg.bgimage_lt[0] = m_iconCfg->image_ltrb_main[0]+1; // image_ltrb_main expects 1-based number
        cfg.bgimage_lt[1] = m_iconCfg->image_ltrb_main[1]+1;
        cfg.bgimage_rb[0] = m_iconCfg->image_ltrb_main[2]+1;
        cfg.bgimage_rb[1] = m_iconCfg->image_ltrb_main[3]+1;
        cfg.bgimage_noalphaflags=0;

        WDL_VirtualWnd_ScaledBlitBG(drawbm,&cfg,
          r.left+origin_x,r.top+origin_y,r.right-r.left,r.bottom-r.top,
          r.left+origin_x,r.top+origin_y,r.right-r.left,r.bottom-r.top,
          alpha,LICE_BLIT_MODE_COPY|LICE_BLIT_FILTER_BILINEAR|LICE_BLIT_USE_ALPHA);

      }
      else
        LICE_ScaledBlit(drawbm,m_iconCfg->image,r.left+origin_x,r.top+origin_y,
          r.right-r.left,
          r.bottom-r.top,
          (float)sx,(float)sy,(float)w,(float)h, alpha,
          LICE_BLIT_MODE_COPY|LICE_BLIT_FILTER_BILINEAR|LICE_BLIT_USE_ALPHA);      
    }
  }
  else
  {
    RECT r=m_position;
    r.left+=origin_x;
    r.right+=origin_x;
    r.top+=origin_y;
    r.bottom+=origin_y;
    if (m_is_button)
    {
      if (WDL_STYLE_WantGlobalButtonBackground(&col))
      {
        LICE_FillRect(drawbm,r.left,r.top,r.right-r.left,r.bottom-r.top,LICE_RGBA_FROMNATIVE(col,255),alpha,LICE_BLIT_MODE_COPY);
      }

      if (ishover || m_forceborder || WDL_STYLE_WantGlobalButtonBorders())
      {
        int cidx=isdown?COLOR_3DSHADOW:COLOR_3DHILIGHT;

        int pencol = GSC(cidx);
        pencol = LICE_RGBA_FROMNATIVE(pencol,255);

        LICE_Line(drawbm,r.left,r.bottom-1,r.left,r.top,pencol,alpha,LICE_BLIT_MODE_COPY,false);
        LICE_Line(drawbm,r.left,r.top,r.right-1,r.top,pencol,alpha,LICE_BLIT_MODE_COPY,false);
        cidx = isdown?COLOR_3DHILIGHT:COLOR_3DSHADOW;
        pencol = GSC(cidx);
        pencol = LICE_RGBA_FROMNATIVE(pencol,255);
        LICE_Line(drawbm,r.right-1,r.top,r.right-1,r.bottom-1,pencol,alpha,LICE_BLIT_MODE_COPY,false);
        LICE_Line(drawbm,r.right-1,r.bottom-1,r.left,r.bottom-1,pencol,alpha,LICE_BLIT_MODE_COPY,false);
      }
    }
    if (m_iconCfg && m_iconCfg->image)
    {
      int sz=16,sz2=16;
      WDL_STYLE_ScaleImageCoords(&sz,&sz2);

      //if (m_position.right-m_position.left > 24) sz=m_position.right-m_position.left-8;
    
      int x=r.left+((r.right-r.left)-sz)/2;
      int y=r.top+((r.bottom-r.top)-sz2)/2;
      if (m_is_button)
      {
        if (isdown && ishover) { x++; y++; }
      }

      LICE_ScaledBlit(drawbm,m_iconCfg->image,x,y,sz,sz2,0.0f,0.0f,
        (float)m_iconCfg->image->getWidth(),
        (float)m_iconCfg->image->getHeight(),alpha,LICE_BLIT_MODE_COPY|LICE_BLIT_FILTER_BILINEAR|LICE_BLIT_USE_ALPHA);

    }
  }

  if (!m_iconCfg || m_forcetext)
  {
    RECT r2=m_position;
    r2.left+=origin_x;
    r2.right+=origin_x;
    r2.top+=origin_y;
    r2.bottom+=origin_y;

    if (m_checkstate>=0 && !m_iconCfg)
    {
      RECT tr=r2;
      int sz=tr.bottom-tr.top;
      r2.left+=sz+2;

      tr.top+=2;
      tr.bottom-=2;
      sz-=4;
      sz&=~1;
      LICE_FillRect(drawbm ,tr.left,tr.top,sz,sz,LICE_RGBA(255,255,255,255),alpha,LICE_BLIT_MODE_COPY);
      LICE_Line(drawbm,tr.left,tr.top,tr.left+sz,tr.top,LICE_RGBA(128,128,128,255),alpha,LICE_BLIT_MODE_COPY,false);
      LICE_Line(drawbm,tr.left+sz,tr.top,tr.left+sz,tr.bottom,LICE_RGBA(128,128,128,255),alpha,LICE_BLIT_MODE_COPY,false);
      LICE_Line(drawbm,tr.left+sz,tr.bottom,tr.left,tr.bottom,LICE_RGBA(128,128,128,255),alpha,LICE_BLIT_MODE_COPY,false);
      LICE_Line(drawbm,tr.left,tr.bottom,tr.left,tr.top,LICE_RGBA(128,128,128,255),alpha,LICE_BLIT_MODE_COPY,false);
      int nl = (m_checkstate>0) ? 3:0;        
      if (isdown) nl ^= 2;

      if (nl&1)
        LICE_Line(drawbm,tr.left+2,tr.bottom-2,tr.left+sz-2,tr.top+2,LICE_RGBA(0,0,0,255),alpha,LICE_BLIT_MODE_COPY,false);
      if (nl&2)
        LICE_Line(drawbm,tr.left+2,tr.top+2,tr.left+sz-2,tr.bottom-2,LICE_RGBA(0,0,0,255),alpha,LICE_BLIT_MODE_COPY,false);


    }

    LICE_IFont *font = m_textfont;
    bool isVert=false;
    if (font && m_textfontv && m_position.right-m_position.left < m_position.bottom - m_position.top)
    {
      isVert=true;
      font = m_textfontv;
    }
    // draw text
    if (font&&m_textlbl.Get()[0])
    {
      int fgc=m_forcetext_color ? m_forcetext_color : LICE_RGBA_FROMNATIVE(GSC(COLOR_BTNTEXT),255);
      //font->SetCombineMode(LICE_BLIT_MODE_COPY, alpha); // this affects the glyphs that get cached
      font->SetBkMode(TRANSPARENT);
      font->SetTextColor(fgc);

      r2.left += m_margin_l;
      r2.right -= m_margin_r;
      r2.top += m_margin_t;
      r2.bottom -= m_margin_b;

      if (isdown)
      {
        if (m_textalign<0) r2.left+=1;
        else if (m_textalign>0) r2.right+=1;
        else r2.left+=2;
        r2.top+=2;
      }
      int f = DT_SINGLELINE|DT_NOPREFIX;
      if (isVert)
      {
        if (m_textalign == 0)
        {
          RECT mr={0,};
          font->DrawText(drawbm,m_textlbl.Get(),-1,&mr,f|DT_CALCRECT);
          f |= (mr.bottom < r2.bottom-r2.top) ? DT_VCENTER : DT_TOP;
        }
        else
          f |= m_textalign<0?DT_TOP:DT_BOTTOM;

        f |= DT_CENTER;
      }
      else
      {
        if (m_textalign == 0)
        {
          RECT mr={0,};
          font->DrawText(drawbm,m_textlbl.Get(),-1,&mr,f|DT_CALCRECT);
          f |= (mr.right < r2.right-r2.left) ? DT_CENTER : DT_LEFT;
        }
        else
          f |= m_textalign<0?DT_LEFT:DT_RIGHT;

        f |= DT_VCENTER;
      }
      font->DrawText(drawbm,m_textlbl.Get(),-1,&r2,f);
    }
    
  }

  if (m_bgcol1_msg)
  {
    int brcol=-100;
    SendCommand(m_bgcol1_msg,(INT_PTR)&brcol,GetID(),this);
    if (brcol != -100)
    {
      RECT r=m_position;

      int bh=(r.bottom-r.top)/5;
      if (bh<1) bh=1;
      int bw=(r.right-r.left)/5;
      if (bw<1) bw=1;

      LICE_FillRect(drawbm,
        r.left+origin_x,r.top+origin_y,
        r.right-r.left,
        bh,LICE_RGBA_FROMNATIVE(brcol,255),0.75,LICE_BLIT_MODE_COPY);

      LICE_FillRect(drawbm,
        r.left+origin_x,r.top+origin_y+bh,
        bw,
        r.bottom-r.top-bh*2,LICE_RGBA_FROMNATIVE(brcol,255),0.75,LICE_BLIT_MODE_COPY);

      LICE_FillRect(drawbm,
        r.right+origin_x-bw,r.top+origin_y+bh,
        bw,
        r.bottom-r.top-bh*2,LICE_RGBA_FROMNATIVE(brcol,255),0.75,LICE_BLIT_MODE_COPY);

      LICE_FillRect(drawbm,
        r.left+origin_x,r.bottom+origin_y-bh,
        r.right-r.left,
        bh,LICE_RGBA_FROMNATIVE(brcol,255),0.75,LICE_BLIT_MODE_COPY);
    }
  }

} 
コード例 #7
0
ファイル: SnM_VWnd.cpp プロジェクト: Breeder/sws
void SNM_DynSizedText::OnPaint(LICE_IBitmap *drawbm, int origin_x, int origin_y, RECT *cliprect)
{
	RECT r = m_position;
	r.left += origin_x;
	r.right += origin_x;
	r.top += origin_y;
	r.bottom += origin_y;

	int h = r.bottom-r.top;
	int w = r.right-r.left;

	ColorTheme* ct = SNM_GetColorTheme();
	int col = m_col;
	if (!col)
		col = ct ? LICE_RGBA_FROMNATIVE(ct->main_text, m_alpha) : LICE_RGBA(255,255,255,255);

	if (m_wantBorder)
		LICE_DrawRect(drawbm,r.left,r.top,w,h,col,0.2f);

	// title lane
	int laneHeight = GetTitleLaneHeight();
	if (WantTitleLane() && HasTitleLane())
	{
		if (m_wantBorder)
			LICE_Line(drawbm, r.left,r.top+laneHeight-1,r.right,r.top+laneHeight-1,col,0.2f);

		// title's band coloring (works for all themes)
		LICE_FillRect(drawbm,r.left,r.top,r.right-r.left,laneHeight,col,1.0f,LICE_BLIT_MODE_OVERLAY);
		LICE_FillRect(drawbm,r.left,r.top,r.right-r.left,laneHeight,col,1.0f,LICE_BLIT_MODE_OVERLAY);

		static LICE_CachedFont sFont;
		if (!sFont.GetHFont()) // single lazy init..
		{
			LOGFONT lf = {
				SNM_FONT_HEIGHT, 0,0,0,FW_BOLD,FALSE,FALSE,FALSE,DEFAULT_CHARSET,
				OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,SNM_FONT_NAME
			};
			sFont.SetFromHFont(CreateFontIndirect(&lf),LICE_FONT_FLAG_OWNS_HFONT|LICE_FONT_FLAG_FORCE_NATIVE);
			// others props are set on demand (support theme switches)
		}
		sFont.SetBkMode(TRANSPARENT);
		sFont.SetTextColor(LICE_RGBA_FROMNATIVE(WDL_STYLE_GetSysColor(COLOR_WINDOW), 255)); // "negative" color

		{
			RECT tr = {r.left,r.top,r.right,r.top+laneHeight};
			char buf[64] = "";
			_snprintfSafe(buf, sizeof(buf), " %s ", m_title.Get()); // trick for better display when left/right align
			sFont.DrawText(drawbm, buf, -1, &tr, DT_SINGLELINE|DT_NOPREFIX|DT_VCENTER|m_titleAlign);
		}

		// resize draw rect: take band into account
		r.top += laneHeight;
		h = r.bottom-r.top;
	}


	// ok, now the meat: render lines with a dynamic sized text
	if (!m_lines.GetSize() || !m_lines.Get(m_maxLineIdx))
		return;


///////////////////////////////////////////////////////////////////////////////
#ifndef _SNM_MISC // 1st sol.: full width but several fonts can be tried


	// initial font height estimation
	// touchy: the better estimation, the less cpu use!
	int estimFontH = int((w*2.65)/m_lines.Get(m_maxLineIdx)->GetLength()); // 2.65 = average from tests..
	if (estimFontH > int(h/m_lines.GetSize())+0.5)
		estimFontH = int(h/m_lines.GetSize()+0.5);

	// check if the current font can do the job
	if (m_lastFontH>=SNM_FONT_HEIGHT && abs(estimFontH-m_lastFontH) < 2) // tolerance: 2 pixels
	{
#ifdef _SNM_DYN_FONT_DEBUG
		OutputDebugString("SNM_DynSizedText::OnPaint() - Skip font creation\n");
#endif
		m_font.SetTextColor(col);
		DrawLines(drawbm, &r, m_lastFontH);
	}
	else
	{
		m_lastFontH = estimFontH;
#ifdef _SNM_DYN_FONT_DEBUG
		int dbgTries=0;
#endif
		while(m_lastFontH>SNM_FONT_HEIGHT)
		{
			HFONT lf = CreateFont(m_lastFontH,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET,
				OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,m_fontName.Get());

			m_font.SetFromHFont(lf, LICE_FONT_FLAG_OWNS_HFONT|LICE_FONT_FLAG_FORCE_NATIVE);
			m_font.SetBkMode(TRANSPARENT);
			m_font.SetTextColor(col);

			RECT tr = {0,0,0,0};

			// DT flags must be consistent with DrawLines()
			m_font.DrawText(NULL, m_lines.Get(m_maxLineIdx)->Get(), -1, &tr, DT_SINGLELINE|DT_BOTTOM|DT_NOPREFIX|DT_CALCRECT);

			if ((tr.right - tr.left) > (w-int(w*0.02+0.5))) // room: 2% of w
			{
				m_font.SetFromHFont(NULL,LICE_FONT_FLAG_OWNS_HFONT);
				DeleteObject(lf);
				m_lastFontH--;
#ifdef _SNM_DYN_FONT_DEBUG
				dbgTries++;
#endif
			}
			else
			{
				DrawLines(drawbm, &r, m_lastFontH);
				// no font deletion: will try to re-use it..
				break;
			}
		}
#ifdef _SNM_DYN_FONT_DEBUG
		char dbg[256];
		_snprintfSafe(dbg, sizeof(dbg), "SNM_DynSizedText::OnPaint() - %d tries, estim: %d, real: %d\n", dbgTries, estimFontH, m_lastFontH);
		OutputDebugString(dbg);
#endif
	}


///////////////////////////////////////////////////////////////////////////////
#else // 2nd sol.: render text in best effort, single font creation


/*JFB commented: truncated text..
	int fontHeight = int((w*2.65)/m_lines.Get(m_maxLineIdx)->GetLength()); // 2.65 = average from tests..
	if (fontHeight > int(h/m_lines.GetSize())+0.5)
		fontHeight = int(h/m_lines.GetSize()+0.5);
*/
	// font height estimation (safe but it does not use all the available width/height)
	int fontHeight = int(h/m_lines.GetSize() + 0.5);
	while (fontHeight>SNM_FONT_HEIGHT && (fontHeight*m_lines.Get(m_maxLineIdx)->GetLength()*0.55) > w) // 0.55: h/w factor
		fontHeight--;

	if (fontHeight>=SNM_FONT_HEIGHT)
	{
		HFONT lf = CreateFont(fontHeight,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET,
			OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,m_fontName.Get());
		m_font.SetFromHFont(lf, LICE_FONT_FLAG_OWNS_HFONT|LICE_FONT_FLAG_FORCE_NATIVE);
		m_font.SetBkMode(TRANSPARENT);
		m_font.SetTextColor(col);
		DrawLines(drawbm, &r, fontHeight);
		m_font.SetFromHFont(NULL,LICE_FONT_FLAG_OWNS_HFONT);
		DeleteObject(lf);
	}
#endif
}
コード例 #8
0
void WDL_VirtualStaticText::OnPaint(LICE_IBitmap *drawbm, int origin_x, int origin_y, RECT *cliprect)
{
  RECT r=m_position;
  r.left+=origin_x;
  r.right+=origin_x;
  r.top += origin_y;
  r.bottom += origin_y;

  if (m_bkbm && m_bkbm->bgimage)
  {
    WDL_VirtualWnd_ScaledBlitBG(drawbm,m_bkbm,
      r.left,r.top,r.right-r.left,r.bottom-r.top,
      r.left,r.top,r.right-r.left,r.bottom-r.top,
      1.0,LICE_BLIT_MODE_COPY|LICE_BLIT_FILTER_BILINEAR|LICE_BLIT_USE_ALPHA);

    if (m_dotint && LICE_GETA(m_bg)) 
    {
        float amt = LICE_GETA(m_bg)/255.0f;

        // todo: apply amt

        float rv=LICE_GETR(m_bg)/255.0f;
        float gv=LICE_GETG(m_bg)/255.0f;
        float bv=LICE_GETB(m_bg)/255.0f;

        float avg=(rv+gv+bv)*0.33333f;
        if (avg<0.05f)avg=0.05f;

        float sc=0.5f*amt;
        float sc2 = (amt-sc)/avg;

        float sc3=32.0f * amt;
        float sc4=64.0f*(avg-0.5f) * amt;

        // tint
        LICE_MultiplyAddRect(drawbm,
          r.left,r.top,
            r.right-r.left,
            r.bottom-r.top,
            sc+rv*sc2 + (1.0-amt),
            sc+gv*sc2 + (1.0-amt),
            sc+bv*sc2 + (1.0-amt),
            1,
            (rv-avg)*sc3+sc4,
            (gv-avg)*sc3+sc4,
            (bv-avg)*sc3+sc4,
            0);
    }
  }
  else 
  {
    if (LICE_GETA(m_bg))
    {
      LICE_FillRect(drawbm,r.left,r.top,r.right-r.left,r.bottom-r.top,m_bg,LICE_GETA(m_bg)/255.0f,LICE_BLIT_MODE_COPY);
    }

    if (m_wantborder)
    {    
      int cidx=COLOR_3DSHADOW;

      int pencol = WDL_STYLE_GetSysColor(cidx);
      pencol = LICE_RGBA_FROMNATIVE(pencol,255);

      LICE_Line(drawbm,r.left,r.bottom-1,r.left,r.top,pencol,1.0f,LICE_BLIT_MODE_COPY,false);
      LICE_Line(drawbm,r.left,r.top,r.right-1,r.top,pencol,1.0f,LICE_BLIT_MODE_COPY,false);
      cidx=COLOR_3DHILIGHT;
      pencol = WDL_STYLE_GetSysColor(cidx);
      pencol = LICE_RGBA_FROMNATIVE(pencol,255);
      LICE_Line(drawbm,r.right-1,r.top,r.right-1,r.bottom-1,pencol,1.0f,LICE_BLIT_MODE_COPY,false);
      LICE_Line(drawbm,r.right-1,r.bottom-1,r.left,r.bottom-1,pencol,1.0f,LICE_BLIT_MODE_COPY,false);

      r.left++;
      r.bottom--;
      r.top++;
      r.right--;

    }
  }


  if (m_text.Get()[0])
  {

    r.left += m_margin_l;
    r.right -= m_margin_r;
    r.top += m_margin_t;
    r.bottom -= m_margin_b;

    m_didvert=m_vfont && (r.right-r.left)<(r.bottom-r.top);
    LICE_IFont *font = m_didvert ? m_vfont : m_font;


    if (font)
    {
      font->SetBkMode(TRANSPARENT);

    
      m_didalign=m_align;
      if (m_didalign==0)
      {
        RECT r2={0,0,0,0};
        font->DrawText(drawbm,m_text.Get(),-1,&r2,DT_SINGLELINE|DT_VCENTER|DT_LEFT|DT_NOPREFIX|DT_CALCRECT);
        if (r2.right > r.right-r.left) m_didalign=-1;
      }

      int tcol=m_fg ? m_fg : LICE_RGBA_FROMNATIVE(WDL_STYLE_GetSysColor(COLOR_BTNTEXT));
      font->SetTextColor(tcol);
      if (m_fg && LICE_GETA(m_fg) != 0xff) font->SetCombineMode(LICE_BLIT_MODE_COPY,LICE_GETA(m_fg)/255.0f);
      font->DrawText(drawbm,m_text.Get(),-1,&r,DT_SINGLELINE|DT_VCENTER|(m_didalign<0?DT_LEFT:m_didalign>0?DT_RIGHT:DT_CENTER)|DT_NOPREFIX);
      if (m_fg && LICE_GETA(m_fg) != 0xff) font->SetCombineMode(LICE_BLIT_MODE_COPY,1.0f);
    }


  }
  WDL_VWnd::OnPaint(drawbm,origin_x,origin_y,cliprect);
}
コード例 #9
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;
}
コード例 #10
0
ファイル: virtwnd-slider.cpp プロジェクト: aidush/openmpt
void WDL_VirtualSlider::OnPaint(LICE_IBitmap *drawbm, int origin_x, int origin_y, RECT *cliprect)
{
  origin_x += m_position.left; // convert drawing origin to local coords
  origin_y += m_position.top;

  bool isVert = GetIsVert();

  int rsize=m_maxr-m_minr;
  if (rsize<1)rsize=1;

  int viewh=m_position.bottom-m_position.top;
  int vieww=m_position.right-m_position.left;

  WDL_VirtualWnd_BGCfg *back_image=m_skininfo && m_skininfo->bgimagecfg[isVert].bgimage ? &m_skininfo->bgimagecfg[isVert] : 0;
  LICE_IBitmap *bm_image=m_skininfo ? m_skininfo->thumbimage[isVert] : 0;
  int bm_w=16,bm_h=16,bm_w2=16,bm_h2=16;
  int imgoffset=0;
  HBITMAP bm=0;
  bool wantKnob=false;
  if (bm_image)
  {
    bm_w2=bm_w=bm_image->getWidth();
    bm_h2=bm_h=bm_image->getHeight();
    AdjustThumbImageSize(vieww,viewh,m_skininfo,isVert,&bm_w2,&bm_h2,&imgoffset,&wantKnob,m_knobbias);
  }
  else
  {
    bm_image=WDL_STYLE_GetSliderBitmap2(isVert);
    if (bm_image)
    {
      bm_w2=bm_w=bm_image->getWidth();
      bm_h2=bm_h=bm_image->getHeight();
    }
    AdjustThumbImageSize(vieww,viewh,NULL,isVert,&bm_w2,&bm_h2,&imgoffset,&wantKnob,m_knobbias);
  }

  float alpha = (m_grayed ? 0.25f : 1.0f);

  m_is_knob = wantKnob;

  if (isVert||wantKnob)
  {
    int pos = ((m_maxr-m_pos)*(viewh-bm_h2))/rsize; //viewh - bm_h2 - ((m_pos-m_minr) * (viewh - bm_h2))/rsize;

    if (wantKnob)
    {
      int sz= min(vieww,viewh);
      origin_x += (vieww-sz)/2;
      origin_y += (viewh-sz)/2;
      vieww = viewh = sz;       
      back_image = m_knobbg[sz>28];

      if (back_image && !back_image->bgimage) back_image=NULL;
    }


    if (back_image)
    {
      WDL_VirtualWnd_ScaledBlitBG(drawbm,back_image,
        origin_x,origin_y,vieww,viewh,
        origin_x,origin_y,vieww,viewh,
        1.0f,LICE_BLIT_MODE_COPY|LICE_BLIT_FILTER_BILINEAR|LICE_BLIT_USE_ALPHA);
                                            
      if (m_bgcol1_msg)
      {
        int brcol=-100;
        SendCommand(m_bgcol1_msg,(INT_PTR)&brcol,GetID(),this);
        if (brcol != -100)
        {
          static LICE_MemBitmap tmpbm;//not threadsafe
          tmpbm.resize(vieww,viewh);
          WDL_VirtualWnd_ScaledBlitBG(&tmpbm,back_image,0,0,vieww,viewh,
              0,0,vieww,viewh,1.0f,LICE_BLIT_MODE_COPY|LICE_BLIT_FILTER_BILINEAR);

          LICE_ClearRect(&tmpbm,0,0,vieww,viewh,LICE_RGBA(0,0,0,255),LICE_RGBA(GetRValue(brcol),GetGValue(brcol),GetBValue(brcol),0));

          RECT r={0,0,vieww,viewh};
          LICE_Blit(drawbm,&tmpbm,origin_x,origin_y,&r,0.5,LICE_BLIT_MODE_COPY|LICE_BLIT_USE_ALPHA);
        }
      }
    }

    if (!wantKnob)
    {
      int zlc = m_zl_color;
      if (!zlc && m_skininfo) zlc = m_skininfo->zeroline_color;
      if (!back_image || zlc)
      {
        int center=m_center;
        if (center < 0) center=WDL_STYLE_GetSliderDynamicCenterPos();

        int y=((m_maxr-center)*(viewh-bm_h2))/rsize + ((bm_h-1)/2-imgoffset);

        if (!zlc) zlc = LICE_RGBA_FROMNATIVE(GSC(COLOR_BTNTEXT),255);
        LICE_Line(drawbm,origin_x+2,origin_y+y,origin_x+vieww-2,origin_y+y, zlc, LICE_GETA(zlc)/255.0, LICE_BLIT_MODE_COPY,false);
      }


      if (!back_image)
      {

        LICE_pixel fgcol  = GSC(COLOR_3DHILIGHT);
        fgcol = LICE_RGBA_FROMNATIVE(fgcol,255);
        LICE_pixel bgcol=GSC(COLOR_3DSHADOW);
        if (m_bgcol1_msg)
          SendCommand(m_bgcol1_msg,(INT_PTR)&bgcol,GetID(),this);
        bgcol = LICE_RGBA_FROMNATIVE(bgcol,255);


        int offs= (vieww - 4)/2;
        // white with black border, mmm

        RECT r={origin_x + offs,origin_y + bm_h2/3, origin_x + offs + 5,origin_y + viewh - bm_h2/3};

        LICE_FillRect(drawbm,r.left+1,r.top+1,
                             r.right-r.left-2,r.bottom-r.top-2,bgcol,1.0f,LICE_BLIT_MODE_COPY);

        LICE_Line(drawbm,r.left+1,r.top,r.right-2,r.top,fgcol,1.0f,LICE_BLIT_MODE_COPY,false);
        LICE_Line(drawbm,r.left+1,r.bottom-1,r.right-2,r.bottom-1,fgcol,1.0f,LICE_BLIT_MODE_COPY,false);

        LICE_Line(drawbm,r.left,r.top+1,r.left,r.bottom-2,fgcol,1.0f,LICE_BLIT_MODE_COPY,false);
        LICE_Line(drawbm,r.right-1,r.top+1,r.right-1,r.bottom-2,fgcol,1.0f,LICE_BLIT_MODE_COPY,false);    

      }

      if (bm_image)
      {
        int ypos=origin_y+pos-imgoffset;
        int xpos=origin_x;

        RECT r={0,0,bm_w2,bm_h};
  /*      if (vieww<bm_w)
        {
          r.left=(bm_w-vieww)/2;
          r.right=r.left+vieww;
        }
        else 
        */
        xpos+=(vieww-bm_w2)/2;

        m_tl_extra=origin_y-ypos;
        if (m_tl_extra<0)m_tl_extra=0;

        m_br_extra=ypos+(r.bottom-r.top) - (origin_y+m_position.bottom-m_position.top);
        if (m_br_extra<0)m_br_extra=0;


        LICE_Blit(drawbm,bm_image,xpos,ypos,&r,alpha,LICE_BLIT_MODE_COPY|LICE_BLIT_USE_ALPHA);    
      }
    }
    else
    {
      LICE_pixel col  = m_knob_color ? m_knob_color : LICE_RGBA_FROMNATIVE(GSC(COLOR_3DHILIGHT),255);

      float alpha = LICE_GETA(col)/255.0f;
      int cx=origin_x+vieww/2;
      int cy=origin_y+viewh/2;
      float rd = vieww/2-4 + m_knob_lineextrasize;
      float r2=rd*0.125f;
      if (!back_image) LICE_Circle(drawbm, cx, cy, rd, col, alpha, LICE_BLIT_MODE_COPY, true);

      float val;
      
      int center=m_center;
      if (center < 0) center=WDL_STYLE_GetSliderDynamicCenterPos();
      if (center > m_minr && (m_pos < center || center >= m_maxr)) val = (m_pos-center) / (double)(center-m_minr);
      else val = (m_pos-center) / (double)(m_maxr-center);
      #define KNOBANGLE_MAX (3.14159*7.0/8.0);
      float a = val*KNOBANGLE_MAX;
      float sina=sin(a);
      float cosa=cos(a);
      float x1=cx+r2*sina;
      float y1=cy-r2*cosa;
      float x2=cx+rd*sina;
      float y2=cy-rd*cosa;
      LICE_FLine(drawbm, x1, y1, x2, y2, col, alpha, LICE_BLIT_MODE_COPY, true);

    }
  }
  else
  {
    int pos = ((m_pos-m_minr) * (vieww - bm_w2))/rsize;

    if (back_image)
    {
      WDL_VirtualWnd_ScaledBlitBG(drawbm,back_image,
        origin_x,origin_y,vieww,viewh,
        origin_x,origin_y,vieww,viewh,
        1.0,LICE_BLIT_MODE_COPY|LICE_BLIT_FILTER_BILINEAR|LICE_BLIT_USE_ALPHA);
      // blit, tint color too?

      if (m_bgcol1_msg)
      {
        int brcol=-100;
        SendCommand(m_bgcol1_msg,(INT_PTR)&brcol,GetID(),this);
        if (brcol != -100)
        {
          static LICE_MemBitmap tmpbm; //not threadsafe
          tmpbm.resize(vieww,viewh);

          WDL_VirtualWnd_ScaledBlitBG(&tmpbm,back_image,0,0,vieww,viewh,
              0,0,vieww,viewh,1.0,LICE_BLIT_MODE_COPY|LICE_BLIT_FILTER_BILINEAR);

          LICE_ClearRect(&tmpbm,0,0,vieww,viewh,LICE_RGBA(0,0,0,255),LICE_RGBA(GetRValue(brcol),GetGValue(brcol),GetBValue(brcol),0));

          RECT r={0,0,vieww,viewh};
          LICE_Blit(drawbm,&tmpbm,origin_x,origin_y,&r,0.5,LICE_BLIT_MODE_COPY|LICE_BLIT_USE_ALPHA);
        }
      }

    }

    int zlc = m_zl_color;
    if (!zlc && m_skininfo) zlc = m_skininfo->zeroline_color;
    if (!back_image || zlc)
    {
      int center=m_center;
      if (center < 0) center=WDL_STYLE_GetSliderDynamicCenterPos();

      int x=((center-m_minr)*(vieww-bm_w2))/rsize + bm_w/2 - imgoffset;

      if (!zlc) zlc = LICE_RGBA_FROMNATIVE(GSC(COLOR_BTNTEXT),255);

      LICE_Line(drawbm,origin_x+x,origin_y+2,origin_x+x,origin_y+viewh-2,
        zlc, LICE_GETA(zlc)/255.0, LICE_BLIT_MODE_COPY,false);
    }

    if (!back_image)
    {
      LICE_pixel fgcol  = GSC(COLOR_3DHILIGHT);
      fgcol = LICE_RGBA_FROMNATIVE(fgcol,255);
      LICE_pixel bgcol=GSC(COLOR_3DSHADOW);
      if (m_bgcol1_msg)
        SendCommand(m_bgcol1_msg,(INT_PTR)&bgcol,GetID(),this);
      bgcol = LICE_RGBA_FROMNATIVE(bgcol,255);

      int offs= (viewh - 4)/2;
      // white with black border, mmm
      RECT r={origin_x + bm_w2/3,origin_y + offs, origin_x + vieww - bm_w2/3,origin_y + offs + 5};

      LICE_FillRect(drawbm,r.left+1,r.top+1,
                           r.right-r.left-2,r.bottom-r.top-2,bgcol,1.0f,LICE_BLIT_MODE_COPY);

      LICE_Line(drawbm,r.left+1,r.top,r.right-2,r.top,fgcol,1.0f,LICE_BLIT_MODE_COPY,false);
      LICE_Line(drawbm,r.left+1,r.bottom-1,r.right-2,r.bottom-1,fgcol,1.0f,LICE_BLIT_MODE_COPY,false);

      LICE_Line(drawbm,r.left,r.top+1,r.left,r.bottom-2,fgcol,1.0f,LICE_BLIT_MODE_COPY,false);
      LICE_Line(drawbm,r.right-1,r.top+1,r.right-1,r.bottom-2,fgcol,1.0f,LICE_BLIT_MODE_COPY,false);    

    }

    if (bm_image)
    {
      int xpos=origin_x+pos-imgoffset;
      int ypos=origin_y;

      RECT r={0,0,bm_w,bm_h2};
      /*if (viewh<bm_h)
      {
        r.top=(bm_h-viewh)/2;
        r.bottom=r.top+viewh;
      }
      else 
      */
      ypos+=(viewh-bm_h2)/2;


      m_tl_extra=origin_x-xpos;
      if (m_tl_extra<0)m_tl_extra=0;

      m_br_extra=xpos+(r.right-r.left) - (origin_x+m_position.right-m_position.left);
      if (m_br_extra<0)m_br_extra=0;

      /*      if (xpos < origin_x)
      {
        r.left += (origin_x-xpos);
        xpos=origin_x;
      }
      if (xpos+(r.right-r.left) > origin_x+m_position.right-m_position.left)
        r.right = origin_x+m_position.right-m_position.left - (xpos-r.left);
*/

      LICE_Blit(drawbm,bm_image,xpos,ypos,&r,alpha,LICE_BLIT_MODE_COPY|LICE_BLIT_USE_ALPHA);    
    }
  }

}
コード例 #11
0
ファイル: lice_ico.cpp プロジェクト: 0x4d52/wdl-ol
static LICE_IBitmap *icoToBitmap(HICON icon, LICE_IBitmap *bmpOut)
{
  int icon_w = 16, icon_h=16;

#ifdef _WIN32
  ICONINFO ii={0,};
  if (GetIconInfo(icon,&ii))
  {
    bool blah=false;
    if (ii.hbmColor)
    {
      BITMAP bm={0,};
      if (GetObject(ii.hbmColor,sizeof(bm),&bm) && bm.bmWidth && bm.bmHeight)
      {
        icon_w=bm.bmWidth;
        icon_h=bm.bmHeight;
        blah=true;
      }
      DeleteObject(ii.hbmColor);
    }
    if (ii.hbmMask)
    {
      BITMAP bm={0,};
      if (!blah && GetObject(ii.hbmMask,sizeof(bm),&bm) && bm.bmWidth && bm.bmHeight)
      {
        icon_w=bm.bmWidth;
        icon_h=bm.bmHeight;
      }
      DeleteObject(ii.hbmMask);
    }
  }
#else
  BITMAP bm={0,};
  if (GetObject(icon,sizeof(bm),&bm) && bm.bmWidth && bm.bmHeight) // SWELL's GetObject() works on icons
  {
    icon_w=bm.bmWidth;
    icon_h=bm.bmHeight;
  }

#endif

  LICE_SysBitmap tempbm(icon_w*2,icon_h);
  LICE_FillRect(&tempbm,0,0,icon_w,icon_h,LICE_RGBA(0,0,0,255),1.0f,LICE_BLIT_MODE_COPY);
#ifdef _WIN32
  DrawIconEx(tempbm.getDC(),0,0,icon,icon_w,icon_h,0,NULL,DI_NORMAL);
#else
  {
    RECT r={0,0,icon_w,icon_h};
    DrawImageInRect(tempbm.getDC(),icon,&r);
  }
#endif

  LICE_FillRect(&tempbm,icon_w,0,icon_w,icon_h,LICE_RGBA(255,255,255,255),1.0f,LICE_BLIT_MODE_COPY);
#ifdef _WIN32
  DrawIconEx(tempbm.getDC(),icon_w,0,icon,icon_w,icon_h,0,NULL,DI_NORMAL);
#else
  {
    RECT r={icon_w,0,icon_w+icon_w,icon_h};
    DrawImageInRect(tempbm.getDC(),icon,&r);
  }
#endif

  if (!bmpOut) bmpOut = new LICE_MemBitmap(icon_w,icon_h);
  else bmpOut->resize(icon_w,icon_h);

  int y; // since we have the image drawn on white and on black, we can calculate the alpha channel...
  for(y=0;y<icon_h;y++)
  {
    int x;
    for(x=0;x<icon_w;x++)
    {
      LICE_pixel p = LICE_GetPixel(&tempbm,x,y);
      LICE_pixel p2 = LICE_GetPixel(&tempbm,x+icon_w,y);

      int r1=LICE_GETR(p);
      int g1=LICE_GETG(p);
      int b1=LICE_GETB(p);

      int alpha=255 - (LICE_GETR(p2)-r1);
      if (alpha>=255) alpha=255;
      else if (alpha>0)
      {
        r1 = (r1*255)/alpha; // LICE stores its alpha channel non-premultiplied, so we need to scale these up.
        g1 = (g1*255)/alpha;
        b1 = (b1*255)/alpha;
        if (r1>255)r1=255;
        if (g1>255)g1=255;
        if (b1>255)b1=255;
      }
      else alpha=0;
      LICE_PutPixel(bmpOut,x,y,LICE_RGBA(r1,g1,b1,alpha),1.0f,LICE_BLIT_MODE_COPY);
    }
  }

  return bmpOut;
}
コード例 #12
-1
ファイル: lice_bmp.cpp プロジェクト: Brado231/Faderport_XT
static LICE_IBitmap *hbmToBit(HBITMAP hbm, LICE_IBitmap *bmp)
{
  BITMAP bm;
  GetObject(hbm, sizeof(BITMAP), (LPSTR)&bm);

  LICE_SysBitmap sysbitmap(bm.bmWidth,bm.bmHeight);
  
#ifdef _WIN32
  HDC hdc=CreateCompatibleDC(NULL);
  HGDIOBJ oldBM=SelectObject(hdc,hbm);

  BitBlt(sysbitmap.getDC(),0,0,bm.bmWidth,bm.bmHeight,hdc,0,0,SRCCOPY);
  GdiFlush();

  if (!bmp) bmp=new LICE_MemBitmap(bm.bmWidth,bm.bmHeight);
  LICE_Copy(bmp,&sysbitmap);

  SelectObject(hdc,oldBM);
  DeleteDC(hdc);
  #else
  LICE_Clear(&sysbitmap,0);
  RECT r={0,0,bm.bmWidth,bm.bmHeight};
  DrawImageInRect(sysbitmap.getDC(),hbm,&r);
  if (!bmp) bmp=new LICE_MemBitmap(bm.bmWidth,bm.bmHeight);
  LICE_Copy(bmp,&sysbitmap);
  #endif

  LICE_FillRect(bmp,0,0,bmp->getWidth(),bmp->getHeight(),LICE_RGBA(0,0,0,255),1.0f,LICE_BLIT_MODE_ADD);

  return bmp;
}