コード例 #1
0
ファイル: setjoystick.cpp プロジェクト: jamesblunt/antimicro
void SetJoystick::writeConfig(QXmlStreamWriter *xml)
{
    if (!isSetEmpty())
    {
        xml->writeStartElement("set");

        xml->writeAttribute("index", QString::number(index+1));

        if (!name.isEmpty())
        {
            xml->writeTextElement("name", name);
        }

        for (int i=0; i < getNumberSticks(); i++)
        {
            JoyControlStick *stick = getJoyStick(i);
            stick->writeConfig(xml);
        }

        for (int i=0; i < getNumberVDPads(); i++)
        {
            VDPad *vdpad = getVDPad(i);
            if (vdpad)
            {
                vdpad->writeConfig(xml);
            }
        }

        for (int i=0; i < getNumberAxes(); i++)
        {
            JoyAxis *axis = getJoyAxis(i);
            if (!axis->isPartControlStick() && axis->hasControlOfButtons())
            {
                axis->writeConfig(xml);
            }
        }

        for (int i=0; i < getNumberHats(); i++)
        {
            JoyDPad *dpad = getJoyDPad(i);
            dpad->writeConfig(xml);
        }

        for (int i=0; i < getNumberButtons(); i++)
        {
            JoyButton *button = getJoyButton(i);
            if (button && !button->isPartVDPad())
            {
                button->writeConfig(xml);
            }
        }

        xml->writeEndElement();
    }
}
コード例 #2
0
ファイル: setjoystick.cpp プロジェクト: jlsandell/antimicro
void SetJoystick::readConfig(QXmlStreamReader *xml)
{
    if (xml->isStartElement() && xml->name() == "set")
    {
        //reset();

        xml->readNextStartElement();
        while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "set"))
        {
            if (xml->name() == "button" && xml->isStartElement())
            {
                int index = xml->attributes().value("index").toString().toInt();
                JoyButton *button = getJoyButton(index-1);
                if (button)
                {
                    button->readConfig(xml);
                }
                else
                {
                    xml->skipCurrentElement();
                }
            }
            else if (xml->name() == "axis" && xml->isStartElement())
            {
                int index = xml->attributes().value("index").toString().toInt();
                JoyAxis *axis = getJoyAxis(index-1);
                if (axis)
                {
                    axis->readConfig(xml);
                }
                else
                {
                    xml->skipCurrentElement();
                }
            }
            else if (xml->name() == "dpad" && xml->isStartElement())
            {
                int index = xml->attributes().value("index").toString().toInt();
                JoyDPad *dpad = getJoyDPad(index-1);
                if (dpad)
                {
                    dpad->readConfig(xml);
                }
                else
                {
                    xml->skipCurrentElement();
                }
            }
            else if (xml->name() == "stick" && xml->isStartElement())
            {
                int stickIndex = xml->attributes().value("index").toString().toInt();

                if (stickIndex > 0)
                {
                    stickIndex -= 1;
                    JoyControlStick *stick = getJoyStick(stickIndex);
                    if (stick)
                    {
                        stick->readConfig(xml);
                    }
                    else
                    {
                        xml->skipCurrentElement();
                    }
                }
                else
                {
                    xml->skipCurrentElement();
                }
            }
            else if (xml->name() == "vdpad" && xml->isStartElement())
            {
                int index = xml->attributes().value("index").toString().toInt();
                VDPad *vdpad = getVDPad(index-1);
                if (vdpad)
                {
                    vdpad->readConfig(xml);
                }
                else
                {
                    xml->skipCurrentElement();
                }
            }
            else
            {
                // If none of the above, skip the element
                xml->skipCurrentElement();
            }

            xml->readNextStartElement();
        }
    }
}
コード例 #3
0
ファイル: np2.cpp プロジェクト: histat/dc-np2
bool dcsys_task()
{
	enum {
		CMD_MENU = 1,
	};
	int cmd = 0;
  
	Event ev;
	static  unsigned int tick = 0;

	unsigned int tm = Timer() - tick;
	if (tm < USEC_TO_TIMER(1000000/60)) {
		return __dc_avail;
	}
  
	tick += tm;

	int x, y;

	int cJoy = 0;
	static int pJoy;
	static unsigned int repeatTime;

	if (__dc_avail) {

		dc_mouseaxis1 = 0;
		dc_mouseaxis2 = 0;

		while (PollEvent(ev)) {
      
			switch (ev.type) {
				
			case EVENT_KEYDOWN:
				switch (ev.key.keycode) {
				case KBD_S1: case KBD_S2:
					cmd = CMD_MENU;
					break;
	  
				default:
					dckbd_keydown(ev.key.keycode);
				}
				break;
	
			case EVENT_KEYUP:
				dckbd_keyup(ev.key.keycode);
				break;
	
			case EVENT_MOUSEMOTION:
				dc_mouseaxis1 += ev.motion.x;
				dc_mouseaxis2 += ev.motion.y;
				break;

			case EVENT_MOUSEBUTTONDOWN:
				switch (ev.button.button) {
				case EVENT_BUTTON_LEFT:
					mousemng_buttonevent(MOUSEMNG_LEFTDOWN);
					break;

				case EVENT_BUTTON_RIGHT:
					mousemng_buttonevent(MOUSEMNG_RIGHTDOWN);
					break;
				}
				break;
      
			case EVENT_MOUSEBUTTONUP:
				switch (ev.button.button) {
				case EVENT_BUTTON_LEFT:
					mousemng_buttonevent(MOUSEMNG_LEFTUP);
					break;

				case EVENT_BUTTON_RIGHT:
					mousemng_buttonevent(MOUSEMNG_RIGHTUP);
					break;
				}
				break;

			case EVENT_JOYAXISMOTION:
				x = 0;
				y = 0;
	
				if (ev.jaxis.axis == 0) {
					x = ev.jaxis.value;
				}
				if (ev.jaxis.axis == 1) {
					y = ev.jaxis.value;
				}

				dc_mouseaxis1 += x;
				dc_mouseaxis2 += y;
	  
				break;

			case EVENT_JOYBUTTONDOWN:

				if (ev.jbutton.button == JOY_START)
					cmd = CMD_MENU;
	
				if (ev.jbutton.button == JOY_RTRIGGER)
					__skbd_avail = !__skbd_avail;

				if (__skbd_avail && ev.jbutton.button == JOY_A)
					softkbddc_down();

				if (__skbd_avail && ev.jbutton.button == JOY_B)
					__use_bg = !__use_bg;
	
				if (__skbd_avail) {
					cJoy = ev.jbutton.button & 0xffff;
	  
				} else {
					switch (ev.jbutton.button) {

					case JOY_UP:
						dckbd_keydown(JOY1_UP);
						break;
	    
					case JOY_DOWN:
						dckbd_keydown(JOY1_DOWN);
						break;
	    
					case JOY_LEFT:
						dckbd_keydown(JOY1_LEFT);
						break;
	    
					case JOY_RIGHT:
						dckbd_keydown(JOY1_RIGHT);
						break;
	    
					case JOY_A:
						dckbd_keydown(JOY1_A);
						break;
	    
					case JOY_B:
						dckbd_keydown(JOY1_B);
						break;

					case JOY_X:
						mousemng_buttonevent(MOUSEMNG_LEFTDOWN);
						break;
	    
					case JOY_Y:
						mousemng_buttonevent(MOUSEMNG_RIGHTDOWN);
						break;
					}
				}
				break;
	
			case EVENT_JOYBUTTONUP:

				softkbddc_up();

				if (__skbd_avail) {

					pJoy = 0;
					repeatTime = 0;

				} else {
	  
					switch (ev.jbutton.button) {
	    
					case JOY_UP:
						dckbd_keyup(JOY1_UP);
						break;
	    
					case JOY_DOWN:
						dckbd_keyup(JOY1_DOWN);
						break;
	    
					case JOY_LEFT:
						dckbd_keyup(JOY1_LEFT);
						break;
	    
					case JOY_RIGHT:
						dckbd_keyup(JOY1_RIGHT);
						break;
	    
					case JOY_A:
						dckbd_keyup(JOY1_A);
						break;
	    
					case JOY_B:
						dckbd_keyup(JOY1_B);
						break;

					case JOY_X:
						mousemng_buttonevent(MOUSEMNG_LEFTUP);
						break;

					case JOY_Y:
						mousemng_buttonevent(MOUSEMNG_RIGHTUP);
						break;
					}
				}
				break;
	
			case EVENT_QUIT:
				__dc_avail = false;
				break;
			}
		}
	}


	if (__skbd_avail) {

		dc_joyinput = 0;

		int button = 0;
    
		if (cJoy) {
			repeatTime = Timer() + USEC_TO_TIMER(1000000/60*30);
			pJoy = cJoy;
			button = cJoy;
		} else if (repeatTime < Timer()) {

			button = pJoy;
			repeatTime = Timer() + USEC_TO_TIMER(1000000/60*10);
		}

		softkbddc_send(button);

	} else
		getJoyButton(JOYSTICKID1, &dc_joyinput);

	if (sys_updates & (SYS_UPDATECFG | SYS_UPDATEOSCFG)) {
		initsave();
		sysmng_initialize();
	}

	switch (cmd) {
	case CMD_MENU:
		sysmenu_menuopen();
		break;
	}

	scrnmng_update();
	softkbddc_draw();
	ta_commit_frame();
  
	return __dc_avail;
}