1

I am having to write my own mouse-over code for a particular control in a C++/VCL application. The question is, given ANY combination of foreground and background colors, how do you calculate a highlight color to indicate that the mouse is over that control?

I've found the articles on how to convert RGB to HSL and adjust the lightness (references: how to highlight a given color in c sharp and algorithm to switch between rgb and hsb color values), so I've got the math part. It's the determination of what to do when, say, the text color is already white. Or if the user is using black on white, lightening the black makes it grey on white, and very hard to read.

I was thinking I probably want to do something like take the background color, find its opposite on the color wheel (and I have no idea how to do that). If that color is too close (however you determine that) to the text color, make it lighter or darker.

Does anyone have an algorithm they are willing to share?

Thanks!

Edit: This question was marked as a duplicate of Determine font color based on background color. That solution chooses either black or white as a font color given a background color. I want to go one step further and choose a third color as a highlight when the mouse is over that text. Thanks!

Community
  • 1
  • 1
Karen Cate
  • 272
  • 3
  • 15
  • 1
    I disagree that this is duplicate. Please open the question again. – Philipp Dec 29 '15 at 21:46
  • Flip foreground with background. No calculation, never fails. – Amit Dec 29 '15 at 22:40
  • I agree that this is not a duplicate of "Determine font color based on background color". The result of that function will be either black or white, which is not at all what I'm looking for. Amit, I am currently flipping the foreground and background colors, and it's just not the modern style we are trying to create. – Karen Cate Dec 30 '15 at 00:55

0 Answers0