mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 19:42:17 +02:00
ZLTextHighlighting.getBackgroundColor()
This commit is contained in:
parent
18b720ba65
commit
0e8ea71169
6 changed files with 39 additions and 20 deletions
|
@ -389,12 +389,12 @@ public final class FBView extends ZLTextView {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ZLColor getSelectedBackgroundColor() {
|
public ZLColor getSelectionBackgroundColor() {
|
||||||
return myReader.getColorProfile().SelectionBackgroundOption.getValue();
|
return myReader.getColorProfile().SelectionBackgroundOption.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ZLColor getSelectedForegroundColor() {
|
public ZLColor getSelectionForegroundColor() {
|
||||||
return myReader.getColorProfile().SelectionForegroundOption.getValue();
|
return myReader.getColorProfile().SelectionForegroundOption.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,7 +415,7 @@ public final class FBView extends ZLTextView {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ZLColor getHighlightingColor() {
|
public ZLColor getHighlightingBackgroundColor() {
|
||||||
return myReader.getColorProfile().HighlightingOption.getValue();
|
return myReader.getColorProfile().HighlightingOption.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package org.geometerplus.zlibrary.text.view;
|
package org.geometerplus.zlibrary.text.view;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.util.ZLColor;
|
||||||
|
|
||||||
interface ZLTextHighlighting {
|
interface ZLTextHighlighting {
|
||||||
boolean clear();
|
boolean clear();
|
||||||
|
|
||||||
|
@ -27,4 +29,6 @@ interface ZLTextHighlighting {
|
||||||
ZLTextPosition getEndPosition();
|
ZLTextPosition getEndPosition();
|
||||||
ZLTextElementArea getStartArea(ZLTextPage page);
|
ZLTextElementArea getStartArea(ZLTextPage page);
|
||||||
ZLTextElementArea getEndArea(ZLTextPage page);
|
ZLTextElementArea getEndArea(ZLTextPage page);
|
||||||
|
|
||||||
|
ZLColor getBackgroundColor();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,17 @@
|
||||||
|
|
||||||
package org.geometerplus.zlibrary.text.view;
|
package org.geometerplus.zlibrary.text.view;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.util.ZLColor;
|
||||||
|
|
||||||
class ZLTextManualHighlighting implements ZLTextHighlighting {
|
class ZLTextManualHighlighting implements ZLTextHighlighting {
|
||||||
|
private final ZLTextView myView;
|
||||||
private ZLTextPosition myStartPosition;
|
private ZLTextPosition myStartPosition;
|
||||||
private ZLTextPosition myEndPosition;
|
private ZLTextPosition myEndPosition;
|
||||||
|
|
||||||
|
ZLTextManualHighlighting(ZLTextView view) {
|
||||||
|
myView = view;
|
||||||
|
}
|
||||||
|
|
||||||
void setup(ZLTextPosition start, ZLTextPosition end) {
|
void setup(ZLTextPosition start, ZLTextPosition end) {
|
||||||
myStartPosition = new ZLTextFixedPosition(start);
|
myStartPosition = new ZLTextFixedPosition(start);
|
||||||
myEndPosition = new ZLTextFixedPosition(end);
|
myEndPosition = new ZLTextFixedPosition(end);
|
||||||
|
@ -56,4 +63,8 @@ class ZLTextManualHighlighting implements ZLTextHighlighting {
|
||||||
public ZLTextElementArea getEndArea(ZLTextPage page) {
|
public ZLTextElementArea getEndArea(ZLTextPage page) {
|
||||||
return page.TextElementMap.getLastBefore(myEndPosition);
|
return page.TextElementMap.getLastBefore(myEndPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ZLColor getBackgroundColor() {
|
||||||
|
return myView.getHighlightingBackgroundColor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package org.geometerplus.zlibrary.text.view;
|
package org.geometerplus.zlibrary.text.view;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.util.ZLColor;
|
||||||
|
|
||||||
class ZLTextSelection implements ZLTextHighlighting {
|
class ZLTextSelection implements ZLTextHighlighting {
|
||||||
static class Point {
|
static class Point {
|
||||||
int X;
|
int X;
|
||||||
|
@ -261,6 +263,10 @@ class ZLTextSelection implements ZLTextHighlighting {
|
||||||
return cmp > 0 || (cmp == 0 && !lastPageArea.isLastInElement());
|
return cmp > 0 || (cmp == 0 && !lastPageArea.isLastInElement());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ZLColor getBackgroundColor() {
|
||||||
|
return myView.getSelectionBackgroundColor();
|
||||||
|
}
|
||||||
|
|
||||||
private class Scroller implements Runnable {
|
private class Scroller implements Runnable {
|
||||||
private final ZLTextPage myPage;
|
private final ZLTextPage myPage;
|
||||||
private final boolean myScrollForward;
|
private final boolean myScrollForward;
|
||||||
|
|
|
@ -60,13 +60,11 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
private ZLTextRegion.Soul mySelectedRegionSoul;
|
private ZLTextRegion.Soul mySelectedRegionSoul;
|
||||||
private boolean myHighlightSelectedRegion = true;
|
private boolean myHighlightSelectedRegion = true;
|
||||||
|
|
||||||
private ZLTextSelection mySelection;
|
private final ZLTextSelection mySelection = new ZLTextSelection(this);
|
||||||
private ZLTextManualHighlighting myHighlighting;
|
private final ZLTextManualHighlighting myHighlighting = new ZLTextManualHighlighting(this);
|
||||||
|
|
||||||
public ZLTextView(ZLApplication application) {
|
public ZLTextView(ZLApplication application) {
|
||||||
super(application);
|
super(application);
|
||||||
mySelection = new ZLTextSelection(this);
|
|
||||||
myHighlighting = new ZLTextManualHighlighting();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void setModel(ZLTextModel model) {
|
public synchronized void setModel(ZLTextModel model) {
|
||||||
|
@ -743,14 +741,14 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawBackgroung(
|
private void drawBackgroung(
|
||||||
ZLTextHighlighting highligting, ZLColor color,
|
ZLTextHighlighting highlighting,
|
||||||
ZLTextPage page, ZLTextLineInfo info, int from, int to, int x, int y
|
ZLTextPage page, ZLTextLineInfo info, int from, int to, int x, int y
|
||||||
) {
|
) {
|
||||||
if (!highligting.isEmpty() && from != to) {
|
if (!highlighting.isEmpty() && from != to) {
|
||||||
final ZLTextElementArea fromArea = page.TextElementMap.get(from);
|
final ZLTextElementArea fromArea = page.TextElementMap.get(from);
|
||||||
final ZLTextElementArea toArea = page.TextElementMap.get(to - 1);
|
final ZLTextElementArea toArea = page.TextElementMap.get(to - 1);
|
||||||
final ZLTextElementArea selectionStartArea = highligting.getStartArea(page);
|
final ZLTextElementArea selectionStartArea = highlighting.getStartArea(page);
|
||||||
final ZLTextElementArea selectionEndArea = highligting.getEndArea(page);
|
final ZLTextElementArea selectionEndArea = highlighting.getEndArea(page);
|
||||||
if (selectionStartArea != null
|
if (selectionStartArea != null
|
||||||
&& selectionEndArea != null
|
&& selectionEndArea != null
|
||||||
&& selectionStartArea.compareTo(toArea) <= 0
|
&& selectionStartArea.compareTo(toArea) <= 0
|
||||||
|
@ -768,7 +766,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
} else {
|
} else {
|
||||||
right = selectionEndArea.XEnd;
|
right = selectionEndArea.XEnd;
|
||||||
}
|
}
|
||||||
getContext().setFillColor(color);
|
getContext().setFillColor(highlighting.getBackgroundColor());
|
||||||
getContext().fillRectangle(left, top, right, bottom);
|
getContext().fillRectangle(left, top, right, bottom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -776,8 +774,8 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
|
|
||||||
private static final char[] SPACE = new char[] { ' ' };
|
private static final char[] SPACE = new char[] { ' ' };
|
||||||
private void drawTextLine(ZLTextPage page, ZLTextLineInfo info, int from, int to, int x, int y) {
|
private void drawTextLine(ZLTextPage page, ZLTextLineInfo info, int from, int to, int x, int y) {
|
||||||
drawBackgroung(mySelection, getSelectedBackgroundColor(), page, info, from, to, x, y);
|
drawBackgroung(mySelection, page, info, from, to, x, y);
|
||||||
drawBackgroung(myHighlighting, getHighlightingColor(), page, info, from, to, x, y);
|
drawBackgroung(myHighlighting, page, info, from, to, x, y);
|
||||||
|
|
||||||
final ZLPaintContext context = getContext();
|
final ZLPaintContext context = getContext();
|
||||||
final ZLTextParagraphCursor paragraph = info.ParagraphCursor;
|
final ZLTextParagraphCursor paragraph = info.ParagraphCursor;
|
||||||
|
@ -798,7 +796,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
drawWord(
|
drawWord(
|
||||||
areaX, areaY, (ZLTextWord)element, charIndex, -1, false,
|
areaX, areaY, (ZLTextWord)element, charIndex, -1, false,
|
||||||
mySelection.isAreaSelected(area)
|
mySelection.isAreaSelected(area)
|
||||||
? getSelectedForegroundColor() : getTextColor(getTextStyle().Hyperlink)
|
? getSelectionForegroundColor() : getTextColor(getTextStyle().Hyperlink)
|
||||||
);
|
);
|
||||||
} else if (element instanceof ZLTextImageElement) {
|
} else if (element instanceof ZLTextImageElement) {
|
||||||
final ZLTextImageElement imageElement = (ZLTextImageElement)element;
|
final ZLTextImageElement imageElement = (ZLTextImageElement)element;
|
||||||
|
@ -836,7 +834,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
area.XStart, area.YEnd - context.getDescent() - getTextStyle().getVerticalShift(),
|
area.XStart, area.YEnd - context.getDescent() - getTextStyle().getVerticalShift(),
|
||||||
word, start, len, area.AddHyphenationSign,
|
word, start, len, area.AddHyphenationSign,
|
||||||
mySelection.isAreaSelected(area)
|
mySelection.isAreaSelected(area)
|
||||||
? getSelectedForegroundColor() : getTextColor(getTextStyle().Hyperlink)
|
? getSelectionForegroundColor() : getTextColor(getTextStyle().Hyperlink)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,10 +88,10 @@ abstract class ZLTextViewBase extends ZLView {
|
||||||
public abstract ZLFile getWallpaperFile();
|
public abstract ZLFile getWallpaperFile();
|
||||||
public abstract ZLPaintContext.WallpaperMode getWallpaperMode();
|
public abstract ZLPaintContext.WallpaperMode getWallpaperMode();
|
||||||
public abstract ZLColor getBackgroundColor();
|
public abstract ZLColor getBackgroundColor();
|
||||||
public abstract ZLColor getSelectedBackgroundColor();
|
public abstract ZLColor getSelectionBackgroundColor();
|
||||||
public abstract ZLColor getSelectedForegroundColor();
|
public abstract ZLColor getSelectionForegroundColor();
|
||||||
|
public abstract ZLColor getHighlightingBackgroundColor();
|
||||||
public abstract ZLColor getTextColor(ZLTextHyperlink hyperlink);
|
public abstract ZLColor getTextColor(ZLTextHyperlink hyperlink);
|
||||||
public abstract ZLColor getHighlightingColor();
|
|
||||||
|
|
||||||
ZLPaintContext.Size getTextAreaSize() {
|
ZLPaintContext.Size getTextAreaSize() {
|
||||||
return new ZLPaintContext.Size(getTextColumnWidth(), getTextAreaHeight());
|
return new ZLPaintContext.Size(getTextColumnWidth(), getTextAreaHeight());
|
||||||
|
@ -319,7 +319,7 @@ abstract class ZLTextViewBase extends ZLView {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (markStart < length) {
|
if (markStart < length) {
|
||||||
context.setFillColor(getHighlightingColor());
|
context.setFillColor(getHighlightingBackgroundColor());
|
||||||
int endPos = Math.min(markStart + markLen, length);
|
int endPos = Math.min(markStart + markLen, length);
|
||||||
final int endX = x + context.getStringWidth(str, offset + markStart, endPos - markStart);
|
final int endX = x + context.getStringWidth(str, offset + markStart, endPos - markStart);
|
||||||
context.fillRectangle(x, y - context.getStringHeight(), endX - 1, y + context.getDescent());
|
context.fillRectangle(x, y - context.getStringHeight(), endX - 1, y + context.getDescent());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue