Ejemplo n.º 1
0
void move_button_down(){
    uint16_t x, y;
    deselect_button(button_posx, button_posy);
    int all_revealed = 1;
   
    i = 0;
    while (i < rows && all_revealed){
        if (button_arr[i][button_posy].state == 0) all_revealed = 0;
        i++;
    }

    if (all_revealed){
        if (button_posy < columns - 1){
            x = button_posx;
            y = button_posy + 1;

            if (button_arr[x][y].state == 0){
                select_button(x,y);
            } else {
                button_posx = x;
                button_posy = y;
                move_button_down();
            }
        } else {
            x = 0;
            y = 0;

            if (button_arr[x][y].state == 0){
                select_button(x,y);
            } else {
                button_posx = x;
                button_posy = y;
                move_button_down();
            }
        }
    }else 
    if (button_posx < rows - 1){
        x = button_posx+1;
        y = button_posy;

        if (button_arr[x][y].state == 0){
            select_button(x,y);
        } else {
            button_posx = x;
            button_posy = y;
            move_button_down();
        }
    } else {
        x = 0;
        y = button_posy;

        if (button_arr[x][y].state == 0){
            select_button(x,y);
        } else {
            button_posx = x;
            button_posy = y;
            move_button_down();
        }
    }
}
Ejemplo n.º 2
0
Archivo: button.c Proyecto: att/uwin
/**
*** select_button()
*** Given (x,y) and uberbutton, returns pointer to referred button, or NULL
**/
button_info *select_button(button_info *ub,int x,int y)
{
  int i;
  int row;
  int column;
  button_info *b;

  if (!(ub->flags&b_Container))
    return ub;

  x -= buttonXPad(ub) + buttonFrame(ub);
  y -= buttonYPad(ub) + buttonFrame(ub);

  if(x >= ub->c->width || x < 0 || y >= ub->c->height || y < 0)
    return ub;

  column = x * ub->c->num_columns / ub->c->width;
  row = y * ub->c->num_rows / ub->c->height;
  i = button_belongs_to(ub, column + row * ub->c->num_columns);
  if (i == -1)
    return ub;
  b = ub->c->buttons[i];

  return select_button(
      b, x + ub->c->xpos - buttonXPos(b, i),
      y + ub->c->ypos - buttonYPos(b, i));
}
Ejemplo n.º 3
0
/* Move the cursor around and use command icons.
 */
