Skip to content

Commit 92429ae

Browse files
committed
screen stuff
1 parent a653eeb commit 92429ae

3 files changed

Lines changed: 44 additions & 9 deletions

File tree

707 Bytes
Binary file not shown.

compiler.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,10 @@ def transpile(self, code: str, lang: str = "c") -> str:
295295
'',
296296
'#include <stdio.h>',
297297
'#include <string.h>',
298+
'#include <SDL.h>', # Include SDL for windowing
299+
'',
300+
# Declare global string variable
298301
'char str[256] = "";',
299-
'#include <SDL.h>',
300302
''
301303
]
302304
self.global_vars.clear()
@@ -310,6 +312,9 @@ def transpile(self, code: str, lang: str = "c") -> str:
310312
self.indent_level = 1
311313
self.block_stack.clear()
312314
self.vars.clear()
315+
window_width = 640
316+
window_height = 480
317+
window_title = "BScript Window"
313318

314319
i = 0
315320
while i < len(lines):
@@ -551,28 +556,41 @@ def transpile(self, code: str, lang: str = "c") -> str:
551556
i += 1
552557
continue
553558

554-
# Window
559+
# windowSize command
560+
m = re.match(r'windowSize\s+(\d+)\s*,\s*(\d+);', line)
561+
if m:
562+
window_width = int(m.group(1))
563+
window_height = int(m.group(2))
564+
i += 1
565+
continue
566+
567+
# windowTitle command
568+
m = re.match(r'windowTitle\s+"([^"]*)";', line)
569+
if m:
570+
window_title = m.group(1)
571+
i += 1
572+
continue
573+
574+
# window command
555575
if line == 'window;':
556576
if windowed:
557577
raise Exception("Window already created, cannot create another")
558-
continue
559-
560578
windowed = True
579+
561580
sdl_code = [
562581
"int main(int argc, char* argv[]) {",
563582
" if (SDL_Init(SDL_INIT_VIDEO) != 0) {",
564583
" printf(\"SDL_Init Error: %s\\n\", SDL_GetError());",
565584
" return 1;",
566585
" }",
567-
" SDL_Window* window = SDL_CreateWindow(\"BScript Window\",",
586+
f" SDL_Window* window = SDL_CreateWindow(\"{window_title}\",",
568587
" SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,",
569-
" 640, 480, SDL_WINDOW_SHOWN);",
588+
f" {window_width}, {window_height}, SDL_WINDOW_SHOWN);",
570589
" if (!window) {",
571590
" printf(\"SDL_CreateWindow Error: %s\\n\", SDL_GetError());",
572591
" SDL_Quit();",
573592
" return 1;",
574593
" }",
575-
576594
" SDL_Event e;",
577595
" int running = 1;",
578596
" while (running) {",
@@ -583,7 +601,6 @@ def transpile(self, code: str, lang: str = "c") -> str:
583601
" }",
584602
" SDL_Delay(16);",
585603
" }",
586-
587604
" SDL_DestroyWindow(window);",
588605
" SDL_Quit();"
589606
]

docs/ScreenFunctions.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# Screen Functions
22

3-
Under construction!
3+
## Creating Windows
4+
5+
````
6+
window;
7+
````
8+
9+
Running this creates a window. Simple as that. Before you run this command, you'll may want to use a couple other commands
10+
11+
## Window Parameters
12+
13+
````
14+
windowSize 1280,720;
15+
windowTitle "Window Name";
16+
window; //Only open the window AFTER the parameters are set. If not, the commands won't do anything.
17+
````
18+
19+
The window paremeters should be pretty self explanatory, but `windowSize` sets the dimensions of the window and `WindowTitle` sets the window title.
20+
21+
422

523
[< Previous Page](functions.html) | [Next Page >](advanced.html)

0 commit comments

Comments
 (0)