Blank image when no mode is selected.
This commit is contained in:
@@ -5,6 +5,7 @@ import common
|
|||||||
|
|
||||||
const
|
const
|
||||||
supportedExts = @[".png", ".jpg", ".jpeg"]
|
supportedExts = @[".png", ".jpg", ".jpeg"]
|
||||||
|
placeholderImg = slurp("resources/blank.png")
|
||||||
foxesUrl = "https://randomfox.ca/floof/"
|
foxesUrl = "https://randomfox.ca/floof/"
|
||||||
inspiroUrl = "http://inspirobot.me/api?generate=true"
|
inspiroUrl = "http://inspirobot.me/api?generate=true"
|
||||||
|
|
||||||
@@ -75,6 +76,13 @@ func calcImageSize(maxWidth, maxHeight, imgWidth, imgHeight: int): tuple[width:
|
|||||||
# Image Provider procs
|
# Image Provider procs
|
||||||
########################
|
########################
|
||||||
|
|
||||||
|
proc getPlaceHolder(ip: ImageProvider): FileOpResult =
|
||||||
|
## Provide the placeholder image.
|
||||||
|
## This is used when no mode is active
|
||||||
|
let f = fmt"{tmpFile}.blank"
|
||||||
|
writeFile(f, placeholderImg)
|
||||||
|
return newFileOpResult(f)
|
||||||
|
|
||||||
proc getFox(ip: ImageProvider): FileOpResult =
|
proc getFox(ip: ImageProvider): FileOpResult =
|
||||||
## Download image from the fox API
|
## Download image from the fox API
|
||||||
try:
|
try:
|
||||||
@@ -131,14 +139,14 @@ proc getLocalFile(ip: var ImageProvider): FileOpResult =
|
|||||||
proc getFileName(ip: var ImageProvider): FileOpResult =
|
proc getFileName(ip: var ImageProvider): FileOpResult =
|
||||||
## Get the temporary file name of the next file to display
|
## Get the temporary file name of the next file to display
|
||||||
case ip.mode
|
case ip.mode
|
||||||
|
of Mode.None:
|
||||||
|
return ip.getPlaceHolder()
|
||||||
of Mode.File:
|
of Mode.File:
|
||||||
return ip.getLocalFile()
|
return ip.getLocalFile()
|
||||||
of Mode.Foxes:
|
of Mode.Foxes:
|
||||||
return ip.getFox()
|
return ip.getFox()
|
||||||
of Mode.Inspiro:
|
of Mode.Inspiro:
|
||||||
return ip.getInspiro()
|
return ip.getInspiro()
|
||||||
else:
|
|
||||||
return newFileOpResultError("Not implemented")
|
|
||||||
|
|
||||||
########################
|
########################
|
||||||
# Exported procs
|
# Exported procs
|
||||||
@@ -147,8 +155,6 @@ proc getFileName(ip: var ImageProvider): FileOpResult =
|
|||||||
proc next*(ip: var ImageProvider, maxWidth, maxHeight: int): FileOpResult =
|
proc next*(ip: var ImageProvider, maxWidth, maxHeight: int): FileOpResult =
|
||||||
## Uses the image provider to get a new image ready to display.
|
## Uses the image provider to get a new image ready to display.
|
||||||
## `width` and `height` should be the size of the window.
|
## `width` and `height` should be the size of the window.
|
||||||
if ip.mode == Mode.None:
|
|
||||||
return newFileOpResultError("No mode active")
|
|
||||||
|
|
||||||
let op = ip.getFileName()
|
let op = ip.getFileName()
|
||||||
if not op.success: return op
|
if not op.success: return op
|
||||||
|
|||||||
@@ -98,7 +98,6 @@ proc updateImage(image: Image): bool =
|
|||||||
if imageProvider.mode == Mode.None:
|
if imageProvider.mode == Mode.None:
|
||||||
log "No display mode"
|
log "No display mode"
|
||||||
label.notify "No mode selected"
|
label.notify "No mode selected"
|
||||||
return true
|
|
||||||
|
|
||||||
var wWidth, wHeight: int
|
var wWidth, wHeight: int
|
||||||
window.getSize(wWidth, wHeight)
|
window.getSize(wWidth, wHeight)
|
||||||
@@ -110,6 +109,7 @@ proc updateImage(image: Image): bool =
|
|||||||
return
|
return
|
||||||
|
|
||||||
image.setFromFile(op.file)
|
image.setFromFile(op.file)
|
||||||
|
if imageProvider.mode != Mode.None:
|
||||||
label.notify
|
label.notify
|
||||||
except:
|
except:
|
||||||
let
|
let
|
||||||
|
|||||||
BIN
src/resources/blank.png
Normal file
BIN
src/resources/blank.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
Reference in New Issue
Block a user