GUI_status ActorView::KeyDown(SDL_keysym key)
{
	if(!show_cursor) // FIXME: don't rely on show_cursor to get/pass focus
		return(GUI_PASS);
	KeyBinder *keybinder = Game::get_game()->get_keybinder();
	ActionType a = keybinder->get_ActionType(key);

	switch(keybinder->GetActionKeyType(a))
	{
		case SOUTH_WEST_KEY:
		case NORTH_WEST_KEY:
		case WEST_KEY:
			moveCursorToButton(cursor_pos.x - 1);
			break;
		case NORTH_EAST_KEY:
		case SOUTH_EAST_KEY:
		case EAST_KEY:
			moveCursorToButton(cursor_pos.x + 1);
			break;
		case DO_ACTION_KEY:
			select_button();
			break;
		case NORTH_KEY: // would otherwise move invisible mapwindow cursor
		case SOUTH_KEY:
			break;
		default:
//			set_show_cursor(false); // newAction() can move cursor here
			return GUI_PASS;
	}
	return(GUI_YUM);
}
Ejemplo n.º 4
0
void move_button_left(){
    uint16_t x, y;
    deselect_button(button_posx, button_posy);

    if (button_posy > 0){
        x = button_posx;
        y = button_posy - 1;
        if (button_arr[x][y].state == 0){
            select_button(x,y);
        } else {
            button_posx = x;
            button_posy = y;
            move_button_left();
        }
    } else if (button_posx > 0){
        x = button_posx - 1;
        y = columns - 1;
        
        if (button_arr[x][y].state == 0){
            select_button(x,y);
        } else {
            button_posx = x;
            button_posy = y;
            move_button_left();
        }    
    } else {
        x = rows - 1;
        y = columns - 1;
        
        if (button_arr[x][y].state == 0){
            select_button(x,y);
        } else {
            button_posx = x;
            button_posy = y;
            move_button_left();
        }    
    }
}
Ejemplo n.º 5
0
void move_button_right() {
    uint16_t x, y;
    deselect_button(button_posx, button_posy);

    if(button_posy < columns - 1) {
        x = button_posx;
        y = button_posy + 1;
        if (button_arr[x][y].state == 0){
            select_button(x,y);
        } else {
            button_posx = x;
            button_posy = y;
            move_button_right();
        }    
    } else if (button_posx < rows - 1){
        x = button_posx + 1;
        y = 0;
        if (button_arr[x][y].state == 0){
            select_button(x,y);
        } else {
            button_posx = x;
            button_posy = y;
            move_button_right();
        }    
    } else {
        x = 0;
        y = 0;
        if (button_arr[x][y].state == 0){
            select_button(x,y);
        } else {
            button_posx = x;
            button_posy = y;
            move_button_right();
        }    
    }
}
Ejemplo n.º 6
0
//! With this setup it would seem like main() must be the first function in this file, otherwise
//! the wrong function gets called on reset.
void main(void)
{
    volatile INT32U ulLoop;
    volatile INT16U event;
    volatile INT16U push;
    //Hardware upstarts
    initHW();

    //! Start the OLED display and write a message on it
    RIT128x96x4Init(ulSSI_FREQUENCY);
    RIT128x96x4StringDraw("EMP", 					15, 42, mainFULL_SCALE);
    RIT128x96x4StringDraw("enter the code.....",	 5, 49, mainFULL_SCALE);
    RIT128x96x4StringDraw("SW2 SW3 SW4 SW5 SW6", 		15, 57, mainFULL_SCALE);
    // Entry Password see under inputs
    // Wait for the select key to be pressed
    while (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1));
    // Wait for the select key to be pressed
    while (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_0));
    // Wait for the select key to be pressed
    while (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1));
    // Wait for the select key to be pressed
    while (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2));
    // Wait for the select key to be pressed
    while (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3));

    // Clean the OLED display.
    RIT128x96x4Clear();
    //
    // Loop forever.
    //
    while (1)
    {

        // Statmashine function
        // This is where a statemachine could be added
        event = GetKeyEvents();
        push = select_button();
        statemashine(event , push);
        //all functions the

    }

}
Ejemplo n.º 7
0
void Calculator::render(int idx) {
    selected_button_idx = idx;

    ncurses::endwin();
    ncurses::refresh();

    // reset outer_{w,h} appropriately
    getmaxyx(ncurses::stdscr, stdscr_h, stdscr_w);
    if (stdscr_w < MIN_OUTER_W ||
        stdscr_h < MIN_OUTER_H) {
        // too small to display!
        ;
    }
    outer.w = std::min(stdscr_w - 2 * MIN_OUTER_X, MAX_OUTER_W);
    outer.h = std::min(stdscr_h - 2 * MIN_OUTER_Y, MAX_OUTER_H);
    num_buttons_x = (outer.w - GAP_X_BTWN_BUTTONS) /
                    (BUTTON_W + GAP_X_BTWN_BUTTONS);
    num_buttons_y = (outer.h - 2 * GAP_Y_BTWN_BUTTONS - main_display->getH()) /
                    (BUTTON_W + GAP_X_BTWN_BUTTONS);
    outer.w = num_buttons_x * BUTTON_W + (num_buttons_x - 1) * GAP_X_BTWN_BUTTONS +
                    2 * INNER_MARGIN_X;
    outer.x = (stdscr_w - outer.w)/2;
    outer.h = num_buttons_y * BUTTON_H + num_buttons_y * GAP_Y_BTWN_BUTTONS +
                    main_display->getH() + 2 * INNER_MARGIN_Y;
    outer.y = (stdscr_h - outer.h)/2;

    // key help
    key_help->undisplay();
    key_help->setX((outer.w - key_help->getW()) / 2);
    key_help->setY((outer.h - key_help->getH()) / 2);

    // main display
    main_display->undisplay();
    main_display->setW(outer.w - 2 * INNER_MARGIN_X);
    main_display->setX(outer.x + INNER_MARGIN_X);
    main_display->setY(outer.y + INNER_MARGIN_Y);

    // keys
    int pos_x_cnt{0};
    int pos_y_cnt{0};

    for (auto it = buttons.begin(); it != buttons.end(); it++) {
        (*it)->undisplay();
    }

    auto it = buttons.begin();
    if (selected_button_idx != DEFAULT_SELECTED_BUTTON_IDX) {
        int adv = (selected_button_idx / (num_buttons_x * num_buttons_y)) *
            (num_buttons_x * num_buttons_y);
        std::advance(it, adv);
    }

    for (int n = 0; it != buttons.end() && n < (num_buttons_x * num_buttons_y); it++, n++) {
        int x = main_display->getX() +
                pos_x_cnt * (BUTTON_W + GAP_X_BTWN_BUTTONS);
        int y = main_display->getY() + main_display->getH() + GAP_Y_BTWN_BUTTONS +
                pos_y_cnt * (BUTTON_H + GAP_Y_BTWN_BUTTONS);
        (*it)->setX(x);
        (*it)->setY(y);
        (*it)->redisplay();

        bool reach_x_limit{false};
        bool reach_y_limit{false};
        if ((x + GAP_X_BTWN_BUTTONS + BUTTON_W + INNER_MARGIN_X) > (outer.x + outer.w)) {
            reach_x_limit = true;
        }
        if ((y + GAP_Y_BTWN_BUTTONS + BUTTON_H + INNER_MARGIN_Y) > (outer.y + outer.h)) {
            reach_y_limit = true;
        }
        if (reach_x_limit && reach_y_limit) {
            break;
        } else if (reach_x_limit) {
            pos_x_cnt = 0;
            pos_y_cnt++;
        } else {
            pos_x_cnt++;
        }
    }
    if (selected_button_idx != DEFAULT_SELECTED_BUTTON_IDX) {
        select_button(idx);
    }

    main_display->redisplay();
};