Commit 9898fae8 authored by Daniel Dreibrodt's avatar Daniel Dreibrodt

SliderBackground Generator can now generate vertical sliders

SliderBackgrounds can now be delete through the normal delete item action
parent 4e1dd22b
......@@ -1570,8 +1570,18 @@ public class Main extends JFrame implements ActionListener, TreeSelectionListene
private void deleteSelectedItem() {
if(getSelectedItem()!=null) {
if(s.getItem(getSelectedItem()).getClass().equals(SliderBackground.class)) {
/* TODO */
Item i = s.getItem(getSelectedItem());
if(i.getClass().equals(SliderBackground.class)) {
Object[] options= {Language.get("CHOICE_YES"),Language.get("CHOICE_NO")};
int n = JOptionPane.showOptionDialog(this,Language.get("DEL_CONFIRM_MSG").replaceAll("%n",getSelectedItem()),Language.get("DEL_CONFIRM_TITLE"),
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,options,options[1]);
if(n==0) {
SliderBackground sbg = (SliderBackground)i;
Slider parentSlider = sbg.getParentSlider();
//TODO make undoable
parentSlider.removeBG();
s.updateItems();
}
} else {
java.util.List<Item> p = s.getParentListOf(getSelectedItem());
if(p!=null) {
......@@ -1579,7 +1589,6 @@ public class Main extends JFrame implements ActionListener, TreeSelectionListene
int n = JOptionPane.showOptionDialog(this,Language.get("DEL_CONFIRM_MSG").replaceAll("%n",getSelectedItem()),Language.get("DEL_CONFIRM_TITLE"),
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,options,options[1]);
if(n==0) {
Item i = s.getItem(getSelectedItem());
ItemDeletionEvent ide = new ItemDeletionEvent(p,i,p.indexOf(i),s);
p.remove(s.getItem(getSelectedItem()));
s.updateItems();
......
......@@ -33,7 +33,6 @@ public class SliderBGBuilder {
BufferedImage bg,e1,middle,e2,overlay;
int width, height, margin_top, margin_bottom, margin_left, margin_right, overlay_x, overlay_y;
public int nbframes;
int total_height;
boolean usebg, usee1, usee2, useoverlay, tile_bg, tile_middle, horizontal;
int bg_width = 0, e1_width = 0, middle_width = 0, e2_width = 0, e1_height = 0, e2_height = 0, middle_height = 0, bg_height = 0;
BufferedImage output;
......@@ -106,76 +105,182 @@ public class SliderBGBuilder {
System.out.println("tile_bg: "+tile_bg);
System.out.println("tile_middle: "+tile_middle);
}
public void build() {
if (horizontal && cancontinue) {
//Calculate the number of frames
nbframes = width-margin_left-margin_right+1;
total_height = nbframes*height;
//Calculate the result image's height
int total_height = nbframes*height;
//Create the result image
output = new BufferedImage(width,total_height,BufferedImage.TYPE_INT_ARGB);
//Create the graphics surface to draw on
Graphics2D g = output.createGraphics();
//Show the progress window
pg_win = new ProgressWindow(sbgg, Language.get("SBGGEN_PROGRESS"));
for (int i=0;i<=nbframes;i++) {
for (int i=0;i<=nbframes;i++) { //One increment is one pixel column drawn more, thus i = slider filling width
System.out.println("Processing frame "+i+" of "+nbframes+"...");
//Update progress window
pg_win.setProgress(nbframes/100*i);
if(usebg) {
if(tile_bg) {
int bg_r = (int)(width/bg_width);
int bg_d = width % bg_width;
for (int x=0;x<bg_r;x++) {
if(usebg) { //If a background is used
if(tile_bg) { //If the background is to be tiled
int bg_num = (int)(width/bg_width); //Number of full images fitting into the slider area
int bg_rest_width = width % bg_width; //Pixels that have to be filled with part of the background
for (int x=0;x<bg_num;x++) {
//System.out.println("Drawing BG-Tile #"+x);
g.drawImage(bg,x*bg_width,height*i,sbgg);
}
g.drawImage(bg,bg_r*bg_width,height*i,bg_d,height,sbgg);
g.drawImage(bg.getSubimage(0, 0, bg_rest_width, height),bg_num*bg_width,height*i,sbgg);
}
else {
//If background resizing is set to stretch, do so
g.drawImage(bg,0,height*i,width,height,sbgg);
}
}
if (i>0) {
if(i<=e1_width) {
BufferedImage tmp = e1.getSubimage(0, 0, i, e1_height);
g.drawImage(tmp,margin_left,height*i+margin_top,i,height-margin_top-margin_bottom,sbgg);
if (i>0) {
if(i<=e1_width) {
//If the right edge image's width has not yet been fully reached
//Say the edge looks like <000, then at this point only e.g. <00 is drawn
g.drawImage(e1.getSubimage(0, 0, i, e1_height), margin_left, height*i+margin_top, sbgg);
}
else if (i<=e1_width+middle_width) {
g.drawImage(e1,margin_left,height*i+margin_top,sbgg);
if(!tile_middle)
else if (i<=e1_width+middle_width) {
//If the end of the middle image has not yet been reached
//Say right edge + middle image look like <000===, then now only e.g. <000== is drawn
if(e1!=null) g.drawImage(e1,margin_left,height*i+margin_top,sbgg); //Draw the full right edge
if(!tile_middle) {
//If the middle image is to be stretched
g.drawImage(middle,margin_left+e1_width,height*i+margin_top,i-e1_width,height-margin_top-margin_bottom,sbgg);
}
else {
//If the middle image is to be tiled, draw a subportion of it
g.drawImage(middle.getSubimage(0, 0, i-e1_width,height-margin_top-margin_bottom),
margin_left+e1_width,height*i+margin_top,i-e1_width,height-margin_top-margin_bottom,sbgg);
margin_left+e1_width, height*i+margin_top, sbgg);
}
}
else if(i<=e1_width+middle_width+e2_width) {
else if(i<=e1_width+middle_width+e2_width) {
//If the width of the full slider (right edge + middle + left edge) hast not yet been fully drawn
//Say the full slider looks like this: <000===000>
//Then now only something like this is drawn: <000===00
g.drawImage(e1,margin_left,height*i+margin_top,sbgg);
g.drawImage(middle,margin_left+e1_width,height*i+margin_top,sbgg);
g.drawImage(e2,margin_left+e1_width+middle_width,height*i+margin_top,i-e1_width-middle_width,height-margin_top-margin_bottom,sbgg);
g.drawImage(e2.getSubimage(0, 0, i-e1_width-middle_width, height-margin_top-margin_bottom),
margin_left+e1_width+middle_width, height*i+margin_top, sbgg);
}
else {
g.drawImage(e1,margin_left,height*i+margin_top,sbgg);
else {
//Now the slider frames can be drawn normally, full width of right edge + middle + left edge has been reached
//Now only the middle image needs to be resized/tiled, both edges are drawn fully
//Say the right edge looks like this: <000 the left like this: 000> and the midle like this ===
//Then now is drawn something like <000=========000>
g.drawImage(e1,margin_left,height*i+margin_top,sbgg); //Draw the full right edge
if (tile_middle) {
int gap = i-e1_width-e2_width;
int middle_r = gap/middle_width;
int middle_d = gap % middle_width;
for (int x=0;x<middle_r;x++) {
//If the middle image has to be tiled;
int gap = i-e1_width-e2_width; //The width of the space between right and left edge, that has to be filled by the middle image
int middle_num = gap/middle_width; //Number of full middle images fitting into the gap
int middle_rest_width = gap % middle_width; //Rest pixels that need to be filled with the middle image
for (int x=0;x<middle_num;x++) { //Draw the full middle images
g.drawImage(middle,margin_left+e1_width+x*middle_width,height*i+margin_top,sbgg);
}
g.drawImage(middle, margin_left+e1_width+middle_r*middle_width, height*i+margin_top, middle_d, height-margin_top-margin_bottom, sbgg);
//Draw the rest
g.drawImage(middle.getSubimage(0, 0, middle_rest_width, height-margin_top-margin_bottom),
margin_left+e1_width+middle_num*middle_width, height*i+margin_top, sbgg);
}
else {
int gap = i-e1_width-e2_width;
//If the middle image is to be stretched
int gap = i-e1_width-e2_width; //The width of the space between right and left edge, that has to be filled by the middle image
g.drawImage(middle,margin_left+e1_width,height*i+margin_top,gap,height-margin_top-margin_bottom,sbgg);
}
g.drawImage(e2,margin_left+i-e2_width,height*i+margin_top,sbgg);
g.drawImage(e2,margin_left+i-e2_width,height*i+margin_top,sbgg); //Draw the full left edge
}
}
if(useoverlay) {
//Draw the overlay image. It is not resized to fit the slider.
g.drawImage(overlay,overlay_x,overlay_y+height*i,sbgg);
}
}
}
else if(!horizontal && cancontinue) {
JOptionPane.showMessageDialog(sbgg,"Sorry, generating of vertical sliders has not yet been implemented.");
//Calculate the number of frames
nbframes = height-margin_top-margin_bottom+1;
//Calculate the result image's width
int total_width = nbframes*width;
//Create the result image
output = new BufferedImage(total_width,height,BufferedImage.TYPE_INT_ARGB);
//Create the graphics surface to draw on
Graphics2D g = output.createGraphics();
//Show the progress window
pg_win = new ProgressWindow(sbgg, Language.get("SBGGEN_PROGRESS"));
for (int i=0;i<=nbframes;i++) { //One increment is one pixel row drawn more, thus i = slider filling height
System.out.println("Processing frame "+i+" of "+nbframes+"...");
//Update progress window
pg_win.setProgress(nbframes/100*i);
if(usebg) { //If a background is used
if(tile_bg) { //If the background is to be tiled
int bg_num = (int)(height/bg_height); //Number of full images fitting into the slider area
int bg_rest_height = height % bg_height; //Pixels that have to be filled with part of the background
for (int y=0;y<bg_num;y++) {
//System.out.println("Drawing BG-Tile #"+x);
g.drawImage(bg,width*i,bg_height*y,sbgg);
}
g.drawImage(bg.getSubimage(0, bg_height-bg_rest_height, bg_width, bg_rest_height),width*i,bg_height*bg_num,sbgg);
}
else {
//If background resizing is set to stretch, do so
g.drawImage(bg,0,height*i,width,height,sbgg);
}
}
if (i>0) {
if(i<=e2_height) { //If the bottom edge image's height has not yet been fully reached
//Draw a subimage of the bottom edge's image
g.drawImage(e2.getSubimage(0, e2_height-i, e2_width, i), width*i+margin_right, height-margin_bottom-i, sbgg);
}
else if (i<=e2_height+middle_height) { //If the end of the middle image has not yet been reached
if(e2!=null) g.drawImage(e2, width*i+margin_left, height-margin_bottom-e2_height,sbgg); //Draw the full bottom edge
if(!tile_middle) {
//If the middle image is to be stretched
g.drawImage(middle, margin_left+width*i, height-margin_bottom-i, middle_width, i-e1_height,sbgg);
}
else {
//If the middle image is to be tiled, draw a subportion of it
g.drawImage(middle.getSubimage(0, middle_height-(i-e1_height), middle_width, i-e1_height), margin_left+width*i, height-margin_bottom-i, sbgg);
}
}
else if(i<=e2_height+middle_height+e1_height) { //If the height of the full slider (bottom edge + middle + tpü edge) hast not yet been fully drawn
if(e2!=null) g.drawImage(e2, width*i+margin_left, height-margin_bottom-e2_height,sbgg); //Draw the full bottom edge
g.drawImage(middle, width*i+margin_left, height-margin_bottom-middle_height-e2_height, sbgg); //Draw the full middle image
g.drawImage(e1.getSubimage(0, e1_height-(i-e2_height-middle_height), e1_width, i-e2_height-middle_height),
margin_left+width*i, height-margin_bottom-i, sbgg); //Draw a part of the top edge
}
else { //Now the slider frames can be drawn normally, full height of right edge + middle + left edge has been reached
if(e2!=null) g.drawImage(e2, width*i+margin_left, height-margin_bottom-e2_height,sbgg); //Draw the full bottom edge
if (tile_middle) {
//If the middle image has to be tiled;
int gap = i-e1_height-e2_height; //The height of the space between top and bottom edge, that has to be filled by the middle image
int middle_num = gap/middle_height; //Number of full middle images fitting into the gap
int middle_rest_height = gap % middle_height; //Rest pixels that need to be filled with the middle image
for (int y=0;y<middle_num;y++) { //Draw the full middle images
g.drawImage(middle, margin_left+width*i, height-margin_bottom-e2_height-(y+1)*middle_height, sbgg);
}
//Draw the rest
if(middle_rest_height>0) g.drawImage(middle.getSubimage(0, 0, middle_width, middle_rest_height),
margin_left+width*i, height-margin_bottom-e2_height-middle_num*middle_height-middle_rest_height,
middle_width, middle_rest_height, sbgg);
}
else {
//If the middle image is to be stretched
int gap = i-e1_height-e2_height; //The height of the space between top and bottom edge, that has to be filled by the middle image
g.drawImage(middle,margin_left+width*i, height-i+e1_height ,middle_width, gap, sbgg);
}
g.drawImage(e1, width*i+margin_left, height-(i+1), sbgg); //Draw the full top edge
}
}
if(useoverlay) {
//Draw the overlay image. It is not resized to fit the slider.
g.drawImage(overlay,overlay_x+width*i,overlay_y,sbgg);
}
}
}
}
public void save(File f) {
try {
ImageIO.write(output, "png", f);
......@@ -184,6 +289,5 @@ public class SliderBGBuilder {
JOptionPane.showMessageDialog(sbgg,Language.get("ERROR_SAVEPNG_MSG")+"\n"+e.toString(),Language.get("ERROR_SAVEPNG_TITLE"),JOptionPane.ERROR_MESSAGE);
return;
}
}
}
}
......@@ -149,9 +149,6 @@ public class SliderBGGen extends JFrame implements ActionListener{
card_step1.add(btt_l);
btt_l.setBounds(280,105,100,100);
btt_rb.setEnabled(false);
btt_l.setEnabled(false);
ButtonGroup dir_bg = new ButtonGroup();
dir_bg.add(ltr_rb);
ltr_rb.addActionListener(this);
......@@ -421,8 +418,14 @@ public class SliderBGGen extends JFrame implements ActionListener{
Bitmap b = new Bitmap(s, f);
s.resources.add(b);
sbg.image_tf.setText(b.id);
sbg.nbvert_tf.setText(String.valueOf(sbgb.nbframes));
sbg.nbhoriz_tf.setText("1");
if (sbgb.horizontal) {
sbg.nbvert_tf.setText(String.valueOf(sbgb.nbframes));
sbg.nbhoriz_tf.setText("1");
}
else {
sbg.nbvert_tf.setText("1");
sbg.nbhoriz_tf.setText(String.valueOf(sbgb.nbframes));
}
sbg.padhoriz_tf.setText("0");
sbg.padvert_tf.setText("0");
setVisible(false);
......
......@@ -106,7 +106,7 @@ public class Slider extends Item implements ActionListener{
NodeList nodes = n.getChildNodes();
for(int i=0;i<nodes.getLength();i++) {
if(nodes.item(i).getNodeName().equals("SliderBackground"))
sbg = new SliderBackground(nodes.item(i),s);
sbg = new SliderBackground(nodes.item(i),s,this);
}
up_res = s.getImageResource(up);
......
......@@ -47,13 +47,13 @@ public class SliderBackground extends Item implements ActionListener {
public int nbvert = NBVERT_DEFAULT;
public int padhoriz = PADHORIZ_DEFAULT;
public int padvert = PADVERT_DEFAULT;
JFrame frame;
private JFrame frame;
public JTextField id_tf, image_tf, nbhoriz_tf, nbvert_tf, padhoriz_tf, padvert_tf;
JButton gen_btn, ok_btn, cancel_btn, help_btn;
ImageResource image_res;
BufferedImage bi = null;
String bitmap_str = "";
Slider sl;
private JButton gen_btn, ok_btn, cancel_btn, help_btn;
private ImageResource image_res;
private BufferedImage bi = null;
private String bitmap_str = "";
private Slider parent;
private float sliderVal = 0.5f;
......@@ -65,9 +65,11 @@ public class SliderBackground extends Item implements ActionListener {
* Parses a SliderBackground from a XML node
* @param n The XML node
* @param s_ The parent skin
* @param pr The parent slider
*/
public SliderBackground(Node n, Skin s_) {
public SliderBackground(Node n, Skin s_, Slider pr) {
s = s_;
parent = pr;
id = XML.getStringAttributeValue(n, "id", Language.get("UNNAMED").replaceAll("%t", type).replaceAll("%i", String.valueOf(s.getNewId())));
......@@ -112,7 +114,7 @@ public class SliderBackground extends Item implements ActionListener {
public SliderBackground(Skin s_, Slider sl_) {
s = s_;
sl = sl_;
parent = sl_;
image = "none";
id = Language.get("UNNAMED").replaceAll("%t", type).replaceAll("%i", String.valueOf(s.getNewId()));
showOptions();
......@@ -346,7 +348,7 @@ public class SliderBackground extends Item implements ActionListener {
frame.dispose();
frame = null;
if(!created) {
sl.removeBG();
parent.removeBG();
}
}
}
......@@ -433,4 +435,7 @@ public class SliderBackground extends Item implements ActionListener {
if(image.equals(oldid)) image = newid;
}
public Slider getParentSlider() {
return parent;
}
}
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