ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 How to draw rating stars?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

skippix

USA
68 Posts

Posted - Feb 15 2021 :  19:04:27  Show Profile  Reply
I have a table with filenames and rating 0-5. I can load the TImageEnMView from the table, but I'd like to mimic this to show the stars.



Any suggestions, code snippets, or examples would be greatly appreciated!

Skip

xequte

38693 Posts

Posted - Feb 16 2021 :  15:55:45  Show Profile  Reply
Hi Skip

Well the easiest way would be to use a star character (e.g. U+2605):

https://unicode-search.net/unicode-namesearch.pl?term=STAR

Then you can just specify it for the bottom text.

Otherwise you would need to custom draw it using:

http://www.imageen.com/help/TImageEnMView.OnImageDraw2.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

skippix

USA
68 Posts

Posted - Feb 25 2021 :  09:21:05  Show Profile  Reply
Thanks, Nigel!

I've got something working that will do until I have more time to go deeper.

I kinda used the first method. I could not figure out how to code for "U+2605" and all I could find on the internet was really deep, involved coding. I ended up copying and pasting the star into my unit as a constant (const _star = '#9733;';) and saving the unit with UTF8 encoding.

In my grid load, I use the following

  x := TheGrid.AppendImage;
  TheGrid.ImageFileName[x] := sl[i];
  if (sbtnToggleRatingMode.Down) and (ckbShowImageRatingOnGrid.Checked) then
    begin
      ia.FileName := ExtractFileName(sl[i]);
      TheGrid.ImageTopText[x] := ia.SeqNo;
      TheGrid.ImageBottomText[x] := GetFileStars(sl[i]);
    end;

function TfrmAssetCurator.GetFileStars (sFile: String): String;
var cds: TClientDataSet;
  ia: TImageAsset;
begin
  cds := FRollData.FetchCDS ('FlagAndTag');
  ia := TImageAsset.Create(sFile);
  with cds do
    begin
      Filter := 'filename=' + QuotedStr(ia.MasterName);
      Filtered := True;
      Result := ShowStars (FieldByName('rating').AsString);
      Filtered := False;
    end;
  FreeAndNil(ia);
end;

function TfrmAssetCurator.ShowStars (sIn: String): String;
var z: Integer;
  i: Integer;
begin
  Result := '';
  if (sIn = '') or (sIn = '0') then
    begin
      Exit;
    end
  else
    begin
      i := StrtoInt(sIn);
      for z := 1 to i do
        begin
          Result := Result + _star;
        end;
    end;
end;


Here's a screenshot of the result


Cheers, and thanks again,
Skip
Go to Top of Page

xequte

38693 Posts

Posted - Feb 25 2021 :  15:34:48  Show Profile  Reply
Nice work, Skip. It looks really good.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: