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
 TIEColorPalette suggestion
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

859 Posts

Posted - Sep 15 2017 :  14:34:12  Show Profile  Reply
Hello,

I need the TIEColorPalette control to select a Foreground color and a Background color:



For this purpose, I need to LEFT-click on a cell to select the Foreground color (mark the cell with "F") and to RIGHT-click on a cell to select the background color (mark the cell with "B").

Is this possible?

This could be easily achieved with this code:

procedure TformMain.IEColorPalette1CellClick(Button: TMouseButton; 
    Shift: TShiftState; Index: Integer; aColor: TColor; 
    var Allow: Boolean; var CellChar: Char);
begin
  if Button = mbLeft then
    CellChar := 'F' 
  else if Button = mbRight then
    CellChar := 'B'
  else
    CellChar := '';
end;

w2m

USA
1990 Posts

Posted - Sep 15 2017 :  16:53:48  Show Profile  Reply
I tried to create a demo to achieve this by getting the TShiftState (ieLeft or ieRight) in OnNMouseDown, then draw the 'F'or 'B' on the selected cell's canvas depending on the TShiftState and then set a global var AForgroundColor or ABackgroundColor value.

Unfortunately, the IEColorPalette1PaintCell event used to draw on the canvas is executed before the cell colors are drawn, so I was not successful. I could draw the text but it is over written by the cells color rect. You could probably draw your own cells first by setting Handled parameter to True and then draw the cell colors and then the text ('F' or 'B') on the canvas, but I did not want to take the time to do that much work.

It seems like there should be another event (eg. OnPaintCellText) that occurs after IEColorPalette1PaintCell to draw the text on the canvas. If possible the new event should also provide a parameter that indicates which button was pressed so a Foreground and background color could be set.

I am not sure if the ImageEn folks want to extend the component to allow selecting two colors but that would probably be the best route to go, otherwise you need to use multiple events OnMouseDown, OnPaintCell and the new event OnPaintCellText to draw the cells, text and to set the two color values.

This is a bit farther than I want to go.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

xequte

38172 Posts

Posted - Sep 17 2017 :  21:05:28  Show Profile  Reply
Hi

I have added OnAfterPaintCell. Email me if you want a pre-release.


// Draw an "F" on the foreground color, and a "B" on background color
procedure TMainForm.IEColorPalette1AfterPaintCell(ACanvas: TCanvas; CellRect: TRect;
    aColor: TColor; Index: Integer; aState: TIEColorCellState; var aStyle:
    TIETransparentStyle; var Handled: Boolean);
var
  cellChar: string;
begin
  cellChar := '';
  if aColor = fForegroundColor then
    cellChar := 'F'
  else
  if aColor = fBackgroundColor then
    cellChar := 'B';

  if cellChar <> '' then
  begin
    ACanvas.Brush.Style := bsClear;
    ACanvas.Font.Style := [ fsBold ];

    // Draw text in center of cell
    ACanvas.TextOut( CellRect.Left + ( CellRect.Right - CellRect.Left ) div 2 - ACanvas.TextWidth( cellChar ) div 2,
                     CellRect.Top + ( CellRect.Bottom - CellRect.Top ) div 2 - ACanvas.TextHeight( cellChar ) div 2,
                     cellChar );
  end;
end;


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

PeterPanino

859 Posts

Posted - Sep 18 2017 :  07:12:31  Show Profile  Reply
Nigel,

thank you very much!

How can the cellChar color be controlled, i.e. making it bright in a dark cell color and making it dark in a bright cell color?
Go to Top of Page

xequte

38172 Posts

Posted - Sep 19 2017 :  19:38:06  Show Profile  Reply
Hi Peter

Bill's suggestion in the other post looks good:

https://www.imageen.com/ieforum/topic.asp?TOPIC_ID=3235

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