Skip to content

Commit 7164643

Browse files
committed
v1.1.3
1 parent 34ed4aa commit 7164643

File tree

3 files changed

+54
-9
lines changed

3 files changed

+54
-9
lines changed

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# visualizer (v1.1.2)
1+
# visualizer (v1.1.3)
22

33
This project aims to make a quick visual representation for a C++ project (though Python support is planned).
44

@@ -22,6 +22,18 @@ sudo apt install libclang-11-dev
2222
python3 visualizer.py cpp --target examples/segment_tree --scale 0.5
2323
```
2424

25+
You can also use `--bruteforce 1` to avoid errors.
26+
27+
## Keyboard control:
28+
29+
UP, DOWN, LEFT, RIGHT - move respectively
30+
31+
0 - increase size (zoom in)
32+
33+
9 - decrease size (zoom out)
34+
35+
## About colors:
36+
2537
```
2638
Loops are Red,
2739
Code lines are Blue,
@@ -51,10 +63,9 @@ Why not use `<insert your favorite C++ parser>`?
5163
so only by using a compiler can we get a 100% correct output.
5264
Easiest example is `operator <<` which in most parsers is registered as a `binary expression`, when in reality it is a `function call`.
5365

54-
# What's new in v1.1.2?
55-
* Functions defined in .h files in class are now detected
56-
* Fixed bug, when functions where doubled in structures
57-
* Lines always curve up (idk, looks better)
66+
# What's new in v1.1.3?
67+
* OMG, FINALLY RESIZE!!! (literally took 10 min to implement, no idea why didn't do it earlier)
68+
* OMG, FINALLY MOVE AROUND!!! (literally took another 10 min to implement, no idea why didn't do it earlier)
5869

5970
# Known bugs // missing features:
6071
* Function calls inside Loop and If conditions are not registered

visualizer/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def output_verbose(verbose: bool, *args):
4848

4949
class Scaler:
5050
def __init__(self, initial_scale: float = 1):
51+
self.current_scale = initial_scale
5152
self.MIN_SIZE = 0
5253
self.FUNCTIONS_ACCESS_SPECIFIER_BUFFER = 0
5354
self.BUFFER_SIZE_VERTICAL = 0
@@ -60,6 +61,7 @@ def __init__(self, initial_scale: float = 1):
6061
self.rescale(initial_scale)
6162

6263
def rescale(self, scale: float = 1):
64+
self.current_scale = scale
6365
# TODO: add profiles
6466
self.MIN_SIZE = max(int(50 * scale), 1)
6567
self.FUNCTIONS_ACCESS_SPECIFIER_BUFFER = int(10 * scale)

visualizer/visualizer.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ def __init__(self, scale: float):
215215

216216
self.should_redraw = False
217217
self.a = False
218+
219+
self.global_offset_x = 100
220+
self.global_offset_y = 0
218221
# FIXME: make this 'a' a proper thing (it's used for showing blocks)
219222
# TODO: add side-by-side code comparison
220223

@@ -249,12 +252,12 @@ def on_resize(self, width: float, height: float):
249252
for i in self.parser.code_tree.roots:
250253
self.compute_node_size(i, self.scaler)
251254

252-
offset_x = 100
255+
tmp_offset_x = 0
253256

254257
for i in self.parser.code_tree.roots:
255-
self.compute_node_position(i, self.scaler, offset_x, (self.height - self.graphics_info[i].size_y) // 2)
256-
offset_x += self.scaler.OBJECTS_BUFFER
257-
offset_x += self.graphics_info[i].size_x
258+
self.compute_node_position(i, self.scaler, self.global_offset_x + tmp_offset_x, self.global_offset_y + (self.height - self.graphics_info[i].size_y) // 2)
259+
tmp_offset_x += self.scaler.OBJECTS_BUFFER
260+
tmp_offset_x += self.graphics_info[i].size_x
258261

259262
for i in self.parser.code_tree.function_calls:
260263
self.compute_function_call_graphics_info(i)
@@ -496,3 +499,32 @@ def recursive_node_draw(self, node):
496499

497500
def update(self, delta_time):
498501
pass
502+
503+
def on_key_press(self, symbol, modifier):
504+
should_recalculate = False
505+
if symbol == arcade.key.UP:
506+
self.global_offset_y -= 50
507+
should_recalculate = True
508+
elif symbol == arcade.key.DOWN:
509+
self.global_offset_y += 50
510+
should_recalculate = True
511+
elif symbol == arcade.key.RIGHT:
512+
self.global_offset_x -= 50
513+
should_recalculate = True
514+
elif symbol == arcade.key.LEFT:
515+
self.global_offset_x += 50
516+
should_recalculate = True
517+
elif symbol == arcade.key.KEY_0:
518+
self.scaler.rescale(self.scaler.current_scale * 1.05)
519+
should_recalculate = True
520+
elif symbol == arcade.key.KEY_9:
521+
self.scaler.rescale(self.scaler.current_scale * 0.95)
522+
should_recalculate = True
523+
524+
# FIXME: probably this should be made more elegant
525+
if should_recalculate:
526+
self.on_resize(self.width, self.height)
527+
528+
529+
530+

0 commit comments

Comments
 (0)