/* Checks for a click and clicks the control */ int checkClick(control* ctrl, control* window, SDL_Rect parent, SDL_MouseButtonEvent event) { coordinates calculated_rects; SDL_Rect ctrl_rect; int err; if (ctrl != NULL) { err = checkClick(ctrl->next,window,parent,event); if (err != OK) return err; calculated_rects = calculateRectangles(parent,ctrl->rect); ctrl_rect = calculated_rects.to; switch(ctrl->ctrl_type) { case ctrl_window: case ctrl_panel: err = checkClick(ctrl->children,window,ctrl_rect,event); if (err != OK) return err; break; case ctrl_button: if ((event.x >= ctrl_rect.x) && (event.x <= (ctrl_rect.x+ctrl_rect.w)) && (event.y >= ctrl_rect.y) && (event.y <= (ctrl_rect.y+ctrl_rect.h))) { err = ctrl->clickControl(ctrl,window,event); if (err == OK) return CLICK; return err; } break; default: break; } } return OK; }
void WidgetInput::logic() { if (checkClick()) { inFocus = true; } // if clicking elsewhere unfocus the text box if (inp->pressing[MAIN1]) { if (!isWithin(pos, inp->mouse)) { inFocus = false; } } if (inFocus) { // handle text input text += inp->inkeys; if (text.length() > max_characters) { text = text.substr(0, max_characters); } // handle backspaces if (!inp->lock[DELETE] && inp->pressing[DELETE]) { inp->lock[DELETE] = true; text = text.substr(0, text.length()-1); } // animate cursor // cursor visible one second, invisible the next cursor_frame++; if (cursor_frame == FRAMES_PER_SEC+FRAMES_PER_SEC) cursor_frame = 0; } }
void Sensing::mousePressed(int xPos, int yPos, int button) { if(_recordMode) { checkClick(xPos, yPos); } }
/* Chescks for a mouse click event in the given window */ int checkClickEvent(control* window, SDL_Event event) { SDL_MouseButtonEvent e = event.button; if (window != NULL) { if (window->ctrl_type == ctrl_window) { return checkClick(window,window,window->rect,e); } } return OK; }
void KeyMap::update(Vector2i m_pos,bool clik,string keyIn) { checkHover(m_pos); checkClick(clik); activeCharDisplay.setString(activeChar); if(toggled && keyIn.size() != 0) { activeChar = keyIn[0]; toggle(); } return; }
void WidgetInput::logic() { if (checkClick()) { inFocus = true; } // if clicking elsewhere unfocus the text box if (inp->pressing[MAIN1]) { if (!isWithin(pos, inp->mouse)) { inFocus = false; } } if (inFocus) { if (inp->inkeys != "") { // handle text input text += inp->inkeys; if (text.length() > max_characters) { text = text.substr(0, max_characters); } } // handle backspaces if (!inp->lock[DEL] && inp->pressing[DEL]) { inp->lock[DEL] = true; // remove utf-8 character int n = text.length()-1; while (n > 0 && ((text[n] & 0xc0) == 0x80) ) n--; text = text.substr(0, n); } // animate cursor // cursor visible one second, invisible the next cursor_frame++; if (cursor_frame == FRAMES_PER_SEC+FRAMES_PER_SEC) cursor_frame = 0; } }
int WidgetScrollBar::checkClick() { int r = checkClick(inpt->mouse.x,inpt->mouse.y); return r; }
bool WidgetButton::checkClick() { return checkClick(inpt->mouse.x,inpt->mouse.y); }
bool WidgetListBox::checkClick() { return checkClick(inpt->mouse.x,inpt->mouse.y); }
bool WidgetSlider::checkClick() { if (!enabled) return false; return checkClick(inpt->mouse.x,inpt->mouse.y); }
bool WidgetListBox::checkClick() { if (checkClick(inpt->mouse.x,inpt->mouse.y)) return true; else return false; }
bool WidgetInput::logic(int x, int y) { Point mouse(x, y); // Change the hover state hover = isWithinRect(pos, mouse); if (checkClick()) { edit_mode = true; } // if clicking elsewhere unfocus the text box if (inpt->pressing[MAIN1]) { if (!isWithinRect(pos, inpt->mouse)) { edit_mode = false; } } if (edit_mode) { inpt->slow_repeat[DEL] = true; inpt->slow_repeat[LEFT] = true; inpt->slow_repeat[RIGHT] = true; inpt->startTextInput(); if (inpt->inkeys != "") { // handle text input // only_numbers will restrict our input to 0-9 characters if (!only_numbers || (inpt->inkeys[0] >= 48 && inpt->inkeys[0] <= 57)) { text.insert(cursor_pos, inpt->inkeys); cursor_pos += inpt->inkeys.length(); trimText(); } // HACK: this prevents normal keys from triggering common menu shortcuts for (size_t i = 0; i < inpt->key_count; ++i) { if (inpt->pressing[i]) { inpt->lock[i] = true; inpt->repeat_ticks[i] = 1; } } } // handle backspaces if (inpt->pressing[DEL] && inpt->repeat_ticks[DEL] == 0) { if (!text.empty() && cursor_pos > 0) { // remove utf-8 character // size_t old_cursor_pos = cursor_pos; size_t n = cursor_pos-1; while (n > 0 && ((text[n] & 0xc0) == 0x80)) { n--; } text = text.substr(0, n) + text.substr(cursor_pos, text.length()); cursor_pos -= (cursor_pos) - n; trimText(); } } // cursor movement if (!text.empty() && cursor_pos > 0 && inpt->pressing[LEFT] && inpt->repeat_ticks[LEFT] == 0) { cursor_pos--; trimText(); } else if (!text.empty() && cursor_pos < text.length() && inpt->pressing[RIGHT] && inpt->repeat_ticks[RIGHT] == 0) { inpt->lock[RIGHT] = true; cursor_pos++; trimText(); } // defocus with Enter or Escape if (accept_to_defocus && inpt->pressing[ACCEPT] && !inpt->lock[ACCEPT]) { inpt->lock[ACCEPT] = true; edit_mode = false; } else if (inpt->pressing[CANCEL] && !inpt->lock[CANCEL]) { inpt->lock[CANCEL] = true; edit_mode = false; } } else { inpt->slow_repeat[DEL] = false; inpt->slow_repeat[LEFT] = false; inpt->slow_repeat[RIGHT] = false; inpt->stopTextInput(); } return true; }