Skip to content

Commit ae6818a

Browse files
author
larspalo
committed
Changed image/mask on and off handling to not depend on wrong things and behave correctly when any of them are removed.
1 parent 7b75f57 commit ae6818a

File tree

1 file changed

+42
-38
lines changed

1 file changed

+42
-38
lines changed

src/GUIButtonPanel.cpp

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -757,27 +757,22 @@ void GUIButtonPanel::setButton(GUIButton *button) {
757757
if (m_button->getImageOn() != wxEmptyString) {
758758
wxString relativeImageOn = GOODF_functions::removeBaseOdfPath(m_button->getImageOn());
759759
m_imageOnPathField->SetValue(relativeImageOn);
760-
m_addImageOffBtn->Enable();
761760
} else {
762761
m_imageOnPathField->SetValue(wxEmptyString);
763-
m_addImageOffBtn->Disable();
764762
m_addMaskOnBtn->Disable();
765-
m_addMaskOffBtn->Disable();
766763
}
767764
if (m_button->getImageOff() != wxEmptyString) {
768765
wxString relativeImageOff = GOODF_functions::removeBaseOdfPath(m_button->getImageOff());
769766
m_imageOffPathField->SetValue(relativeImageOff);
770767
} else {
771768
m_imageOffPathField->SetValue(wxEmptyString);
772-
m_addMaskOnBtn->Disable();
773769
m_addMaskOffBtn->Disable();
774770
}
775771
if (m_button->getMaskOn() != wxEmptyString) {
776772
wxString relativeMaskOn = GOODF_functions::removeBaseOdfPath(m_button->getMaskOn());
777773
m_maskOnPathField->SetValue(relativeMaskOn);
778774
} else {
779775
m_maskOnPathField->SetValue(wxEmptyString);
780-
m_addMaskOffBtn->Disable();
781776
}
782777
if (m_button->getMaskOff() != wxEmptyString) {
783778
wxString relativeMaskOff = GOODF_functions::removeBaseOdfPath(m_button->getMaskOff());
@@ -926,44 +921,56 @@ void GUIButtonPanel::OnAddImageOnBtn(wxCommandEvent& WXUNUSED(event)) {
926921
if (path != wxEmptyString) {
927922
wxImage img = wxImage(path);
928923
if (img.IsOk()) {
929-
m_button->setImageOn(path);
930924
int width = img.GetWidth();
931925
int height = img.GetHeight();
932-
m_button->setBitmapWidth(width);
933-
m_button->setBitmapHeight(height);
934-
m_button->setWidth(width);
935-
m_button->setHeight(height);
936-
m_button->setMouseRectWidth(width - m_button->getMouseRectLeft());
937-
m_button->setMouseRectHeight(height - m_button->getMouseRectTop());
938-
m_button->setMouseRadius(std::min(width, height) / 2);
939-
m_button->setTextRectWidth(width - m_button->getTextRectLeft());
940-
m_button->setTextRectHeight(height - m_button->getTextRectTop());
941-
m_button->setTextBreakWidth(m_button->getTextRectWidth() - (m_button->getTextRectWidth() < 50 ? 4 : 14));
942-
UpdateSpinRanges();
943-
UpdateDefaultSpinValues();
944-
wxString relativePath = GOODF_functions::removeBaseOdfPath(m_button->getImageOn());
945-
m_imageOnPathField->SetValue(relativePath);
946-
m_addImageOffBtn->Enable();
926+
if (m_button->getImageOff() == wxEmptyString || (width == m_button->getBitmapWidth() && height == m_button->getBitmapHeight())) {
927+
m_button->setImageOn(path);
928+
m_button->setBitmapWidth(width);
929+
m_button->setBitmapHeight(height);
930+
m_button->setWidth(width);
931+
m_button->setHeight(height);
932+
m_button->setMouseRectWidth(width - m_button->getMouseRectLeft());
933+
m_button->setMouseRectHeight(height - m_button->getMouseRectTop());
934+
m_button->setMouseRadius(std::min(width, height) / 2);
935+
m_button->setTextRectWidth(width - m_button->getTextRectLeft());
936+
m_button->setTextRectHeight(height - m_button->getTextRectTop());
937+
m_button->setTextBreakWidth(m_button->getTextRectWidth() - (m_button->getTextRectWidth() < 50 ? 4 : 14));
938+
UpdateSpinRanges();
939+
UpdateDefaultSpinValues();
940+
wxString relativePath = GOODF_functions::removeBaseOdfPath(m_button->getImageOn());
941+
m_imageOnPathField->SetValue(relativePath);
942+
m_addMaskOnBtn->Enable();
943+
} else {
944+
wxMessageDialog msg(this, wxT("Image on bitmap size doesn't match existing bitmap!"), wxT("Wrong bitmap size"), wxOK|wxCENTRE|wxICON_ERROR);
945+
msg.ShowModal();
946+
}
947947
}
948948
} else {
949949
// the user has clicked cancel which returns an empty string
950950
if (m_button->getImageOn() != wxEmptyString) {
951-
wxMessageDialog msg(this, wxT("Image on value is not empty! Do you want to empty it?"), wxT("Empty image on value?"), wxYES_NO|wxCENTRE|wxICON_EXCLAMATION);
951+
wxMessageDialog msg(this, wxT("Image on value is not empty! Do you want to empty it? (Also removes mask on if set, may remove image/mask off if set and they won't match default values)"), wxT("Empty image on value?"), wxYES_NO|wxCENTRE|wxICON_EXCLAMATION);
952952
if (msg.ShowModal() == wxID_YES) {
953953
// then we empty the value in button and panel
954954
m_button->setImageOn(wxEmptyString);
955+
m_button->setMaskOn(wxEmptyString);
955956
m_button->updateBuiltinBitmapValues();
956957
UpdateSpinRanges();
957958
UpdateDefaultSpinValues();
958959
m_imageOnPathField->SetValue(wxEmptyString);
959-
m_addImageOffBtn->Disable();
960+
m_maskOnPathField->SetValue(wxEmptyString);
960961
m_addMaskOnBtn->Disable();
961-
m_addMaskOffBtn->Disable();
962+
if (m_button->getImageOff() != wxEmptyString) {
963+
// the off bitmap must be evaluated to whether it may stay or not
964+
wxImage offImg = wxImage(m_button->getImageOff());
965+
if (!offImg.IsOk() || offImg.GetWidth() != m_button->getBitmapWidth() || offImg.GetHeight() != m_button->getBitmapHeight()) {
966+
m_button->setImageOff(wxEmptyString);
967+
m_button->setMaskOff(wxEmptyString);
968+
m_imageOffPathField->SetValue(wxEmptyString);
969+
m_maskOffPathField->SetValue(wxEmptyString);
970+
m_addMaskOffBtn->Disable();
971+
}
972+
}
962973
}
963-
} else {
964-
m_addImageOffBtn->Disable();
965-
m_addMaskOnBtn->Disable();
966-
m_addMaskOffBtn->Disable();
967974
}
968975
}
969976
}
@@ -979,25 +986,26 @@ void GUIButtonPanel::OnAddImageOffBtn(wxCommandEvent& WXUNUSED(event)) {
979986
m_button->setImageOff(path);
980987
wxString relativePath = GOODF_functions::removeBaseOdfPath(m_button->getImageOff());
981988
m_imageOffPathField->SetValue(relativePath);
982-
m_addMaskOnBtn->Enable();
989+
m_addMaskOffBtn->Enable();
983990
::wxGetApp().m_frame->PanelGUIPropertyIsChanged();
991+
} else {
992+
wxMessageDialog msg(this, wxT("Image off bitmap size must match on bitmap!"), wxT("Wrong bitmap size"), wxOK|wxCENTRE|wxICON_ERROR);
993+
msg.ShowModal();
984994
}
985995
}
986996
} else {
987997
// the user has clicked cancel which returns an empty string
988998
if (m_button->getImageOff() != wxEmptyString) {
989-
wxMessageDialog msg(this, wxT("Image off value is not empty! Do you want to empty it?"), wxT("Empty image off value?"), wxYES_NO|wxCENTRE|wxICON_EXCLAMATION);
999+
wxMessageDialog msg(this, wxT("Image off value is not empty! Do you want to empty it? (Also removes mask off if set)"), wxT("Empty image off value?"), wxYES_NO|wxCENTRE|wxICON_EXCLAMATION);
9901000
if (msg.ShowModal() == wxID_YES) {
9911001
// then we empty the value in button and panel
9921002
m_button->setImageOff(wxEmptyString);
1003+
m_button->setMaskOff(wxEmptyString);
9931004
m_imageOffPathField->SetValue(wxEmptyString);
994-
m_addMaskOnBtn->Disable();
1005+
m_maskOffPathField->SetValue(wxEmptyString);
9951006
m_addMaskOffBtn->Disable();
9961007
::wxGetApp().m_frame->PanelGUIPropertyIsChanged();
9971008
}
998-
} else {
999-
m_addMaskOnBtn->Disable();
1000-
m_addMaskOffBtn->Disable();
10011009
}
10021010
}
10031011
}
@@ -1013,7 +1021,6 @@ void GUIButtonPanel::OnAddMaskOnBtn(wxCommandEvent& WXUNUSED(event)) {
10131021
m_button->setMaskOn(path);
10141022
wxString relativePath = GOODF_functions::removeBaseOdfPath(m_button->getMaskOn());
10151023
m_maskOnPathField->SetValue(relativePath);
1016-
m_addMaskOffBtn->Enable();
10171024
}
10181025
}
10191026
} else {
@@ -1024,10 +1031,7 @@ void GUIButtonPanel::OnAddMaskOnBtn(wxCommandEvent& WXUNUSED(event)) {
10241031
// then we empty the value in button and panel
10251032
m_button->setMaskOn(wxEmptyString);
10261033
m_maskOnPathField->SetValue(wxEmptyString);
1027-
m_addMaskOffBtn->Disable();
10281034
}
1029-
} else {
1030-
m_addMaskOffBtn->Disable();
10311035
}
10321036
}
10331037
}

0 commit comments

Comments
 (0)