void CGradientStatic::CreateGradient(CDC *pDC, CRect *pRect)
{
	m_Mem.cx = pRect->Width();
	m_Mem.cy = pRect->Height();

	if(m_Mem.dc.GetSafeHdc())
	{	
		if(m_Mem.bmp.GetSafeHandle() && m_Mem.pold)
			m_Mem.dc.SelectObject(m_Mem.pold);
		m_Mem.dc.DeleteDC();
	}
	m_Mem.dc.CreateCompatibleDC(pDC);
	
	if(m_Mem.bmp.GetSafeHandle())
		m_Mem.bmp.DeleteObject();
	m_Mem.bmp.CreateCompatibleBitmap(pDC, m_Mem.cx, m_Mem.cy);

	m_Mem.pold = m_Mem.dc.SelectObject(&m_Mem.bmp);

//-----------------------------------------------------------------

	if(m_bHorizontal)
	{
		DrawHorizontalGradient();
		DrawHorizontalText(pRect);
	}
	else
	{
		DrawVerticalGradient();
		DrawVerticalText(pRect);		
	}
}
Exemple #2
0
/** Draw the tray background on a drawable. */
void ClearTrayDrawable(const TrayComponentType *cp)
{
   const Drawable d = cp->pixmap != None ? cp->pixmap : cp->window;
   if(colors[COLOR_TRAY_BG1] == colors[COLOR_TRAY_BG2]) {
      JXSetForeground(display, rootGC, colors[COLOR_TRAY_BG1]);
      JXFillRectangle(display, d, rootGC, 0, 0, cp->width, cp->height);
   } else {
      DrawHorizontalGradient(d, rootGC, colors[COLOR_TRAY_BG1],
                             colors[COLOR_TRAY_BG2], 0, 0,
                             cp->width, cp->height);
   }
}
Exemple #3
0
/** Draw a clock tray component. */
void DrawClock(ClockType *clk, const TimeType *now)
{

   TrayComponentType *cp;
   const char *timeString;
   int width;
   int rwidth;

   /* Only draw if the time changed. */
   if(now->seconds == clk->lastTime.seconds) {
      return;
   }

   /* Clear the area. */
   cp = clk->cp;
   if(colors[COLOR_CLOCK_BG1] == colors[COLOR_CLOCK_BG2]) {
      JXSetForeground(display, rootGC, colors[COLOR_CLOCK_BG1]);
      JXFillRectangle(display, cp->pixmap, rootGC, 0, 0,
                      cp->width, cp->height);
   } else {
      DrawHorizontalGradient(cp->pixmap, rootGC,
                             colors[COLOR_CLOCK_BG1], colors[COLOR_CLOCK_BG2],
                             0, 0, cp->width, cp->height);
   }

   /* Determine if the clock is the right size. */
   timeString = GetTimeString(clk->format, clk->zone);
   width = GetStringWidth(FONT_CLOCK, timeString);
   rwidth = width + 4;
   if(rwidth == clk->cp->requestedWidth || clk->userWidth) {

      /* Draw the clock. */
      RenderString(cp->pixmap, FONT_CLOCK, COLOR_CLOCK_FG,
                   (cp->width - width) / 2,
                   (cp->height - GetStringHeight(FONT_CLOCK)) / 2,
                   cp->width, timeString);

      UpdateSpecificTray(clk->cp->tray, clk->cp);

   } else {

      /* Wrong size. Resize. */
      clk->cp->requestedWidth = rwidth;
      ResizeTray(clk->cp->tray);

   }

}
Exemple #4
0
/** Load a gradient background. */
void LoadGradientBackground(BackgroundNode *bp) {

   XColor color1;
   XColor color2;
   char *temp;
   char *sep;
   int len;

   sep = strchr(bp->value, ':');
   if(!sep) {
      bp->pixmap = None;
      bp->window = None;
      return;
   }

   /* Get the first color. */
   len = (int)(sep - bp->value);
   temp = AllocateStack(len + 1);
   memcpy(temp, bp->value, len);
   temp[len] = 0;
   ParseColor(temp, &color1);
   ReleaseStack(temp);

   /* Get the second color. */
   len = strlen(sep + 1);
   temp = AllocateStack(len + 1);
   memcpy(temp, sep + 1, len);
   temp[len] = 0;
   ParseColor(temp, &color2);
   ReleaseStack(temp);

   /* Create the window. */
   bp->window = JXCreateSimpleWindow(display, rootWindow, 0, 0,
                                     rootWidth, rootHeight, 0, 0, 0);

   bp->pixmap = JXCreatePixmap(display, bp->window,
                               rootWidth, rootHeight, rootDepth);

   if(color1.pixel == color2.pixel) {
      JXSetForeground(display, rootGC, color1.pixel);
      JXFillRectangle(display, bp->pixmap, rootGC,
                      0, 0, rootWidth, rootHeight);
   } else {
      DrawHorizontalGradient(bp->pixmap, rootGC,
         color1.pixel, color2.pixel, 0, 0, rootWidth, rootHeight);
   }

}
Exemple #5
0
/** Draw a button. */
void DrawButton(ButtonNode *bp)
{

   ColorType fg;
   long bg1, bg2;
   long up, down;
   DecorationsType decorations;

   Drawable drawable;
   GC gc;
   int x, y;
   int width, height;
   int xoffset, yoffset;

   int iconWidth, iconHeight;
   int textWidth, textHeight;
   
   Assert(bp);

   drawable = bp->drawable;
   x = bp->x;
   y = bp->y;
   width = bp->width;
   height = bp->height;
   gc = JXCreateGC(display, drawable, 0, NULL);

   /* Determine the colors to use. */
   switch(bp->type) {
   case BUTTON_LABEL:
      fg = COLOR_MENU_FG;
      bg1 = colors[COLOR_MENU_BG];
      bg2 = colors[COLOR_MENU_BG];
      up = colors[COLOR_MENU_UP];
      down = colors[COLOR_MENU_DOWN];
      decorations = settings.menuDecorations;
      break;
   case BUTTON_MENU_ACTIVE:
      fg = COLOR_MENU_ACTIVE_FG;
      bg1 = colors[COLOR_MENU_ACTIVE_BG1];
      bg2 = colors[COLOR_MENU_ACTIVE_BG2];
      down = colors[COLOR_MENU_ACTIVE_UP];
      up = colors[COLOR_MENU_ACTIVE_DOWN];
      decorations = settings.menuDecorations;
      break;
   case BUTTON_TRAY:
      fg = COLOR_TRAYBUTTON_FG;
      bg1 = colors[COLOR_TRAYBUTTON_BG1];
      bg2 = colors[COLOR_TRAYBUTTON_BG2];
      up = colors[COLOR_TRAYBUTTON_UP];
      down = colors[COLOR_TRAYBUTTON_DOWN];
      decorations = settings.trayDecorations;
      break;
   case BUTTON_TRAY_ACTIVE:
      fg = COLOR_TRAYBUTTON_ACTIVE_FG;
      bg1 = colors[COLOR_TRAYBUTTON_ACTIVE_BG1];
      bg2 = colors[COLOR_TRAYBUTTON_ACTIVE_BG2];
      down = colors[COLOR_TRAYBUTTON_ACTIVE_UP];
      up = colors[COLOR_TRAYBUTTON_ACTIVE_DOWN];
      decorations = settings.trayDecorations;
      break;
   case BUTTON_TASK:
      fg = COLOR_TASKLIST_FG;
      bg1 = colors[COLOR_TASKLIST_BG1];
      bg2 = colors[COLOR_TASKLIST_BG2];
      up = colors[COLOR_TASKLIST_UP];
      down = colors[COLOR_TASKLIST_DOWN];
      decorations = settings.trayDecorations;
      break;
   case BUTTON_TASK_ACTIVE:
      fg = COLOR_TASKLIST_ACTIVE_FG;
      bg1 = colors[COLOR_TASKLIST_ACTIVE_BG1];
      bg2 = colors[COLOR_TASKLIST_ACTIVE_BG2];
      down = colors[COLOR_TASKLIST_ACTIVE_UP];
      up = colors[COLOR_TASKLIST_ACTIVE_DOWN];
      decorations = settings.trayDecorations;
      break;
   case BUTTON_MENU:
   default:
      fg = COLOR_MENU_FG;
      bg1 = colors[COLOR_MENU_BG];
      bg2 = colors[COLOR_MENU_BG];
      up = colors[COLOR_MENU_UP];
      down = colors[COLOR_MENU_DOWN];
      decorations = settings.menuDecorations;
      break;
   }

   /* Draw the background. */
   if(bp->fill) {

      /* Draw the button background. */
      JXSetForeground(display, gc, bg1);
      if(bg1 == bg2) {
         /* single color */
         JXFillRectangle(display, drawable, gc, x, y, width, height);
      } else {
         /* gradient */
         DrawHorizontalGradient(drawable, gc, bg1, bg2,
                                x, y, width, height);
      }

   }

   /* Draw the border. */
   if(bp->border) {
      if(decorations == DECO_MOTIF) {
         JXSetForeground(display, gc, up);
         JXDrawLine(display, drawable, gc, x, y, x + width - 1, y);
         JXDrawLine(display, drawable, gc, x, y, x, y + height - 1);
         JXSetForeground(display, gc, down);
         JXDrawLine(display, drawable, gc, x, y + height - 1,
                    x + width - 1, y + height - 1);
         JXDrawLine(display, drawable, gc, x + width - 1, y,
                    x + width - 1, y + height - 1);
      } else {
         JXSetForeground(display, gc, down);
         JXDrawRectangle(display, drawable, gc, x, y, width - 1, height - 1);
      }
   }

   /* Determine the size of the icon (if any) to display. */
   iconWidth = 0;
   iconHeight = 0;
   if(bp->icon) {
      if(bp->icon == &emptyIcon) {
         iconWidth = Min(width - 4, height - 4);
         iconHeight = iconWidth;
      } else {
         const int ratio = (bp->icon->width << 16) / bp->icon->height;
         iconHeight = height - 4;
         iconWidth = (iconHeight * ratio) >> 16;
         if(iconWidth > width - 4) {
            iconWidth = width - 4;
            iconHeight = (iconWidth << 16) / ratio;
         }
      }
   }

   /* Determine how much room is left for text. */
   textWidth = 0;
   textHeight = 0;
   if(bp->text && (width > height || !bp->icon)) {
      textWidth = GetStringWidth(bp->font, bp->text);
      textHeight = GetStringHeight(bp->font);
      if(iconWidth > 0 && textWidth + iconWidth + 7 > width) {
         textWidth = width - iconWidth - 7;
      } else if(iconWidth == 0 && textWidth + 5 > width) {
         textWidth = width - 5;
      }
      textWidth = textWidth < 0 ? 0 : textWidth;
   }

   /* Determine the offset of the text in the button. */
   if(bp->alignment == ALIGN_CENTER || width <= height) {
      xoffset = (width - iconWidth - textWidth + 1) / 2;
      if(xoffset < 0) {
         xoffset = 0;
      }
   } else {
      xoffset = 2;
   }

   /* Display the icon. */
   if(bp->icon) {
      yoffset = (height - iconHeight + 1) / 2;
      PutIcon(bp->icon, drawable, colors[fg],
              x + xoffset, y + yoffset,
              iconWidth, iconHeight);
      xoffset += iconWidth + 2;
   }

   /* Display the label. */
   if(textWidth > 0) {
      yoffset = (height - textHeight + 1) / 2;
      RenderString(drawable, bp->font, fg,
                   x + xoffset, y + yoffset,
                   textWidth, bp->text);
   }

   JXFreeGC(display, gc);

}
Exemple #6
0
/** Draw a button. */
void DrawButton(ButtonNode *bp) {

   long outlinePixel;
   long topPixel, bottomPixel;
   ColorType fg;
   long bg1, bg2;

   Drawable drawable;
   GC gc;
   int x, y;
   int width, height;
   int xoffset, yoffset;

   int iconWidth, iconHeight;
   int textWidth, textHeight;
   
   Assert(bp);

   drawable = bp->drawable;
   gc = bp->gc;
   x = bp->x;
   y = bp->y;
   width = bp->width;
   height = bp->height;

   /* Determine the colors to use. */
   switch(bp->type) {
   case BUTTON_LABEL:
      fg = COLOR_MENU_FG;
      bg1 = colors[COLOR_MENU_BG];
      bg2 = colors[COLOR_MENU_BG];
      outlinePixel = colors[COLOR_MENU_BG];
      topPixel = colors[COLOR_MENU_BG];
      bottomPixel = colors[COLOR_MENU_BG];
      break;
   case BUTTON_MENU_ACTIVE:
      fg = COLOR_MENU_ACTIVE_FG;
      bg1 = colors[COLOR_MENU_ACTIVE_BG1];
      bg2 = colors[COLOR_MENU_ACTIVE_BG2];
      if(bg1 == bg2) {
         outlinePixel = colors[COLOR_MENU_ACTIVE_OL];
      } else {
         outlinePixel = colors[COLOR_MENU_ACTIVE_DOWN];
      }
      topPixel = colors[COLOR_MENU_ACTIVE_UP];
      bottomPixel = colors[COLOR_MENU_ACTIVE_DOWN];
      break;
   case BUTTON_TASK:
      fg = COLOR_TASK_FG;
      bg1 = colors[COLOR_TASK_BG1];
      bg2 = colors[COLOR_TASK_BG2];
      topPixel = colors[COLOR_TASK_UP];
      bottomPixel = colors[COLOR_TASK_DOWN];
      outlinePixel = bottomPixel;
      break;
   case BUTTON_TASK_ACTIVE:
      fg = COLOR_TASK_ACTIVE_FG;
      bg1 = colors[COLOR_TASK_ACTIVE_BG1];
      bg2 = colors[COLOR_TASK_ACTIVE_BG2];
      topPixel = colors[COLOR_TASK_ACTIVE_DOWN];
      bottomPixel = colors[COLOR_TASK_ACTIVE_UP];
      outlinePixel = bottomPixel;
      break;
   case BUTTON_MENU:
   default:
      fg = COLOR_MENU_FG;
      bg1 = colors[COLOR_MENU_BG];
      bg2 = colors[COLOR_MENU_BG];
      outlinePixel = colors[COLOR_MENU_DOWN];
      topPixel = colors[COLOR_MENU_UP];
      bottomPixel = colors[COLOR_MENU_DOWN];
      break;
   }

   /* Draw the background. */
   switch(bp->type) {
   case BUTTON_TASK:
      /* Flat taskbuttons (only icon) for widths < 48 */
      if(width < 48) {
         break;
      }
      /* conditional fallthrough is intended */  
   default:

      /* Draw the button background. */
      JXSetForeground(display, gc, bg1);
      if(bg1 == bg2) {
         /* single color */
         JXFillRectangle(display, drawable, gc,
            x + 1, y + 1, width - 1, height - 1);
      } else {
         /* gradient */
         DrawHorizontalGradient(drawable, gc, bg1, bg2,
            x + 1, y + 1, width - 2, height - 1);
      }

      /* Draw the outline. */
      JXSetForeground(display, gc, outlinePixel);
#ifdef USE_XMU
      XmuDrawRoundedRectangle(display, drawable, gc, x, y, 
         width, height, 3, 3);
#else
      JXDrawRectangle(display, drawable, gc, x, y, width, height);
#endif

      break;
   }

   /* Determine the size of the icon (if any) to display. */
   iconWidth = 0;
   iconHeight = 0;
   if (bp->icon) {
      if(width < height) {
         GetScaledIconSize(bp->icon, width - 5, &iconWidth, &iconHeight);
      } else {
         GetScaledIconSize(bp->icon, height - 5, &iconWidth, &iconHeight);
      }
   }

   /* Determine how much room is left for text. */
   textWidth = 0;
   textHeight = 0;
   if(bp->text) {
      textWidth = GetStringWidth(bp->font, bp->text);
      textHeight = GetStringHeight(bp->font);
      if(textWidth + iconWidth + 8 > width) {
         textWidth = width - iconWidth - 8;
         if(textWidth < 0) {
            textWidth = 0;
         }
      }
   }

   /* Determine the offset of the text in the button. */
   switch(bp->alignment) {
   case ALIGN_CENTER:
      xoffset = width / 2 - (iconWidth + textWidth) / 2;
      if(xoffset < 0) {
         xoffset = 0;
      }
      break;
   case ALIGN_LEFT:
   default:
      xoffset = 3;
      break;
   }

   /* Display the icon. */
   if(bp->icon) {
      yoffset = height / 2 - iconHeight / 2;
      PutIcon(bp->icon, drawable, x + xoffset, y + yoffset,
         iconWidth, iconHeight);
      xoffset += iconWidth + 2;
   }

   /* Display the label. */
   if(bp->text && textWidth) {
      yoffset = height / 2 - textHeight / 2;
      RenderString(drawable, bp->font, fg, x + xoffset, y + yoffset,
         textWidth, NULL, bp->text);
   }

}