Пример #1
0
static int incr(int x, int y)
{
    if (inbox(&accept, x, y))
	return 1;
    if (inbox(&cancel, x, y))
	return -1;
    if (inbox(&plus, x, y)) {
	mag++;
	draw_mag();
    }
    else if (inbox(&minus, x, y) && mag > 1) {
	mag--;
	draw_mag();
    }
    return 0;
}
Пример #2
0
void airbear::heart(){
  if(digitalRead(heartpin)==1){
    vs1053.playFullFile("Sounds/confirm.mp3");
    latch("hrtp");
    MqttBlock(5000);//Force mqtt to wait until received message TODO add timeout
    inbox();
  }//end if
}//endfunction
Пример #3
0
static int pick(int x, int y, int button)
{
    int n;

    if (inbox(&more, x, y)) {
	cancel_which();
	if (page + 1 >= npages)
	    return 0;
	page++;
	return -1;
    }
    if (inbox(&less, x, y)) {
	cancel_which();
	if (page == 0)
	    return 0;
	page--;
	return -1;
    }
    if (inbox(&cancel, x, y)) {
	if (which == -2)
	    return -2;
	cancel_which();
	which = -2;
	R_standard_color(RED);
	Outline_box(cancel.top, cancel.bottom, cancel.left, cancel.right);
	R_flush();
	return 0;
    }
    /* search name list. handle double click */
    for (n = 0; n < count; n++)
	if (inbox(&list[n].box, x, y)) {
	    if (n == which)	/* second click! */
		return 1;
	    cancel_which();
	    which = n;
	    R_standard_color(RED);
	    Outline_box(list[n].box.top, list[n].box.bottom,
			list[n].box.left, list[n].box.right);
	    R_flush();
	    return 0;		/* ignore first click */
	}

    cancel_which();
    return 0;
}
Пример #4
0
int check(int p,int q,int pp,int qq,int step)
{
    int i,l,r,x;
    int direc=pp>p?1:-1;
    //printf("%d %d %d\n",l,r,x);
    for(i=1;i<=step;i++)
    {
        l=maxx(1,maxx(q-i,qq-(dist-i)));
        //printf("%d %d %d %d\n",i,l,r,x);
        r=minn(n,minn(q+i,qq+(dist-i)));
        x=p+direc*i;
        //printf("%d %d %d %d\n",i,l,r,x);
        if(((x==p3-i||x==p3+i)&&havecross(l,r,q3-i,q3+i))
        ||(aabs(p3,x)<i&&(inbox(q3-i,l,r)||inbox(q3+i,l,r))))
        return i;
    }
    return INF;
}
Пример #5
0
void windy::app::compositable_map_menu() {

	auto animations =
		this->_environment->project()->assets()->collection()->get(layer::groupable);

	if (animations.empty()) {
		nana::msgbox mb(*this, L"Error!");
		mb << L"Create an animation first.";
		mb.show();
	}
	else {
		nana::inputbox::text name(L"<bold blue>Name</>");

		std::vector<std::wstring> nana_vector;

		for (auto& animation : animations) {
			auto name = animation->name();
			nana_vector.push_back(std::wstring(name.begin(), name.end()));
		}

		nana::inputbox::text options(L"Animation", nana_vector);

		nana::inputbox inbox(*this,
			L"Please input the <bold>creation parameters</> for the mapping.",
			L"Map");

		inbox.verify([this, &name](nana::window handle) {

			auto object_buffer_name = name.value();
			std::string object_name(object_buffer_name.begin(), object_buffer_name.end());

			if (object_name.empty())
			{
				nana::msgbox mb(handle, L"Invalid input");
				mb << L"Name should not be empty, please input the mapping name.";
				mb.show();
				return false; //verification failed
			}

			return true; //verified successfully
		});

		if (inbox.show_modal(name, options/*, file,*/)) {

			auto mapping_buffer_name = name.value();
			auto animation_buffer_name = options.value();

			auto mapping_name =
				std::string(mapping_buffer_name.begin(), mapping_buffer_name.end());

			auto animation_name =
				std::string(animation_buffer_name.begin(), animation_buffer_name.end());
			
		}
	}
}
Пример #6
0
QList<QObject*> QSpotifyUser::playlistsAsQObject() const
{
    QList<QObject*> list;
    if (auto inb = inbox()) {
        list.append((QObject*)inb);
    }
    list.append((QObject*)starredList());
    list.append(playlistContainer()->formattedPlaylists());
    return list;
}
Пример #7
0
Файл: user.cpp Проект: aox/aox
UString User::mailboxName( const UString & name ) const
{
    if ( name.titlecased() == "INBOX" )
        return inbox()->name();
    if ( name.startsWith( "/" ) )
        return name;
    UString n;
    n = home()->name();
    n.append( '/' );
    n.append( name );
    return n;
}
Пример #8
0
static int pick(int x, int y)
{
    int n;
    int cur;

    cur = which;
    cancel_which();
    if (inbox(&more, x, y)) {
	if (curp >= group.points.count)
	    return 0;
	first_point = curp;
	pager = 1;
	return 1;
    }
    if (inbox(&less, x, y)) {
	if (first_point == 0)
	    return 0;
	first_point -= nlines;
	if (first_point < 0)
	    first_point = 0;
	pager = 1;
	return 1;
    }
    if (!inbox(&report, x, y)) {
	return 0;
    }

    n = (y - report.top) / height;
    if (n == cur) {		/* second click! */
	if (!delete_mode) {
	    group.points.status[first_point + n] =
		!group.points.status[first_point + n];
	    compute_transformation();
	    show_point(first_point + n, 1);
	    return 1;
	}
	else {
	    delete_control_point(first_point + n);
	    first_point = 0;
	    compute_transformation();
	    pager = 1;
	    return 1;
	}
    }

    /* first click */
    which = n;
    show_point(first_point + n, 0);
    if (!delete_mode)
	R_standard_color(RED);
    else
	R_standard_color(ORANGE);

    Outline_box((report.top + n * height) + 1, report.top + (n + 1) * height,
		report.left, report.right - 1);

    R_flush();

    return 0;			/* ignore first click */

}
Пример #9
0
static PyObject * shift(PyObject * self, 
	PyObject * args, PyObject * kwds) {
	PyArrayObject * pos, * arowvectors, *abox, *amin, *amax;
	static char * kwlist[] = {"POS", "ROWVECTORS", "BOX", "MIN", "MAX", NULL};
	if(!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!O!O!", kwlist,
		&PyArray_Type, &pos,
		&PyArray_Type, &arowvectors,
		&PyArray_Type, &abox,
		&PyArray_Type, &amin,
		&PyArray_Type, &amax))
		return NULL;
	
	int D = PyArray_DIMS(pos)[1];
	npy_intp length = PyArray_DIMS(pos)[0];
	int i,j;
	npy_intp p;
	amin = (PyArrayObject *) PyArray_Cast(amin, NPY_INT);
	amax = (PyArrayObject *) PyArray_Cast(amax, NPY_INT);
	abox = (PyArrayObject *) PyArray_Cast(abox, NPY_FLOAT);
	arowvectors = (PyArrayObject *) PyArray_Cast(arowvectors, NPY_FLOAT);
	int min[3] = {0}, max[3] = {0};
	float box[3];
	float rowvectors[3][3];
	for(i = 0; i < D; i++) {
		min[i] = *((int*)PyArray_GETPTR1(amin, i));
		max[i] = *((int*)PyArray_GETPTR1(amax, i));
		box[i] = *((float*)PyArray_GETPTR1(abox, i));
		for(j = 0; j < D; j++) {
			rowvectors[i][j] = *((float*)PyArray_GETPTR2(arowvectors, i, j));
		}
	}
