Skip to content

Commit

Permalink
UI: Fix 0,0 size transform bug when resizing sources
Browse files Browse the repository at this point in the history
Fix a bug where if a source's width or height becomes 0 while you're
stretching the size of a source or modifying it from the transform
dialog, it would become permanently invisible

Closes #7962
  • Loading branch information
jp9000 committed May 20, 2023
1 parent 38e5411 commit fcfc2eb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
12 changes: 10 additions & 2 deletions UI/window-basic-preview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1492,9 +1492,17 @@ void OBSBasicPreview::StretchItem(const vec2 &pos)

obs_source_t *source = obs_sceneitem_get_source(stretchItem);

uint32_t source_cx = obs_source_get_width(source);
uint32_t source_cy = obs_source_get_height(source);

/* if the source's internal size has been set to 0 for whatever reason
* while resizing, do not update transform, otherwise source will be
* stuck invisible until a complete transform reset */
if (!source_cx || !source_cy)
return;

vec2 baseSize;
vec2_set(&baseSize, float(obs_source_get_width(source)),
float(obs_source_get_height(source)));
vec2_set(&baseSize, float(source_cx), float(source_cy));

vec2 size;
vec2_set(&size, br.x - tl.x, br.y - tl.y);
Expand Down
26 changes: 20 additions & 6 deletions UI/window-basic-transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,10 @@ void OBSBasicTransform::RefreshControls()
obs_sceneitem_get_crop(item, &crop);

obs_source_t *source = obs_sceneitem_get_source(item);
float width = float(obs_source_get_width(source));
float height = float(obs_source_get_height(source));
uint32_t source_cx = obs_source_get_width(source);
uint32_t source_cy = obs_source_get_height(source);
float width = float(source_cx);
float height = float(source_cy);

int alignIndex = AlignToList(osi.alignment);
int boundsAlignIndex = AlignToList(osi.bounds_alignment);
Expand All @@ -260,6 +262,10 @@ void OBSBasicTransform::RefreshControls()
ui->sizeY->setValue(osi.scale.y * height);
ui->align->setCurrentIndex(alignIndex);

bool valid_size = source_cx != 0 && source_cy != 0;
ui->sizeX->setEnabled(valid_size);
ui->sizeY->setEnabled(valid_size);

ui->boundsType->setCurrentIndex(int(osi.bounds_type));
ui->boundsAlign->setCurrentIndex(boundsAlignIndex);
ui->boundsWidth->setValue(osi.bounds.x);
Expand Down Expand Up @@ -308,15 +314,23 @@ void OBSBasicTransform::OnControlChanged()
return;

obs_source_t *source = obs_sceneitem_get_source(item);
double width = double(obs_source_get_width(source));
double height = double(obs_source_get_height(source));
uint32_t source_cx = obs_source_get_width(source);
uint32_t source_cy = obs_source_get_height(source);
double width = double(source_cx);
double height = double(source_cy);

obs_transform_info oti;
obs_sceneitem_get_info(item, &oti);

/* do not scale a source if it has 0 width/height */
if (source_cx != 0 && source_cy != 0) {
oti.scale.x = float(ui->sizeX->value() / width);
oti.scale.y = float(ui->sizeY->value() / height);
}

oti.pos.x = float(ui->positionX->value());
oti.pos.y = float(ui->positionY->value());
oti.rot = float(ui->rotation->value());
oti.scale.x = float(ui->sizeX->value() / width);
oti.scale.y = float(ui->sizeY->value() / height);
oti.alignment = listToAlign[ui->align->currentIndex()];

oti.bounds_type = (obs_bounds_type)ui->boundsType->currentIndex();
Expand Down

0 comments on commit fcfc2eb

Please sign in to comment.