| 181 | } |
| 182 | |
| 183 | void PtCanvas::drawPixelTree(bool all) |
| 184 | { |
| 185 | |
| 186 | static int times_called = 0; |
| 187 | |
| 188 | times_called++; |
| 189 | |
| 190 | // print("draw pixel tree: {}", times_called); |
| 191 | |
| 192 | /// which vertical slice to draw at x = 0 |
| 193 | const auto v_begin = all ? 0 : pwidget_->horizontalScrollBar()->value(); |
| 194 | /// how many slices are visible |
| 195 | const auto visible_slices = pwidget_->width(); |
| 196 | const auto v_end = all ? totalSlices() : v_begin + visible_slices; |
| 197 | |
| 198 | bool end_reached = false; |
| 199 | |
| 200 | for (auto slice = v_begin; slice < v_end && !end_reached; ++slice) |
| 201 | { |
| 202 | int x = slice - v_begin; |
| 203 | int first_idx = slice * compression_; |
| 204 | |
| 205 | /// is silce selected? |
| 206 | bool selected = selected_slices_.find(slice) != selected_slices_.end(); |
| 207 | |
| 208 | QRgb color = dark_mode_ ? qRgb(215, 225, 215) : qRgb(30, 40, 30); |
| 209 | |
| 210 | if (selected) |
| 211 | { |
| 212 | color = qRgb(255, 0, 0); |
| 213 | } |
| 214 | |
| 215 | /// See if there is a solution node (warning: duplication / bad code!) |
| 216 | /// (Note that this has to be separate from drawing, as the solution line |
| 217 | /// should go behind the actual nodes) |
| 218 | bool has_solutions = false; |
| 219 | for (auto idx = first_idx; idx < first_idx + compression_; ++idx) |
| 220 | { |
| 221 | if (idx == pi_seq_.size()) |
| 222 | { |
| 223 | end_reached = true; |
| 224 | break; |
| 225 | } |
| 226 | const auto node = pi_seq_[idx].nid; |
| 227 | |
| 228 | if (tree_.getStatus(node) == tree::NodeStatus::SOLVED) |
| 229 | { |
| 230 | has_solutions = true; |
| 231 | break; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | if (has_solutions) |
| 236 | { |
| 237 | for (auto y = 0; y < tree_.depth(); ++y) |
| 238 | { |
| 239 | pimage_->drawPixel(x, y, colors::solution); |
| 240 | } |