#if 0
	printf("box = %f %f %f\n", box[0], box[1], box[2]);
	printf("min = %d %d %d\n", min[0], min[1], min[2]);
	printf("max = %d %d %d\n", max[0], max[1], max[2]);
	printf("rowvectors = %f %f %f\n", rowvectors[0][0], rowvectors[0][1], rowvectors[0][2]);
	printf("rowvectors = %f %f %f\n", rowvectors[1][0], rowvectors[1][1], rowvectors[1][2]);
	printf("rowvectors = %f %f %f\n", rowvectors[2][0], rowvectors[2][1], rowvectors[2][2]);
	printf("D = %d\n", D);
#endif
	int I[3] = {0,0,0};
	int failed_count = 0;
	#pragma omp parallel for private(I) reduction(+: failed_count)
	for(p = 0; p < length; p++) {
		int i;
		float * ppos[3];
		float shifted[3];
		float original[3];
		for(i = 0; i < D; i++) {
			ppos[i] = (float *) PyArray_GETPTR2(pos, p, i);
			original[i] = *(ppos[i]);
		}
		
		tryshift(original, shifted, rowvectors, I, D);
		if(!inbox(shifted, box, D)) {
			int newI[3];
			for(newI[0] = min[0]; newI[0] <= max[0]; newI[0]++)
			for(newI[1] = min[1]; newI[1] <= max[1]; newI[1]++)
			for(newI[2] = min[2]; newI[2] <= max[2]; newI[2]++) {
				tryshift(original, shifted, rowvectors, newI, D);
				if(inbox(shifted, box, D)) {
					for(i = 0; i < D; i++) {
						I[i] = newI[i];
					}
					goto out_of_here;
				}
			}
			out_of_here:;
		}
		if(!inbox(shifted, box, D)) {
			printf("%f %f %f to ", original[0], original[1], original[2]);
			printf("%f %f %f faild\n", shifted[0], shifted[1], shifted[2]);
			for(i = 0; i < D; i++) {
				shifted[i] = original[i];
			}
			failed_count++;
		}
		for(i = 0; i < D; i++) {
			*(ppos[i]) = shifted[i];
		}
	}
