Skip to content

Commit

Permalink
Add code to GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
thabetx committed Aug 11, 2024
0 parents commit f828472
Show file tree
Hide file tree
Showing 16 changed files with 1,135 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build-main.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
IF NOT exist build (mkdir build && echo build dir created)
odin build main -debug -out:build/dima-deb.exe && pushd build && dima-deb.exe && popd
REM odin build main -o:aggressive -out:build/dima.exe -subsystem:windows -disable-assert -no-bounds-check && pushd build && dima.exe && popd
4 changes: 4 additions & 0 deletions build-program.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
IF NOT exist build (mkdir build && echo build dir created)
odin build program -debug -build-mode:dll -out:build/program.dll -vet
REM odin build program -o:aggressive -disable-assert -no-bounds-check

3 changes: 3 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
IF NOT exist build (mkdir build && echo build dir created)
odin build main -o:aggressive -out:build/dima.exe -subsystem:windows -disable-assert -no-bounds-check && echo "dima.exe built in the build folder"
pause
Binary file added data/fantasque/FantasqueSansMono-Regular.ttf
Binary file not shown.
93 changes: 93 additions & 0 deletions data/fantasque/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Copyright (c) 2013-2017, Jany Belluz ([email protected])

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
8 changes: 8 additions & 0 deletions data/tutorial.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
xxxxxxxxxxx....................;Press 'e' to edit;Press 'e';Edit Habits;
xxxxxxxxxx.....................;Take a Walk;;;
xxxxxxxxxxx.............-------;Read the book;;;START book.pdf
------xxxxx....................;Write;;;START obsidian.lnk
-------------------------------;;;;
x-x-x-x-x-x-.-.-.-.-.-.-.-.-.-.;Study Math;;;
-x-x-x-x-x-.-.-.-.-.-.-.-.-.-.-;Study Programming;;;

3 changes: 3 additions & 0 deletions launch/launch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// cl -TC -c foo.c && lib -nologo foo.obj -out:foo.lib
#include <stdlib.h>
void launch(const char *cmd) { system(cmd); }
Binary file added launch/launch.lib
Binary file not shown.
148 changes: 148 additions & 0 deletions main/main.odin
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package main

import "../program"
import "core:dynlib"
import "core:fmt"
import "core:os"
import "core:os/os2"
import "core:strings"
import ray "vendor:raylib"

API :: struct {
setup: proc(state: ^program.State),
draw: proc(),
}

api: API
api_load_time: os.File_Time
font: ray.Font
st: program.State
old_st: program.State

// foreign import launch_lib "../launch/launch.lib"
// foreign launch_lib {
// launch :: proc(_: cstring) ---
// }

load :: proc() -> bool {
dll_name :: "program"
dll_ext :: ".dll"
full_name :: dll_name + dll_ext

if os.is_file(full_name) == false {
fmt.println(full_name, "doesn't exit")
return false
}

last_write_time, last_write_err := os.last_write_time_by_name(full_name)
if last_write_err != os.ERROR_NONE || api_load_time == last_write_time do return false
new_name := fmt.tprintf("{}_{}{}", dll_name, last_write_time, dll_ext)
api_load_time = last_write_time

// command := fmt.ctprintf("copy {} {}", full_name, new_name)
// fmt.println(command)
// launch(command)
copy_error := os2.copy_file(new_name, full_name)
// NOTE: This returns an error even if the copy is successful
// if copy_error != nil {
// fmt.printfln("failed to copy {} to {}. Reason: {}.", full_name, new_name, copy_error)
// return false
// }
_, ok := dynlib.initialize_symbols(&api, new_name)

if !ok {
fmt.printfln("failed to load {}: {}", dynlib.last_error())
return false
}
return true
}

main :: proc() {
{ //ui_init()
ray.SetTraceLogLevel(.WARNING)
window_config := ray.ConfigFlags{.MSAA_4X_HINT, .WINDOW_RESIZABLE}
// window_config += {.WINDOW_UNDECORATED}
// window_config += {.WINDOW_UNFOCUSED}

ray.SetConfigFlags(window_config)
ray.InitWindow(1000, 500, "Dima")
ray.SetTargetFPS(60)
ray.SetExitKey(.Q)

fantasque := #load("../data/fantasque/FantasqueSansMono-Regular.ttf")
font = ray.LoadFontFromMemory(".ttf", &fantasque[0], i32(len(fantasque)), 100, nil, 0)
ray.GenTextureMipmaps(&font.texture)
ray.SetTextureFilter(font.texture, .BILINEAR)
st.quads = make([dynamic]program.Quad, 0, 1000)
st.text = make([dynamic]program.Text, 0, 1000)
}

when ODIN_DEBUG == false {
program.setup(&st)
}

for ray.WindowShouldClose() == false {
free_all(context.temp_allocator)

{ // ui_clear
old_st = st
clear_dynamic_array(&st.quads)
clear_dynamic_array(&st.circles)
clear_dynamic_array(&st.text)
st.window_dims = {f32(ray.GetScreenWidth()), f32(ray.GetScreenHeight())}
st.mouse = ray.GetMousePosition()
st.mouse_left_released = ray.IsMouseButtonReleased(.LEFT)
st.mouse_left_pressed = ray.IsMouseButtonPressed(.LEFT)
st.mouse_right_released = ray.IsMouseButtonReleased(.RIGHT)
st.mouse_right_pressed = ray.IsMouseButtonPressed(.RIGHT)
st.dt = ray.GetFrameTime()
st.e_pressed = ray.IsKeyPressed(.E)
st.t_pressed = ray.IsKeyPressed(.T)
st.b_pressed = ray.IsKeyPressed(.B)
}

when ODIN_DEBUG {
loaded := load()
if loaded do api.setup(&st)
api.draw()
} else {
program.draw()
}

{ //draw
if old_st.hand_cursor != st.hand_cursor {
if st.hand_cursor {
ray.SetMouseCursor(.POINTING_HAND)
} else {
ray.SetMouseCursor(.DEFAULT)
}
}

if old_st.window_dims != st.window_dims {
ray.SetWindowSize(i32(st.window_dims.x), i32(st.window_dims.y))
}

ray.BeginDrawing();defer ray.EndDrawing()
ray.ClearBackground(st.clear_color.rgba)

for q in st.quads {
ray.DrawRectangleV(q.pos, q.dims, q.color.xyzw)
}
for c in st.circles {
ray.DrawCircleV(c.pos, c.radius, c.color.xyzw)
}
for t in st.text {
s := strings.clone_to_cstring(t.s, context.temp_allocator)
text_width := ray.MeasureTextEx(font, s, t.size, 0).x
x := t.pos.x
if t.algnment == .center {
x -= text_width / 2
}
if t.algnment == .right {
x -= text_width
}
ray.DrawTextEx(font, s, {x, t.pos.y}, t.size, 0, t.color.xyzw)
}
}
}
}
1 change: 1 addition & 0 deletions odinfmt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "character_width": 140, }
Loading

0 comments on commit f828472

Please sign in to comment.