Advertisement
nikeedev

Untitled

Jan 29th, 2023
1,110
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.95 KB | None | 0 0
  1. module main
  2.  
  3. import gg
  4. import gx
  5. import os
  6.  
  7.  
  8. struct App {
  9. mut:
  10.     ctx    &gg.Context = unsafe { nil }
  11.     img  gg.Image
  12.     file_name string
  13. }
  14.  
  15. const (
  16.     win_width = 800
  17.     win_height = 600
  18. )
  19.  
  20. fn main() {
  21.     println(os.args.len)
  22.  
  23.     if os.args.len < 1  {
  24.         println("Usage: imgview <filename>.png/.jpg/.jpeg")
  25.         return
  26.     }
  27.     else {
  28.         mut file_name := os.args[1]
  29.  
  30.         mut app := &App{
  31.             ctx: 0,
  32.             file_name: file_name
  33.         }
  34.  
  35.         app.ctx = gg.new_context(
  36.             bg_color: gx.white
  37.             width: win_width
  38.             height: win_height
  39.             create_window: true
  40.             window_title: "imgview - ${file_name}"
  41.             frame_fn: frame
  42.             user_data: app
  43.             init_fn: init
  44.         )
  45.  
  46.         app.ctx.run()
  47.  
  48.     }
  49. }
  50.  
  51. fn init(mut app &App) {
  52.  
  53.     app.img = app.ctx.create_image(os.resource_abs_path(app.file_name))
  54.  
  55. }
  56.  
  57. fn (app &App) draw() {
  58.  
  59.     app.ctx.draw_image(0, 0, app.img.width, app.img.height, app.img)
  60.  
  61. }
  62.  
  63. fn frame(app &App) {
  64.     app.ctx.begin()
  65.     app.draw()
  66.     app.ctx.end()
  67. }
  68.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement