Skip to content
This repository has been archived by the owner on Jan 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #34 from Ethosa/nightly
Browse files Browse the repository at this point in the history
Nightly v0.4.0
  • Loading branch information
Ethosa authored Oct 17, 2021
2 parents f731548 + 84a003b commit 3a47afa
Show file tree
Hide file tree
Showing 115 changed files with 2,151 additions and 2,091 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Build examples
run: |
cd examples
for dir in hello_world calculator novel snake screensaver roguelike; do
for dir in hello_world calculator novel snake screensaver roguelike builder_features; do
(
cd "$dir"
nim c main.nim
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Ethosa
Copyright (c) 2021 Ethosa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The Nim GUI/2D framework based on OpenGL and SDL2.
[![channel icon](https://patrolavia.github.io/telegram-badge/follow.png)](https://t.me/nim1love)
[![channel icon](https://patrolavia.github.io/telegram-badge/chat.png)](https://t.me/nodesnim)

<h4>Stable version - 0.3.2</h4>
<h4>Stable version - 0.4.0</h4>
</div>

## Install
Expand Down Expand Up @@ -67,7 +67,7 @@ This section contains links to documentation for all nodes.
|[Anchor][] |[Node][] |[Control][] |[Node2D][] |[Node3D][] |[Drawable][] |
|[Color][] |[Canvas][] |[ColorRect][] |[Sprite][] |[GeometryInstance][]|[GradientDrawable][]|
|[Font][] |[Scene][] |[TextureRect][] |[AnimatedSprite][] |[Camera3D][] | |
|[Enums][] |[AudioStreamPlayer][]|[Label][] |[YSort][] | | |
|[Enums][] |[AudioStreamPlayer][]|[Label][] |[YSort][] |[Sprite3D][] | |
|[Exceptions][] |[AnimationPlayer][] |[Button][] |[CollisionShape2D][]| | |
|[Image][] | |[EditText][] |[Camera2D][] | | |
|[Input][] | |[Box][] |[TileMap][] | | |
Expand All @@ -84,6 +84,7 @@ This section contains links to documentation for all nodes.
| | |[Switch][] | | | |
| | |[SubWindow][] | | | |
| | |[CheckBox][] | | | |
| | |[ToolTip][] | | | |



Expand Down Expand Up @@ -154,6 +155,7 @@ Also use [`niminst`](https://github.com/nim-lang/niminst) tool for generate an i
[Font]:https://ethosa.github.io/nodesnim/nodesnim/core/font.html
[StyleSheet]:https://ethosa.github.io/nodesnim/nodesnim/core/stylesheet.html
[TileSet]:https://ethosa.github.io/nodesnim/nodesnim/core/tileset.html
[Scripts]:https://ethosa.github.io/nodesnim/nodesnim/core/scripts.html

[Node]:https://ethosa.github.io/nodesnim/nodesnim/nodes/node.html
[Canvas]:https://ethosa.github.io/nodesnim/nodesnim/nodes/canvas.html
Expand Down Expand Up @@ -183,6 +185,7 @@ Also use [`niminst`](https://github.com/nim-lang/niminst) tool for generate an i
[Switch]:https://ethosa.github.io/nodesnim/nodesnim/nodescontrol/switch.html
[SubWindow]:https://ethosa.github.io/nodesnim/nodesnim/nodescontrol/subwindow.html
[CheckBox]:https://ethosa.github.io/nodesnim/nodesnim/nodescontrol/checkbox.html
[ToolTip]:https://ethosa.github.io/nodesnim/nodesnim/nodescontrol/tooltip.html

[Node2D]:https://ethosa.github.io/nodesnim/nodesnim/nodes2d/node2d.html
[Sprite]:https://ethosa.github.io/nodesnim/nodesnim/nodes2d/sprite.html
Expand All @@ -197,6 +200,7 @@ Also use [`niminst`](https://github.com/nim-lang/niminst) tool for generate an i
[Node3D]:https://ethosa.github.io/nodesnim/nodesnim/nodes3d/node3d.html
[GeometryInstance]:https://ethosa.github.io/nodesnim/nodesnim/nodes3d/geometry_instance.html
[Camera3D]:https://ethosa.github.io/nodesnim/nodesnim/nodes3d/camera3d.html
[Sprite3D]:https://ethosa.github.io/nodesnim/nodesnim/nodes3d/sprite3d.html

[Drawable]:https://ethosa.github.io/nodesnim/nodesnim/graphics/drawable.html
[GradientDrawable]:https://ethosa.github.io/nodesnim/nodesnim/graphics/gradient_drawable.html
Expand Down
41 changes: 41 additions & 0 deletions examples/builder_features/main.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# author: Ethosa
import nodesnim


Window("SceneBuilder")


build:
# Create node.
# var main = Scene(name = "main")
- Scene main:
# Create node with params.
# var rect = ColorRect(name = "rect")
# rect.color = Color(0.6, 0.5, 1)
- ColorRect rect(color: Color(0.6, 0.5, 1)):
# handle Mouse press event.
# rect.on_press = proc(self: NodeRef, x, y: float) =
@onPress(x, y):
rect.color.r -= 0.01
# handle Mouse release event.
# rect.on_release = proc(self: NodeRef, x, y: float) =
@onRelease(x, y):
rect.color.r = 0.6

# Create a new Label with params.
# var hw = Label(name = "hw")
# hw.anchor = Anchor(0.5, 0.5, 0.5, 0.5)
- Label hw(anchor: Anchor(0.5, 0.5, 0.5, 0.5)):
# Call Label method:
# hw.setText("Hello, world!")
call setText("Hello, world!")

# Repeating nodes can be written briefly:
- Node node0(is_ready: true, call hide())
- Node2D node1(is_ready: true, call hide())
- Node3D node2(is_ready: true, call hide())
- Control node3(is_ready: true, call hide())


addMainScene(main)
windowLaunch()
1 change: 1 addition & 0 deletions examples/builder_features/nim.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--path:"../../src"
1 change: 1 addition & 0 deletions examples/builder_features/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# SceneBuilder features
204 changes: 204 additions & 0 deletions examples/calculator/material_ui.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
# --- Material UI calculator --- #
import
strutils,
nodesnim


type
TokenType {.size: sizeof(int8).} = enum
NUMBER,
OPERATOR,
RPAR,
LPAR
Token = ref object
token_type: TokenType
token_value: string
TokenTree = seq[Token]

proc parseQuery(query: string): TokenTree =
result = @[]
for c in query:
if c.isDigit() or c == '.':
if result.len > 0 and not result[^1].isNil() and result[^1].token_type == NUMBER:
result[^1].token_value &= $c
else:
result.add(Token(token_type: NUMBER, token_value: $c))
elif c in "+-/*":
result.add(Token(token_type: OPERATOR, token_value: $c))
when false:
for i in result:
echo i.token_value

proc findHigh(tree: TokenTree): int =
result = -1
let tokens = "/*-+"
for token in tokens:
for i in tree.low..tree.high:
if tree[i].token_type == OPERATOR and tree[i].token_value == $token:
return i-1


proc calculate(tree: TokenTree): float =
result = 0f

var
t = tree
index = t.findHigh()

while index != -1:
case t[index+1].token_value
of "/":
t[index].token_value = $(t[index].token_value.parseFloat() / t[index+2].token_value.parseFloat())
of "*":
t[index].token_value = $(t[index].token_value.parseFloat() * t[index+2].token_value.parseFloat())
of "-":
t[index].token_value = $(t[index].token_value.parseFloat() - t[index+2].token_value.parseFloat())
of "+":
t[index].token_value = $(t[index].token_value.parseFloat() + t[index+2].token_value.parseFloat())
t.del(index+2)
t.del(index+1)
index = t.findHigh()
if t.len == 1:
result = parseFloat(t[0].token_value)

Window("material ui calculator", ((64+32)*4)+16, 480)
env.setBackgroundColor(Color("#FAFAFA"))


var
query: string = ""
big_font = loadFont(standard_font_path, 32)
medium = loadFont(standard_font_path, 24)
small = loadFont(standard_font_path, 16)

build:
- Button number_button:
call setStyle(style({color: "#EEEEEE"}))
call resize(64+32, 64)
call setTextFont(loadFont(standard_font_path, 24))
- Button operator_button:
call setStyle(style({color: "#F5F5F5"}))
call resize(64+32, 51.2f)
call setTextFont(loadFont(standard_font_path, 22))

number_button.normal_background.setStyle(style({background-color: "#424242"}))
number_button.hover_background.setStyle(style({background-color: "#616161"}))
number_button.press_background.setStyle(style({background-color: "#757575"}))

operator_button.normal_background.setStyle(style({background-color: "#616161"}))
operator_button.hover_background.setStyle(style({background-color: "#757575"}))
operator_button.press_background.setStyle(style({background-color: "#9E9E9E"}))


when false:
query = "123+1*5-200/10"
var
parsed = parseQuery(query)
calculated = calculate(parsed)


build:
- Scene main:
- HBox hbox:
separator: 0
call setPadding(8, 8, 8, 8)
call move(0, 200)
- GridBox numbers:
separator: 0
call setRow(3)
- Vbox operators:
separator: 0
- Control result_back:
call resize(((64+32)*4), 200)
call move(8, 8)
call setStyle(style({
background-color: "#4DD0E1",
shadow: true,
shadow-offset: "0 8"
}))
- Label text:
call setTextFont(loadFont(standard_font_path, 32))
call setTextColor(Color("#fff"))
call setTextAlign(1, 1, 1, 1)
call setAnchor(1, 1, 1, 1)
call setSizeAnchor(1, 0.5)
call setPadding(16, 16, 16, 16)


for i in 0..11:
numbers.addChild(number_button.duplicate())
if i < 9:
numbers.getChild(i).ButtonRef.setText($(i+1))
numbers.getChild(i).ButtonRef@onClick(self, x, y):
query &= self.ButtonRef.getText()
text.setText(query)
elif i == 9:
numbers.getChild(i).ButtonRef.setText(".")
numbers.getChild(i).ButtonRef@onClick(self, x, y):
if query.len > 0 and query[^1] != '.':
query &= self.ButtonRef.getText()
text.setText(query)
elif i == 10:
numbers.getChild(i).ButtonRef.setText("0")
numbers.getChild(i).ButtonRef@onClick(self, x, y):
if query.len > 0:
query &= self.ButtonRef.getText()
text.setText(query)
elif i == 11:
numbers.getChild(i).ButtonRef.setText("=")
numbers.getChild(i).ButtonRef@onClick(self, x, y):
if query.len > 0 and query[^1] in "/*-+":
query = "0"
var calculated = parseQuery(query).calculate()
query = $calculated
text.setText(query)

for i in 0..4:
operators.addChild(operator_button.duplicate())
case i
of 0:
operators.getChild(i).ButtonRef.setText("DEL")
operators.getChild(i).ButtonRef@onClick(self, x, y):
if query.len > 0:
query = query[0..^2]
text.setText(query)
of 1:
operators.getChild(i).ButtonRef.setText("+")
operators.getChild(i).ButtonRef@onClick(self, x, y):
if query.len > 0:
if query[^1] notin "-+/*":
query &= "+"
else:
query = query[0..^2] & "+"
text.setText(query)
of 2:
operators.getChild(i).ButtonRef.setText("")
operators.getChild(i).ButtonRef@onClick(self, x, y):
if query.len > 0:
if query[^1] notin "-+/*":
query &= "-"
else:
query = query[0..^2] & "-"
text.setText(query)
of 3:
operators.getChild(i).ButtonRef.setText("÷")
operators.getChild(i).ButtonRef@onClick(self, x, y):
if query.len > 0:
if query[^1] notin "-+/*":
query &= "/"
else:
query = query[0..^2] & "/"
text.setText(query)
else:
operators.getChild(i).ButtonRef.setText("×")
operators.getChild(i).ButtonRef@onClick(self, x, y):
if query.len > 0:
if query[^1] notin "-+/*":
query &= "*"
else:
query = query[0..^2] & "*"
text.setText(query)


addMainScene(main)
windowLaunch()
4 changes: 2 additions & 2 deletions examples/novel/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ build:
call setTexture(akiko_default)
call setTextureAnchor(0.5, 0.5, 0.5, 0.5)
texture_mode: TEXTURE_KEEP_ASPECT_RATIO
visible: GONE
visibility: GONE
- Label dialog_text:
call setSizeAnchor(0.8, 0.3)
call setAnchor(0.1, 0.6, 0, 0)
Expand Down Expand Up @@ -65,7 +65,7 @@ foreground_rect@on_input(self, event):
if stage < dialog.len():
name_charapter.setText(dialog[stage][0])
dialog_text.setText(dialog[stage][1])
charapter.visible = dialog[stage][2]
charapter.visibility = dialog[stage][2]
inc stage


Expand Down
16 changes: 9 additions & 7 deletions examples/readme.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
# Examples

## [Hello world](https://github.com/Ethosa/nodesnim/blob/master/examples/hello_world)
## [Hello world](https://github.com/Ethosa/nodesnim/blob/nightly/examples/hello_world)
![Hello world](https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/1.png)

## [Calculator](https://github.com/Ethosa/nodesnim/blob/master/examples/calculator)
## [Calculator](https://github.com/Ethosa/nodesnim/blob/nightly/examples/calculator)
![Calculator](https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/2.png)

## [Snake game](https://github.com/Ethosa/nodesnim/blob/master/examples/snake)
## [Snake game](https://github.com/Ethosa/nodesnim/blob/nightly/examples/snake)
![Snake game](https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/3.png)

## [Screen saver](https://github.com/Ethosa/nodesnim/blob/master/examples/screensaver)
## [Screen saver](https://github.com/Ethosa/nodesnim/blob/nightly/examples/screensaver)
![Screen saver](https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/4.png)

## [Novel](https://github.com/Ethosa/nodesnim/blob/master/examples/novel)
## [Novel](https://github.com/Ethosa/nodesnim/blob/nightly/examples/novel)
![Novel](https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/5.png)

## [Roguelike](https://github.com/Ethosa/nodesnim/blob/master/examples/roguelike)
## [Roguelike](https://github.com/Ethosa/nodesnim/blob/nightly/examples/roguelike)
![Roguelike](https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/6.png)

## [Sample messenger](https://github.com/Ethosa/nodesnim/blob/master/examples/sample_messenger)
## [Sample messenger](https://github.com/Ethosa/nodesnim/blob/nightly/examples/sample_messenger)
![Sample messenger](https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/7.png)

## [Builder features](https://github.com/Ethosa/nodesnim/blob/nightly/examples/builder_features)
Loading

0 comments on commit 3a47afa

Please sign in to comment.