Beispiel #1
0
/* TODO: make a new type "alphablock" containing a block and a selection */
int pasteblock(ZZTblock *dest, ZZTblock *src, selection destsel, selection srcsel, int x, int y)
{
	int srcpos;     /* Current index in source */
	int row, col;   /* Current row and col in dest */

	/* Paste */

	srcpos = 0;     /* Start at beginning of source object */
	for (row = y; row < src->height + y && row < dest->height; row++) {
		for (col = x; col < src->width + x && col < dest->width; col++, srcpos++) {
			/* Paste the currently indexed tile from source to (row, col) in dest */

			if (row < 0 || col < 0)
				continue;

			/* Only copy selected tiles */
			if (!isselected(destsel, col, row) || !isselected(srcsel, col - x, row - y))
				continue;

			/* Can't use plot because we want to maintain terrain under creatures
			 * from the source block, not the destination block */
			zztTileSet(dest, col, row, src->tiles[srcpos]);
		}
		/* If the loop stopped short of using every column in src, advance
		 * the srcpos index to ignore these columns */
		srcpos += (src->width + x) - col;
		col = src->width + x;
	}

	/* Success! */
	return 1;
}
Beispiel #2
0
int	select(void)
{
	int	sel;
	char	ch;
	int	quit;


	screen();
	selectwindow();

	_setcursortype(_NOCURSOR);

	sel=0;
	quit=0;
	while (!quit)
	{
		drawlist(sel);
		ch=getch();
		if (ch==0)
			ch=getch();
		switch (ch)
		{
		case	72:  	if (sel>=1) sel--;
				break;
		case	80:	if (sel<nummods-1) sel++;
				break;
		case	73:	if (sel>=6) sel-=6; else sel=0;
				break;
		case	81:	if (sel<nummods-6) sel+=6; else sel=nummods-1;
				break;
		case	71:	sel=0;
				break;
		case	79:	sel=nummods-1;
				break;
		case	59:     if (!isselected(sel+1))
					toggle(sel);
				defaultmodule=isselected(sel+1);
				break;
		case	32:	toggle(sel);
				break;
		case	13:	quit=2;
				break;
		case	27:	quit=1;
				break;
		}
	}

	_setcursortype(_NORMALCURSOR);
	window(1,1,80,25);
	textbackground(BLACK);
	textcolor(LIGHTGRAY);
	clrscr();
	return	quit-1;
}
Beispiel #3
0
void floodselect(ZZTblock* block, selection fillsel, int x, int y)
{
	/* If we've already been selected, go back a level */
	if (isselected(fillsel, x, y))
		return;

	/* Select ourselves. That makes us special */
	selectpos(fillsel, x, y);

	/* A little to the left */
	if (x > 0) {
		if (tileEquivalent(zztTileAt(block, x, y), zztTileAt(block, x - 1, y)))
			floodselect(block, fillsel, x - 1, y);
	}

	/* A little to the right */
	if (x < block->width - 1) {
		if (tileEquivalent(zztTileAt(block, x, y), zztTileAt(block, x + 1, y)))
			floodselect(block, fillsel, x + 1, y);
	}

	/* A little to the north */
	if (y > 0) {
		if (tileEquivalent(zztTileAt(block, x, y), zztTileAt(block, x, y - 1)))
			floodselect(block, fillsel, x, y - 1);
	}

	/* A little to the south */
	if (y < block->height - 1) {
		if (tileEquivalent(zztTileAt(block, x, y), zztTileAt(block, x, y + 1)))
			floodselect(block, fillsel, x, y + 1);
	}
}
Beispiel #4
0
int	toggle(int sel)
{
	int	which;

	if ((which=isselected(sel+1))!=0)
	{
		if (which<=defaultmodule)
			defaultmodule--;
		return removeitem(which-1);
	}
	else
		return additem(sel+1);
}
Beispiel #5
0
int getlistitem(listbox obj)
{
	int index, count;

	if (! obj)
		return -1;
	switch (obj->kind)
	{
	case ListboxObject:
	  return sendmessage(obj->handle, LB_GETCURSEL, 0, 0L);
	case MultilistObject:
	  count = sendmessage(obj->handle, LB_GETCOUNT, 0, 0L);
	  for (index=0; index < count; index++)
	    if (isselected(obj, index))
	      return index;
	  return -1;
	case DroplistObject:
	case DropfieldObject:
	  return sendmessage(obj->handle, CB_GETCURSEL, 0, 0L);
	default:
	  return -1;
	}
}
Beispiel #6
0
int	drawlist(int sel)
{
	int 	toprow;
	int	i;
	char	line[90];
	char	temp[10];
	char	*lptr;
	int	which;
	int	num;


	struct	text_info t;
	struct	modrec m;

	if (nummods<24)
		toprow=0;
	else
	{
		toprow=sel-12;
		if (toprow<0)
			toprow=0;
		if (toprow+24>nummods)
			toprow=nummods-24;
	}

	gettextinfo(&t);
	for (i=0; i<(nummods>=24 ? 24 : nummods); i++)
	{
		num=i+toprow;

		_fmemcpy(&m,&mods[num],sizeof(struct modrec));

		if (num==sel)
		{
			if (defaultmodule &&
			    defaultmodule==isselected(num+1))
				tc=YELLOW;
			else
				tc=(WHITE);
			tb=(BLACK);
		}
		else
		{
			tb=(CYAN);
			if (isselected(num+1))
				if (defaultmodule==isselected(num+1))
					tc=YELLOW;
				else
					tc=(WHITE);
			else
				tc=(BLACK);
		}

		wmemset(line,(((tb<<4)+tc)<<8)+0x20,40);

		addto(line+16,m.title);

		line[40*2]=' ';
		line[40*2+1]=CYAN*16+YELLOW;
		if (toprow>0 && i==0)
			line[40*2]='';

		if (toprow+24<nummods && i==23)
			line[40*2]='';


		lptr=line;

		/* Tag location */

		tb=CYAN;
		tc=WHITE;

		if ((which=isselected(num+1))!=0)
			sprintf(temp,"%2d ",which);
		else
			strcpy(temp,"   ");

		lptr=addto(lptr,temp);

		/* Statistics */

		for (which=1; which<8; which+=which)
			if (m.opts&which)
			{
				if (m.exist&which)
					tc=(LIGHTCYAN);
				else
					tc=(DARKGRAY);

				lptr=addto(lptr,
				(which==1 ? "C" :
				(which==2 ? "D" : "G")));

			}
			else
				lptr=addto(lptr," ");

		lptr=addto(lptr," ");

		puttext(t.winleft,t.wintop+i,t.winright,t.wintop+i,line);
	}
	return	1;
}
Beispiel #7
0
SEXP Win_selectlist(SEXP args)
{
    SEXP choices, preselect, ans = R_NilValue;
    const char **clist;
    int i, j = -1, n, mw = 0, multiple, nsel = 0;
    int xmax, ymax, ylist, fht, h0;
    Rboolean haveTitle;

    choices = CAR(args);
    if(!isString(choices)) error(_("invalid '%s' argument"), "choices");
    preselect = CADR(args);
    if(!isNull(preselect) && !isString(preselect))
	error(_("invalid '%s' argument"), "preselect");
    multiple = asLogical(CADDR(args));
    if(multiple == NA_LOGICAL) multiple = 0;
    haveTitle = isString(CADDDR(args));
    if(!multiple && isString(preselect) && LENGTH(preselect) != 1)
	error(_("invalid '%s' argument"), "preselect");

    n = LENGTH(choices);
    clist = (const char **) R_alloc(n + 1, sizeof(char *));
    for(i = 0; i < n; i++) {
	clist[i] = translateChar(STRING_ELT(choices, i));
	mw = max(mw, gstrwidth(NULL, SystemFont, clist[i]));
    }
    clist[n] = NULL;

    fht = getSysFontSize().height;

    xmax = max(170, mw+60); /* allow for scrollbar */
    if(ismdi()) {
	RECT *pR = RgetMDIsize();
	h0 = pR->bottom;
    } else {
	h0 = deviceheight(NULL);
    }
    ymax = min(80+fht*n, h0-100); /* allow for window widgets, toolbar */
    ylist = ymax - 60;
    wselect = newwindow(haveTitle ? translateChar(STRING_ELT(CADDDR(args), 0)):
			(multiple ? _("Select one or more") : _("Select one")),
			rect(0, 0, xmax, ymax),
			Titlebar | Centered | Modal | Floating);
    setbackground(wselect, dialog_bg());
    if(multiple)
	f_list = newmultilist(clist, rect(10, 10, xmax-25, ylist), NULL, finish);
    else
	f_list = newlistbox(clist, rect(10, 10, xmax-25, ylist), NULL, finish);
    if(!isNull(preselect) && LENGTH(preselect)) {
	for(i = 0; i < n; i++)
	    for(j = 0; j < LENGTH(preselect); j++)
		if(strcmp(clist[i], translateChar(STRING_ELT(preselect, j))) == 0) {
		    setlistitem(f_list, i);
		    break;
		}
    }
    bFinish = newbutton(G_("OK"), rect(xmax-160, ymax-40, 70, 25), finish);
    bCancel = newbutton(G_("Cancel"), rect(xmax-80, ymax-40, 70, 25), cancel);
    setkeydown(wselect, key1);
    show(wselect);
    done = 0;
    while(!done) {
	R_WaitEvent();
	R_ProcessEvents();
    }

    if(multiple) {
	if (done == 1) { /* Finish */
	    for(i = 0; i < n; i++)  if(isselected(f_list, i)) nsel++;
	    PROTECT(ans = allocVector(STRSXP, nsel));
	    for(i = 0, j = 0; i < n; i++)
		if(isselected(f_list, i))
		    SET_STRING_ELT(ans, j++, mkChar(clist[i]));
	} else { /* cancel */
	    PROTECT(ans = allocVector(STRSXP, 0));
	}
    } else
	PROTECT(ans = mkString(selected));

    cleanup();
    show(RConsole);
    R_ProcessEvents();
    UNPROTECT(1);
    return ans;
}
Beispiel #8
0
/* Update the display.
 */
