Exemple #1
0
int main()
{
	sf::ContextSettings settings;
	settings.antialiasingLevel = 8;

	sf::RenderWindow window(sf::VideoMode(800, 600), "Lab7", sf::Style::Default, settings);
	sf::View view = sf::View(sf::FloatRect(0, 0, float(window.getSize().x), float(window.getSize().y)));
	window.setView(view);
	window.setVerticalSyncEnabled(true);

	sf::Clock clock;
	
	//init some objects
	struct tm time = getTime();
	struct vectorObjects shapes = initVectorObjects();
	sf::Vector2f center = getCenter(window);
	sf::Text text = initText("rubik.ttf");
	resize(window, shapes);
	setFirstPosition(shapes);

	while (window.isOpen())
	{
		sf::Time elapsed = clock.restart();
		animationUpdate(elapsed, shapes);

		drawWindows(window, shapes, text);

		window.display();
		events(window, shapes);
	}

	return 0;
}
void XBScene1::drawIntoFBO()
{
    XBScene1GUI *myGUI = (XBScene1GUI *) gui;

    float windowScale = XBSettingsManager::getInstance().getWindowScale();

    fbo.begin();
    {
        ofPushMatrix();
        ofScale(windowScale, windowScale);
        if (showFacadeImage)
            templateImage.draw(0, 0);
        else
            ofBackground(0);

        if (showTemplate) {
            ofSetColor(255);
            svg.draw();
        }

        drawDirector();
        drawPiano();

        // draw time markers
        if (myGUI->showTimeMarker) {
            ofSetColor(220);
            ofDrawLine(0, violinTimeIndex, ofGetWidth() / windowScale, violinTimeIndex);
            ofDrawLine(celloTimeIndex, 0, celloTimeIndex, ofGetHeight() / windowScale);
        }

        if(myGUI->drawWindows)
            drawWindows();

        // mask for removing the windows
        if (maskWindows == true) {
            ofPushStyle();
            ofEnableBlendMode(OF_BLENDMODE_MULTIPLY);
            mask.draw(0, 0);
            ofPopStyle();
        }
        drawViolinCello();
        ofPopMatrix();
        drawMusiciansWindows();

        drawGUI();
    }
    fbo.end();
    blur.apply(&fbo, 1, myGUI->blurAmount);
    if(animating)
        myGUI->glowAmount.getParameter().cast<int>() = animtedGlowAmount;
    applyPostFX();
}
Exemple #3
0
int main()
{
    int max_rows, max_cols;
    int fake = 7;

	WINDOW* statusbar = nullptr;
	WINDOW* treeview = nullptr;
	WINDOW* commandline = nullptr;

	pugi::xml_document doc;
	pugi::xml_parse_result result;
	struct Group* root;
    struct Group* current_selection;

	std::string command = "";

	char server_addr[IP_ADDRLEN] = "127.0.0.1";
	char buffer[8192];
	unsigned short port = 26750;
	struct sockaddr_in server;
	struct in_addr addr;
	socklen_t server_size = sizeof server;
	int sock;
	int packlen;

	initscr();
    getmaxyx(stdscr, max_rows, max_cols);

	if (has_colors() == FALSE)
	{
		endwin();
		std::cerr << "\nncurses: colors not supported.\n";
		return 1;
	}

	start_color();
	init_pair(1, COLOR_WHITE, COLOR_BLACK);
	init_pair(2, COLOR_RED, COLOR_BLACK);

	attron(COLOR_PAIR(1));
	//attron(A_BOLD);

	cbreak(); // we don't need to push [enter]
	noecho(); // pressed keys are not displayed
	keypad(stdscr, TRUE);
    keypad(commandline, TRUE);

	move(7,1);
	printw("Sending request to %s:%i...", server_addr, port);

	std::string packet_1 = "1oeila";
	const unsigned packet_1_len = packet_1.length();

	if (inet_pton(AF_INET, server_addr, &addr) <= 0) // returns 1 on success
    {
        printw("Invalid IP address (inet_pton).");
        refresh();
        getch();
        endwin();
        return 1;
    }

	memset(&server, 0, sizeof server);
	server.sin_family = AF_INET;
    server.sin_port = htons(port);
    server.sin_addr = addr;

	sock = socket(AF_INET, SOCK_DGRAM, 0);

	packlen = sendto(sock, packet_1.c_str(), packet_1_len, 0, (struct sockaddr*)&server, sizeof(server));
	if (packlen <= 0)
	{
		printw("error");
		refresh();
		getch();
		endwin();
		return 1;
	}
	printw("done");
	move(8,1);
	printw("Waiting for response...");
	refresh();

	packlen = recvfrom(sock, buffer, sizeof buffer, 0, (struct sockaddr*)&server, &server_size);
	if (packlen <= 0)
	{
		printw("error");
		refresh();
		getch();
		endwin();
		return 1;
	}
	printw("done");

	move(9,1);
    printw("Loading tree...");
	result = doc.load_buffer(buffer, sizeof buffer);

	switch (result.status)
    {
        case pugi::status_ok:
        {
        	printw("done");
        	move(10,1);
        	printw("Rebuilding tree...");
        	root = populate_tree(doc.first_child().first_child());  // -> TreeStructure -> Root 
        	if (root == nullptr)
        	{
        		refresh();
        		getch();
        		endwin();
        		return 1;
        	}
        	else
            {
        		printw("done");
                getch();
            }
            break;
        }
        case pugi::status_io_error:
        case pugi::status_file_not_found:
        {
            printw("IO error.");
            refresh();
            getchar();
            endwin();
            return 1;
        }
        case pugi::status_out_of_memory:
        {
            printw("out of memory.");
            refresh();
            getchar();
            endwin();
            return 1;
        }
        case pugi::status_internal_error:
        {
            printw("internal error while loading.");
            refresh();
            getchar();
            endwin();
            return 1;
        }
        default:
        {
            printw("error while parsing.");
            refresh();
            getchar();
            endwin();
            return 1;
        }
    }

    drawWindows(&statusbar, &treeview, &commandline);
    drawTree(&treeview, root, 2, 3, 1);
    mvwprintw(statusbar, 1, max_cols-18, "Total groups: %i", root->total_subgroups+1);
    wrefresh(statusbar);

    wmove(commandline, 1, 3);

    current_selection = root;

    while (1)
    {
    	int keypress = getch();

        if (keypress == KEY_LEFT) // return to father node
        {
            if (current_selection->father != nullptr) // if not root
            {
                current_selection = current_selection->father;
                drawTree(&treeview, root, 2, 3, current_selection->id);
            }
        }
        else if (keypress == KEY_RIGHT) // enter the first child
        {
            if (current_selection->total_subgroups) // if has children
            {
                current_selection = current_selection->children[0];
                drawTree(&treeview, root, 2, 3, current_selection->id);
            }
        }
        else if (keypress == KEY_UP) // navigate through siblings
        {
            if (current_selection->id > 1) // if not root
            {
                int sibling_index = getIndexById(current_selection->father, current_selection->id) - 1;

                if (sibling_index >= 0) // check bounds
                {
                    current_selection = current_selection->father->children[sibling_index];
                    drawTree(&treeview, root, 2, 3, current_selection->id);
                }
            }
        }
        else if (keypress == KEY_DOWN) // navigate through siblings
        {
            if (current_selection->id > 1) // if not root
            {
                int sibling_index = getIndexById(current_selection->father, current_selection->id) + 1;

                if (sibling_index < current_selection->father->children.size()) // check bounds
                {
                    current_selection = current_selection->father->children[sibling_index];
                    drawTree(&treeview, root, 2, 3, current_selection->id);
                }
            }
        }
    	else if ((keypress >= 'A' && keypress <= 'Z') || (keypress >= 'a' && keypress <= 'z') || (keypress >= '0' && keypress <= '9') || keypress == ' ') // command
    	{
    		command += (char)keypress;
    		waddch(commandline, keypress);
    		wrefresh(commandline);
    	}
    	else if (keypress == 127 || keypress == 8) // backspace
    	{
    		int slen = command.length(), c_y, c_x;
    		if (slen > 0)
    		{
    			command.erase(command.end()-1);
    			getyx(commandline, c_y, c_x);
    			mvwaddch(commandline, c_y, c_x-1, ' ');
                wmove(commandline, c_y, c_x-1);
                wrefresh(commandline);
    		}
        }
    	else if (keypress == 10) // enter
    	{
            if (command == "")
            {
                endwin();
                delete root;
                return 1;
            }

            std::string buf;
            std::vector<std::string> tokens;
            std::stringstream ss(command);

            // split the command into individual words (delim == ' ')

            while (ss >> buf)
            {
                tokens.push_back(buf);
            }

            /*if (tokens[0] == "datetime")
            {
                time_t current_time;
                struct tm* time_info;
                char timeString[9];

                time(&current_time);
                time_info = localtime(&current_time);
                strftime(timeString, sizeof(timeString), "%H:%M:%S", time_info);

                mvwprintw(treeview, fake++, 50, ">> server replies: %s", timeString);
                wrefresh(treeview);
            }
            else
            {
                endwin();
                delete root;
                return 1;
            }*/
    	}
        else if (keypress == KEY_LEFT)
        {
            endwin();
            delete root;
            return 1;
        }
    }