2019-11-20 07:10:19 +03:00
|
|
|
|
module main
|
|
|
|
|
|
|
|
|
|
import gg
|
|
|
|
|
import gx
|
2020-06-04 17:05:12 +03:00
|
|
|
|
import os
|
2021-01-29 13:13:06 +03:00
|
|
|
|
import math
|
2019-11-20 07:10:19 +03:00
|
|
|
|
|
|
|
|
|
const (
|
2020-10-18 09:48:13 +03:00
|
|
|
|
win_width = 600
|
2020-05-30 13:52:23 +03:00
|
|
|
|
win_height = 700
|
2020-10-18 09:48:13 +03:00
|
|
|
|
bg_color = gx.white
|
2019-11-20 07:10:19 +03:00
|
|
|
|
)
|
|
|
|
|
|
2020-05-30 13:52:23 +03:00
|
|
|
|
const (
|
2021-04-29 02:17:37 +03:00
|
|
|
|
text = '
|
2020-05-30 13:52:23 +03:00
|
|
|
|
Once upon a midnight dreary, while I pondered, weak and weary,
|
|
|
|
|
Over many a quaint and curious volume of forgotten lore—
|
|
|
|
|
While I nodded, nearly napping, suddenly there came a tapping,
|
|
|
|
|
As of some one gently rapping, rapping at my chamber door.
|
|
|
|
|
“’Tis some visitor,” I muttered, “tapping at my chamber door—
|
|
|
|
|
Only this and nothing more.”
|
|
|
|
|
|
|
|
|
|
Ah, distinctly I remember it was in the bleak December;
|
|
|
|
|
And each separate dying ember wrought its ghost upon the floor.
|
|
|
|
|
Eagerly I wished the morrow;—vainly I had sought to borrow
|
|
|
|
|
From my books surcease of sorrow—sorrow for the lost Lenore—
|
|
|
|
|
For the rare and radiant maiden whom the angels name Lenore—
|
|
|
|
|
Nameless here for evermore.
|
|
|
|
|
|
|
|
|
|
And the silken, sad, uncertain rustling of each purple curtain
|
|
|
|
|
Thrilled me—filled me with fantastic terrors never felt before;
|
|
|
|
|
So that now, to still the beating of my heart, I stood repeating
|
|
|
|
|
“’Tis some visitor entreating entrance at my chamber door—
|
|
|
|
|
Some late visitor entreating entrance at my chamber door;—
|
|
|
|
|
This it is and nothing more.”
|
|
|
|
|
|
|
|
|
|
Presently my soul grew stronger; hesitating then no longer,
|
|
|
|
|
“Sir,” said I, “or Madam, truly your forgiveness I implore;
|
|
|
|
|
But the fact is I was napping, and so gently you came rapping,
|
|
|
|
|
And so faintly you came tapping, tapping at my chamber door,
|
|
|
|
|
That I scarce was sure I heard you”—here I opened wide the door;—
|
|
|
|
|
Darkness there and nothing more.
|
|
|
|
|
|
|
|
|
|
Deep into that darkness peering, long I stood there wondering, fearing,
|
|
|
|
|
Doubting, dreaming dreams no mortal ever dared to dream before;
|
|
|
|
|
But the silence was unbroken, and the stillness gave no token,
|
|
|
|
|
And the only word there spoken was the whispered word, “Lenore?”
|
|
|
|
|
This I whispered, and an echo murmured back the word, “Lenore!”—
|
|
|
|
|
Merely this and nothing more.
|
|
|
|
|
|
|
|
|
|
Back into the chamber turning, all my soul within me burning,
|
|
|
|
|
Soon again I heard a tapping somewhat louder than before.
|
|
|
|
|
“Surely,” said I, “surely that is something at my window lattice;
|
|
|
|
|
Let me see, then, what thereat is, and this mystery explore—
|
|
|
|
|
Let my heart be still a moment and this mystery explore;—
|
|
|
|
|
’Tis the wind and nothing more!”
|
|
|
|
|
'
|
2020-10-18 09:48:13 +03:00
|
|
|
|
lines = text.split('\n')
|
2020-05-30 13:52:23 +03:00
|
|
|
|
)
|
|
|
|
|
|
2020-06-04 17:05:12 +03:00
|
|
|
|
struct App {
|
2019-11-20 07:10:19 +03:00
|
|
|
|
mut:
|
2022-09-15 07:59:31 +03:00
|
|
|
|
gg &gg.Context = unsafe { nil }
|
2019-11-20 07:10:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-04 17:05:12 +03:00
|
|
|
|
fn main() {
|
2020-10-18 09:48:13 +03:00
|
|
|
|
mut app := &App{
|
|
|
|
|
gg: 0
|
|
|
|
|
}
|
2021-01-29 13:13:06 +03:00
|
|
|
|
mut font_path := os.resource_abs_path(os.join_path('..', 'assets', 'fonts', 'RobotoMono-Regular.ttf'))
|
|
|
|
|
$if android {
|
|
|
|
|
font_path = 'fonts/RobotoMono-Regular.ttf'
|
|
|
|
|
}
|
|
|
|
|
app.gg = gg.new_context(
|
2019-11-20 07:35:13 +03:00
|
|
|
|
width: win_width
|
|
|
|
|
height: win_height
|
2020-06-04 17:05:12 +03:00
|
|
|
|
create_window: true
|
2021-12-06 23:39:43 +03:00
|
|
|
|
window_title: 'Raven text'
|
2020-06-04 17:05:12 +03:00
|
|
|
|
user_data: app
|
|
|
|
|
bg_color: bg_color
|
|
|
|
|
frame_fn: frame
|
2021-01-29 13:13:06 +03:00
|
|
|
|
font_path: font_path // window_user_ptr: ctx
|
2021-04-14 03:59:34 +03:00
|
|
|
|
// native_rendering: true
|
2021-01-29 13:13:06 +03:00
|
|
|
|
)
|
2020-06-04 17:05:12 +03:00
|
|
|
|
app.gg.run()
|
2019-11-20 07:10:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-04 17:05:12 +03:00
|
|
|
|
fn frame(mut app App) {
|
|
|
|
|
app.gg.begin()
|
2021-01-29 13:13:06 +03:00
|
|
|
|
width := gg.window_size().width
|
|
|
|
|
mut scale_factor := math.round(f32(width) / win_width)
|
|
|
|
|
if scale_factor <= 0 {
|
|
|
|
|
scale_factor = 1
|
|
|
|
|
}
|
|
|
|
|
text_cfg := gx.TextCfg{
|
|
|
|
|
size: 16 * int(scale_factor)
|
|
|
|
|
}
|
2020-05-30 13:52:23 +03:00
|
|
|
|
mut y := 10
|
|
|
|
|
for line in lines {
|
2021-01-29 13:13:06 +03:00
|
|
|
|
app.gg.draw_text(10, y, line, text_cfg)
|
2020-06-04 17:05:12 +03:00
|
|
|
|
y += 30
|
2020-05-30 13:52:23 +03:00
|
|
|
|
}
|
2020-06-04 17:05:12 +03:00
|
|
|
|
app.gg.end()
|
2019-11-20 07:10:19 +03:00
|
|
|
|
}
|