Пример #1
0
bool Root::loadFrom(std::string name) {
    auto xml =
        Kriti::ResourceRegistry::get<Kriti::XMLResource>("conv/" + name);

    if(!xml) return false;

    auto objects = xml->doc().first_element_by_path("/conversation/objects");

    // First pass to create objects.
    for(auto c = objects.first_child(); c ; c = c.next_sibling()) {
        int id = c.attribute("id").as_int();
        if(!std::strcmp(c.name(), "node")) {
            m_nodeMap[id] = boost::make_shared<Node>();
        }
        else if(!std::strcmp(c.name(), "context")) {
            m_contextMap[id] = boost::make_shared<Context>();
        }
        else if(!std::strcmp(c.name(), "link")) {
            m_linkMap[id] = boost::make_shared<Link>();
        }
        else {
            Message3(Game, Debug, "Unknown object type " << c.name());
        }
    }

    // Second pass to parse objects.
    for(auto c = objects.first_child(); c ; c = c.next_sibling()) {
        int id = c.attribute("id").as_int();
        if(!std::strcmp(c.name(), "node")) {
            loadNode(id, c);
        }
        else if(!std::strcmp(c.name(), "context")) {
            loadContext(id, c);
        }
        else if(!std::strcmp(c.name(), "link")) {
            loadLink(id, c);
        }
        else {
            Message3(Game, Debug, "Unknown object type " << c.name());
        }
    }

    if(!m_rootNode) {
        Message3(Game, Error, "Couldn't load conversation \"" << name
            << "\": no root node");
        return false;
    }

    return true;
}
Пример #2
0
void MainWindow::clickLink()
{
	connect(view, SIGNAL(linkClicked(QUrl)), this, SLOT(loadLink(QUrl)));
}
Пример #3
0
int main (int argc, char* argv[]) {

	SDL_Init(SDL_INIT_EVERYTHING);
	IMG_Init(IMG_INIT_PNG);

	const std::string IMAGE_DIRECTORY = "C:\\Users\\dK\\Documents\\Visual " \
		                                "Studio 2012\\Projects\\SdlDemoProject\\Debug\\resources\\";

	const std::string LINK_IMAGE = IMAGE_DIRECTORY + "KidLink-1.png";
	const std::string BACKGROUND = IMAGE_DIRECTORY + "TerribleBackground.png";

	Renderer* renderer = new Renderer("SdlDemo", 500, 500, SDL_WINDOW_SHOWN);

	renderer->clearRenderer(0xFF, 0xFF, 0xFF);

	Texture* background = new Texture();

	AnimatedTexture* linkTexture = loadLink(LINK_IMAGE, renderer->getRenderer());

	if (!background->loadFromFile(BACKGROUND, renderer->getRenderer())) {
		delete linkTexture;
		delete renderer;
		IMG_Quit();
		SDL_Quit();
		return 1;
	}

	SDL_Rect blocks[10];

	blocks[0].x = 0;
	blocks[0].y = 0;
	blocks[1].x = 50;
	blocks[1].y = 0;
	blocks[2].x = 0;
	blocks[2].y = 50;
	blocks[3].x = 200;
	blocks[3].y = 200;
	blocks[4].x = 250;
	blocks[4].y = 250;
	blocks[5].x = 450;
	blocks[5].y = 400;
	blocks[6].x = 450;
	blocks[6].y = 450;
	blocks[7].x = 400;
	blocks[7].y = 450;
	blocks[8].x = 450;
	blocks[8].y = 0;
	blocks[9].x = 0;
	blocks[9].y = 450;


	for (int i = 0; i < 10; i++) {
		blocks[i].w = 50;
		blocks[i].h = 50;
	}

	SDL_Rect linkLocation = {100, 100, 50, 87};
	SDL_Rect oldPosition;
	SDL_Rect frame = linkTexture->getCurrentFrame()->getDiminsions();
	SDL_Rect draw = {0, 0, 500, 500};

	SDL_Event events;

	int xAccelorator = 0; 
	int yAccelorator = 0;

	while (true) {

		SDL_PumpEvents();

		oldPosition = linkLocation;

		if (SDL_PeepEvents(&events, 1, SDL_GETEVENT, SDL_QUIT, SDL_KEYUP)) {

			if (events.type == SDL_QUIT || (events.key.type == SDL_KEYDOWN && events.key.keysym.scancode == SDL_SCANCODE_ESCAPE)) {
				break;
			}
			else if (events.key.type == SDL_KEYDOWN && events.key.keysym.scancode == SDL_SCANCODE_DOWN) {
				 yAccelorator = 5;
				 linkTexture->animate("WalkDown");
			}
			else if (events.key.type == SDL_KEYDOWN && events.key.keysym.scancode == SDL_SCANCODE_UP) {
				yAccelorator = -5;
				linkTexture->animate("WalkUp");
			}
			else if (events.key.type == SDL_KEYDOWN && events.key.keysym.scancode == SDL_SCANCODE_RIGHT) {
				xAccelorator = 5;
				linkTexture->animate("WalkRight");
			}
			else if (events.key.type == SDL_KEYDOWN && events.key.keysym.scancode == SDL_SCANCODE_LEFT) {
				xAccelorator = -5;
				linkTexture->animate("WalkLeft");
			}

			if (events.key.type == SDL_KEYUP) {
				frame = linkTexture->getIdleFrame()->getDiminsions();
				linkTexture->reset();
			} else {
				frame = linkTexture->getCurrentFrame()->getDiminsions();
			}

			linkLocation.x += xAccelorator;
			linkLocation.y += yAccelorator;

			if (linkLocation.x < 0 || linkLocation.x + linkLocation.w > 500) {
				linkLocation = oldPosition;
			}
			if (linkLocation.y < 0 || linkLocation.y + linkLocation.h > 500) {
				linkLocation = oldPosition;
			}

			for (int i = 0; i < 10; i++) {
				if ((blocks[i].x + blocks[i].w >= linkLocation.x && linkLocation.x + linkLocation.w >= blocks[i].x) &&
				    (blocks[i].y + blocks[i].h >= linkLocation.y && linkLocation.y + linkLocation.h >= blocks[i].y)) {
					   linkLocation = oldPosition;
				}
			}

			SDL_FlushEvents(SDL_QUIT, SDL_KEYUP);
			xAccelorator = 0;
			yAccelorator = 0;
		}
		renderer->clearRenderer(0xFF, 0xFF, 0xFF);

		renderer->drawToRenderer(background->getTexture(), draw);
		renderer->drawToRenderer(linkTexture->getTexture(), linkLocation, frame);

		SDL_SetRenderDrawColor(renderer->getRenderer(), 20, 100, 20, 0xFF);

		for (int i = 0; i < 10; i++) {
			SDL_RenderFillRect(renderer->getRenderer(), &blocks[i]);
		}

		renderer->update();
	}

	delete background;
	delete linkTexture;
	delete renderer;
	IMG_Quit();
	SDL_Quit();
	return 0;
}
Пример #4
0
int XMIResource::processElement(xmlTextReaderPtr reader)
{
    const xmlChar *name = xmlTextReaderConstLocalName(reader);
    parent = NB_XCOS_NAMES;

    // lookup for known node names
    // thanks to the string intern-ing, the pointer comparison could be used
    auto found = std::find(constXcosNames.begin(), constXcosNames.end(), name);
    enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
    switch (current)
    {
        case e_Diagram:
        {
            // the root diagram should be decoded
            model::BaseObject o(root, DIAGRAM);

            processed.push_back(o);
            return loadDiagram(reader, o);
        }
        case e_child:
        {
            // this is a child of a diagram, resolve the type and call the loaders
            // iterate on attributes to lookup for EMF type

            // iterate on attributes
            for (int rc = xmlTextReaderMoveToFirstAttribute(reader); rc > 0; rc = xmlTextReaderMoveToNextAttribute(reader))
            {
                const xmlChar* nsURI  = xmlTextReaderConstNamespaceUri(reader);
                if (nsURI != xsiNamespaceUri)
                {
                    continue;
                }

                auto foundName = std::find(constXcosNames.begin(), constXcosNames.end(), xmlTextReaderConstLocalName(reader));
                enum xcosNames currentName = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), foundName));
                if (currentName != e_type)
                {
                    continue;
                }

                const xmlChar* value = xmlTextReaderConstValue(reader);
                const xmlChar* valueWithoutPrefix = BAD_CAST(std::strchr((const char*) value, ':'));
                if (valueWithoutPrefix == nullptr)
                {
                    valueWithoutPrefix = value;
                }
                else
                {
                    // remove the leading ':'
                    valueWithoutPrefix = valueWithoutPrefix + 1;
                }
                const xmlChar* interned = xmlTextReaderConstString(reader, valueWithoutPrefix);

                auto found = std::find(constXcosNames.begin(), constXcosNames.end(), interned);
                enum xcosNames current = static_cast<enum xcosNames>(std::distance(constXcosNames.begin(), found));
                switch (current)
                {
                    case e_Block:
                    {
                        ScicosID o = controller.createObject(BLOCK);

                        // assign the child
                        model::BaseObject parent = processed.back();
                        std::vector<ScicosID> children;
                        controller.getObjectProperty(parent.id(), parent.kind(), CHILDREN, children);
                        children.push_back(o);
                        controller.setObjectProperty(parent.id(), parent.kind(), CHILDREN, children);

                        model::BaseObject child(o, BLOCK);
                        processed.push_back(child);
                        return loadBlock(reader, child);
                    }
                    case e_Link:
                    {
                        ScicosID o = controller.createObject(LINK);

                        // assign the child
                        model::BaseObject parent = processed.back();
                        std::vector<ScicosID> children;
                        controller.getObjectProperty(parent.id(), parent.kind(), CHILDREN, children);
                        children.push_back(o);
                        controller.setObjectProperty(parent.id(), parent.kind(), CHILDREN, children);

                        model::BaseObject child(o, LINK);
                        processed.push_back(child);
                        return loadLink(reader, child);
                    }
                    case e_Annotation:
                    {
                        ScicosID o = controller.createObject(ANNOTATION);

                        // assign the child
                        model::BaseObject parent = processed.back();
                        std::vector<ScicosID> children;
                        controller.getObjectProperty(parent.id(), parent.kind(), CHILDREN, children);
                        children.push_back(o);
                        controller.setObjectProperty(parent.id(), parent.kind(), CHILDREN, children);

                        model::BaseObject child(o, ANNOTATION);
                        return loadAnnotation(reader, child);
                    }
                    default:
                        sciprint("Not handled child type=%s at line %d\n", *found,
                                 xmlTextReaderGetParserLineNumber(reader) - 1);
                        return -1;
                }
            }
            break;
        }
        case e_in: // no break on purpose
        case e_out: // no break on purpose
        case e_ein: // no break on purpose
        case e_eout:
        {
            ScicosID o = controller.createObject(PORT);

            enum object_properties_t p;
            switch (current)
            {
                case e_in:
                    p = INPUTS;
                    break;
                case e_out:
                    p = OUTPUTS;
                    break;
                case e_ein:
                    p = EVENT_INPUTS;
                    break;
                case e_eout:
                    p = EVENT_OUTPUTS;
                    break;
                default:
                    return -1;
            }

            model::BaseObject parent = processed.back();
            // add the port them to the parent
            std::vector<ScicosID> ports;
            controller.getObjectProperty(parent.id(), parent.kind(), p, ports);
            ports.push_back(o);
            controller.setObjectProperty(parent.id(), parent.kind(), p, ports);

            // decode content
            model::BaseObject child(o, PORT);
            return loadPort(reader, child);
        }
        case e_geometry:
            // geometry is used for rectangle coordinates of its parent
            return loadGeometry(reader, processed.back());
        case e_nzcross:
            // nzcross is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_nmode:
            // nmode is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_rpar:
            // rpar is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_ipar:
            // ipar is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_opar:
            // ipar is a Block property
            return loadBase64(reader, OPAR, processed.back());
        case e_state:
            // state is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_dstate:
            // dstate is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_odstate:
            // odstate is a Block property
            return loadBase64(reader, ODSTATE, processed.back());
        case e_equations:
            // equation is a Block property
            return loadBase64(reader, EQUATIONS, processed.back());
        case e_expression:
            // expression is a Block property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_exprs:
            // exprs is a Block property
            return loadBase64(reader, EXPRS, processed.back());
        case e_controlPoint:
            // controlPoint is a link property
            return loadPoint(reader, processed.back());
        case e_context:
            // context is a Layer property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        case e_properties:
            // properties is a Diagram property
            return loadSimulationConfig(reader, processed.back());
        case e_datatype:
            // datatype is a Port property
            if (!xmlTextReaderIsEmptyElement(reader))
            {
                parent = current;
            }
            return 1;
        default:
            sciprint("Unknown \"%s\" element name at line %d\n", name, xmlTextReaderGetParserLineNumber(reader) - 1);
            return -1;
    }

    return 1;
}