Пример #1
0
void ComponentRepeat::notePositions(GlushkovBuildState &bs) {
    assert(m_max > 0);
    assert(m_max == NoLimit || m_max < MAX_MAX_BOUND);

    /* Note: We can construct smaller subgraphs if we're not maintaining edge
     * priorities. */

    // We create one copy only through a recursive call to notePositions(),
    // first() and last(). Then we clone its positions and store the
    // appropriate firsts and lasts values for the copies.
    posFirst = bs.getBuilder().numVertices();
    sub_comp->notePositions(bs);

    u32 copies = m_max < NoLimit ? m_max : MAX(m_min, 1);
    DEBUG_PRINTF("building %u copies of repeated region\n", copies);
    m_firsts.clear();
    m_lasts.clear();
    m_firsts.resize(copies);
    m_lasts.resize(copies);

    m_firsts[0] = sub_comp->first();
    m_lasts[0] = sub_comp->last();

    postSubNotePositionHook();

    posLast = bs.getBuilder().numVertices() - 1;
    u32 vcount = posLast + 1 - posFirst;

    // If we're making more than one copy, then our firsts and lasts must only
    // contain vertices inside [posFirst, posLast]: anything else means we have
    // an embedded anchor or otherwise weird situation.
    if (copies > 1) {
        checkPositions(m_firsts[0], bs);
        checkPositions(m_lasts[0], bs);
    }

    // Avoid enormous expansions
    if (vcount * copies > MAX_POSITIONS_EXPANDED) {
        throw ParseError("Bounded repeat is too large.");
    }

    // Add positions for the rest of the copies
    size_t copyPositions = vcount * (copies - 1);
    bs.getBuilder().makePositions(copyPositions);

    // Calculate our firsts and lasts for the copies
    for (u32 i = 1; i < copies; ++i) {
        m_firsts[i] = m_firsts[0];
        m_lasts[i] = m_lasts[0];
        u32 base = i * vcount;
        addBase(base, m_firsts[i], m_lasts[i]);
    }

    recordPosBounds(posFirst, bs.getBuilder().numVertices());
    precalc_firsts(); /* ComponentRepeat requires firsts to be calculated ahead
                       * of time and cached due to expense */
}
Пример #2
0
static void handleViewResized(void *self, WMNotification * notification)
{
	WMSplitView *sPtr = (WMSplitView *) self;

#if 0
	printf("---- (handleViewResized - 1) ----\n");
	dumpSubviews(sPtr);
#endif

	updateConstraints(sPtr);
	checkSizes(sPtr);

	if (sPtr->constrainProc || sPtr->flags.subviewsWereManuallyMoved) {
		distributeOffsetFormEnd(sPtr, _GetSplitViewSize() - getTotalSize(sPtr));
		checkPositions(sPtr);
		updateSubviewsGeom(sPtr);
	} else
		adjustSplitViewSubviews(sPtr);

	assert(checkSizes(sPtr) == 0);

#if 0
	printf("---- (handleViewResized - 2) ----\n");
	dumpSubviews(sPtr);
#endif
}
Пример #3
0
static void adjustSplitViewSubviews(WMSplitView * sPtr)
{
	W_SplitViewSubview *p;
	int i, count, adjSize, adjPad;

	CHECK_CLASS(sPtr, WC_SplitView);

#if 0
	printf("---- (adjustSplitViewSubviews - 1) ----\n");
	dumpSubviews(sPtr);
#endif

	if ((count = _GetSubviewsCount()) < 1)
		return;

	adjSize = (_GetSplitViewSize() - ((count - 1) * DIVIDER_THICKNESS)) / count;
	adjPad = (_GetSplitViewSize() - ((count - 1) * DIVIDER_THICKNESS)) % count;
	for (i = 0; i < count; i++) {
		p = _GetPSubviewStructAt(i);
		p->size = adjSize;
	}

	distributeOffsetEqually(sPtr, adjPad - checkSizes(sPtr));

	checkPositions(sPtr);
	updateSubviewsGeom(sPtr);

	sPtr->flags.subviewsWereManuallyMoved = 0;

#if 0
	printf("---- (adjustSplitViewSubviews - 2) ----\n");
	dumpSubviews(sPtr);
#endif
}
Пример #4
0
void ScoutDataClass::update()
{
	checkPositions();
}
Пример #5
0
static void dragDivider(WMSplitView * sPtr, int clickX, int clickY)
{
	int divider, pos, ofs, done, dragging;
	int i, count;
	XEvent ev;
	WMScreen *scr;
	int minCoord, maxCoord, coord;

	if (sPtr->constrainProc) {
		updateConstraints(sPtr);
		checkSizes(sPtr);
		distributeOffsetFormEnd(sPtr, _GetSplitViewSize() - getTotalSize(sPtr));
		checkPositions(sPtr);
		updateSubviewsGeom(sPtr);
	}

	scr = sPtr->view->screen;
	divider = ofs = pos = done = 0;
	coord = (sPtr->flags.vertical) ? clickX : clickY;
	count = _GetSubviewsCount();
	if (count < 2)
		return;

	for (i = 0; i < count - 1; i++) {
		pos += _GetSizeAt(i) + DIVIDER_THICKNESS;
		if (coord < pos) {
			ofs = coord - pos + DIVIDER_THICKNESS;
			done = 1;
			break;
		}
		divider++;
	}

	if (!done)
		return;

	getMinMaxDividerCoord(sPtr, divider, &minCoord, &maxCoord);

	done = 0;
	dragging = 0;
	while (!done) {
		WMMaskEvent(scr->display, ButtonMotionMask | ButtonReleaseMask | ExposureMask, &ev);

		coord = (sPtr->flags.vertical) ? ev.xmotion.x : ev.xmotion.y;

		switch (ev.type) {
		case ButtonRelease:
			done = 1;
			if (dragging)
				drawDragingRectangle(sPtr, pos);
			break;

		case MotionNotify:
			if (dragging)
				drawDragingRectangle(sPtr, pos);
			if (coord - ofs < minCoord)
				pos = minCoord;
			else if (coord - ofs > maxCoord)
				pos = maxCoord;
			else
				pos = coord - ofs;
			drawDragingRectangle(sPtr, pos);
			dragging = 1;
			break;

		default:
			WMHandleEvent(&ev);
			break;
		}
	}

	if (dragging) {
		W_SplitViewSubview *p1, *p2;
		int totSize;

		p1 = _GetPSubviewStructAt(divider);
		p2 = _GetPSubviewStructAt(divider + 1);

		totSize = p1->size + DIVIDER_THICKNESS + p2->size;

		p1->size = pos - p1->pos;
		p2->size = totSize - p1->size - DIVIDER_THICKNESS;
		p2->pos = p1->pos + p1->size + DIVIDER_THICKNESS;

		resizeView(sPtr, p1->view, p1->size);
		moveView(sPtr, p2->view, p2->pos);
		resizeView(sPtr, p2->view, p2->size);
		sPtr->flags.subviewsWereManuallyMoved = 1;
	}
}
Пример #6
0
int main() {
    setlocale(LC_ALL, "Portuguese");
    int lin, col;
    Point pos;
    Stack *ways;
    BoolPos currentSituation;
    int i;

    FILE *arquivo;
    arquivo = fopen("labirinto.txt", "r");

    if(arquivo == NULL) {
        printf("Erro ao carregar o labirinto, arquivo não pode ser aberto.");
        return 0;
    }

    fscanf(arquivo, "%i %i", &lin, &col);
    printf("Labirinto %i x %i\n\n", lin, col);

    // Alocate +1 to acomodate the \0 at end of final line
    char (*maze)[col] = (char(*)[col]) malloc((sizeof(char)*lin*col) + 1);

    for(i=0; i<lin; i++) {
        fscanf(arquivo, "%s", maze[i]);
    }

    if (!searchEntry(lin, col, maze, &pos)) {
        printf("\nNão há entrada para esse labirinto, impossível continuar");
        return 0;
    }

    ways = createStack(lin * col);
    push(ways, pos);
    maze[pos.x][pos.y] = 'v';
    while(maze[pos.x][pos.y] != MAZE_OUT) {
        checkPositions(&currentSituation, &pos, lin, col, maze);

        if(maze[pos.x][pos.y] == MAZE_WAY) {
            maze[pos.x][pos.y] = 'v'; //Move
        }

        printf("\nTentativa: %i x %i", pos.x, pos.y);

        if(currentSituation.left == 0 && currentSituation.bottom == 0 && currentSituation.right == 0 && currentSituation.top == 0) {
            if (!pop(ways, &pos)) {
                printf("\nEntrada encontrada não leva para uma saída!\n");

                if(searchEntry(lin, col, maze, &pos)) {
                    printf("Nova entrada encontrada! Resolvendo...\n");
                    push(ways, pos);
                }
                else {
                    printf("\n\nNão foi possível encontrar o caminhos a(s) entrada(s) encontrada(s) não levam à uma saída!\n");
                    break;
                }
            }
        } else {
            push(ways, pos);
        }
    }

    printf("\n\nLabirinto descoberto com sucesso!\nO caminho é:\n\n");

    while(pop(ways, &pos) == TRUE) {
        printf("%iº passo: %i x %i\n", ways->topo +1, pos.x, pos.y);
    }

    deinitStack(ways);
    printf("\n\n");

    free(maze);
    fclose(arquivo);

    system("Pause");
    return 0;
}