• Advertisement
Sign in to follow this  
  • entries
    208
  • comments
    383
  • views
    65737

LINE WRAPPING!!!1!11!

Sign in to follow this  

139 views



It only took four hours and three complete rewrites of the algo. [smile]

Now all I have to do is hook it up with the message box width and height and I have the msgbox class ready to go.


public void drawWithBounds(Graphics2D g, String text, int x, int y, int w, int h) {
h = y+h;
double space_width = getPixelWidth(g, " ");
double line_height = getPixelHeight(g, "T")+3;
String[] split_text = text.split(" ");

double[] split_width = new double[split_text.length];
for (int i = 0; i < split_text.length; i++) {
split_width = getPixelWidth(g, split_text);
}

int splits_in_this_line;
double width_of_this_line;
int current_split;
String current_line = "";
//////////////////////////////////////////////////////
while (true) {
splits_in_this_line = 0;
width_of_this_line = 0;
current_split = 0;
while (width_of_this_line < w) {
width_of_this_line += split_width[current_split]+space_width;
current_split++;
if (current_split >= split_width.length) width_of_this_line = w+10;
}
if (current_split != split_width.length)
current_split--;

for (int i = 0; i current_line += split_text+" ";
}
g.setColor(java.awt.Color.white);
g.drawString(current_line, x, y);
////////////////////////////////////////////////////////////////////////
if (y > h) return;
y += line_height;
text = "";
current_line = "";
for (int i = current_split; i < split_text.length; i++) {
text += split_text+" ";
}
split_text = text.split(" ");
split_width= new double[split_text.length];
for (int i = 0; i split_width = getPixelWidth(g, split_text);
}
}

}

Sign in to follow this  


1 Comment


Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement