/***************************************************** ** ** BasicWesternChart --- OnResponsiveChartEvent ** ******************************************************/ bool BasicWesternChart::OnResponsiveChartEvent( const MPoint p, const int /* keyMod */ ) { const ObjectId old1_marked = h1marked; const ObjectId old2_marked = h2marked; h1marked = ONONE; h2marked = ONONE; //for( uint i = 0; i < obs.size() && i < h1rects.size() && i < h2rects.size(); i++ ) for( uint i = 0; i < obs.size(); i++ ) { if ( pointInRect( p, h1rect[obs[i]] )) { //printf( "MATCH RECT1 %d planet %d\n", i, obs[i] ); h1marked = obs[i]; return h1marked != old1_marked; } if ( pointInRect( p, h2rect[obs[i]] )) { //printf( "MATCH RECT2 %d planet %d\n", i, obs[i] ); h2marked = obs[i]; return h2marked != old2_marked; } } //printf( "OnResponsiveChartEvent RETURN %d\n", old1_marked != ONONE || old2_marked != ONONE ); // this point can only be reached if there is no match in the chart. repaint is only required if one was marked before return old1_marked != ONONE || old2_marked != ONONE; }
void guihckContextMouseMove(guihckContext* ctx, float sx, float sy, float dx, float dy) { chckPoolIndex iter = 0; guihckMouseAreaId* mouseAreaId = NULL; chckIterPool* mouseAreas = queryMouseAreasIntersectingLine(ctx, sx, sy, dx, dy); bool handled = false; while(!handled && (mouseAreaId = chckIterPoolIter(mouseAreas, &iter))) { _guihckMouseArea* mouseArea = chckPoolGet(ctx->mouseAreas, *mouseAreaId); if(!mouseArea->functionMap.mouseMove && !mouseArea->functionMap.mouseEnter && !mouseArea->functionMap.mouseExit) continue; bool s = pointInRect(sx, sy, &mouseArea->rect); bool d = pointInRect(dx, dy, &mouseArea->rect); if(s && d) { if(mouseArea->functionMap.mouseMove) handled = mouseArea->functionMap.mouseMove(ctx, mouseArea->elementId, guihckElementGetData(ctx, mouseArea->elementId), sx, sy, dx, dy); } else if(s) { if(mouseArea->functionMap.mouseExit) handled = mouseArea->functionMap.mouseExit(ctx, mouseArea->elementId, guihckElementGetData(ctx, mouseArea->elementId), sx, sy, dx, dy); } else if(d) { if(mouseArea->functionMap.mouseEnter) handled = mouseArea->functionMap.mouseEnter(ctx, mouseArea->elementId, guihckElementGetData(ctx, mouseArea->elementId), sx, sy, dx, dy); } } free(mouseAreas); }
bool XUIObject::pointInRegion(int x, int y) { int over = pointInRect(x, y); if (over) { RootWnd *child = m_wnd->findRootWndChild(x, y); over &= (child == NULL || child == m_wnd); } return over; }
chckIterPool* queryMouseAreasIntersectingLine(guihckContext* ctx, float sx, float sy, float dx, float dy) { chckIterPool* result = chckIterPoolNew(4, 4, sizeof(guihckMouseAreaId)); guihckMouseAreaId mouseAreaIter = 0; _guihckMouseArea* mouseArea = NULL; while((mouseArea = chckPoolIter(ctx->mouseAreas, &mouseAreaIter))) { /* Should be replaced by querying a quad tree*/ if(pointInRect(sx, sy, &mouseArea->rect) || pointInRect(dx, dy, &mouseArea->rect)) { guihckMouseAreaId id = mouseAreaIter - 1; chckIterPoolAdd(result, &id, NULL); } } return sortMouseAreasByElementOrder(ctx, result); }
bool CollisionMgr::checkCollision(GWO obj1, GWO obj2) { int x1 = 0, y1 = 0; int h1 = 0, w1 = 0; obj1.getPos(x1, y1); obj1.getDimensions(w1, h1); if (pointInRect(x1, y1, obj2) || pointInRect(x1 + w1, y1, obj2) || pointInRect(x1, y1 + h1, obj2) || pointInRect(x1 + w1, y1 + h1, obj2)) { return true; } return false; }
bool Rect::collide(const Shape* shape, vec::Vector2& normal) const { // Check for a null-pointer if (shape == NULL) return false; bool isColliding = false; // If rect-rect collision if (shape->getTypeEnum() == RECT) { const Rect* r = dynamic_cast<const Rect*>(shape); // Check for a null cast if (r == NULL) return false; if (r->getPos().dist(this->getPos()) < getRad() + r->getRad()) { //Check if any point lies inside the other rect if (pointInRect(r->tl, normal) || pointInRect(r->tr, normal) || pointInRect(r->br, normal) || pointInRect(r->bl, normal)) isColliding = true; if (r->pointInRect(tl, normal) || r->pointInRect(tr, normal) || r->pointInRect(br, normal) || r->pointInRect(bl, normal)) isColliding = true; } } // If rect-circ collision else if (shape->getTypeEnum() == CIRC) { const Circ* c = dynamic_cast<const Circ*>(shape); // Check for a null cast if (c == NULL) return false; isColliding = collideRC(*this, *c, normal); } return isColliding; }
//! \copydoc Widdget::handleMouseMotionEvent void Button::handleMouseMotionEvent(SDL_MouseMotionEvent event) { SDL_Rect rect = this->getRenderRect(); // hovered if(pointInRect(Point{event.x, event.y}, Rectangle(rect)) && m_state != State::Pressed) { m_state = State::Hovered; } // neutral (not hovered) else if(m_state != State::Pressed) m_state = State::Neutral; }
void FontEditWindow::onLButtonDown(BOOL, int x, int y, UINT) { if (magPosition < 2) // dont' grab anything if we're less than 100% return; mouseDown.x = x; mouseDown.y = y; if (pointInRect(x, y, fontBaselineRect)) { baselineMouseDownY = fontEdit->getBaseline(); grabbed = Grab_Font_Base; } else if (pointInRect(x, y, charBaselineRect)) { baselineMouseDownY = currentCharInfo->baseline; grabbed = Grab_Char_Base; } else ;// FORWARD_WM_LBUTTONDOWN( fDoubleClick, x, y, keyFlags, defWindowProc); }
void touch_timer(){ LCD_RECT timerRect; timerRect.left = 0; timerRect.right = 128; timerRect.top = 46; timerRect.bottom = 66; lcd_clearScreen(mblack); while (!(touch_get_cursor(&m_point))){ //what timer mode? if (timermode == 0){ //stopped mode //TODO: print 00:00:00.00 to screen in bignum, centered while (!(touch_get_cursor(&m_point))){} while ((touch_get_cursor(&m_point))){} //debounce //if it is outside numbers go to next display mode if (!pointInRect(m_point,timerRect)){oil_temp_gauge();} //if it is on numbers go to mode 1 if (pointInRect(m_point,timerRect)){ //store millis of start time timerStartMillis = millis(); timermode = 1; } } if (timermode == 1){ //running and screen mode while (!(touch_get_cursor(&m_point))){ //TODO: display code for running timer goes here //current timer value = millis() - timer start } while (touch_get_cursor(&m_point)){} //debounce //if it is on numbers go to mode 2 if (pointInRect(m_point,timerRect)){ timermode == 0; timerStoppedMillis = 0; touch_timer(); } } //if it is outside go to next display mode if (!(pointInRect(m_point,timerRect))){ oil_temp_gauge(); } } }
/** * Checks to see if the widget, self, has the mouse over it. This consists of * two checks; firstly seeing if the mouse is inside of the widgets bounding * rectangle; secondly, if the widget has a mask, seeing if the location is * masked or not. * * @param self The widget we want to see if the mouse is over. * @param location The location of the mouse, in absolute terms. * @return True if the mouse is over the widget, false otherwise. */ static bool widgetHasMouse(widget *self, point location) { const rect bounds = widgetAbsoluteBounds(self); // Check to see if it is in the widgets bounding box bool hasMouse = pointInRect(location, bounds); // If the widget has a mask; ensure the location is not masked if (hasMouse && self->maskEnabled) { // Work out where the mouse is relative to the widget const point relativeLocation = pointSub(location, bounds.topLeft); // We have the mouse if the point is NOT masked hasMouse = !widgetPointMasked(self, relativeLocation); } return hasMouse; }
//! \copydoc Widget::handleMouseButtonEvent void Button::handleMouseButtonEvent(SDL_MouseButtonEvent event) { SDL_Rect rect = this->getRenderRect(); // button event inside of button if(pointInRect(Point{event.x, event.y}, Rectangle(rect))) { // pressed if(event.type == SDL_MOUSEBUTTONDOWN && m_state != State::Pressed) m_state = State::Pressed; else if(event.type == SDL_MOUSEBUTTONUP && m_state == State::Pressed){ m_doClickCallbacks = true; m_state = State::Hovered; } } // if its not in the button, then we set the state back and do not call callback else{ m_state = State::Neutral; } }
IRenderable* EditorMap::getSceneGeom(const vec3& pnt) { for (auto it = mStaticSceneGeom.begin(); it != mStaticSceneGeom.end(); ++it) { if (dynamic_cast<RdrRect*>(*it)) { RdrRect* rect = static_cast<RdrRect*>(*it); for (int i = 0; i < 4; ++i) { if (pointInRenderableRect(rect->getChildren()[i], pnt)) return const_cast<IRenderable*>(rect->getChildren()[i]); } if (pointInRect(rect->box(), pnt)) { return rect; } } else if (dynamic_cast<RdrTri*>(*it)) { RdrTri* tri = static_cast<RdrTri*>(*it); for (int i = 0; i < 3; ++i) { if (pointInRenderableRectParentTri(tri->getChildren()[i], pnt)) return const_cast<IRenderable*>(tri->getChildren()[i]); } if (pointIsInTri(tri->getBase(), pnt)) { return tri; } } } return nullptr; }
/***************************************************** ** ** BasicVedicChart --- getFieldForScreenPos ** ******************************************************/ uint BasicVedicChart::getFieldForScreenPos( const MPoint &p ) { //printf( "BasicVedicChart::getFieldForScreenPos %f %f count %d\n", p.real(), p.imag(), field_count ); for( uint i = 0; i < field_count && i < fields.size(); i++ ) { //printf( "BasicVedicChart::getFieldForScreenPos %f %f RECT %s\n", p.x, p.y, str2char( fields[i].rect.toString()) ); if ( pointInRect( p, fields[i].rect )) { const double x = ( p.real() - fields[i].rect.x ) / fields[i].rect.width; const double y = ( p.imag() - fields[i].rect.y ) / fields[i].rect.height; switch( fields[i].fieldtype ) { case FIELD_TYPE_FULL: // all fields in south indian chart, sbc, fixed rasis in east indian chart return i; break; case FIELD_TYPE_NE: // east: taurus and sag if ( x >= y ) return i; break; case FIELD_TYPE_SW: // east: gemini and scorpio if ( x <= y ) return i; break; case FIELD_TYPE_NW: // east: leo and pisces if ( 1 - x >= y ) return i; break; case FIELD_TYPE_SE: // east: virgo and aquarius if ( 1 - x <= y ) return i; break; case FIELD_TYPE_N: // north: houses 2 and 12 if ( fabs( x - .5 ) <= .5 * ( 1 - y )) return i; break; case FIELD_TYPE_W: // north: houses 3 and 5 if ( fabs( y - .5 ) <= .5 * ( 1 - x )) return i; break; case FIELD_TYPE_S: // north: houses 6 and 8 if ( fabs( x - .5 ) <= .5 * y ) return i; break; case FIELD_TYPE_E: // north: houses 9 and 11 if ( fabs( y - .5 ) <= .5 * x ) return i; break; case FIELD_TYPE_DIAMOND:// north: houses 1: 4: 7: 10 if ( .5 - fabs( x - .5 ) >= fabs( y - .5 )) return i; break; default: printf( "BasicVedicChart::getFieldForScreenPos WARN: invalid field type %d at postion %u\n", fields[i].fieldtype, i ); break; } } } //return UINT_FOR_NOT_FOUND; return UINT_FOR_OUTSIDE; }
/************************************************************** *** ** BasicVedicChart --- OnResponsiveChartEvent *** ***************************************************************/ bool BasicVedicChart::OnResponsiveChartEvent( const MPoint p, const int /* keyMod */ ) { bool changed = false; uint f = UINT_FOR_NOT_FOUND; int status = 0; if ( p != MPoint( -1, -1 )) { f = getFieldForScreenPos( p ); //printf( "F %d\n", f ); } //printf( "Marked field is %d f is %d markedFieldStatus %d offset %d\n", markedField, f, markedFieldStatus, positionOffset ); if ( markedField != f ) changed = true; markedField = f; if ( f == UINT_FOR_NOT_FOUND ) { markedFieldStatus = 0; } else { const VedicChartBehaviorConfig &bcfg = chartprops->getVedicChartBehaviorConfig(); if ( bcfg.highlightOnMouseOver ) status |= CHART_FIELD_STATUS_MARKUP; if ( bcfg.zoomOnMouseOver ) status |= CHART_FIELD_STATUS_ZOOM; if ( bcfg.aspectingObjectsMode == 1 ) status |= CHART_FIELD_STATUS_ASPECTING; if ( bcfg.aspectedObjectsMode == 1 ) status |= CHART_FIELD_STATUS_ASPECTED; if ( bcfg.allAspectsMode == 1 && charttype != CT_PARTNER ) status |= CHART_FIELD_STATUS_ALL_ASPECTS; if ( wxGetKeyState( WXK_SHIFT )) { if ( bcfg.aspectingObjectsMode == 2 ) status |= CHART_FIELD_STATUS_ASPECTING; if ( bcfg.aspectedObjectsMode == 2 ) status |= CHART_FIELD_STATUS_ASPECTED; if ( bcfg.allAspectsMode == 2 && charttype != CT_PARTNER ) status |= CHART_FIELD_STATUS_ALL_ASPECTS; } if ( wxGetKeyState( WXK_CONTROL )) { if ( bcfg.aspectingObjectsMode == 3 ) status |= CHART_FIELD_STATUS_ASPECTING; if ( bcfg.aspectedObjectsMode == 3 ) status |= CHART_FIELD_STATUS_ASPECTED; if ( bcfg.allAspectsMode == 3 && charttype != CT_PARTNER ) status |= CHART_FIELD_STATUS_ALL_ASPECTS; } if ( wxGetKeyState( WXK_ALT )) { if ( bcfg.aspectingObjectsMode == 4 ) status |= CHART_FIELD_STATUS_ASPECTING; if ( bcfg.aspectedObjectsMode == 4 ) status |= CHART_FIELD_STATUS_ASPECTED; if ( bcfg.allAspectsMode == 4 && charttype != CT_PARTNER ) status |= CHART_FIELD_STATUS_ALL_ASPECTS; } // test if mouse position is within transit rect (used for non cummutative partner aspects) if ( charttype == CT_RADIX || charttype == CT_TRANSIT ) status |= CHART_FIELD_STATUS_POS_FULL; else { if ( pointInRect( p, transitrect )) status |= CHART_FIELD_STATUS_POS_INNER; else status |= CHART_FIELD_STATUS_POS_OUTER; } //printf( "Status now %d\n", status ); if ( status != markedFieldStatus ) changed = true; markedFieldStatus = status; } //printf( "Ende BasicVedicChart::OnResponsiveChartEvent point %f %f markedField %d markedFieldStatus %d status %d changed %d\n", p.real(), p.imag(), markedField, markedFieldStatus, status, changed ); return changed; }
void updateEditor(SDL_Event event, EditorData* data) { GUI_sendEventToGUI(data->gui, &event); const unsigned char* keyboardState = SDL_GetKeyboardState(NULL); int2 mousePixel; SDL_GetMouseState(&mousePixel.x, &mousePixel.y); float2 mousePos = pixelToPoint(&data->view, mousePixel); updateBones(data); switch (event.type) { case SDL_KEYDOWN: { switch (event.key.keysym.scancode) { case SDL_SCANCODE_S: if (event.key.keysym.mod == KMOD_LCTRL) { SDL_Event lastEvent = data->lowEventStack.Top(); if (lastEvent.key.keysym.scancode == SDL_SCANCODE_S && lastEvent.key.keysym.mod == KMOD_LCTRL) { // save skeleton GUI_WidgetID widget = GUI_addContainer(data->gui, GUI_MAIN_WIDGET, { 400 - 100, 300 - 25, 200, 50}, GUI_Container::Orientation::HORIZONTAL); auto callbackSave = [](GUI* gui, GUI_WidgetID widgetID, void* editorData) { EditorData* data = (EditorData*)editorData; GUI_WidgetID widget = GUI_getParentWidget(gui, widgetID); const char* filename = GUI_getTextfield(gui, GUI_getChildWidget(gui, widget, 0)).text; saveSkeleton(filename, &data->skeleton[0], &data->names[0], data->skeleton.size()); GUI_removeWidget(gui, widget); }; auto callbackCancel = [](GUI* gui, GUI_WidgetID widgetID, void*) { GUI_WidgetID widget = GUI_getParentWidget(gui, widgetID); GUI_removeWidget(gui, widget); }; GUI_addTextfield(data->gui, widget, { 0, 0, -1, -1 }, "filename"); GUI_addButton(data->gui, widget, { 0, 0, 50, -1 }, "Save", data, callbackSave); GUI_addButton(data->gui, widget, { 0, 0, 50, -1 }, "Cancel", 0, callbackCancel); break; } else if (lastEvent.key.keysym.scancode == SDL_SCANCODE_O && lastEvent.key.keysym.mod == KMOD_LCTRL) { // load skeleton GUI_WidgetID widget = GUI_addContainer(data->gui, GUI_MAIN_WIDGET, { 400 - 100, 300 - 15, 200, 30 }, GUI_Container::Orientation::HORIZONTAL); auto callbackLoad = [](GUI* gui, GUI_WidgetID widgetID, void* editorData) { EditorData* data = (EditorData*)editorData; GUI_WidgetID widget = GUI_getParentWidget(gui, widgetID); const char* filename = GUI_getTextfield(gui, GUI_getChildWidget(gui, widget, 0)).text; strcpy(data->skeletonName, filename); const SkeletonSave* save = loadSkeleton(filename); if (save != 0) { data->bones.clear(); data->skeleton.clear(); data->constraints.clear(); data->names.clear(); const char* name = save->names; for (int i = 0; i < save->numBones; ++i) { Bone newBone; newBone.jointAngle = { 1, 0 }; newBone.jointPos = save->jointPos[i]; newBone.parentJoint = save->parentJoints[i]; newBone.name = data->names.push({ { 0 } }); memcpy(data->names[newBone.name].string, name, save->nameLen[i] * sizeof(char)); name += save->nameLen[i]; Constraint constraint; constraint.minAngle = -PI; constraint.maxAngle = 3 * PI; data->skeleton.push(newBone); data->constraints.push(constraint); } updateBones(data); } GUI_removeWidget(gui, widget); }; auto callbackCancel = [](GUI* gui, GUI_WidgetID widgetID, void*) { GUI_WidgetID widget = GUI_getParentWidget(gui, widgetID); GUI_removeWidget(gui, widget); }; GUI_addTextfield(data->gui, widget, { 0, 0, -1, -1 }, "filename"); GUI_addButton(data->gui, widget, { 0, 0, 50, -1 }, "Load", data, callbackLoad); GUI_addButton(data->gui, widget, { 0, 0, 50, -1 }, "Cancel", 0, callbackCancel); break; } data->lowEventStack.Push(event); } break; case SDL_SCANCODE_K: if (event.key.keysym.mod == KMOD_LCTRL) { SDL_Event lastEvent = data->lowEventStack.Top(); if (lastEvent.key.keysym.scancode == SDL_SCANCODE_S && lastEvent.key.keysym.mod == KMOD_LCTRL) { // save keyFrame GUI_WidgetID widget = GUI_addContainer(data->gui, GUI_MAIN_WIDGET, { 400 - 100, 300 - 15, 200, 30 }, GUI_Container::Orientation::HORIZONTAL); auto callbackSave = [](GUI* gui, GUI_WidgetID widgetID, void* editorData) { EditorData* data = (EditorData*)editorData; GUI_WidgetID widget = GUI_getParentWidget(gui, widgetID); const char* filename = GUI_getTextfield(gui, GUI_getChildWidget(gui, widget, 0)).text; saveKeyFrame(filename, &data->skeleton[0], &data->names[0], data->skeleton.size()); GUI_removeWidget(gui, widget); }; auto callbackCancel = [](GUI* gui, GUI_WidgetID widgetID, void*) { GUI_WidgetID widget = GUI_getParentWidget(gui, widgetID); GUI_removeWidget(gui, widget); }; GUI_addTextfield(data->gui, widget, { 0, 0, -1, -1 }, "filename"); GUI_addButton(data->gui, widget, { 0, 0, 50, -1 }, "Save", data, callbackSave); GUI_addButton(data->gui, widget, { 0, 0, 50, -1 }, "Cancel", 0, callbackCancel); break; } else if (lastEvent.key.keysym.scancode == SDL_SCANCODE_O && lastEvent.key.keysym.mod == KMOD_LCTRL) { // load keyframe GUI_WidgetID widget = GUI_addContainer(data->gui, GUI_MAIN_WIDGET, { 400 - 100, 300 - 15, 200, 30 }, GUI_Container::Orientation::HORIZONTAL); auto callbackLoad = [](GUI* gui, GUI_WidgetID widgetID, void* editorData) { EditorData* data = (EditorData*)editorData; GUI_WidgetID widget = GUI_getParentWidget(gui, widgetID); const char* filename = GUI_getTextfield(gui, GUI_getChildWidget(gui, widget, 0)).text; strcpy(data->frameName, filename); const KeyFrameSave* save = loadKeyFrame(filename); if (save != 0) { const char* name = save->names; for (int i = 0; i < save->numBones; ++i) { int nameID = -1; for (int j = 0; j < data->names.size(); ++j) { if (strncmp(name, data->names[j].string, save->nameLen[i]) == 0) { nameID = j; break; } } if (nameID != -1) { if (data->skeleton[nameID].name == nameID) { data->skeleton[nameID].jointAngle = save->jointAngles[i]; } else { for (int j = 0; j < data->skeleton.size(); j++) { if (data->skeleton[j].name = nameID) data->skeleton[j].jointAngle = save->jointAngles[i]; } } } name += save->nameLen[i]; } updateBones(data); } GUI_removeWidget(gui, widget); }; auto callbackCancel = [](GUI* gui, GUI_WidgetID widgetID, void*) { GUI_WidgetID widget = GUI_getParentWidget(gui, widgetID); GUI_removeWidget(gui, widget); }; GUI_addTextfield(data->gui, widget, { 0, 0, -1, -1 }, "filename"); GUI_addButton(data->gui, widget, { 0, 0, 50, -1 }, "Load", data, callbackLoad); GUI_addButton(data->gui, widget, { 0, 0, 50, -1 }, "Cancel", 0, callbackCancel); break; } data->lowEventStack.Push(event); } break; default: data->lowEventStack.Push(event); break; } break; } case SDL_MOUSEBUTTONDOWN: { data->newBone = -1; if (keyboardState[SDL_SCANCODE_A]) { for (int i = 0; i < data->bones.size(); ++i) { if (pointInRect(mousePos, data->bones[i].rect)) { int name = data->names.push({ "test" }); Bone newBone; newBone.jointAngle = { 1, 0 }; newBone.jointPos = { 0, 0 }; newBone.parentJoint = i; newBone.name = name; Constraint constraint; constraint.minAngle = -PI; constraint.maxAngle = 3 * PI; int newBoneID = data->skeleton.push(newBone); data->constraints.push(constraint); int* ids = new int[data->skeleton.size()]; sortSkeleton(&data->skeleton[0], data->skeleton.size(), ids); Constraint* tempConstraints = new Constraint[data->constraints.size()]; memcpy(tempConstraints, &data->constraints[0], sizeof(Constraint) * data->constraints.size()); for (int i = 0; i < data->constraints.size(); ++i) { data->constraints[i] = tempConstraints[ids[i]]; } delete[] tempConstraints; //find bone again data->newBone = ids[newBoneID]; // rebuild bone selection updateBones(data); delete[]ids; break; } } } else if (keyboardState[SDL_SCANCODE_N]) { for (int i = 0; i < data->bones.size(); ++i) { if (pointInRect(mousePos, data->bones[i].rect)) { int2 pos = pointToPixel(&data->view, float2{ data->bones[i].rect.x + 10, data->bones[i].rect.y }); GUI_WidgetID widget = GUI_addContainer(data->gui, GUI_MAIN_WIDGET, intRect{ pos.x, pos.y, 100, 30 }, GUI_Container::HORIZONTAL); struct Args { EditorData* data; int boneId; }*args = new Args{ data, i }; auto callbackOk = [](GUI* gui, GUI_WidgetID widgetID, void* args) { EditorData* data = ((Args*)args)->data; int boneID = ((Args*)args)->boneId; GUI_WidgetID parentID = GUI_getParentWidget(gui, widgetID); const char* newName = GUI_getTextfield(gui, GUI_getChildWidget(gui, parentID, 0)).text; strcpy(data->names[data->skeleton[boneID].name].string, newName); GUI_removeWidget(gui, parentID); delete args; }; GUI_addTextfield(data->gui, widget, intRect{ 0, 0, -1, -1 }, data->names[data->skeleton[i].name].string); GUI_addButton(data->gui, widget, intRect{ 0, 0, 30, -1 }, "OK", args, callbackOk); break; } } } else { for (int i = 0; i < data->bones.size(); i++) { if (pointInRect(mousePos, data->bones[i].rect)) { data->selectedBones.push(i); data->grabbedBone = i; } } if (data->grabbedBone == -1 && !keyboardState[SDL_SCANCODE_LCTRL]) data->selectedBones.clear(); } break; } case SDL_MOUSEBUTTONUP: { data->grabbedBone = -1; break; } case SDL_MOUSEMOTION: { if (SDL_GetMouseState(0, 0) == SDL_BUTTON_MIDDLE) { data->view.position.x -= (event.motion.xrel / data->view.scale.x); data->view.position.y -= (event.motion.yrel / data->view.scale.y); } else { float2 motion = rotate({ (float)event.motion.xrel, (float)event.motion.yrel }, data->view.angle) * float2{ 1 / data->view.scale.x, 1 / data->view.scale.y }; if (data->newBone != -1) { float2 angle = getBoneWorldTransform(&data->skeleton[0], data->skeleton.size(), data->newBone).angle; float2 rel = rotate(float2{ motion.x, motion.y }, negateRotation(angle)); data->skeleton[data->newBone].jointPos += rel; } if (data->grabbedBone != -1) { if (keyboardState[SDL_SCANCODE_LCTRL]) { float2 angle = getBoneWorldTransform(&data->skeleton[0], data->skeleton.size(), data->skeleton[data->grabbedBone].parentJoint).angle; float2 rel = rotate(float2{ motion.x, motion.y }, negateRotation(angle)); data->skeleton[data->grabbedBone].jointPos += rel; } else { animateCCDIKSelection(&data->skeleton[0], &data->constraints[0], data->skeleton.size(), &data->selectedBones[0], data->selectedBones.size(), data->grabbedBone, mousePos - float2{ 400, 300 }); } } } break; } case SDL_MOUSEWHEEL: { data->view.scale.x += event.wheel.y*0.1f; data->view.scale.y += event.wheel.y*0.1f; break; } } }
/* Determine whether the given point is inside the threshold marker */ static gboolean pointInThresholdMarker(GreyrampProperties *properties, const int x, const int y) { GdkRectangle markerRect; getThresholdMarkerRect(properties, &markerRect); return pointInRect(x, y, &markerRect); }
void ScrollableContainer::onEvent(GuiEvent & evt) { if(evt.type == MOUSE_EVENT) { int mX = evt.mouse.x - getX(); int mY = evt.mouse.y - getY(); if(evt.mouse.type == CLICK) { if(mX <= childArea.w && mY <= childArea.h) { for(it = widgets.begin();it != widgets.end();++it) { if((*it)->isActive()) { evt.mouse.x -= getX(); evt.mouse.y -= getY(); if((*it)->isPointInside(evt.mouse.x,evt.mouse.y)) { (*it)->onEvent(evt); } evt.mouse.x += getX(); evt.mouse.y += getY(); } } } } if(hScroll || vScroll) { if(evt.mouse.type == BUTTON_DOWN) { if(hScroll && pointInRect(mX,mY,hScrollRect)) { vDrag = false; hDrag = true; prevMx = mX; prevMy = mY; } if(vScroll && pointInRect(mX,mY,vScrollRect)) { vDrag = true; hDrag = false; prevMx = mX; prevMy = mY; } } if(evt.mouse.type == MOUSE_MOVE) { if(vDrag) { int am = mY - prevMy; if(am < 0) { if(vScrollRect.y + am < 0) am = -vScrollRect.y; } else if(am > 0) { if(vScrollRect.y + vScrollRect.h + am > childArea.h) am = childArea.h - vScrollRect.h - vScrollRect.y; } int chAm = am * -1.0 * vCoef; vScrollRect.y += am; moveAllChildren(0,chAm); } if(hDrag) { int am = mX - prevMx; if(am < 0) { if(hScrollRect.x + am < 0) am = -hScrollRect.x; } else if(am > 0) { if(hScrollRect.x + hScrollRect.w + am > childArea.w) am = childArea.w - hScrollRect.w - hScrollRect.x; } int chAm = am * -1.0 * hCoef; hScrollRect.x += am; moveAllChildren(chAm,0); } prevMx = mX; prevMy = mY; } if(evt.mouse.type == BUTTON_UP) { vDrag = false; hDrag = false; } } } }
bool Widget::hit(int x, int y) { return pointInRect(rect, x, y); }
void four_bar(){ //for debugging float boost = 0; float oilT = 0; float T1 = 0; float T2 = 0; bmp_draw("fourbar",0,0); while (!(touch_get_cursor(&m_point))){ //get Boost, OilT, T1, and T2 boost++; oilT++; T1++; T2++; if (boost >= maxBoost){boost = 0;} if (oilT >= maxOilT){oilT = 0;} if (T1 >= maxT1){T1 = 0;} if (T2 >= maxT1){T2 = 0;} COLOR conditionColor = mwhite; //draw rectangles inside rectangles //only 86 ticks on a bar //lcd_clear (x, y, x1, y2, fill); //draws a solid rect fill with no border //bst rect = (39, 13) to (125, 33) if (boost >= severeBoost){conditionColor = fadedRed;} else if (boost >= warnBoost){conditionColor = fadedYellow;} else {conditionColor = fadedGreen;} lcd_rectangle(39,13,(int(39.0+(boost * 86.0/maxBoost))),33,conditionColor,conditionColor); lcd_rectangle(int((39.0+(boost * 86.0/(float)maxBoost))),13,125,33,mblack,mblack); //blacken the rest //oilt rect = (39, 38) to (125, 58) if (oilT >= severeOilT){conditionColor = fadedRed;} else if (oilT >= warnOilT){conditionColor = fadedYellow;} else {conditionColor = fadedGreen;} lcd_rectangle(39,38,(39+(oilT * 86/maxOilT)),58,conditionColor,conditionColor); lcd_rectangle((39+(oilT * 86/maxOilT)),38,125,58,mblack,mblack); //t1 rect = (39, 64) to (125, 84) if (T1 >= severeT1){conditionColor = fadedRed;} else if (T1 >= warnT1){conditionColor = fadedYellow;} else {conditionColor = fadedGreen;} lcd_rectangle(39,64,(39+(T1 * 86/maxT1)),84,conditionColor,conditionColor); lcd_rectangle((39+(T1 * 86/maxT1)),64,125,84,mblack,mblack); //T2 rect = (39, 90) to (125, 110) if (T2 >= severeT2){conditionColor = fadedRed;} else if (T2 >= warnT2){conditionColor = fadedYellow;} else {conditionColor = fadedGreen;} lcd_rectangle(39,90,(39+(T2 * 86/maxT2)),110,conditionColor,conditionColor); lcd_rectangle((39+(T2 * 86/maxT2)),90,125,110,mblack,mblack); //print values on top of bars in white char out[7]; fmtDouble(boost, 2, out, 7); lcd_puts(out, 95, 18, lightBlue, mblack); fmtDouble(oilT, 2, out, 7); lcd_puts(out, 95, 43, lightBlue, mblack); fmtDouble(T1, 2, out, 7); lcd_puts(out, 95, 69, lightBlue, mblack); fmtDouble(T2, 2, out, 7); lcd_puts(out, 95, 93, lightBlue, mblack); delay (100); //bmp_draw("fourbar",0,0); } //when a touch is detected get coords //go to mode of what is touched if it is boost or oilT //otherwise go to next display while (touch_get_cursor(&m_point)){ //debounce hold LCD_RECT boostRect; boostRect.left = 0; boostRect.right = 128; boostRect.top = 11; boostRect.bottom = 34; LCD_RECT oilRect; oilRect.left = 0; oilRect.right = 128; oilRect.top = 36; oilRect.bottom = 59; if (pointInRect(m_point,boostRect)){boost_gauge();} if (pointInRect(m_point,oilRect)){oil_temp_gauge();} } xygraph(); //click anywhere else and it goes to xygraph }