Example #1
0
int main(int argc, char **argv) {


	SDL_Init( SDL_INIT_VIDEO );
	screen = SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE );
	cr = cairosdl_create (screen);

	SDL_WM_SetCaption( WINDOW_TITLE, 0 );

	#ifdef __WIN32__
		HINSTANCE handle = ::GetModuleHandle(NULL);
		mainicon = ::LoadIcon(handle, "main");
		SDL_SysWMinfo wminfo;
		SDL_VERSION(&wminfo.version);
		if (SDL_GetWMInfo(&wminfo) == 1) ::SetClassLong(wminfo.window, GCL_HICON, (LONG) mainicon);
	#endif


	SDL_EnableKeyRepeat(300, 50);    
	SDL_EnableUNICODE(1);



	
	wrapper = new WinAxrWrapper();
	AXRCore::p core = wrapper->getCore();
	wrapper->hwnd = wminfo.window;

	wrapper->loadFile();


	SDL_Event event;
	while (SDL_WaitEvent(&event)) {
			if (event.type == SDL_QUIT) {
				break;
			} else if (event.type == SDL_MOUSEBUTTONDOWN) {
				AXRCore::p core = wrapper->getCore();
				HSSContainer::p root = core->getController()->getRoot();
				if (root) {
					HSSPoint thePoint;
					thePoint.x = event.button.x;
					thePoint.y = event.button.y;
					root->handleEvent(HSSEventTypeMouseDown, &thePoint);
				}
			} else if (event.type == SDL_MOUSEBUTTONUP) {
				AXRCore::p core = wrapper->getCore();
				HSSContainer::p root = core->getController()->getRoot();
				if (root) {
					HSSPoint thePoint;
					thePoint.x = event.button.x;
					thePoint.y = event.button.y;
					root->handleEvent(HSSEventTypeMouseUp, &thePoint);
				}
			} else if (event.type == SDL_MOUSEMOTION) {
				AXRCore::p core = wrapper->getCore();
				HSSContainer::p root = core->getController()->getRoot();
				if (root) {
					HSSPoint thePoint;
					thePoint.x = event.motion.x;
					thePoint.y = event.motion.y;
					root->handleEvent(HSSEventTypeMouseMove, &thePoint);
				}
			} else if (event.type == SDL_KEYDOWN) {
			} else if (event.type == SDL_KEYUP) {
				if(event.key.keysym.sym == SDLK_F5) {
					reload();
				} else if(event.key.keysym.sym == SDLK_o && (event.key.keysym.mod & KMOD_CTRL) ) {
					wrapper->loadFile();
				}
			} else if(event.type == SDL_VIDEORESIZE) {
				cairosdl_destroy (cr);
				screen = SDL_SetVideoMode (event.resize.w, event.resize.h, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE);
				SDL_SetAlpha(screen,SDL_SRCALPHA,CAIROSDL_AMASK);
				cr = cairosdl_create (screen);
				wrapper->setNeedsDisplay(true);
			} else {
			}
			render();

			SDL_Flip(screen);
			//SDL_Delay(1000/30);
	}
	SDL_Quit();
	#ifdef __WIN32__
		::DestroyIcon(mainicon);
	#endif
	return 0;
}
Example #2
0
void HSSRequest::fire()
{
    AXRDocument* document = this->getController()->document();

    //if there is no target
    if (this->target->empty())
    {
        document->loadXMLFile(this->src);
    }
    else
    {
        switch (this->mode)
        {
        default:
        {
            AXRController::p controller = AXRController::p(new AXRController(document));
            XMLParser::p xmlParser(new XMLParser(controller.data()));
            HSSParser::p hssParser(new HSSParser(controller.data()));
            AXRBuffer::p baseFile = document->getFile();
            AXRBuffer::p newFile;
            try
            {
                newFile = document->getFile(this->src);
            }
            catch (const AXRError &e)
            {
                e.raise();
            }

            if (newFile)
            {
                bool loadingSuccess = xmlParser->loadFile(newFile);
                if (!loadingSuccess)
                {
                    AXRError("AXRDocument", "Could not load the XML file").raise();
                }
                else
                {
                    HSSContainer::p root = qSharedPointerCast<HSSContainer > (controller->getRoot());

                    if (root)
                    {
                        std::vector<QUrl> loadSheets = controller->loadSheetsGet();
                        for (std::vector<QUrl>::iterator sheetsIt = loadSheets.begin(); sheetsIt != loadSheets.end(); ++sheetsIt)
                        {
                            AXRBuffer::p hssfile;
                            try
                            {
                                hssfile = document->getFile(*sheetsIt);
                            }
                            catch (const AXRError &e)
                            {
                                e.raise();
                                continue;
                            }

                            if (!hssParser->loadFile(hssfile))
                            {
                                AXRError("AXRDocument", "Could not load the HSS file").raise();
                            }
                        }

                        controller->matchRulesToContentTree();

                        HSSSimpleSelection::const_iterator targetIt, childIt;
                        for (targetIt = this->target->begin(); targetIt != this->target->end(); ++targetIt)
                        {
                            const HSSDisplayObject::p & theDO = *targetIt;
                            HSSContainer::p theContainer = HSSContainer::asContainer(theDO);
                            if (theContainer)
                            {
                                theContainer->clear();
                                for (childIt = root->getChildren()->begin(); childIt != root->getChildren()->end(); ++childIt)
                                {
                                    const HSSDisplayObject::p & theChild = *childIt;
                                    theContainer->add(theChild);
                                }
                            }
                        }

                        root->setNeedsRereadRules(true);
                        root->recursiveReadDefinitionObjects();
                        root->handleEvent(HSSEventTypeLoad, NULL);
                        document->setNeedsDisplay(true);
                    }
                }
            }

            //                AXRDocument::tp document = AXRDocument::getInstance();
            //                AXRWrapper * document = document->getWrapper();
            //                AXRBuffer::p baseFile = document->getFile();
            //
            //                bool loadingSuccess = document->loadFile(baseFile->basePath+this->src, this->src);
            //                if(loadingSuccess){
            //                    unsigned i, size;
            //                    for (i=0, size=this->target.size(); i<size; ++i) {
            //                        std_log1("Adding loaded file to target");
            //
            //                        if(this->target[i]->isA(HSSObjectTypeContainer)){
            //                            const HSSContainer::p & theCont = qSharedPointerCast<HSSContainer>(this->target[i]);
            //                            const HSSContainer::p & loadedRoot = fileController.getRoot();
            //                            theCont->add(loadedRoot);
            //
            //                            unsigned j, k, size2, size3;
            //                            HSSSimpleSelection::p scope = theCont->getChildren();
            //                            for (j=0, size2=fileController.rulesSize(); j<size2; ++j) {
            //                                HSSRule::p & theRule = fileController.rulesGet(j);
            //                                theRule->childrenAdd(theRule);
            //                            }
            //                            for (j=0, size2=theCont->rulesSize(); j<size2; ++j) {
            //                                HSSRule::p theRule = theCont->rulesGet(j);
            //                                for (k=0, size3=theRule->childrenSize(); k<size3; ++k) {
            //                                    HSSRule::p childRule = theRule->childrenGet(k);
            //                                    this->getController()->recursiveMatchRulesToDisplayObjects(childRule, scope, theCont);
            //                                }
            //                            }
            //
            //                            theCont->recursiveReadDefinitionObjects();
            //                            theCont->setNeedsLayout(true);
            //                        }
            //                    }
            //                }
            break;
        }
        }
    }
}