mrichards42/xword

Selecting a cell hides its background color/image

Opened this issue · 2 comments

When a cell with a background color or image is selected, the selection color takes full precedent over the background, hiding it completely. This can make it more challenging to solve these puzzles, especially in cases where the background is thematic rather than just for contrast.

Maybe it would work better to draw the selection color with some amount of transparency so background images still appear and so shaded squares are tinted differently and stand out a bit more.

Unfortunately, this looks like it might be a bit tricky. The obvious solution (to me at least) is to draw the highlight color with some transparency. This requires enabling XWORD_USE_GC and using wxGraphicsContext since the regular DC doesn't support transparency here. But this context seems significantly slower, at least on my machine + w/ alpha transparency, and lags behind my keyboard input somewhat. It's also tricky to get the colors to line up - for example, we want to draw the text with the same background color as the cell, but now that color is alpha blended, which means doing so will apply alpha a second time and won't match exactly. Maybe you could erase the rectangle from the selection first before drawing the text... but it gets messy.

I wonder if it might be feasible to do something like:

  • For background images, reorder the drawing so these are drawn above the background color, while keeping them below the outline. EDIT: I guess only works if the images are transparent, which almost certainly won't always be the case
  • For colors, if we're drawing a selected cell that already has its own background color, manually calculate a blended version of those colors and use that as the highlight instead.

Hmm, yeah that would be nice to fix. A number of thoughts come to mind as alternatives to transparency:

  • There's sort of an existing convention of drawing the highlight as a thick border in some cases (rebus, diagramless black squares). That might work, but it might also make it look too much like entering a rebus :)
  • Could do something like hatching, or a fine pattern overlay (like a bayer dithering matrix). Puzzleme uses very coarse hatching if you're playing a partner crossword and the two cursors intersect (it's a bit too aggressive IMO, but that's one way someone else is solving this problem).
  • The manually calculated background sounds promising and I'd guess covers the 80% case, which is a good start.

Maybe some combination where either a manually blended or simple pattern overlay is used for colored cells, and something else for images? Potentially even using GCDC to alpha blend images since there are probably fewer of those in a row?