13
$\begingroup$

The current colour in a Graphics object can be retrieved using CurrentValue["Color"] for use in Dynamic stuff.

Example:

Graphics[
 {RGBColor[2/3, 1/3, 2/3],
  Dynamic[{If[CurrentValue["MouseOver"], 
     Darker@CurrentValue["Color"]], Disk[]}]
  }]

How can I retrieve the current FaceForm colour?

Graphics[
 {FaceForm[RGBColor[2/3, 1/3, 2/3]], EdgeForm[Black],
  Dynamic[{
     If[CurrentValue["MouseOver"], 
        Darker@CurrentValue[(* what do I write here? *)]], 
     Disk[]}]
  }]
$\endgroup$
  • 1
    $\begingroup$ @Kuba Here is a nice use of CurrentValue["Color"] if you have not seen it before. $\endgroup$ – Mr.Wizard Jun 27 '15 at 13:48
  • 1
    $\begingroup$ @Kuba It's not at all academic. I have a plotting function that plots some sort of "map", with the colours for each map area coming from the user. At some point I found a need to highlight each area on hover, preferably while still keeping the shade of its colour. Having access to the current colour value simplifies the code a lot because I don't need to re-build the whole map from the source data to add highlighting, I can just modify it. In other words, it's not necessary to store the colours separately, they can just be a natural part of the Graphics object. $\endgroup$ – Szabolcs Jun 27 '15 at 14:27
  • $\begingroup$ @Kuba What did you mean then? $\endgroup$ – Mr.Wizard Jun 27 '15 at 15:24
  • $\begingroup$ @Kuba Like this :-). I was using tooltips to identify which area was which, but it turns out that sometimes the pointer location is inaccurate. So I needed confirmation to know that I was indeed hovering the area I thought I was hovering. $\endgroup$ – Szabolcs Jun 27 '15 at 15:25
  • $\begingroup$ @Mr.Wizard Maybe I was too picky but OP example just asks about this approach. Moreover, I'm a little bit of pejudiced about styles/events inheritance as I faced couple of "exceptions" with events handlers. That's why I'm usually starting with brute force approach in such cases :) $\endgroup$ – Kuba Jun 27 '15 at 15:30
11
$\begingroup$

I believe you want "FrontFaceColor" which can be found as a specification in this list:

Graphics[{FaceForm[RGBColor[2/3, 1/3, 2/3]], EdgeForm[Black], 
  Dynamic[{If[CurrentValue["MouseOver"], Darker @ CurrentValue["FrontFaceColor"]], 
    Disk[]}]}]

enter image description hereenter image description here

You may also find "FrontFaceOpacity" of use.


Simply guessing I found that "BackFaceColor" is also valid, e.g.:

Graphics3D[
 {FaceForm[Yellow, Blue],
  Dynamic[{If[CurrentValue["MouseOver"], CurrentValue["BackFaceColor"]], Cuboid[]}]
 },
 PlotRange -> {{-1/4, 5/4}, {1/4, 5/4}, {-1/4, 5/4}}
]

enter image description hereenter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ And there's also EdgeColor. Excellent! Thank you, this'll simplify my code significantly. $\endgroup$ – Szabolcs Jun 27 '15 at 14:24
  • $\begingroup$ @Szabolcs You're welcome. I would appreciate your vote on this if I do not have it already; there's lots of great stuff in there just waiting to be applied! $\endgroup$ – Mr.Wizard Jun 27 '15 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.