Esempio n. 1
0
// Takes a grid of values, each of which is 0 or 100, and fills in some middle values in the interstices.
void antiAlias(unsigned char mask[COLS][ROWS]) {
	short i, j, x, y, dir, nbCount;
	const short intensity[5] = {0, 0, 35, 50, 60};
	
	for (i=0; i<COLS; i++) {
		for (j=0; j<ROWS; j++) {
			if (mask[i][j] < 100) {
				nbCount = 0;
				for (dir=0; dir<4; dir++) {
					x = i + nbDirs[dir][0];
					y = j + nbDirs[dir][1];
					if (coordinatesAreInWindow(x, y) && mask[x][y] == 100) {
						nbCount++;
					}
				}
				mask[i][j] = intensity[nbCount];
			}
		}
	}
}
Esempio n. 2
0
// Draws the button to the screen, or to a display buffer if one is given.
// Button back color fades from -50% intensity at the edges to the back color in the middle.
// Text is white, but can use color escapes.
//		Hovering highlight augments fore and back colors with buttonHoverColor by 20%.
//		Pressed darkens the middle color (or turns it the hover color if the button is black).
void drawButton(brogueButton *button, enum buttonDrawStates highlight, cellDisplayBuffer dbuf[COLS][ROWS]) {
	short i, textLoc, width, midPercent, symbolNumber, opacity, oldRNG;
	color fColor, bColor, fColorBase, bColorBase, bColorEdge, bColorMid;
	uchar displayCharacter;
	
	if (!(button->flags & B_DRAW)) {
		return;
	}
    //assureCosmeticRNG;
	oldRNG = rogue.RNG;
    rogue.RNG = RNG_COSMETIC;
    
	symbolNumber = 0;
	
	width = strLenWithoutEscapes(button->text);
	bColorBase = button->buttonColor;
	fColorBase = ((button->flags & B_ENABLED) ? white : gray);
	
	if (highlight == BUTTON_HOVER && (button->flags & B_HOVER_ENABLED)) {
		//applyColorAugment(&fColorBase, &buttonHoverColor, 20);
		//applyColorAugment(&bColorBase, &buttonHoverColor, 20);
		applyColorAverage(&fColorBase, &buttonHoverColor, 25);
		applyColorAverage(&bColorBase, &buttonHoverColor, 25);
	}
	
	bColorEdge	= bColorBase;
	bColorMid	= bColorBase;
	applyColorAverage(&bColorEdge, &black, 50);
	
	if (highlight == BUTTON_PRESSED) {
		applyColorAverage(&bColorMid, &black, 75);
		if (COLOR_DIFF(bColorMid, bColorBase) < 50) {
			bColorMid	= bColorBase;
			applyColorAverage(&bColorMid, &buttonHoverColor, 50);
		}
	}
	bColor = bColorMid;
	
	opacity = button->opacity;
	if (highlight == BUTTON_HOVER || highlight == BUTTON_PRESSED) {
		opacity = 100 - ((100 - opacity) * opacity / 100); // Apply the opacity twice.
	}
	
	for (i = textLoc = 0; i < width && i + button->x < COLS; i++, textLoc++) {
		while (button->text[textLoc] == COLOR_ESCAPE) {
			textLoc = decodeMessageColor(button->text, textLoc, &fColorBase);
		}
		
		fColor = fColorBase;
		
		if (button->flags & B_GRADIENT) {
            midPercent = smoothHiliteGradient(i, width - 1);
			bColor = bColorEdge;
			applyColorAverage(&bColor, &bColorMid, midPercent);
		}
		
		if (highlight == BUTTON_PRESSED) {
			applyColorAverage(&fColor, &bColor, 30);
		}
		
		if (button->opacity < 100) {
			applyColorAverage(&fColor, &bColor, 100 - opacity);
		}
		
		bakeColor(&fColor);
		bakeColor(&bColor);
		separateColors(&fColor, &bColor);
		
		displayCharacter = button->text[textLoc];
		if (button->text[textLoc] == '*') {
			if (button->symbol[symbolNumber]) {
				displayCharacter = button->symbol[symbolNumber];
			}
			symbolNumber++;
		}
		
		if (coordinatesAreInWindow(button->x + i, button->y)) {
			if (dbuf) {
				plotCharToBuffer(displayCharacter, button->x + i, button->y, &fColor, &bColor, dbuf);
				dbuf[button->x + i][button->y].opacity = opacity;
			} else {
				plotCharWithColor(displayCharacter, button->x + i, button->y, &fColor, &bColor);
			}
		}
	}
    restoreRNG;
}