Initial commit: base-road-network copy
This commit is contained in:
49
src/draw.odin
Normal file
49
src/draw.odin
Normal file
@@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import "core:fmt"
|
||||
import rl "vendor:raylib"
|
||||
|
||||
import "common"
|
||||
|
||||
// Main drawing function
|
||||
draw :: proc(self: ^Simulator, pos: rl.Vector2) {
|
||||
rl.ClearBackground(rl.LIGHTGRAY)
|
||||
|
||||
// draw roads
|
||||
for &road, index in self.roads {
|
||||
start := road.nodes[0]
|
||||
end := road.nodes[1]
|
||||
|
||||
road_colour: rl.Color
|
||||
if road, ok := self.highlighted_road.?; ok && road == u32(index) && self.delete_mode {
|
||||
road_colour = common.ROAD_HIGHLIGHT_COLOUR
|
||||
} else do road_colour = common.ROAD_COLOUR
|
||||
|
||||
rl.DrawLineEx(self.nodes[start].pos, self.nodes[end].pos, common.ROAD_SIZE, road_colour)
|
||||
}
|
||||
|
||||
// draw nodes
|
||||
for &node in self.nodes {
|
||||
// draws the snapping radius if key is held down
|
||||
if self.show_details do rl.DrawCircleV(node.pos, common.NODE_SNAP_RADIUS * common.NODE_RADIUS, common.NODE_SNAP_COLOUR)
|
||||
// draws the node
|
||||
rl.DrawCircleV(node.pos, common.NODE_RADIUS, common.NODE_DONE_COLOUR)
|
||||
}
|
||||
|
||||
// draw temp road if exists
|
||||
if val, ok := self.temp_node.?; ok {
|
||||
rl.DrawLineEx(self.nodes[val].pos, pos, common.ROAD_SIZE, common.ROAD_COLOUR)
|
||||
|
||||
rl.DrawCircleV(self.nodes[val].pos, common.NODE_RADIUS, common.NODE_BUILD_COLOUR)
|
||||
rl.DrawCircleV(pos, common.NODE_RADIUS, common.NODE_CURSOR_COLOUR)
|
||||
}
|
||||
|
||||
draw_ui(self)
|
||||
}
|
||||
|
||||
// Drawing UI text, mostly for debugging purposes
|
||||
@(private="file")
|
||||
draw_ui :: proc(self: ^Simulator) {
|
||||
entity_count := fmt.ctprintf("Nodes: %d\nRoads: %d", len(self.nodes), len(self.roads))
|
||||
rl.DrawText(entity_count, i32(common.WIDTH - 13 * len(entity_count)), common.HEIGHT - 2 * common.TEXT_SIZE, common.TEXT_SIZE, common.TEXT_COLOUR)
|
||||
}
|
||||
Reference in New Issue
Block a user