Пример #1
0
void OBSBasicPreview::GetStretchHandleData(const vec2 &pos)
{
	OBSBasic *main = reinterpret_cast<OBSBasic*>(App()->GetMainWindow());

	OBSScene scene = main->GetCurrentScene();
	if (!scene)
		return;

	HandleFindData data(pos, main->previewScale);
	obs_scene_enum_items(scene, FindHandleAtPos, &data);

	stretchItem     = std::move(data.item);
	stretchHandle   = data.handle;

	if (stretchHandle != ItemHandle::None) {
		matrix4 boxTransform;
		vec3    itemUL;
		float   itemRot;

		stretchItemSize = GetItemSize(stretchItem);

		obs_sceneitem_get_box_transform(stretchItem, &boxTransform);
		itemRot = obs_sceneitem_getrot(stretchItem);
		vec3_from_vec4(&itemUL, &boxTransform.t);

		/* build the item space conversion matrices */
		matrix4_identity(&itemToScreen);
		matrix4_rotate_aa4f(&itemToScreen, &itemToScreen,
				0.0f, 0.0f, 1.0f, RAD(itemRot));
		matrix4_translate3f(&itemToScreen, &itemToScreen,
				itemUL.x, itemUL.y, 0.0f);

		matrix4_identity(&screenToItem);
		matrix4_translate3f(&screenToItem, &screenToItem,
				-itemUL.x, -itemUL.y, 0.0f);
		matrix4_rotate_aa4f(&screenToItem, &screenToItem,
				0.0f, 0.0f, 1.0f, RAD(-itemRot));
	}
}
Пример #2
0
static void update_item_transform(struct obs_scene_item *item)
{
	uint32_t        width         = obs_source_get_width(item->source);
	uint32_t        height        = obs_source_get_height(item->source);
	uint32_t        cx            = calc_cx(item, width);
	uint32_t        cy            = calc_cy(item, height);
	struct vec2     base_origin;
	struct vec2     origin;
	struct vec2     scale         = item->scale;
	struct calldata params;
	uint8_t         stack[128];

	if (os_atomic_load_long(&item->defer_update) > 0)
		return;

	width = cx;
	height = cy;

	vec2_zero(&base_origin);
	vec2_zero(&origin);

	/* ----------------------- */

	if (item->bounds_type != OBS_BOUNDS_NONE) {
		calculate_bounds_data(item, &origin, &scale, &cx, &cy);
	} else {
		cx = (uint32_t)((float)cx * scale.x);
		cy = (uint32_t)((float)cy * scale.y);
	}

	add_alignment(&origin, item->align, (int)cx, (int)cy);

	matrix4_identity(&item->draw_transform);
	matrix4_scale3f(&item->draw_transform, &item->draw_transform,
			scale.x, scale.y, 1.0f);
	matrix4_translate3f(&item->draw_transform, &item->draw_transform,
			-origin.x, -origin.y, 0.0f);
	matrix4_rotate_aa4f(&item->draw_transform, &item->draw_transform,
			0.0f, 0.0f, 1.0f, RAD(item->rot));
	matrix4_translate3f(&item->draw_transform, &item->draw_transform,
			item->pos.x, item->pos.y, 0.0f);

	item->output_scale = scale;

	/* ----------------------- */

	if (item->bounds_type != OBS_BOUNDS_NONE) {
		vec2_copy(&scale, &item->bounds);
	} else {
		scale.x = (float)width  * item->scale.x;
		scale.y = (float)height * item->scale.y;
	}

	add_alignment(&base_origin, item->align, (int)scale.x, (int)scale.y);

	matrix4_identity(&item->box_transform);
	matrix4_scale3f(&item->box_transform, &item->box_transform,
			scale.x, scale.y, 1.0f);
	matrix4_translate3f(&item->box_transform, &item->box_transform,
			-base_origin.x, -base_origin.y, 0.0f);
	matrix4_rotate_aa4f(&item->box_transform, &item->box_transform,
			0.0f, 0.0f, 1.0f, RAD(item->rot));
	matrix4_translate3f(&item->box_transform, &item->box_transform,
			item->pos.x, item->pos.y, 0.0f);

	/* ----------------------- */

	item->last_width  = width;
	item->last_height = height;

	calldata_init_fixed(&params, stack, sizeof(stack));
	calldata_set_ptr(&params, "scene", item->parent);
	calldata_set_ptr(&params, "item", item);
	signal_handler_signal(item->parent->source->context.signals,
			"item_transform", &params);
}
Пример #3
0
static void recalculate_transition_matrix(obs_source_t *tr, size_t idx)
{
    obs_source_t *child;
    struct matrix4 mat;
    struct vec2 pos;
    struct vec2 scale;
    float tr_cx = (float)tr->transition_actual_cx;
    float tr_cy = (float)tr->transition_actual_cy;
    float source_cx;
    float source_cy;
    float tr_aspect = tr_cx / tr_cy;
    float source_aspect;
    enum obs_transition_scale_type scale_type = tr->transition_scale_type;

    lock_transition(tr);

    child = tr->transition_sources[idx];
    if (!child) {
        unlock_transition(tr);
        return;
    }

    source_cx = (float)obs_source_get_width(child);
    source_cy = (float)obs_source_get_height(child);
    unlock_transition(tr);

    if (source_cx == 0.0f || source_cy == 0.0f)
        return;

    source_aspect = source_cx / source_cy;

    if (scale_type == OBS_TRANSITION_SCALE_MAX_ONLY) {
        if (source_cx > tr_cx || source_cy > tr_cy) {
            scale_type = OBS_TRANSITION_SCALE_ASPECT;
        } else {
            scale.x = 1.0f;
            scale.y = 1.0f;
        }
    }

    if (scale_type == OBS_TRANSITION_SCALE_ASPECT) {
        bool use_width = tr_aspect < source_aspect;
        scale.x = scale.y = use_width ?
                            tr_cx / source_cx :
                            tr_cy / source_cy;

    } else if (scale_type == OBS_TRANSITION_SCALE_STRETCH) {
        scale.x = tr_cx / source_cx;
        scale.y = tr_cy / source_cy;
    }

    source_cx *= scale.x;
    source_cy *= scale.y;

    vec2_zero(&pos);
    add_alignment(&pos, tr->transition_alignment,
                  (int)(tr_cx - source_cx),
                  (int)(tr_cy - source_cy));

    matrix4_identity(&mat);
    matrix4_scale3f(&mat, &mat, scale.x, scale.y, 1.0f);
    matrix4_translate3f(&mat, &mat, pos.x, pos.y, 0.0f);
    matrix4_copy(&tr->transition_matrices[idx], &mat);
}