コード例 #1
0
ファイル: button.c プロジェクト: AntaresOne/multirom
int button_keyaction_call(void *data, int act)
{
    button *b = data;
    switch(act)
    {
        case KEYACT_UP:
        case KEYACT_DOWN:
        case KEYACT_CLEAR:
        {
            if(act != KEYACT_CLEAR && b->keyact_frame == NULL)
            {
                fb_add_rect_notfilled(b->level_off + LEVEL_RECT, b->x, b->y, b->w, b->h, C_KEYACT_FRAME, KEYACT_FRAME_W, &b->keyact_frame);
                fb_request_draw();
                return 0;
            }
            else
            {
                list_clear(&b->keyact_frame, &fb_remove_item);
                fb_request_draw();
                return (act == KEYACT_CLEAR) ? 0 : 1;
            }
        }
        case KEYACT_CONFIRM:
        {
            if(b->clicked && !(b->flags & BTN_DISABLED))
                (*b->clicked)(b->action);
            return 0;
        }
        default:
            return 0;
    }
}
コード例 #2
0
ファイル: checkbox.c プロジェクト: Ever-Never/multirom
int checkbox_touch_handler(touch_event *ev, void *data)
{
    checkbox *box = (checkbox*)data;

    if(box->touch_id == -1 && (ev->changed & TCHNG_ADDED))
    {
        if(!in_rect(ev->x, ev->y, box->x-TOUCH, box->y-TOUCH, CHECKBOX_SIZE+TOUCH*2, CHECKBOX_SIZE+TOUCH*2))
            return -1;

        box->touch_id = ev->id;
        box->hover = fb_add_rect(box->x-TOUCH, box->y-TOUCH, CHECKBOX_SIZE+TOUCH*2, CHECKBOX_SIZE+TOUCH*2, CLR_SECONDARY);
        fb_request_draw();
    }

    if(box->touch_id != ev->id)
        return -1;

    if(ev->changed & TCHNG_REMOVED)
    {
        if(in_rect(ev->x, ev->y, box->x-TOUCH, box->y-TOUCH, CHECKBOX_SIZE+TOUCH*2, CHECKBOX_SIZE+TOUCH*2))
        {
            (*box->clicked)(box->selected == NULL);
            checkbox_select(box, (box->selected == NULL));
        }

        fb_rm_rect(box->hover);
        box->hover = NULL;
        box->touch_id = -1;

        fb_request_draw();
    }
    return 0;
}
コード例 #3
0
ファイル: pong.c プロジェクト: AMohseni76/multirom
int pong_do_movement(int step)
{
    if(!movement_steps[step])
    {
        pong_calc_movement();
        return 0;
    }

    int col = movement_steps[step]->collision;
    if(col == COL_NONE || col == COL_LEFT || col == COL_RIGHT)
    {
        ball->x = movement_steps[step]->x;
        ball->y = movement_steps[step]->y;
        if(enable_computer)
            pong_handle_ai();
    }

    switch(col)
    {
        case COL_NONE:
            return step+1;
        case COL_TOP:
        case COL_BOTTOM:
            ball_speed_x = -ball_speed_x;
            break;
        case COL_LEFT:
        case COL_RIGHT:
        {
            int s = col - 1;
            if(ball->x+BALL_W >= paddles[s]->x && ball->x <= paddles[s]->x+PADDLE_W)
            {
                // Increase X speed according to distance from center of paddle.
                ball_speed_x = (float)((ball->x + BALL_W/2) - (paddles[s]->x + PADDLE_W/2))/BALL_SPEED_MOD;
                ball_speed_y = -ball_speed_y;
            }
            else
            {
                pong_add_score(!s);
                for(col = 0; col < 1000; col += 16)
                {
                    fb_request_draw();
                    usleep(16000);
                }
                pong_spawn_ball(s);
            }
            break;
        }
    }

    pong_calc_movement();
    return 0;
}
コード例 #4
0
ファイル: button.c プロジェクト: AntaresOne/multirom
void button_set_checked(button *b, int checked)
{
    if((checked == 1) == ((b->flags & BTN_CHECKED) != 0))
        return;

    if(checked)
        b->flags |= BTN_CHECKED;
    else
        b->flags &= ~(BTN_CHECKED);

    button_update_colors(b);
    fb_request_draw();
}
コード例 #5
0
ファイル: button.c プロジェクト: AntaresOne/multirom
void button_set_hover(button *b, int hover)
{
    if((hover == 1) == ((b->flags & BTN_HOVER) != 0))
        return;

    if(hover)
        b->flags |= BTN_HOVER;
    else
        b->flags &= ~(BTN_HOVER);

    if(b->text)
    {
        button_update_colors(b);
        fb_request_draw();
    }
}
コード例 #6
0
ファイル: button.c プロジェクト: AntaresOne/multirom
void button_enable(button *b, int enable)
{
    if(enable)
        b->flags &= ~(BTN_DISABLED);
    else
    {
        b->flags |= BTN_DISABLED;
        b->flags &= ~(BTN_HOVER);
    }

    if(b->text)
    {
        button_update_colors(b);
        fb_request_draw();
    }
}
コード例 #7
0
ファイル: progressdots.c プロジェクト: lionzeye/multirom
static void progdots_animate(uint32_t diff, void *data)
{
    progdots *p = (progdots*)data;

    if(p->switch_timer <= diff)
    {
        if(++p->active_dot >= PROGDOTS_CNT)
            p->active_dot = 0;

        progdots_set_active(p, p->active_dot);
        fb_request_draw();

        p->switch_timer = SWITCH_SPEED;
    }
    else
        p->switch_timer -= diff;
}
コード例 #8
0
ファイル: pong.c プロジェクト: AMohseni76/multirom
void pong(void)
{
    enable_computer = 1;
    paddle_touch_id[L] = -1;
    paddle_touch_id[R] = -1;

    score_val[L] = 0;
    score_val[R] = 0;

    fb_set_background(BLACK);

    fb_text_proto *p = fb_text_create(0, 0, GRAYISH, SIZE_SMALL, "Press power button to go back");
    p->style = STYLE_ITALIC;
    fb_text *help = fb_text_finalize(p);
    help->y = fb_height/2 - help->h*1.5;
    center_text(help, 0, -1, fb_width, -1);

    // middle line
    fb_add_rect(0, fb_height/2 - 1, fb_width, 1, WHITE);

    score[L] = fb_add_text(0, 0, WHITE, SIZE_EXTRA, "0");
    score[L]->y = fb_height/2 - score[L]->h - 20*DPI_MUL;
    score[R] = fb_add_text(0, fb_height/2 + 20*DPI_MUL, WHITE, SIZE_EXTRA, "0");

    paddles[L] = fb_add_rect(100, PADDLE_Y, PADDLE_W, PADDLE_H, WHITE);
    paddles[R] = fb_add_rect(100, fb_height-PADDLE_Y-PADDLE_H, PADDLE_W, PADDLE_H, WHITE);

    ball = fb_add_rect(0, 0, BALL_W, BALL_W, WHITE);

    pong_spawn_ball(rand()%2);
    pong_calc_movement();

    add_touch_handler(&pong_touch_handler, NULL);

    int step = 0;
    volatile int run = 1;
    while(run)
    {
        switch(get_last_key())
        {
            case KEY_POWER:
                run = 0;
                break;
            case KEY_VOLUMEUP:
                ball_speed += 5;
                pong_spawn_ball(rand()%2);
                pong_calc_movement();
                step = 0;
                break;
            case KEY_VOLUMEDOWN:
                if(ball_speed > 5)
                    ball_speed -= 5;
                pong_spawn_ball(rand()%2);
                pong_calc_movement();
                step = 0;
                break;
        }

        step = pong_do_movement(step);

        fb_request_draw();
        usleep(16000);
    }

    rm_touch_handler(&pong_touch_handler, NULL);

    list_clear(&movement_steps, &free);
}