static void render(void)
{
    static char const *buttontext[bval_count] = { 
	"Roll Dice", "  Score  ", "  Again  "
    };
    static char const *slottext[ctl_slots_count] = {
	"Ones", "Twos", "Threes", "Fours", "Fives", "Sixes", "Subtotal",
	"Bonus", "Three of a Kind", "Four of a Kind", "Full House",
	"Small Straight", "Large Straight", "Yahtzee", "Chance", "Total Score"
    };

    char const *text;
    int i, n, x;

    erase();

    /* The dice. */

    x = xDice;
    for (i = ctl_dice ; i < ctl_dice_end ; ++i) {
	if (isselected(controls[i]))
	    aset(a_marked);
	drawacsdie(yDice, x, controls[i].value);
	if (isselected(controls[i]))
	    aset(a_normal);
	x += cxDie + cxDieSpacing;
    }

    /* The button. */

    text = buttontext[controls[ctl_button].value];
    move(yButton, xButton);
    if (isdisabled(controls[ctl_button])) {
	aset(a_dim);
	printw("| %s |", text);
	aset(a_normal);
    } else if (isselected(controls[ctl_button])) {
	addstr("[[");
	aset(a_selected);
	addstr(text);
	aset(a_normal);
	addstr("]]");
    } else {
	printw("[ %s ]", text);
    }

    /* The scoring slots. */

    i = ctl_slots;
    x = xSlots;
    while (i < ctl_slots_end) {
	for (n = 0 ; n < ctl_slots_count / 2 ; ++n, ++i) {
	    move(ySlots + n, x);
	    if (isselected(controls[i]))
		aset(a_selected);
	    printw("%-*s", cxSlot - 3, slottext[i - ctl_slots]);
	    if (controls[i].value >= 0) {
		if (isdisabled(controls[i]) || isselected(controls[i]))
		    printw("%3d", controls[i].value);
	    }
	    aset(a_normal);
	}
	x += cxSlot + cxSlotSpacing;
    }

    move(cyScreen - 1, 0);
    refresh();
}