1 | module main |
2 | |
3 | import gg |
4 | import gx |
5 | import os |
6 | import math |
7 | |
8 | const ( |
9 | win_width = 600 |
10 | win_height = 700 |
11 | bg_color = gx.white |
12 | ) |
13 | |
14 | const ( |
15 | text = ' |
16 | Once upon a midnight dreary, while I pondered, weak and weary, |
17 | Over many a quaint and curious volume of forgotten lore— |
18 | While I nodded, nearly napping, suddenly there came a tapping, |
19 | As of some one gently rapping, rapping at my chamber door. |
20 | “’Tis some visitor,” I muttered, “tapping at my chamber door— |
21 | Only this and nothing more.” |
22 | |
23 | Ah, distinctly I remember it was in the bleak December; |
24 | And each separate dying ember wrought its ghost upon the floor. |
25 | Eagerly I wished the morrow;—vainly I had sought to borrow |
26 | From my books surcease of sorrow—sorrow for the lost Lenore— |
27 | For the rare and radiant maiden whom the angels name Lenore— |
28 | Nameless here for evermore. |
29 | |
30 | And the silken, sad, uncertain rustling of each purple curtain |
31 | Thrilled me—filled me with fantastic terrors never felt before; |
32 | So that now, to still the beating of my heart, I stood repeating |
33 | “’Tis some visitor entreating entrance at my chamber door— |
34 | Some late visitor entreating entrance at my chamber door;— |
35 | This it is and nothing more.” |
36 | |
37 | Presently my soul grew stronger; hesitating then no longer, |
38 | “Sir,” said I, “or Madam, truly your forgiveness I implore; |
39 | But the fact is I was napping, and so gently you came rapping, |
40 | And so faintly you came tapping, tapping at my chamber door, |
41 | That I scarce was sure I heard you”—here I opened wide the door;— |
42 | Darkness there and nothing more. |
43 | |
44 | Deep into that darkness peering, long I stood there wondering, fearing, |
45 | Doubting, dreaming dreams no mortal ever dared to dream before; |
46 | But the silence was unbroken, and the stillness gave no token, |
47 | And the only word there spoken was the whispered word, “Lenore?” |
48 | This I whispered, and an echo murmured back the word, “Lenore!”— |
49 | Merely this and nothing more. |
50 | |
51 | Back into the chamber turning, all my soul within me burning, |
52 | Soon again I heard a tapping somewhat louder than before. |
53 | “Surely,” said I, “surely that is something at my window lattice; |
54 | Let me see, then, what thereat is, and this mystery explore— |
55 | Let my heart be still a moment and this mystery explore;— |
56 | ’Tis the wind and nothing more!” |
57 | ' |
58 | lines = text.split('\n') |
59 | ) |
60 | |
61 | struct App { |
62 | mut: |
63 | gg &gg.Context = unsafe { nil } |
64 | } |
65 | |
66 | fn main() { |
67 | mut app := &App{ |
68 | gg: 0 |
69 | } |
70 | mut font_path := os.resource_abs_path(os.join_path('..', 'assets', 'fonts', 'RobotoMono-Regular.ttf')) |
71 | $if android { |
72 | font_path = 'fonts/RobotoMono-Regular.ttf' |
73 | } |
74 | app.gg = gg.new_context( |
75 | width: win_width |
76 | height: win_height |
77 | create_window: true |
78 | window_title: 'Raven text' |
79 | user_data: app |
80 | bg_color: bg_color |
81 | frame_fn: frame |
82 | font_path: font_path // window_user_ptr: ctx |
83 | // native_rendering: true |
84 | ) |
85 | app.gg.run() |
86 | } |
87 | |
88 | fn frame(mut app App) { |
89 | app.gg.begin() |
90 | width := gg.window_size().width |
91 | mut scale_factor := math.round(f32(width) / win_width) |
92 | if scale_factor <= 0 { |
93 | scale_factor = 1 |
94 | } |
95 | text_cfg := gx.TextCfg{ |
96 | size: 16 * int(scale_factor) |
97 | } |
98 | mut y := 10 |
99 | for line in lines { |
100 | app.gg.draw_text(10, y, line, text_cfg) |
101 | y += 30 |
102 | } |
103 | app.gg.end() |
104 | } |