/*
    ####             #    #     # #
    #   #            #    #       #          The FreeWare C library for 
    #   #  ##   ###  #  # #     # ###             RISC OS machines
    #   # #  # #     # #  #     # #  #   ___________________________________
    #   # ####  ###  ##   #     # #  #                                      
    #   # #        # # #  #     # #  #    Please refer to the accompanying
    ####   ### ####  #  # ##### # ###    documentation for conditions of use
    ________________________________________________________________________

    File:    Icon.GetFgCol.c
    Author:  Copyright  1994 Tim Browse
    Version: 1.00 (05 Mar 1994)
    Purpose: Retrieve the foreground colour of an icon.
*/

#include "Desk.Wimp.h"
#include "Desk.WimpSWIs.h"
#include "Desk.Icon.h"
#include "Desk.Validation.h"
#include "Desk.Str.h"


int Desk_Icon_GetFgCol(const Desk_icon_block *icon)
{
  int colour;

  /* Straightforward case first...*/
  if (!icon->flags.data.font)
    return icon->flags.data.foreground;
  
  /* Icon is anti-aliased - read font validation string colours */
  colour = Desk_Validation_ScanString(icon->data.indirecttext.validstring, 
                                 Desk_iconvalid_FONTCOLOURS);

  /* No colours specified - use default */
  if (colour == 0)
    return Desk_colour_BLACK;
  
  /* Decode second colour digit */
  colour = Desk_Str_DecodeHex(icon->data.indirecttext.validstring[colour+1]);

  /* Limit to legal value */
  if (colour == -1)
    colour = Desk_colour_BLACK;

  return colour;
}

