From 5c4909b4ab28b8243a0c301cde44bdc34118b0b9 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 21 Feb 2021 10:15:54 +0100 Subject: [PATCH] pgui: Some code cleanup for PGItem --- panda/src/pgui/pgItem.cxx | 49 +++++++++++++------------------- panda/src/pgui/pgScrollFrame.cxx | 3 +- panda/src/pgui/pgSliderBar.cxx | 3 +- 3 files changed, 21 insertions(+), 34 deletions(-) diff --git a/panda/src/pgui/pgItem.cxx b/panda/src/pgui/pgItem.cxx index aeff5bff25..6f023b8647 100644 --- a/panda/src/pgui/pgItem.cxx +++ b/panda/src/pgui/pgItem.cxx @@ -347,9 +347,8 @@ void PGItem:: r_prepare_scene(GraphicsStateGuardianBase *gsg, const RenderState *node_state, GeomTransformer &transformer, Thread *current_thread) { LightReMutexHolder holder(_lock); - StateDefs::iterator di; - for (di = _state_defs.begin(); di != _state_defs.end(); ++di) { - NodePath &root = (*di)._root; + for (StateDef &def : _state_defs) { + NodePath &root = def._root; if (!root.is_empty()) { PandaNode *child = root.node(); CPT(RenderState) child_state = node_state->compose(child->get_state()); @@ -375,9 +374,8 @@ xform(const LMatrix4 &mat) { _frame.set(ll[0], ur[0], ll[2], ur[2]); // Transform the individual states and their frame styles. - StateDefs::iterator di; - for (di = _state_defs.begin(); di != _state_defs.end(); ++di) { - NodePath &root = (*di)._root; + for (StateDef &def : _state_defs) { + NodePath &root = def._root; // Apply the matrix to the previous transform. root.set_transform(root.get_transform()->compose(TransformState::make_mat(mat))); @@ -386,8 +384,8 @@ xform(const LMatrix4 &mat) { gr.apply_attribs(root.node()); // Transform the frame style too. - if ((*di)._frame_style.xform(mat)) { - (*di)._frame_stale = true; + if (def._frame_style.xform(mat)) { + def._frame_stale = true; } } mark_internal_bounds_stale(); @@ -767,9 +765,7 @@ move(const MouseWatcherParameter ¶m) { */ void PGItem:: background_press(const MouseWatcherParameter ¶m) { - BackgroundFocus::const_iterator fi; - for (fi = _background_focus.begin(); fi != _background_focus.end(); ++fi) { - PGItem *item = *fi; + for (PGItem *item : _background_focus) { if (!item->get_focus()) { item->press(param, true); } @@ -781,9 +777,7 @@ background_press(const MouseWatcherParameter ¶m) { */ void PGItem:: background_release(const MouseWatcherParameter ¶m) { - BackgroundFocus::const_iterator fi; - for (fi = _background_focus.begin(); fi != _background_focus.end(); ++fi) { - PGItem *item = *fi; + for (PGItem *item : _background_focus) { if (!item->get_focus()) { item->release(param, true); } @@ -795,9 +789,7 @@ background_release(const MouseWatcherParameter ¶m) { */ void PGItem:: background_keystroke(const MouseWatcherParameter ¶m) { - BackgroundFocus::const_iterator fi; - for (fi = _background_focus.begin(); fi != _background_focus.end(); ++fi) { - PGItem *item = *fi; + for (PGItem *item : _background_focus) { if (!item->get_focus()) { item->keystroke(param, true); } @@ -809,9 +801,7 @@ background_keystroke(const MouseWatcherParameter ¶m) { */ void PGItem:: background_candidate(const MouseWatcherParameter ¶m) { - BackgroundFocus::const_iterator fi; - for (fi = _background_focus.begin(); fi != _background_focus.end(); ++fi) { - PGItem *item = *fi; + for (PGItem *item : _background_focus) { if (!item->get_focus()) { item->candidate(param, true); } @@ -1165,11 +1155,10 @@ mouse_to_local(const LPoint2 &mouse_point) const { } /** - * Called when the user changes the frame size. + * Called when the user changes the frame size. Assumes the lock is held. */ void PGItem:: frame_changed() { - LightReMutexHolder holder(_lock); mark_frames_stale(); if (_notify != nullptr) { _notify->item_frame_changed(this); @@ -1202,6 +1191,7 @@ do_get_state_def(int state) { /** * Ensures there is a slot in the array for the given state definition. + * Assumes the lock is already held. */ void PGItem:: slot_state_def(int state) { @@ -1212,6 +1202,7 @@ slot_state_def(int state) { /** * Generates a new instance of the frame geometry for the indicated state. + * Assumes the lock is already held. */ void PGItem:: update_frame(int state) { @@ -1234,15 +1225,14 @@ update_frame(int state) { /** * Marks all the frames in all states stale, so that they will be regenerated - * the next time each state is requested. + * the next time each state is requested. Assumes the lock is already held. */ void PGItem:: mark_frames_stale() { - StateDefs::iterator di; - for (di = _state_defs.begin(); di != _state_defs.end(); ++di) { + for (StateDef &def : _state_defs) { // Remove the old frame, if any. - (*di)._frame.remove_node(); - (*di)._frame_stale = true; + def._frame.remove_node(); + def._frame_stale = true; } mark_internal_bounds_stale(); } @@ -1294,9 +1284,8 @@ clip_frame(ClipPoints &source_points, const LPlane &plane) const { LPoint2 last_point(source_points.back()); bool last_is_in = is_right(last_point - from2d, delta2d); bool all_in = last_is_in; - ClipPoints::const_iterator pi; - for (pi = source_points.begin(); pi != source_points.end(); ++pi) { - LPoint2 this_point(*pi); + + for (LPoint2 this_point : source_points) { bool this_is_in = is_right(this_point - from2d, delta2d); // There appears to be a compiler bug in gcc 4.0: we need to extract this diff --git a/panda/src/pgui/pgScrollFrame.cxx b/panda/src/pgui/pgScrollFrame.cxx index 9631f66685..60920b88f8 100644 --- a/panda/src/pgui/pgScrollFrame.cxx +++ b/panda/src/pgui/pgScrollFrame.cxx @@ -284,11 +284,10 @@ remanage() { } /** - * Called when the user changes the frame size. + * Called when the user changes the frame size. Assumes the lock is held. */ void PGScrollFrame:: frame_changed() { - LightReMutexHolder holder(_lock); PGVirtualFrame::frame_changed(); _needs_remanage = true; _needs_recompute_clip = true; diff --git a/panda/src/pgui/pgSliderBar.cxx b/panda/src/pgui/pgSliderBar.cxx index e085f0f91d..e666d2a496 100644 --- a/panda/src/pgui/pgSliderBar.cxx +++ b/panda/src/pgui/pgSliderBar.cxx @@ -551,11 +551,10 @@ recompute() { } /** - * Called when the user changes the frame size. + * Called when the user changes the frame size. Assumes the lock is held. */ void PGSliderBar:: frame_changed() { - LightReMutexHolder holder(_lock); PGItem::frame_changed(); _needs_remanage = true; _needs_recompute = true;