Commit 01ba03fd authored by Daniel Dreibrodt's avatar Daniel Dreibrodt

More slider editing work (far from finished)

parent 9987497f
......@@ -23,7 +23,15 @@
package vlcskineditor;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
......@@ -138,4 +146,22 @@ public class Helper {
}
}
/**
* Creates a new image cursor
* @param imageFileName The path to the image resource, relative to the main class location
* @param x The x-coordinate of the hot spot
* @param y The y-coordinate of the hot spot
* @param com The Component in which the cursor will be used
* @return The cursor
*/
public static Cursor createImageCursor(String imageFileName, int x, int y, Component com) {
Toolkit tk = Toolkit.getDefaultToolkit();
Image src = tk.createImage(Main.class.getResource(imageFileName));
/*Dimension d = tk.getBestCursorSize(src.getWidth(null), src.getHeight(null));
BufferedImage c = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = c.createGraphics();
g.drawImage(src, 0, 0, com);*/
return tk.createCustomCursor(src, new Point(x,y), imageFileName);
}
}
......@@ -1882,7 +1882,6 @@ public class Main extends JFrame implements ActionListener, TreeSelectionListene
java.awt.Image img = null;
try {
img = Toolkit.getDefaultToolkit().createImage(Main.class.getResource(filename));
//img = ImageIO.read(file);
return new ImageIcon(img);
} catch (Exception ex) {
ex.printStackTrace();
......
......@@ -29,6 +29,7 @@ import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.*;
import vlcskineditor.history.*;
import vlcskineditor.items.Slider;
/**
......@@ -66,6 +67,8 @@ public class PreviewWindow extends JPanel implements MouseListener, MouseMotionL
/** The main program */
private Main m;
private Cursor move_normal_c, path_normal_c, path_active_c, path_add_c, path_del_c;
/** The cursor mode constant indicating that the cursor should move the selected item */
public static final int CURSOR_MOVE = 1;
/** The cursor mode constant indicating that the cursor should edit the path of the selected item */
......@@ -101,7 +104,13 @@ public class PreviewWindow extends JPanel implements MouseListener, MouseMotionL
frame.setResizable(true);
frame.setFrameIcon(Main.preview_icon);
addMouseListener(this);
addMouseMotionListener(this);
addMouseMotionListener(this);
move_normal_c = new Cursor(Cursor.MOVE_CURSOR);
path_normal_c = Helper.createImageCursor("icons/path_cursor.gif", 4, 0, this);
path_active_c = Helper.createImageCursor("icons/path_cursor_active.gif", 4, 0, this);
path_add_c = Helper.createImageCursor("icons/path_cursor_add.gif", 4, 0, this);
path_del_c = Helper.createImageCursor("icons/path_cursor_del.gif", 4, 0, this);
}
/**
* Is invoked when the user deselects a layout.
......@@ -199,7 +208,7 @@ public class PreviewWindow extends JPanel implements MouseListener, MouseMotionL
}
public void mouseClicked(MouseEvent e) {
if(mode==CURSOR_PATH) {
//TODO path editing mouseClicked
}
}
public void mouseDragged(MouseEvent e) {
......@@ -223,12 +232,12 @@ public class PreviewWindow extends JPanel implements MouseListener, MouseMotionL
}
public void mouseEntered(MouseEvent e) {
if(mode==CURSOR_PATH) {
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
setCursor(path_normal_c);
}
}
public void mouseExited(MouseEvent e) {
if(mode==CURSOR_PATH) {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
setCursor(Cursor.getDefaultCursor());
}
}
public void mouseMoved(MouseEvent e) {
......@@ -236,14 +245,38 @@ public class PreviewWindow extends JPanel implements MouseListener, MouseMotionL
if(mode==CURSOR_MOVE) {
if(selected_item.contains(e.getX()/z,e.getY()/z)) {
selected_item.setHover(true);
setCursor(new Cursor(Cursor.MOVE_CURSOR));
setCursor(move_normal_c);
}
else {
selected_item.setHover(false);
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
setCursor(Cursor.getDefaultCursor());
}
} else {
//TODO path editing mouseMoved
if(selected_item.getClass().equals(Slider.class)) {
Slider s = (Slider)selected_item;
int mx = e.getX()/z-s.offsetx-s.x;
int my = e.getY()/z-s.offsety-s.y;
int over = -1;
for(int i=0; i<s.getControlPointNum(); i++) {
int dx = Math.abs(mx-s.getControlX(i));
int dy = Math.abs(my-s.getControlY(i));
if(dx<2 && dy<2) over = i;
}
if(over!=-1) {
if(e.isAltDown()) {
setCursor(path_del_c);
} else {
setCursor(path_active_c);
}
} else {
if(e.isShiftDown()) {
setCursor(path_add_c);
} else {
setCursor(path_normal_c);
}
}
//System.out.println(getCursor().getName());
}
}
}
public void mousePressed(MouseEvent e) {
......
......@@ -168,6 +168,7 @@ public class Skin implements ActionListener{
* @param f The file that should be parsed
* @throws java.lang.Exception
*/
@Deprecated
private void parse(File f) throws Exception {
//System.out.println("Creating Buffered Reader...");
BufferedReader br = new BufferedReader(new FileReader(f));
......@@ -614,6 +615,7 @@ public class Skin implements ActionListener{
* @param id The id of the Bitmap resource
* @return the BufferedImage represented by the resource looked for
*/
@Deprecated
public BufferedImage getBitmapImage(String id) {
Resource r = getResource(id);
if(r==null) {
......
......@@ -42,6 +42,7 @@ public class XML {
* @param field The name of the attribute whose value is to be retrieved
* @return The attribute's value
*/
@Deprecated
public static String getValue(String line, String field) {
int value_start = line.indexOf(" "+field+"=\"") + field.length() +3;
int value_end = line.indexOf("\"",value_start);
......@@ -55,6 +56,7 @@ public class XML {
* @param field
* @return Integer value of the attribute
*/
@Deprecated
public static int getIntValue(String line, String field) {
int i = 0;
try {
......@@ -73,6 +75,7 @@ public class XML {
* @param field
* @return Boolean value of the attribute
*/
@Deprecated
public static boolean getBoolValue(String line, String field) {
boolean b = false;
try {
......
......@@ -66,8 +66,8 @@ public class Slider extends Item implements ActionListener{
ImageResource up_res, over_res, down_res;
Bezier b;
int[] xpos,ypos;
private Bezier b;
private int[] xpos,ypos;
private Point2D.Float sliderPos;
private Point2D.Float[] bezierPoints;
......@@ -207,6 +207,7 @@ public class Slider extends Item implements ActionListener{
}
created=true;
}
public Slider(Skin s_) {
s = s_;
up = "none";
......@@ -216,6 +217,7 @@ public class Slider extends Item implements ActionListener{
s.updateItems();
s.expandItem(id);
}
public Slider(Skin s_, boolean ipt) {
s = s_;
up = "none";
......@@ -223,6 +225,7 @@ public class Slider extends Item implements ActionListener{
inPlaytree = ipt;
created=true;
}
public void updateBezier() {
String[] pnts = points.split("\\),\\(");
xpos = new int[pnts.length];
......@@ -240,6 +243,7 @@ public class Slider extends Item implements ActionListener{
bezierPoints[(int)(f/10)] = b.getPoint(f/100);
}
}
@Override
public void update() {
if(!created) {
......@@ -302,6 +306,7 @@ public class Slider extends Item implements ActionListener{
}
updateToGlobalVariables();
}
@Override
public void showOptions() {
if(frame==null) {
......@@ -629,6 +634,7 @@ public class Slider extends Item implements ActionListener{
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(ok_btn)) {
......@@ -698,12 +704,14 @@ public class Slider extends Item implements ActionListener{
frame = null;
}
}
public void removeBG() {
if(sbg==null) return;
sbg = null;
sbg_chb.setSelected(false);
sbg_btn.setEnabled(false);
}
@Override
public String returnCode(String indent) {
String code = indent+"<Slider";
......@@ -732,10 +740,12 @@ public class Slider extends Item implements ActionListener{
}
return code;
}
@Override
public void draw(Graphics2D g, int z) {
draw(g,0,0,z);
}
@Override
public void draw(Graphics2D g, int x_, int y_, int z) {
if(!created) return;
......@@ -760,24 +770,27 @@ public class Slider extends Item implements ActionListener{
Point2D.Float p2 = bezierPoints[i+1];
g.drawLine((int)(p1.getX()+x+x_)*z,(int)(p1.getY()+y+y_)*z,(int)(p2.getX()+x+x_)*z,(int)(p2.getY()+y+y_)*z);
}
g.setColor(Color.ORANGE);
g.setColor(Color.YELLOW);
for(int i=0;i<xpos.length;i++) {
g.fillOval((xpos[i]+x+x_-1)*z,(ypos[i]+y+y_-1)*z,3,3);
}
}
}
@Override
public boolean contains(int x_,int y_) {
int h = b.getHeight();
int w = b.getWidth();
return (x_>=x+offsetx && x_<=x+offsetx+w && y_>=y+offsety && y_<=y+offsety+h);
}
@Override
public DefaultMutableTreeNode getTreeNode() {
DefaultMutableTreeNode node = new DefaultMutableTreeNode("Slider: "+id);
if(sbg!=null) node.add(sbg.getTreeNode());
return node;
}
@Override
public Item getItem(String id_) {
if(id.equals(id_)) return this;
......@@ -785,6 +798,7 @@ public class Slider extends Item implements ActionListener{
else if(sbg.id.equals(id_)) return sbg;
else return null;
}
@Override
public Item getParentOf(String id_) {
if(sbg!=null) {
......@@ -793,16 +807,19 @@ public class Slider extends Item implements ActionListener{
}
else return null;
}
@Override
public boolean uses(String id_) {
return(((sbg!=null)?sbg.uses(id_):false)||up.equals(id_)||over.equals(id_)||down.equals(id_));
}
@Override
public void renameForCopy(String p) {
String p_ = p;
super.renameForCopy(p);
if(sbg!=null) sbg.renameForCopy(p_);
}
@Override
public void updateToGlobalVariables() {
vis = s.gvars.parseBoolean(visible);
......@@ -822,4 +839,19 @@ public class Slider extends Item implements ActionListener{
if(down.equals(oldid)) down = newid;
}
public Bezier getBezier() {
return b;
}
public int getControlX(int index) {
return xpos[index];
}
public int getControlY(int index) {
return ypos[index];
}
public int getControlPointNum() {
return xpos.length;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment