/** * レイヤ番号が適切かどうか判定 * @param no レイヤ番号 */ void PSD::checkLayerNo(int no) { if (!isLoaded) { TVPThrowExceptionMessage(L"no data"); } if (no < 0 || no >= get_layer_count()) { TVPThrowExceptionMessage(L"not such layer"); } }
void stacked_widget::select_layers(const boost::dynamic_bitset<>& mask) { assert(mask.size() == get_layer_count()); select_layer_impl([&](unsigned int i) { if(mask[i]) { update_selected_layer_index(i); } return mask[i]; }); }
void stacked_widget::select_layer_impl(std::function<bool(unsigned int i)> display_condition) { const unsigned int num_layers = get_layer_count(); // Deselect all layers except the chosen ones. for(unsigned int i = 0; i < num_layers; ++i) { const bool selected = display_condition(i); /* Selecting a previously selected item will deselect it, regardless of the what is passed to * select_item. This causes issues if this function is called when all layers are visible (for * example, initialization). For layers other than the chosen one, this is the desired behavior. * However the chosen layer could *also* be deselected undesirably due to the conditions outlined * above, and as this widget's generator does not stipulate a minimum selection, it's possible to * end up with no layers visible at all. * * This works around that by performing no selection unless necessary to change states. */ if(generator_->is_selected(i) != selected) { generator_->select_item(i, selected); } } // If we already have our chosen layers, exit. if(selected_layer_ >= 0) { return; } // Else, re-show all layers. for(unsigned int i = 0; i < num_layers; ++i) { /* By design, only the last selected item will receive events even if multiple items are visible * and said item is not at the top of the stack. If this point is reached, all layers have already * been hidden by the loop above, so the last layer selected will be the top-most one, as desired. */ generator_->select_item(i, true); } }
bool stacked_widget::layer_selected(const unsigned layer) { assert(layer < get_layer_count()); return generator_->is_selected(layer); }
void stacked_widget::update_selected_layer_index(const int i) { selected_layer_ = utils::clamp<int>(i, -1, get_layer_count() - 1); }