Ejemplo n.º 1
0
bool CMenu::CoreHandleKey(wchar_t key)
{
    if (CBaseScroll::CoreHandleKey(key))
        return true;

    switch (key)
    {
        case KEY_UP:
            Move(-1);
            return true;
        case KEY_DOWN:
            Move(1);
            return true;
        case KEY_LEFT:
            HScroll(-1, true);
            return true;
        case KEY_RIGHT:
            HScroll(1, true);
            return true;
        case KEY_PPAGE:
            Move(-ScrollFieldHeight()+1);
            return true;
        case KEY_NPAGE:
            Move(ScrollFieldHeight()-1);
            return true;
        default:
            if (IsEnter(key))
            {
                PushEvent(EVENT_CALLBACK);
                return true;
            }
            else if (isprint(key)) // Go to item which starts with typed character
            {
                // First try from current position
                TMenuList::iterator cur = m_MenuList.begin() + GetCurrent();
                TMenuList::iterator line = std::lower_bound(cur+1, m_MenuList.end(), key);
                
                if ((line == m_MenuList.end()) || (line->name[0] != key)) // Not found, start from begin
                    line = std::lower_bound(m_MenuList.begin(), cur, key);
                
                if ((line != m_MenuList.end()) && (line->name[0] == key))
                {
                    Move(SafeConvert<int>(std::distance(cur, line)));
                    PushEvent(EVENT_DATACHANGED);
                }
                
                return true;
            }
    }

    return false;
}
Ejemplo n.º 2
0
// could use Window event table for this stuff
BOOL Window::WndProc(TMSG &Msg)
{
	// handle internal actions
	switch (Msg.Msg)
	{
		case WM_QUERYENDSESSION:
		case WM_CLOSE:
			if (!CanClose()) return TRUE; //returns 0
			break;
		case WM_DESTROY:  // quit if main window
			if (this==App::MainWindow) App::Quit();
			if (Flags & W_SAVEPOS) SaveWindowState();
			Flags|=W_DESTROYED;
			Destroy();
			// MainWindow is deleted on program exit
			if (this==App::MainWindow) App::Quit();
			else delete this;
			return TRUE;
		case WM_PAINT:
			PAINTSTRUCT  ps;
			BeginPaint(hWnd, (LPPAINTSTRUCT) &ps);
			SetWindowOrgEx(ps.hdc,xPos,yPos,NULL);
			Paint(ps.hdc,ps.fErase,ps.rcPaint);

			if (StatBar) // draw statbar after window
			{
				SetWindowOrgEx(ps.hdc,0,0,NULL); // dont scroll statbar
				StatBar->Paint(ps.hdc);
			}
			EndPaint(hWnd, (LPPAINTSTRUCT) &ps);
			break;

		case WM_HSCROLL:			HScroll(Msg); break;
		case WM_VSCROLL:			VScroll(Msg); break;
		case WM_SIZE:				WMSize(Msg); break;
		case WM_GETMINMAXINFO:	WMGetMinMaxInfo(Msg); break;
		case WM_COMMAND:
		{
			int id=LOWORD(Msg.wParam);
			if (id>MRU_ID && id<=MRU_ID+MRU_MAX)
			{
				OpenFile(MruList[id-MRU_ID-1]);
				return TRUE;
			}
			else if (id>MRU2_ID && id<=MRU2_ID+MRU_MAX)
			{
				OpenFile2(MruList2[id-MRU2_ID-1]);
				return TRUE;
			}
			break;
		}
		case WM_INITMENU:
			InitMenu((HMENU) Msg.wParam); // handle of menu to initialize 
			break;
 	}
	if (StatBar) StatBar->EV_FIND(Msg);
	//allow user to grab any message
	return EV_FIND(Msg);
}
Ejemplo n.º 3
0
Archivo: game.c Proyecto: yxrkt/DigiPen
//******************//
// Helper Functions //
//******************//
void Move()
{
    struct ControllerState cont = GetControllerState();
    bool moving = FALSE;
    
    // move player
    if ( cont.left  )
    {
        if ( g_cam_x > 0 && ((g_hippy.x + g_hippy.w / 2) == (SCREEN_WIDTH / 2)) )
            HScroll(-WALK_SPEED);
        else if ( g_hippy.x > 0 )
            g_hippy.x -= WALK_SPEED;

        g_hippy.baseFrame = FACE_SIDE;
        ham_SetObjHFlip(g_hippy.sprite, FALSE);
        moving = TRUE;
    }
    if ( cont.right  )
    {
        if ( g_cam_x < (MAP_WIDTH - SCREEN_WIDTH - 1) && ((g_hippy.x + g_hippy.w / 2) == (SCREEN_WIDTH / 2)) )
            HScroll(WALK_SPEED);
        else if ( g_hippy.x < (SCREEN_WIDTH - g_hippy.w) )
            g_hippy.x += WALK_SPEED;

        if ( !moving )
        {
            g_hippy.baseFrame = FACE_SIDE;
            ham_SetObjHFlip(g_hippy.sprite, TRUE);
            moving = TRUE;
        }
    }
    if ( cont.up  )
    {
        if ( g_cam_y > 0 && ((g_hippy.y + g_hippy.h / 2) == (SCREEN_HEIGHT / 2)) )
            VScroll(-WALK_SPEED);
        else if ( g_hippy.y > 0 )
            g_hippy.y -= WALK_SPEED;

        if ( !moving )
        {
            g_hippy.baseFrame = FACE_UP;
            moving = TRUE;
        }
    }
    if ( cont.down  )
    {
        if ( g_cam_y < (MAP_HEIGHT - SCREEN_HEIGHT - 1) && ((g_hippy.y + g_hippy.h / 2) == (SCREEN_HEIGHT / 2)) )
            VScroll(WALK_SPEED);
        else if ( g_hippy.y < (SCREEN_HEIGHT - g_hippy.h) )
            g_hippy.y += WALK_SPEED;

        if ( !moving )
        {
            g_hippy.baseFrame = FACE_DOWN;
            moving = TRUE;
        }
    }

    // move player
    ham_SetBgXY(0, g_cam_x, g_cam_y);
    ham_SetObjXY(g_hippy.sprite, g_hippy.x, g_hippy.y);
    
    // move shroom
    ham_SetObjXY(g_shroom.sprite, g_shroom.x, g_shroom.y);
    
    // move key
    ham_SetObjXY(g_key.sprite, g_key.x, g_key.y);
    
    // set hippy frame
    int animIndex = g_hippy.w * g_hippy.h * (g_hippy.baseFrame + g_hippy.frameDif);
    ham_UpdateObjGfx(g_hippy.sprite, (void *)&hippy_bitmap[animIndex]);
    
    g_count++;
    if ( moving && ((g_count % HIPPY_TPF) == 0) )
        g_hippy.frameDif =(g_hippy.frameDif + 1) % HIPPY_FRAMES;
}