# The MIT License (MIT)
#
# Copyright (C) 2026 Scott Duensing
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

.section Widgets
.topic widget.image
.title Image
.toc 0 Display Widgets
.toc 0 Image
.index Image
.index wgtImage
.index wgtImageFromFile
.index wgtImageSetData
.index wgtImageLoadFile
.index wgtImageSetTransparent

.h2 Image

Displays a bitmap image. Can be created from raw pixel data or loaded from a file on disk (BMP/PNG/etc. via dvxLoadImage). Supports optional stretching to fill the widget and transparent color keys for chroma-key style masking.

Header: widgets/image.h

.h3 Creation

.code
WidgetT *img = wgtImageFromFile(parent, "logo.bmp");
// or from raw pixels:
// WidgetT *img = wgtImage(parent, pixelData, w, h, pitch);
.endcode

.h3 API Functions

.table
  Function                                                             Description
  --------                                                             -----------
  WidgetT *wgtImage(parent, data, w, h, pitch)                         Create from raw pixel data (in display's native format).
  WidgetT *wgtImageFromFile(parent, path)                              Create by loading an image file.
  void wgtImageSetData(w, data, imgW, imgH, pitch)                     Replace the displayed image with new raw pixel data.
  void wgtImageLoadFile(w, path)                                       Replace by loading a new file. Static but exposed via the API struct.
  void wgtImageSetTransparent(w, hasTransparency, keyColor)            Set chroma-key color. Pixels matching keyColor are not drawn.
.endtable

.h3 API Struct (wgtRegisterApi "image")

.table
  Slot             Function
  ----             --------
  create           wgtImage
  fromFile         wgtImageFromFile
  setData          wgtImageSetData
  loadFile         wgtImageLoadFile
  setTransparent   wgtImageSetTransparent
.endtable

.h3 Properties (BASIC Interface)

.table
  Property      Type       Access       Description
  --------      ----       ------       -----------
  Picture       String     Read/Write   Setting writes a file path (loads image). Reading returns the current path.
  Stretch       Boolean    Read/Write   When true, the image stretches to fill the widget; when false, shown at natural size.
  ImageWidth    Integer    Read-only    Width of the currently loaded image in pixels.
  ImageHeight   Integer    Read-only    Height of the currently loaded image in pixels.
.endtable

.h3 Methods

No widget-specific BASIC methods. Setting Picture loads a new image.

.h3 Events

.table
  Callback     Description
  --------     -----------
  onClick      Fires when the image is clicked.
.endtable

.h3 Default Event

"Click" (VB basName: Image).