#if 0
	printf("failed = %d\n", failed_count);
#endif 
	Py_DECREF(abox);
	Py_DECREF(amax);
	Py_DECREF(amin);
	Py_DECREF(arowvectors);
	Py_RETURN_NONE;
}
Пример #10
0
main()
{
   int driver=0, mode=VESA_1024x768x8bit;
   int tickets=0;
   int key,i,j,m,n;
   char *p;
   TERIS t,q;
   initgraph(&driver, &mode, "");
   draw_frame();
   randomize();
   new_teris(&t);
   new_teris(&q);
   show_next_teris(q);
   show_score();
   while(!STOP)
   {
		show_teris(t);
		delay(1);
		tickets++;
		if(tickets>=MAX)
		{
			look1(t);
			if(OK==0)
			{
				show_teris(t);
				inbox(t);
				if(t.y==1) {STOP=0;break;}
				t=q;
				new_teris(&q);
				clear_next_teris();
				show_next_teris(q);
				OK=1;
			}
			clear_teris(t);
			tickets=0;
			t.y++;
			setcolor(GREEN);
			rectangle(X0-1, Y0-1, X0+320, Y0+640);
		}
		while(bioskey(1)!=0)
		{
			key=bioskey(0);
			switch(key)
			{
				case UP:				 
					{
						judge_rotate(t);
						if(EN)
						{
							clear_teris(t);
							t.rotate++;
							if(t.rotate>=4) t.rotate=t.rotate%4;
							show_teris(t);
						}
						else EN=1;
					}break;
				case DOWN:
					{
						look1(t);
						if(OK==1)
						{
							clear_teris(t);
							t.y++;
						}
						if(OK==0)
						{
							show_teris(t);
							inbox(t);
							if(t.y==1) {STOP=0;break;}
							t=q;
							new_teris(&q);
							clear_next_teris();
							show_next_teris(q);
							OK=1;
						}
					}break;
				case LEFT:
					{
						look3(t);
						if(YES)
						{
						clear_teris(t);
						t.x--;
						show_teris(t);
						}
						else YES=1;
						
					}break;
				case RIGHT:
					{
						look2(t);
						if(YES)
						{
						clear_teris(t);
						t.x++;
						show_teris(t);
						}
						else YES=1;
					}break;
				case ESC:
					{
						STOP=1;
					}break;
			}
		}
		
		DELETE(t);
   }
   if(!win)
   {
   		for(i=0;i<10;i++)
   		{
			for(j=0;j<20;j++)
			{
				if(BOX[i][j]==1)
				{	
					m=X0+32*i;
					n=Y0+32*j;
					setfillstyle(SOLID_FILL, 0X0F);
   					bar(m,n, m+32-1, n+32-1);
   					setcolor(BLACK);
      				rectangle(m, n, m+32, n+32);
      				delay(1);
				}
			}
   		}
   }
   else 
   {
   		for(i=0;i<10;i++)
   		{
			for(j=0;j<20;j++)
			{
				if(BOX[i][j]==1)
				{	
					m=X0+32*i;
					n=Y0+32*j;
					setfillstyle(SOLID_FILL, 0X0E);
   					bar(m,n, m+32-1, n+32-1);
   					setcolor(BLACK);
      				rectangle(m, n, m+32, n+32);
      				delay(1);
				}
			}
   		}
   }
   getchar();
   closegraph();
   return 0;
}
Пример #11
0
void render_window()
{
    game_config = GetGameConfig();
    game_levels = GetGameLevels();
    game_levels_count = GetGameLevelsCount();

    arguments = GetArguments();
    user_set = GetUserSettings();
    int start_level = get_start_level();

    save_dir_full = GetSaveDir();
    cache_dir_full = GetCacheDir();
    can_cache = (save_dir_full && cache_dir_full);

//------------------------------------------------------------------------------
    ApplyArguments();

    const SDL_VideoInfo *video_info = SDL_GetVideoInfo();
    if (user_set->geom_x > 0 && user_set->geom_y > 0)
    {
        disp_x = user_set->geom_x;
        disp_y = user_set->geom_y;
    }
    else
    {
        disp_x = video_info->current_w;
        disp_y = video_info->current_h;
    }

    int probe_bpp = (user_set->bpp == 0 ? video_info->vfmt->BitsPerPixel : user_set->bpp);
    disp_bpp = (probe_bpp == 32 ? probe_bpp : 16);

    bool rot = TransformGeom();

//------------------------------------------------------------------------------
#define BTN_SPACE_KOEF 4.5
    int btn_side = disp_y / 7;
    int btn_space = btn_side / BTN_SPACE_KOEF;
    int btns_padded_width = btn_side * 4 + btn_space * 5;
    if (btns_padded_width > disp_x)
    {
        //btn_side = ( wnd_w - 5 * ( btn_side / BTN_SPACE_KOEF ) ) / 4
        btn_side = (int)(disp_x / (4 + 5 / BTN_SPACE_KOEF));
        btn_space = btn_side / BTN_SPACE_KOEF;
    }
    int btns_width = btn_side * 4 + btn_space * 3;
    int font_height = btn_side / 3;
    int font_padding = font_height / 2;

//-- font and labels -----------------------------------------------------------
    TTF_Font *font = TTF_OpenFont(DEFAULT_FONT_FILE, font_height);
    if (!font)
    {
        log_error("Can't load font '%s'. Exiting.", DEFAULT_FONT_FILE);
        return;
    }

    SDL_Surface *levelTextSurface = NULL;
    SDL_Rect levelTextLocation;
    levelTextLocation.y = font_padding;

    SDL_Color fontColor = {0};
#ifndef RGBSWAP
    fontColor.r = 231;
    fontColor.g = 190;
    fontColor.b = 114;
#else
    //--enable-rgb-swap
    fontColor.r = 114;
    fontColor.g = 190;
    fontColor.b = 231;
#endif

    /* Window initialization */
    ingame = true;
    Uint32 sdl_flags = SDL_SWSURFACE;
    if (user_set->fullscreen_mode != FULLSCREEN_NONE)
        sdl_flags |= SDL_FULLSCREEN;
    SDL_Surface *disp = SDL_SetVideoMode(disp_x, disp_y, disp_bpp, sdl_flags);
    if (disp == NULL)
    {
        log_error("Can't set video mode %dx%dx%dbpp. Exiting.", disp_x, disp_y, disp_bpp);
        return;
    }
    screen = disp;
    SDL_Surface *gui_surface = disp;
    SDL_WM_SetCaption("Mokomaze", "Mokomaze");

    /* Draw loading screen */
    SDL_Color whiteColor = {0};
    whiteColor.r = whiteColor.g = whiteColor.b = 255;
    SDL_Surface *titleSurface = TTF_RenderText_Blended(font, "Loading...", whiteColor);
    SDL_Rect title_rect;
    title_rect.x = (disp_x - titleSurface->w) / 2;
    title_rect.y = (disp_y - titleSurface->h) / 2;
    title_rect.w = titleSurface->w;
    title_rect.h = titleSurface->h;
    SDL_BlitSurface(titleSurface, NULL, screen, &title_rect);
    SDL_UpdateRect(screen, title_rect.x, title_rect.y, title_rect.w, title_rect.h);
    SDL_FreeSurface(titleSurface);

//-- load pictures -------------------------------------------------------------
    SDL_Surface *back_pic     = LoadSvg(MDIR "prev-main.svg", btn_side, btn_side, false, false);
    SDL_Surface *forward_pic  = LoadSvg(MDIR "next-main.svg", btn_side, btn_side, false, false);
    SDL_Surface *settings_pic = LoadSvg(MDIR "settings-main.svg", btn_side, btn_side, false, false);
    SDL_Surface *exit_pic     = LoadSvg(MDIR "close-main.svg", btn_side, btn_side, false, false);

    SDL_Surface *back_i_pic    = LoadSvg(MDIR "prev-grey.svg", btn_side, btn_side, false, false);
    SDL_Surface *forward_i_pic = LoadSvg(MDIR "next-grey.svg", btn_side, btn_side, false, false);

    SDL_Surface *back_p_pic    = LoadSvg(MDIR "prev-light.svg", btn_side, btn_side, false, false);
    SDL_Surface *forward_p_pic = LoadSvg(MDIR "next-light.svg", btn_side, btn_side, false, false);

    int tmpx = (rot ? game_config.wnd_h : game_config.wnd_w);
    int tmpy = (rot ? game_config.wnd_w : game_config.wnd_h);
    desk_pic = LoadSvg(MDIR "desk.svg", tmpx, tmpy, rot, true);
    wall_pic = LoadSvg(MDIR "wall.svg", tmpx, tmpy, rot, true);
    int hole_d = game_config.hole_r * 2;
    fin_pic = LoadSvg(MDIR "openmoko.svg", hole_d, hole_d, rot, false);

    if (LoadImgErrors > 0)
    {
        log_error("Some images were not loaded. Exiting.");
        return;
    }

//-- positions of buttons ------------------------------------------------------
    SDL_Rect gui_rect_1, gui_rect_2, gui_rect_3, gui_rect_4;
    gui_rect_1.y = gui_rect_2.y = gui_rect_3.y = gui_rect_4.y = levelTextLocation.y + font_height + font_padding;
    gui_rect_1.x = (disp_x - btns_width) / 2;
    gui_rect_2.x = gui_rect_1.x + btn_side + btn_space;
    gui_rect_3.x = gui_rect_2.x + btn_side + btn_space;
    gui_rect_4.x = gui_rect_3.x + btn_side + btn_space;
//-- for click detection -------------------------------------------------------
    Box gui_box_1, gui_box_2, gui_box_3, gui_box_4;
    gui_box_1.x1 = gui_rect_1.x;
    gui_box_1.y1 = gui_rect_1.y;
    gui_box_1.x2 = gui_rect_1.x + btn_side;
    gui_box_1.y2 = gui_rect_1.y + btn_side;
    gui_box_2.x1 = gui_rect_2.x;
    gui_box_2.y1 = gui_rect_2.y;
    gui_box_2.x2 = gui_rect_2.x + btn_side;
    gui_box_2.y2 = gui_rect_2.y + btn_side;
    gui_box_3.x1 = gui_rect_3.x;
    gui_box_3.y1 = gui_rect_3.y;
    gui_box_3.x2 = gui_rect_3.x + btn_side;
    gui_box_3.y2 = gui_rect_3.y + btn_side;
    gui_box_4.x1 = gui_rect_4.x;
    gui_box_4.y1 = gui_rect_4.y;
    gui_box_4.x2 = gui_rect_4.x + btn_side;
    gui_box_4.y2 = gui_rect_4.y + btn_side;

    //create surface for rendering the level
    render_pic = CreateSurface(SDL_SWSURFACE, game_config.wnd_w, game_config.wnd_h, disp);

    if (user_set->scrolling)
        screen = CreateSurface(SDL_SWSURFACE, game_config.wnd_w, game_config.wnd_h, disp);

    if (user_set->fullscreen_mode != FULLSCREEN_NONE)
        SDL_ShowCursor(!ingame);

    desk_rect.x = 0;
    desk_rect.y = 0;
    desk_rect.w = game_config.wnd_w;
    desk_rect.h = game_config.wnd_h;

    SDL_Rect ball_rect;

    int disp_scroll_border = min(disp_x, disp_y) * 0.27;
    SDL_Rect screen_rect;
    screen_rect.x = 0;
    screen_rect.y = 0;
    screen_rect.w = disp_x;
    screen_rect.h = disp_y;
    SDL_Rect disp_rect;
    disp_rect = screen_rect;

    SDL_Color ballColor = {0};
    ballColor.r = 255;
    ballColor.g = 127;
    ballColor.b = 0;

    User user_set_new = *user_set;
    bool video_set_modified = false;

    /* Settings window initialization */
    settings_init(disp, font_height, user_set, &user_set_new);

    /* Render initialization */
    InitRender();

    /* Input system initialization */
    input_get_dummy(&input);
    SetInput();

    /* Vibro system initialization */
    vibro_get_dummy(&vibro);
    SetVibro();

    /* MazeCore initialization */
    maze_init();
    maze_set_config(game_config);
    maze_set_vibro_callback(BumpVibrate);
    maze_set_levels_data(game_levels, game_levels_count);

    cur_level = start_level;
    RenderLevel();
    RedrawDesk();
    maze_set_level(cur_level);
    ResetPrevPos();

    SDL_Event event;
    bool done = false;
    bool redraw_all = true;
    bool ingame_changed = false;
    int prev_ticks = SDL_GetTicks();
    Point mouse = {0};

//== Game Loop =================================================================
    while (!done)
    {
        bool wasclick = false;
        bool show_settings = false;
        while (SDL_PollEvent(&event))
        {
            bool btndown = false;
            bool btnesc = false;
            if (event.type == SDL_QUIT)
            {
                done = true;
            }
            else if (event.type == SDL_ACTIVEEVENT)
            {
                int g = event.active.gain;
                int s = event.active.state;
                if (ingame && !g && ((s & SDL_APPINPUTFOCUS) || (s & SDL_APPACTIVE)))
                {
                    btndown = true;
                }
            }
            else if (event.type == SDL_MOUSEMOTION)
            {
                mouse.x = event.motion.x;
                mouse.y = event.motion.y;
            }
            else if (event.type == SDL_MOUSEBUTTONUP)
            {
                StopFastChange();
            }
            else if (event.type == SDL_MOUSEBUTTONDOWN)
            {
                btndown = true;
            }
            else if (event.type == SDL_KEYDOWN)
            {
                switch(event.key.keysym.sym)
                {
                case SDLK_q:
                case SDLK_ESCAPE:
                    btnesc = true;
                case SDLK_SPACE:
                case SDLK_p:
                case SDLK_PAUSE:
                    btndown = true;
                    break;
                default:
                    break;
                }
            }
            else if (event.type == SDL_KEYUP)
            {
                switch(event.key.keysym.sym)
                {
                case SDLK_q:
                case SDLK_ESCAPE:
                    if( !wasclick || ingame || show_settings )
                        StopFastChange();
                    else
                        done = true;
                    break;
                case SDLK_SPACE:
                case SDLK_p:
                case SDLK_PAUSE:
                    StopFastChange();
                    break;
                default:
                    break;
                }
            }

            if (btndown)
            {
                if (!ingame)
                {
                    if (inbox(mouse.x, mouse.y, gui_box_1) && !btnesc)
                    {
                        if (cur_level > 0)
                        {
                            SDL_BlitSurface(back_p_pic, NULL, gui_surface, &gui_rect_1);
                            SDL_UpdateRect(gui_surface, gui_rect_1.x, gui_rect_1.y, gui_rect_1.w, gui_rect_1.h);

                            ChangeLevel(cur_level-1, &redraw_all, &wasclick);

                            fastchange_step = -10;
                            StopFastChange();
                            fastchange_timer = SDL_AddTimer(FASTCHANGE_INTERVAL, fastchange_callback, NULL);
                        }
                        continue;
                    }
                    else if (inbox(mouse.x, mouse.y, gui_box_2) && !btnesc)
                    {
                        if (cur_level < game_levels_count - 1)
                        {
                            SDL_BlitSurface(forward_p_pic, NULL, gui_surface, &gui_rect_2);
                            SDL_UpdateRect(gui_surface, gui_rect_2.x, gui_rect_2.y, gui_rect_2.w, gui_rect_2.h);

                            ChangeLevel(cur_level+1, &redraw_all, &wasclick);

                            fastchange_step = +10;
                            StopFastChange();
                            fastchange_timer = SDL_AddTimer(FASTCHANGE_INTERVAL, fastchange_callback, NULL);
                        }
                        continue;
                    }
                    else if (inbox(mouse.x, mouse.y, gui_box_3) && !btnesc)
                    {
                        show_settings = true;
                        RedrawDesk();
                        redraw_all = true;
                        wasclick = true;
                        continue;
                    }
                    else if (inbox(mouse.x, mouse.y, gui_box_4) || btnesc)
                    {
                        done = true;
                        continue;
                    }
                }
                ingame_changed = true;
            } //if (btndown)
        }

        if (ingame_changed)
        {
            ingame = !ingame;
            if (!ingame)
            {
                wasclick = true;
            }
            else
            {
                RedrawDesk();
                redraw_all = true;
            }

            if (user_set->fullscreen_mode == FULLSCREEN_INGAME)
                SDL_WM_ToggleFullScreen(disp);
            if (user_set->fullscreen_mode != FULLSCREEN_NONE)
                SDL_ShowCursor(!ingame);

            prev_ticks = SDL_GetTicks();
            ingame_changed = false;
        }

        if ((!ingame) && (!wasclick) && (must_fastchange))
        {
            int new_cur_level = cur_level + fastchange_dostep;
            clamp_max(new_cur_level, game_levels_count - 1);
            clamp_min(new_cur_level, 0);

            if (new_cur_level != cur_level)
            {
                if (fastchange_dostep < 0)
                {
                    SDL_BlitSurface(back_p_pic, NULL, gui_surface, &gui_rect_1);
                    SDL_UpdateRect(gui_surface, gui_rect_1.x, gui_rect_1.y, gui_rect_1.w, gui_rect_1.h);
                }
                else
                {
                    SDL_BlitSurface(forward_p_pic, NULL, gui_surface, &gui_rect_2);
                    SDL_UpdateRect(gui_surface, gui_rect_2.x, gui_rect_2.y, gui_rect_2.w, gui_rect_2.h);
                }

                ChangeLevel(new_cur_level, &redraw_all, &wasclick);
            }
            must_fastchange = false;
        }

        if (!ingame && !wasclick)
        {
            SDL_Delay(user_set->frame_delay);
            continue;
        }

//-- physics step --------------------------------------------------------------
        int ticks = SDL_GetTicks();
        int delta_ticks = ticks - prev_ticks;
        prev_ticks = ticks;
        clamp_min(delta_ticks, 1);
        clamp_max(delta_ticks, 1000 / 15);

        float acx = 0, acy = 0;
        input.read(&acx, &acy, NULL);
        if (input_cal_cycle)
            input_cal_cycle = (input_calibration_sample(&user_set->input_calibration_data, &acx, &acy, NULL) < MAX_CALIBRATION_SAMPLES);
        input_calibration_adjust(&user_set->input_calibration_data, &acx, &acy, NULL);
        maze_set_speed(user_set->ball_speed);
        maze_set_tilt(acx, acy, 0);
        GameState game_state = maze_step(delta_ticks);

        const dReal *R;
        int tk_px, tk_py, tk_pz;
        maze_get_ball(&tk_px, &tk_py, &tk_pz, &R);
        maze_get_animations(&keys_anim, &final_anim);
//------------------------------------------------------------------------------

        //restore the background
        ball_rect.w = game_config.ball_r * 2;
        ball_rect.h = game_config.ball_r * 2; //
        ball_rect.x = prev_px - game_config.ball_r;
        ball_rect.y = prev_py - game_config.ball_r;
        SDL_BlitSurface(render_pic, &ball_rect, screen, &ball_rect);

        UpdateBufAnimation();
        DrawBall(tk_px, tk_py, tk_pz, R, ballColor);

        //update the screen
        if (!redraw_all && !user_set->scrolling)
        {
            int min_px, max_px;
            int min_py, max_py;
            if (prev_px <= tk_px)
            {
                min_px = prev_px;
                max_px = tk_px;
            }
            else
            {
                min_px = tk_px;
                max_px = prev_px;
            }

            if (prev_py <= tk_py)
            {
                min_py = prev_py;
                max_py = tk_py;
            }
            else
            {
                min_py = tk_py;
                max_py = prev_py;
            }
            min_px -= game_config.ball_r;
            max_px += game_config.ball_r;
            min_py -= game_config.ball_r;
            max_py += game_config.ball_r;
            clamp_min(min_px, 0);
            clamp_max(max_px, game_config.wnd_w - 1);
            clamp_min(min_py, 0);
            clamp_max(max_py, game_config.wnd_h - 1);
            SDL_UpdateRect(screen, min_px, min_py, max_px - min_px, max_py - min_py);
            UpdateScreenAnimation();
        }

        if (user_set->scrolling)
        {
            clamp_min(screen_rect.x, tk_px - disp_x + disp_scroll_border);
            clamp_max(screen_rect.x, tk_px - disp_scroll_border);
            clamp_min(screen_rect.y, tk_py - disp_y + disp_scroll_border);
            clamp_max(screen_rect.y, tk_py - disp_scroll_border);
            clamp(screen_rect.x, 0, game_config.wnd_w - disp_x);
            clamp(screen_rect.y, 0, game_config.wnd_h - disp_y);
            SDL_BlitSurface(screen, &screen_rect, disp, &disp_rect);
        }

        prev_px = tk_px;
        prev_py = tk_py;

//-- GUI -----------------------------------------------------------------------
        if (wasclick && !ingame && !show_settings)
        {
            char txt[32];
            sprintf(txt, "Level %d/%d", cur_level + 1, game_levels_count);
            SDL_FreeSurface(levelTextSurface);
            levelTextSurface = TTF_RenderText_Blended(font, txt, fontColor);
            levelTextLocation.x = (disp_x - levelTextSurface->w) / 2;
            SDL_BlitSurface(levelTextSurface, NULL, gui_surface, &levelTextLocation);

            if (cur_level > 0)
                SDL_BlitSurface(back_pic, NULL, gui_surface, &gui_rect_1);
            else
                SDL_BlitSurface(back_i_pic, NULL, gui_surface, &gui_rect_1);

            if (cur_level < game_levels_count - 1)
                SDL_BlitSurface(forward_pic, NULL, gui_surface, &gui_rect_2);
            else
                SDL_BlitSurface(forward_i_pic, NULL, gui_surface, &gui_rect_2);

            SDL_BlitSurface(settings_pic, NULL, gui_surface, &gui_rect_3);
            SDL_BlitSurface(exit_pic, NULL, gui_surface, &gui_rect_4);
            redraw_all = true;
        }
//------------------------------------------------------------------------------

        //update the whole screen if needed
        if (user_set->scrolling)
        {
            SDL_Flip(disp);
        }
        else if (redraw_all)
        {
            SDL_Flip(screen);
        }
        redraw_all = false;

        if (show_settings)
        {
            bool _video_set_modified = false;
            bool _input_set_modified = false;
            bool _vibro_set_modified = false;
            settings_show(&input_cal_cycle, &_video_set_modified, &_input_set_modified, &_vibro_set_modified);
            if (input_cal_cycle)
                input_calibration_reset();
            if (_video_set_modified)
                video_set_modified = true;
            if (_input_set_modified)
                SetInput();
            if (_vibro_set_modified)
                SetVibro();
            SDL_GetMouseState(&mouse.x, &mouse.y);
            ingame_changed = true;
        }

        switch (game_state)
        {
        case GAME_STATE_FAILED:
            RedrawDesk();
            maze_restart_level();
            ResetPrevPos();
            redraw_all = true;
            break;
        case GAME_STATE_SAVED:
            RedrawDesk();
            maze_reload_level();
            ResetPrevPos();
            redraw_all = true;
            break;
        case GAME_STATE_WIN:
            if (++cur_level >= game_levels_count) cur_level=0;
            RenderLevel();
            RedrawDesk();
            maze_set_level(cur_level);
            ResetPrevPos();
            redraw_all = true;
            break;
        default:
            break;
        }

        SDL_Delay(user_set->frame_delay);
    }
//==============================================================================

    if (video_set_modified)
    {
        user_set->scrolling = user_set_new.scrolling;
        user_set->geom_x = user_set_new.geom_x;
        user_set->geom_y = user_set_new.geom_y;
        user_set->bpp = user_set_new.bpp;
        user_set->fullscreen_mode = user_set_new.fullscreen_mode;
        user_set->frame_delay = user_set_new.frame_delay;
    }

    user_set->level = cur_level + 1;
    SaveUserSettings();

    settings_shutdown();

    SDL_FreeSurface(levelTextSurface);
    TTF_CloseFont(font);
    vibro.shutdown();
    input.shutdown();
}