示例#1
0
void GraphicsMisc::DrawSplitBar(CDC* pDC, const CRect& rSplitter, COLORREF crSplitBar, BOOL bEdged)
{
	BOOL bVert = (rSplitter.Height() > rSplitter.Width());
	DWORD dwEdges = (bEdged ? (bVert ? (GMDR_LEFT | GMDR_RIGHT) : (GMDR_TOP | GMDR_BOTTOM)) : 0);

	DrawRect(pDC, rSplitter, crSplitBar, Darker(crSplitBar, 0.2), 0, dwEdges);

	// draw drag marker (2 x 20)
	int nSplitWidth = min(rSplitter.Width(), rSplitter.Height());
	
	if (nSplitWidth > 2)
	{
		CRect rMarker(rSplitter);
		CPoint ptCentre = rMarker.CenterPoint();
		
		if (bVert)
		{
			rMarker.left = ptCentre.x - 1;
			rMarker.right = ptCentre.x + 1;

			rMarker.top = ptCentre.y - 10;
			rMarker.bottom = ptCentre.y + 10;
		}
		else // horizontal
		{
			rMarker.left = ptCentre.x - 10;
			rMarker.right = ptCentre.x + 10;
			
			rMarker.top = ptCentre.y - 1;
			rMarker.bottom = ptCentre.y + 1;
		}
		
		// use the splitter bkgnd luminance to decide whether
		// to draw the marker lighter or darker
		if (RGBX(crSplitBar).Luminance() > 128)
			pDC->FillSolidRect(rMarker, Darker(crSplitBar, 0.3));
		else
			pDC->FillSolidRect(rMarker, Lighter(crSplitBar, 0.3));
	}
}
示例#2
0
文件: List.c 项目: Lepzulnag/Winbox
// Dessin
void DrawList(Widget *w)
{
	SDL_Surface *scr = w->construct->scr;
	wTHEME *t = w->construct->theme;
	ListArgs *args = w->args;
	wMENU *m = args->menu;
	Uint32 c = Darker(t->color1, 60);
	Uint32 c2 = args->isActive? t->request_c1:t->request_c2;
	if (!c2) c2 = t->color1;
	char *s;

	int ws = nSDL_GetStringWidth(t->font, m->title);
	int xw = (w->bounds.w*3)/5;
	if (!m->title)
		xw = w->bounds.w - 6;
	else if (xw + ws + 9 > w->bounds.w)
		xw = w->bounds.w - ws - 9;
	int x = w->bounds.x + w->bounds.w - xw - 3;
	
	if (m->title)
		DrawClippedStr(scr, t->font, w->bounds.x+3, w->bounds.y+6, m->title);
	DrawFillRectXY(scr, x, w->bounds.y + 3, xw, 14, c2);
	DrawRectXY(scr, x, w->bounds.y + 3, xw, 14, c);
	
	if (!args->isActive) SDL_SetAlpha(t->menus_right, SDL_SRCALPHA, 128);
	DrawSurface(t->menus_right, NULL, scr, &(SDL_Rect) {x+xw-8, w->bounds.y+6, 5, 7});
	if (!args->isActive) SDL_SetAlpha(t->menus_right, SDL_SRCALPHA, SDL_ALPHA_OPAQUE);
	
	if (args->nSelected) {
		s = wMenu_GetSelectedStr(m);
		SDL_Rect clip;
		SDL_GetClipRect(scr, &clip);
		SDL_SetClipRect(scr, &(SDL_Rect) {x+2, w->bounds.y, xw-11, w->bounds.h});
		
		if (args->nSelected>1) {
			char str[strlen(s)+5];
			sprintf(str, "%s,...", s);
			DrawClippedStr(scr, t->menus_font1, x+2, w->bounds.y+6, str);
		}
		else if (args->nSelected==1) DrawClippedStr(scr, t->menus_font1, x+2, w->bounds.y+6, s);
		
		SDL_SetClipRect(scr, &clip);
	}
	else {
		DrawClippedStr(scr, t->menus_font1, x+2 + (xw-4)/2, w->bounds.y+6, "-");
	}
}
示例#3
0
文件: List.c 项目: Lepzulnag/Winbox
int OpenMenu(Widget *w, wMENU *m, int xr, int xl, int minWidth, int y)
{
	if (!w || !m) return MENU_QUIT;
	if (!m->nItems || !m->items) return MENU_QUIT;

	SDL_Surface *scr = w->construct->scr;
	wTHEME *t = w->construct->theme;
	ListArgs *args = w->args;
	wITEM *itm;
	wMENU *menu;
	int x, l;
	SDL_Rect area;
	SDL_Surface *saveImage;
	Uint32 c = Darker(t->color1, 60);
	Uint32 cs1 = Darker(t->menus_c1, 15);	// color selection
	args->cMenu = m;
	args->yItem = 0;
	args->cItem = 0;
	int dItems = min(args->dItems, m->nItems);
	if (!dItems) dItems = m->nItems;
	SDL_Rect clip;
	SDL_GetClipRect(scr, &clip);
	int b;
	int ok = ACTION_CONTINUE;
	
	// calcul de la hauteur
	int h = 10*dItems+2;
	while (h > 234) h-=10, dItems-=1;
	if (y+h > scr->h) y = scr->h - h;
	
	// calcul de la largeur
	int wd = 0;
	for (x=0; x < m->nItems; x++) {
		itm = m->items[x];
		l = nSDL_GetStringWidth(t->menus_font1, itm->str);
		if (l > wd) wd = l;
		l = nSDL_GetStringWidth(t->menus_font2, itm->str);
		if (l > wd) wd = l;
	}
	wd += 10;
	if (m->nItems > dItems) wd += 7;	// pour les scrollbars
	if (wd < minWidth) wd = minWidth;
	if (wd > scr->w) wd = scr->w;
	if (xr+wd > scr->w) {
		if (xl-wd > 0) xr = xl - wd;
		else xr = scr->w - wd;
	}
	
	// sauvegarde de l'image
	area = (SDL_Rect) {xr, y, wd, h};
	saveImage = SDL_CreateRGBSurface(SDL_SWSURFACE, wd, h, 16, 0, 0, 0, 0);
	DrawSurface(scr, &area, saveImage, NULL);
	if ((ok=wExecCallback(w, SIGNAL_ACTION)) != ACTION_CONTINUE) {
		SDL_FreeSurface(saveImage);
		return ok;
	}
	
	do {
		// dessin !!!
		SDL_SetClipRect(scr, &area);
		DrawFillRect(scr, &area, t->menus_c1);
		DrawRect(scr, &area, c);
		
		
		for (x=0; x < dItems; x++) {
			itm = m->items[x + args->yItem];
			
			if (x == args->cItem)
				DrawFillRectXY(scr, xr+1, y+1+10*x, wd-2, 10, cs1);
			
			if (itm->magicNumber == 1) {
				menu = (wMENU *) itm;
				
				if (wMenu_HasSelectedItemOrMenu(menu))
					DrawClippedStr(scr, t->menus_font2, xr+2, y+2+10*x, menu->title);
				else
					DrawClippedStr(scr, t->menus_font1, xr+2, y+2+10*x, menu->title);
				
				DrawSurface(t->menus_right,NULL,scr, &(SDL_Rect){xr+wd - (m->nItems > dItems? 17:8), y+2+10*x, 5, 7});
			}
			
			else {
				if (itm->isSelected)
					DrawClippedStr(scr, t->menus_font2, xr+2, y+2+10*x, itm->str);
				else
					DrawClippedStr(scr, t->menus_font1, xr+2, y+2+10*x, itm->str);
			}
		}
		if (m->nItems > dItems)
			DrawVScrollBar(scr, t, &area, 10*m->nItems+2, 10*args->yItem);
		SDL_SetClipRect(scr, &clip);
		
		
		// activation !!!
		itm = m->items[args->cItem + args->yItem];
	  ACTIVATION:
		SDL_Flip(scr);
		while ((any_key_pressed() && !K_CTRL()) || K_CLICK());
		while (!any_key_pressed());
		
		if (K_CLICK() || K_ENTER()) {
			if (K_ENTER() && args->maxSelected != 1) {
				ok = wExecCallback(w, SIGNAL_CLICK);
				break;
			}
			if (itm->magicNumber == 1) goto NEWMENU;
			
			if (args->maxSelected == 1) {
				if (args->nSelected) wMenu_DeselectAll(args->menu);
				wMenu_SelectItem(m, args->yItem + args->cItem);
				args->nSelected = 1;
				
				DrawSurface(saveImage, NULL, scr, &area);
				SDL_FreeSurface(saveImage);
				saveImage = NULL;
				ok = wExecCallback(w, K_CLICK() || K_ENTER()? SIGNAL_CLICK : SIGNAL_ACTION);
				break;
			}
			
			else if (args->maxSelected >= 0) {
				b = wMenu_IsSelected(m, args->yItem + args->cItem);
				if (!b && args->nSelected)
					if (args->nSelected == args->maxSelected) goto ACTIVATION;
				
				wMenu_SelectItem(m, args->yItem + args->cItem);
				if (b) args->nSelected--;
				else args->nSelected++;
			}
			if ((ok=wExecCallback(w, SIGNAL_CLICK)) != ACTION_CONTINUE)
				break;
		}
		
		else if (K_UP()) {
			if (!args->yItem && !args->cItem) {
				if (K_CTRL()) goto ACTIVATION;
				args->cItem = dItems-1;
				args->yItem = m->nItems-dItems;
			}
			else {
				if (args->cItem) args->cItem--;
				else args->yItem--;
			}
			if ((ok=wExecCallback(w, SIGNAL_ACTION)) != ACTION_CONTINUE)
				break;
		}
		
		else if (K_DOWN()) {
			if (args->yItem + args->cItem >= m->nItems-1) {
				if (K_CTRL()) goto ACTIVATION;
				args->cItem = 0;
				args->yItem = 0;
			}
			else {
				if (args->cItem < dItems-1) args->cItem++;
				else args->yItem++;
			}
			if ((ok=wExecCallback(w, SIGNAL_ACTION)) != ACTION_CONTINUE)
				break;
		}
		
		else if (K_RIGHT() && itm->magicNumber == 1) {
		  NEWMENU:;
			int yI = args->yItem, cI = args->cItem;
			ok = OpenMenu(w, (wMENU *) itm, xr+wd-3, xr, minWidth, y+10*args->cItem);
			
			args->cMenu = m;
			args->yItem = yI;
			args->cItem = cI;
			if (K_ESC() || K_ENTER() || (K_CLICK() && args->maxSelected == 1) || ok != ACTION_CONTINUE) break;
			if ((ok=wExecCallback(w, SIGNAL_ACTION)) != ACTION_CONTINUE)
				break;
		}
		
		else if (K_LEFT()) break;
	} while (!K_ESC());
	
	
	if (saveImage) {
		DrawSurface(saveImage, NULL, scr, &area);
		SDL_FreeSurface(saveImage);
	}
	return ok;
}