bool topLeftResizeCallback( Widget* widget, const Event* e ) { if( Widget_mouseOver( widget, &e->v ) ) { if( e->type == EMousePressed ) { widget->mouseOffset = vec2i_sub( &widget->position, &e->v ); widget->pressed = true; } } if( widget->pressed && widget->mouseOffset.x != 1 ) { vec2i topleft = vec2i_add( &e->v, &widget->mouseOffset ); topleft.x += 5; topleft.y += 23; vec2i bottomright = vec2i_add( &widget->parent->parent->children[WO_Window]->position, &widget->parent->parent->children[WO_Window]->size ); vec2i size = vec2i_sub( &bottomright, &topleft ); Window_resizeLeft( widget->parent->parent->children[WO_Window], size.x ); Window_resizeUp( widget->parent->parent->children[WO_Window], size.y ); if( e->type == EMouseReleased ) widget->pressed = false; return true; } else { widget->mouseOffset = vec2i_c( 1, 1 ); return false; } }
bool moveWindowCallback( Widget* widget, const Event* e ) { if( e->type == EMousePressed ) { if( Widget_mouseOver( widget, &e->v ) ) { widget->mouseOffset = vec2i_sub( &widget->position, &e->v ); widget->pressed = true; } } if( widget->pressed && widget->mouseOffset.x != -1 ) { vec2i pos = vec2i_add( &e->v, &widget->mouseOffset ); Widget_setPosition( widget, &pos ); vec2i win = pos; win.y += 18; Widget_setPosition( widget->children[WO_Window], &win ); vec2i out = pos; out.x -= 5; out.y -= 5; Widget_setPosition( widget->children[WO_Outline], &out ); if( e->type == EMouseReleased ) widget->pressed = false; return true; } else { widget->mouseOffset = vec2i_c( -1, -1 ); return false; } }
void Widget_setPosition( Widget* widget, vec2i* pos ) { vec2i originalPos = widget->position; // TODO FIX widget->position = *pos; widget->moved = true; if( widget->confined ) { if( pos->x < widget->parent->position.x ) widget->position.x = widget->parent->position.x; if( pos->y < widget->parent->position.y ) widget->position.y = widget->parent->position.y; if( pos->x + widget->size.x > widget->parent->position.x + widget->parent->size.x ) widget->position.x = widget->parent->position.x + widget->parent->size.x - widget->size.x; if( pos->y + widget->size.y > widget->parent->position.y + widget->parent->size.y ) widget->position.y = widget->parent->position.y + widget->parent->size.y - widget->size.y; } vec2i offSet = vec2i_sub( pos, &originalPos ); for( u32 i = 0; i < widget->childrenCount; ++i ) { if( widget->children[i]->confined ){ vec2i newPos = vec2i_add( &widget->children[i]->position, &offSet ); Widget_setPosition( widget->children[i], &newPos ); } } }
int ai_block_projectile(controller *ctrl, ctrl_event **ev) { ai *a = ctrl->data; object *o = ctrl->har; iterator it; object **o_tmp; vector_iter_begin(&a->active_projectiles, &it); while((o_tmp = iter_next(&it)) != NULL) { object *o_prj = *o_tmp; if(projectile_get_owner(o_prj) == o) { continue; } if(o_prj->cur_sprite && maybe(a->difficulty)) { vec2i pos_prj = vec2i_add(object_get_pos(o_prj), o_prj->cur_sprite->pos); vec2i size_prj = object_get_size(o_prj); if (object_get_direction(o_prj) == OBJECT_FACE_LEFT) { pos_prj.x = object_get_pos(o_prj).x + ((o_prj->cur_sprite->pos.x * -1) - size_prj.x); } if(fabsf(pos_prj.x - o->pos.x) < 120) { a->cur_act = (o->direction == OBJECT_FACE_RIGHT ? ACT_DOWN|ACT_LEFT : ACT_DOWN|ACT_RIGHT); controller_cmd(ctrl, a->cur_act, ev); return 1; } } } return 0; }
void cb_vs_spawn_object(object *parent, int id, vec2i pos, int g, void *userdata) { scene *s = (scene*)userdata; // Get next animation bk_info *info = bk_get_info(&s->bk_data, id); if(info != NULL) { object *obj = malloc(sizeof(object)); object_create(obj, parent->gs, vec2i_add(pos, vec2f_to_i(parent->pos)), vec2f_create(0,0)); object_set_stl(obj, object_get_stl(parent)); object_set_animation(obj, &info->ani); object_set_spawn_cb(obj, cb_vs_spawn_object, userdata); object_set_destroy_cb(obj, cb_vs_destroy_object, userdata); game_state_add_object(parent->gs, obj, RENDER_LAYER_MIDDLE, 0, 0); } }
Vector2D Vector2D::__add__(const Vector2D& v1) { Vector2D r; vec2i_add(&r.v_, &v_, &v1.v_); return r; }
Widget* Widget_createWindowHead( Widget* window, u32 name ) { Widget* head = Widget_init( WT_WindowHead, &(vec2i){ window->size.x, 17 }, "quadmesh.json", "widgettexture.png", name ); Widget* icon = Widget_init( WT_Sprite, &(vec2i){ 11, 11 }, "quadmesh.json", "winicon.png", -1 ); Widget* cross = Widget_init( WT_Button, &(vec2i){ 11, 11 }, "quadmesh.json", "cross.png", -1 ); // The window contour is composed of 9 rectangles the main one, the ones on the side and the ones in the corners. Widget* windowOutline = Widget_init( WT_Button, &(vec2i){ window->size.x + 10, window->size.y + head->size.y + 11 }, "quadmesh.json", "widgetcontour.png", -1 ); // Corners of the contour Widget* windowCornerTopLeft = Widget_init( WT_Button, &(vec2i){ 5, 5 }, "quadmesh.json", "right.png", -1 ); Widget* windowCornerTopRight = Widget_init( WT_Button, &(vec2i){ 5, 5 }, "quadmesh.json", "bottom.png", -1 ); Widget* windowCornerBottomLeft = Widget_init( WT_Button, &(vec2i){ 5, 5 }, "quadmesh.json", "top.png", -1 ); Widget* windowCornerBottomRight = Widget_init( WT_Button, &(vec2i){ 5, 5 }, "quadmesh.json", "left.png", -1 ); // Sides of the contour Widget* windowSideTop = Widget_init( WT_Button, &(vec2i){ window->size.x, 5 }, "quadmesh.json", "top.png", -1 ); Widget* windowSideLeft = Widget_init( WT_Button, &(vec2i){ 5, window->size.y + head->size.y + 1}, "quadmesh.json", "left.png", -1 ); Widget* windowSideRight = Widget_init( WT_Button, &(vec2i){ 5, window->size.y + head->size.y + 1 }, "quadmesh.json", "right.png", -1 ); Widget* windowSideBottom = Widget_init( WT_Button, &(vec2i){ window->size.x, 5 }, "quadmesh.json", "bottom.png", -1 ); head->position.x = window->position.x; head->position.y = window->position.y - 18; head->depth = window->depth; head->textOffset = vec2i_c( 18, 1 ); head->callback = &moveWindowCallback; vec2i windowExtents = vec2i_add( &window->position, &window->size ); windowOutline->position.x = head->position.x - 5; windowOutline->position.y = head->position.y - 5; windowOutline->depth = window->depth + 1; windowCornerTopLeft->position.x = head->position.x - 5; windowCornerTopLeft->position.y = head->position.y - 5; windowCornerTopLeft->depth = windowOutline->depth - 1; windowCornerTopLeft->callback = &topLeftResizeCallback; windowCornerTopRight->position.x = windowExtents.x; windowCornerTopRight->position.y = head->position.y - 5; windowCornerTopRight->depth = windowOutline->depth - 1; windowCornerTopRight->callback = &topRightResizeCallback; windowCornerBottomLeft->position.x = window->position.x - 5; windowCornerBottomLeft->position.y = windowExtents.y; windowCornerBottomLeft->depth = windowOutline->depth - 1; windowCornerBottomLeft->callback = &bottomLeftResizeCallback; windowCornerBottomRight->position.x = windowExtents.x; windowCornerBottomRight->position.y = windowExtents.y; windowCornerBottomRight->depth = windowOutline->depth - 1; windowCornerBottomRight->callback = &bottomRightResizeCallback; windowSideTop->position.x = window->position.x; windowSideTop->position.y = head->position.y - 5; windowSideTop->depth = windowOutline->depth - 1; windowSideTop->callback = &topResizeCallback; windowSideLeft->position.x = window->position.x - 5; windowSideLeft->position.y = head->position.y; windowSideLeft->depth = windowOutline->depth - 1; windowSideLeft->callback = &leftResizeCallback; windowSideRight->position.x = windowExtents.x; windowSideRight->position.y = head->position.y; windowSideRight->depth = windowOutline->depth - 1; windowSideRight->callback = &rightResizeCallback; windowSideBottom->position.x = window->position.x; windowSideBottom->position.y = windowExtents.y; windowSideBottom->depth = windowOutline->depth - 1; windowSideBottom->callback = &bottomResizeCallback; Widget_addChild( head, window, false, WA_None ); Widget_addChild( head, windowOutline, false, WA_None ); Widget_addChild( windowOutline, windowSideTop, true, WA_None ); Widget_addChild( windowOutline, windowSideLeft, true, WA_None ); Widget_addChild( windowOutline, windowSideRight, true, WA_None ); Widget_addChild( windowOutline, windowSideBottom, true, WA_None ); Widget_addChild( windowOutline, windowCornerTopLeft, true, WA_None ); Widget_addChild( windowOutline, windowCornerTopRight, true, WA_None ); Widget_addChild( windowOutline, windowCornerBottomLeft, true, WA_None ); Widget_addChild( windowOutline, windowCornerBottomRight, true, WA_None ); vec2i iconOffset = vec2i_c( 3, 3 ); icon->position = vec2i_add( &iconOffset, &head->position ); icon->depth = window->depth - 1; vec2i crossOffset = vec2i_c( window->size.x - 13, 3 ); cross->position = vec2i_add( &crossOffset, &head->position ); cross->depth = window->depth - 1; cross->callback = &windowCloseButtonCallback; Widget_addChild( head, icon, true, WA_None ); Widget_addChild( head, cross, true, WA_None ); return head; }
bool Widget_mouseOver( const Widget* widget, const vec2i* mouse ) { vec2i extents = vec2i_add( &widget->position, &widget->size ); if( mouse->x < widget->position.x || mouse->x > extents.x || mouse->y < widget->position.y || mouse->y > extents.y ) return false; return true; }