2015-01-21 21:58:35 +01:00
|
|
|
/*******************************************************************************
|
2015-10-22 00:25:12 +02:00
|
|
|
* Copyright (c) 2015 MINRES Technologies GmbH and others.
|
2015-01-21 21:58:35 +01:00
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* MINRES Technologies GmbH - initial API and implementation
|
|
|
|
*******************************************************************************/
|
2015-01-25 14:23:34 +01:00
|
|
|
package com.minres.scviewer.database.swt.internal;
|
2015-01-21 21:58:35 +01:00
|
|
|
|
2015-10-29 20:02:08 +01:00
|
|
|
import org.eclipse.swt.graphics.Color;
|
2015-01-21 21:58:35 +01:00
|
|
|
import org.eclipse.swt.graphics.Rectangle;
|
|
|
|
|
2015-11-12 23:35:13 +01:00
|
|
|
import com.minres.scviewer.database.ui.ICursor;
|
|
|
|
import com.minres.scviewer.database.ui.WaveformColors;
|
|
|
|
|
|
|
|
public class CursorPainter implements IPainter, ICursor {
|
2015-10-29 20:02:08 +01:00
|
|
|
|
2015-01-21 21:58:35 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
private final WaveformCanvas waveCanvas;
|
2015-10-29 20:02:08 +01:00
|
|
|
|
2015-01-21 21:58:35 +01:00
|
|
|
private long time;
|
|
|
|
|
2015-07-10 13:40:50 +02:00
|
|
|
private boolean isDragging;
|
2015-10-29 20:02:08 +01:00
|
|
|
|
|
|
|
public final int id;
|
|
|
|
|
2019-03-17 20:03:22 +01:00
|
|
|
/// maximum visible canvas position in canvas coordinates
|
|
|
|
int maxPosX;
|
|
|
|
/// maximum visible position in waveform coordinates
|
|
|
|
int maxValX;
|
|
|
|
|
2015-01-21 21:58:35 +01:00
|
|
|
/**
|
|
|
|
* @param i
|
|
|
|
* @param txDisplay
|
|
|
|
*/
|
2015-10-29 20:02:08 +01:00
|
|
|
public CursorPainter(WaveformCanvas txDisplay, long time, int id) {
|
2015-01-21 21:58:35 +01:00
|
|
|
this.waveCanvas = txDisplay;
|
|
|
|
this.time=time;
|
2015-10-29 20:02:08 +01:00
|
|
|
this.id=id;
|
2015-01-21 21:58:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public long getTime() {
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTime(long time) {
|
|
|
|
this.time = time;
|
|
|
|
}
|
|
|
|
|
2015-07-10 13:40:50 +02:00
|
|
|
public boolean isDragging() {
|
2015-10-29 20:02:08 +01:00
|
|
|
return isDragging;
|
|
|
|
}
|
2015-07-10 13:40:50 +02:00
|
|
|
|
2015-10-29 20:02:08 +01:00
|
|
|
public void setDragging(boolean isDragging) {
|
|
|
|
this.isDragging = isDragging;
|
|
|
|
}
|
2015-07-10 13:40:50 +02:00
|
|
|
|
2019-03-17 20:03:22 +01:00
|
|
|
|
2020-06-20 17:58:26 +02:00
|
|
|
public void paintArea(Projection proj, Rectangle clientRect) {
|
|
|
|
Rectangle area = proj.unProject(clientRect);
|
2015-11-06 19:29:36 +01:00
|
|
|
if(this.waveCanvas.painterList.size()>0){
|
2019-03-17 20:03:22 +01:00
|
|
|
|
2015-10-29 20:02:08 +01:00
|
|
|
long scaleFactor=waveCanvas.getScaleFactor();
|
2019-03-17 20:03:22 +01:00
|
|
|
long beginPos = area.x;
|
|
|
|
|
|
|
|
maxPosX = area.x + area.width;
|
2020-06-20 17:58:26 +02:00
|
|
|
maxValX = maxPosX;
|
2019-03-17 20:03:22 +01:00
|
|
|
|
|
|
|
// x position of marker in pixels on canvas
|
2015-10-29 20:02:08 +01:00
|
|
|
int x = (int) (time/scaleFactor);
|
2019-03-17 20:03:22 +01:00
|
|
|
// distance of marker from the top of Canvas' painting area
|
2015-10-29 20:02:08 +01:00
|
|
|
int top = id<0?area.y:area.y+15;
|
2015-11-12 23:35:13 +01:00
|
|
|
Color drawColor=waveCanvas.colors[id<0?WaveformColors.CURSOR.ordinal():WaveformColors.MARKER.ordinal()];
|
|
|
|
Color dragColor = waveCanvas.colors[WaveformColors.CURSOR_DRAG.ordinal()];
|
|
|
|
Color textColor=waveCanvas.colors[id<0?WaveformColors.CURSOR_TEXT.ordinal():WaveformColors.MARKER_TEXT.ordinal()];
|
2019-03-17 20:03:22 +01:00
|
|
|
if(x>=beginPos && x<=maxValX){
|
2020-06-20 17:58:26 +02:00
|
|
|
proj.setForeground(isDragging?dragColor:drawColor);
|
|
|
|
proj.drawLine(x, top, x, area.y+area.height);
|
|
|
|
proj.setBackground(drawColor);
|
|
|
|
proj.setForeground(textColor);
|
2015-10-29 20:02:08 +01:00
|
|
|
Double dTime=new Double(time);
|
2020-06-20 17:58:26 +02:00
|
|
|
proj.drawText((dTime/waveCanvas.getScaleFactorPow10())+waveCanvas.getUnitStr(), x+1, top);
|
2015-01-21 21:58:35 +01:00
|
|
|
}
|
2015-10-29 20:02:08 +01:00
|
|
|
}
|
2019-03-17 20:03:22 +01:00
|
|
|
}
|
2015-01-21 21:58:35 +01:00
|
|
|
}
|