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