Recent

Author Topic: Get BkColor at cursor  (Read 4402 times)

AndyJonson

  • New Member
  • *
  • Posts: 10
Get BkColor at cursor
« on: April 13, 2017, 04:49:51 pm »
How can I get background color at cursor(or any) postion?

Example:

//select some text and press:
procedure TForm1.Button1Click(Sender: TObject);
var
  fp: TFontParams;
begin
  RichMemo1.GetTextAttributes(RichMemo1.SelStart, fp);
  fp.BkColor := clYellow;
  fp.Color := clRed;
  fp.Style := [fsBold];
  RichMemo1.SetTextAttributes(RichMemo1.SelStart, RichMemo1.SelLength, fp);
end;

//then select some text in yellow back color and press:
procedure TForm1.Button2Click(Sender: TObject);
var
  fp: TFontParams;
  cl: TColor;
begin
  RichMemo1.GetTextAttributes(RichMemo1.SelStart, fp);
  //fp.BkColor := clYellow; // I want USE OLD! but... =empty! :(
  cl := fp.BkColor; //empty! :(
  fp.Color := clBlue;
  fp.Style := [fsBold];
  RichMemo1.SetTextAttributes(RichMemo1.SelStart, RichMemo1.SelLength, fp);
end;       

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2280
    • havefunsoft.com
Re: Get BkColor at cursor
« Reply #1 on: April 13, 2017, 05:09:17 pm »
Windows?
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

AndyJonson

  • New Member
  • *
  • Posts: 10
Re: Get BkColor at cursor
« Reply #2 on: April 13, 2017, 05:27:15 pm »
>> Windows?
Yes, but I want multi OS.
Not working in windows...

Zoran

  • Hero Member
  • *****
  • Posts: 1461
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Get BkColor at cursor
« Reply #3 on: April 13, 2017, 06:55:35 pm »
I don't know the answer, but I remember there was a nice small tool written in Lazarus which picks colours anywhere on the screen where you click, so I found the old topic:
http://forum.lazarus.freepascal.org/index.php/topic,12361.0.html

The application is multi-platform, you can download the sources and see how it is done there. Link: https://sourceforge.net/projects/cpicksniff2/

AndyJonson

  • New Member
  • *
  • Posts: 10
Re: Get BkColor at cursor
« Reply #4 on: April 13, 2017, 07:54:54 pm »
no... it not for RichMemo!

I write RTF-editor to quick set font color and back color to selected text by rules (todo+readme.txt => readme.rtf). And I need get current color (font and back) at cursor position and first char of every string...

If I use code from my fist message I can get all font params, without back color!

Many years ago I wrote this programm on Delphi, but it ditn't work on Win10. Now I want make same programm on Lazarus+RichMemo for Win10, Mac and Linux...

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2280
    • havefunsoft.com
Re: Get BkColor at cursor
« Reply #5 on: April 14, 2017, 07:28:32 am »
ok. I can confirm the issue for Windows.
It has been fixed in svn r5836, thus if you're using svn version - you can simply run an update get the fix. The night build should also be updated within the next 24 hours.

but, if you don't want to wait and not using svn, you can easily fix it your self.

open win32richmemoproc.pas (it's located at richmemo package folder under win32)
find the line
Code: Pascal  [Select]
  1.   if Params.HasBkClr then Params.Color:=Params.Color;
  2.  
(it should be line 332)
and replace it with the proper one:
Code: Pascal  [Select]
  1. if Params.HasBkClr then Params.BkColor:=fmt.crBackColor;
  2.  

that's it. It should fix the issue for you.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

AndyJonson

  • New Member
  • *
  • Posts: 10
Re: Get BkColor at cursor
« Reply #6 on: April 14, 2017, 01:46:20 pm »
How can I get new(fixed) version with svn/git?

Zoran

  • Hero Member
  • *****
  • Posts: 1461
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Get BkColor at cursor
« Reply #7 on: April 14, 2017, 03:30:52 pm »
no... it not for RichMemo!

I write RTF-editor to quick set font color and back color to selected text by rules (todo+readme.txt => readme.rtf). And I need get current color (font and back) at cursor position and first char of every string...

If I use code from my fist message I can get all font params, without back color!

Many years ago I wrote this programm on Delphi, but it ditn't work on Win10. Now I want make same programm on Lazarus+RichMemo for Win10, Mac and Linux...

Oh, Sorry, I didn't check which board this topic is in, so I misunderstood completely.  :-[

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2280
    • havefunsoft.com
Re: Get BkColor at cursor
« Reply #8 on: April 15, 2017, 05:54:31 pm »
How can I get new(fixed) version with svn/git?
you can either download a snapshot
(the snapshot includes the fix)

or run an svn command
Code: [Select]
svn co https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr/components/richmemo
if already have the source code checked out you should be able to simply do
Code: [Select]
svn update
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz