Thread: 100% Refactored DrawingArea Class

Page 1 of 2 12 LastLast
Results 1 to 10 of 20
  1. #1 100% Refactored DrawingArea Class 
    Retired. Stop PMing me.

    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    14
    Posts
    7,528
    Thanks given
    1,783
    Thanks received
    2,822
    Discord
    View profile
    Rep Power
    5000
    I took the time to refactor every method in the DrawingArea class and rename the variables it uses to what they are, so it's much less confusing. Now you will be able to see the methods for drawing lines/boxes/unfilled boxes with opacity, etcetera.

    BUT PLEASE NOTE, plugging this into your client will not work straight away because the person to refactor it first renamed some variables incorrectly. I have changed them to be correct.

    Here it is, for you guys to reference, etcetera.
    Code:
    public class DrawingArea extends NodeSub {
    
    	public static void initDrawingArea(int drawingAreaHeight, int drawingAreaWidth, int ai[]) {//method331
    		pixels = ai;
    		width = drawingAreaWidth;
    		height = drawingAreaHeight;
    		setDrawingArea(drawingAreaHeight, 0, drawingAreaWidth, 0);
    	}
    
    	public static void defaultDrawingAreaSize() {//method332
    		startX = 0;
    		topY = 0;
    		endX = width;
    		bottomY = height;
    		lastColumnX = endX - 1;
    		centerX = endX / 2;
    	}
    
    	public static void setDrawingArea(int drawingAreaBottom, int drawingAreaLeft, int drawingAreaRight, int drawingAreaTop) {//method333
    		if(drawingAreaLeft < 0)
    			drawingAreaLeft = 0;
    		if(drawingAreaTop < 0)
    			drawingAreaTop = 0;
    		if(drawingAreaRight > width)
    			drawingAreaRight = width;
    		if(drawingAreaBottom > height)
    			drawingAreaBottom = height;
    		startX = drawingAreaLeft;
    		topY = drawingAreaTop;
    		endX = drawingAreaRight;
    		bottomY = drawingAreaBottom;
    		lastColumnX = endX - 1;
    		centerX = endX / 2;
    		centerY = bottomY / 2;
    	}
    
    	public static void setAllPixelsToZero() {//method334
    		int totalPixels = width * height;
    		for(int j = 0; j < totalPixels; j++)
    			pixels[j] = 0;
    	}
    
    	public static void drawPixelsWithOpacity(int color, int yPos, int pixelWidth, int pixelHeight, int opacityLevel, int xPos) {//method335
    		if(xPos < startX) {
    			pixelWidth -= startX - xPos;
    			xPos = startX;
    		}
    		if(yPos < topY) {
    			pixelHeight -= topY - yPos;
    			yPos = topY;
    		}
    		if(xPos + pixelWidth > endX)
    			pixelWidth = endX - xPos;
    		if(yPos + pixelHeight > bottomY)
    			pixelHeight = bottomY - yPos;
    		int l1 = 256 - opacityLevel;
    		int i2 = (color >> 16 & 0xff) * opacityLevel;
    		int j2 = (color >> 8 & 0xff) * opacityLevel;
    		int k2 = (color & 0xff) * opacityLevel;
    		int k3 = width - pixelWidth;
    		int l3 = xPos + yPos * width;
    		for(int i4 = 0; i4 < pixelHeight; i4++) {
    			for(int j4 = -pixelWidth; j4 < 0; j4++) {
    				int l2 = (pixels[l3] >> 16 & 0xff) * l1;
    				int i3 = (pixels[l3] >> 8 & 0xff) * l1;
    				int j3 = (pixels[l3] & 0xff) * l1;
    				int k4 = ((i2 + l2 >> 8) << 16) + ((j2 + i3 >> 8) << 8) + (k2 + j3 >> 8);
    				pixels[l3++] = k4;
    			}
    			l3 += k3;
    		}
    	}
    
    	public static void drawPixels(int pixelHeight, int yPos, int xPos, int color, int pixelWidth) {//method336
    		if(xPos < startX) {
    			pixelWidth -= startX - xPos;
    			xPos = startX;
    		}
    		if(yPos < topY) {
    			pixelHeight -= topY - yPos;
    			yPos = topY;
    		}
    		if(xPos + pixelWidth > endX)
    			pixelWidth = endX - xPos;
    		if(yPos + pixelHeight > bottomY)
    			pixelHeight = bottomY - yPos;
    		int k1 = width - pixelWidth;
    		int l1 = xPos + yPos * width;
    		for(int i2 = -pixelHeight; i2 < 0; i2++) {
    			for(int j2 = -pixelWidth; j2 < 0; j2++)
    				pixels[l1++] = color;
    			l1 += k1;
    		}
    	}
    
    	public static void drawUnfilledPixels(int xPos, int pixelWidth, int pixelHeight, int color, int yPos) {//method337
    		drawHorizontalLine(yPos, color, pixelWidth, xPos);
    		drawHorizontalLine((yPos + pixelHeight) - 1, color, pixelWidth, xPos);
    		drawVerticalLine(yPos, color, pixelHeight, xPos);
    		drawVerticalLine(yPos, color, pixelHeight, (xPos + pixelWidth) - 1);
    	}
    
    	public static void drawUnfilledPixelsWithOpacity(int yPos, int pixelHeight, int opacityLevel, int color, int pixelWidth, int xPos) {//method338
    		drawHorizontalLineWithOpacity(color, pixelWidth, yPos, opacityLevel, xPos);
    		drawHorizontalLineWithOpacity(color, pixelWidth, (yPos + pixelHeight) - 1, opacityLevel, xPos);
    		if(pixelHeight >= 3) {
    			drawVerticalLineWithOpacity(color, xPos, opacityLevel, yPos + 1, pixelHeight - 2);
    			drawVerticalLineWithOpacity(color, (xPos + pixelWidth) - 1, opacityLevel, yPos + 1, pixelHeight - 2);
    		}
    	}
    
    	public static void drawHorizontalLine(int yPos, int lineColor, int lineWidth, int xPos) {//method339
    		if(yPos < topY || yPos >= bottomY)
    			return;
    		if(xPos < startX) {
    			lineWidth -= startX - xPos;
    			xPos = startX;
    		}
    		if(xPos + lineWidth > endX)
    			lineWidth = endX - xPos;
    		int i1 = xPos + yPos * width;
    		for(int j1 = 0; j1 < lineWidth; j1++)
    			pixels[i1 + j1] = lineColor;
    	}
    
    	public static void drawHorizontalLineWithOpacity(int lineColor, int lineWidth, int yPos, int opacityLevel, int xPos) {//method340
    		if(yPos < topY || yPos >= bottomY)
    			return;
    		if(xPos < startX) {
    			lineWidth -= startX - xPos;
    			xPos = startX;
    		}
    		if(xPos + lineWidth > endX)
    			lineWidth = endX - xPos;
    		int j1 = 256 - opacityLevel;
    		int k1 = (lineColor >> 16 & 0xff) * opacityLevel;
    		int l1 = (lineColor >> 8 & 0xff) * opacityLevel;
    		int i2 = (lineColor & 0xff) * opacityLevel;
    		int i3 = xPos + yPos * width;
    		for(int j3 = 0; j3 < lineWidth; j3++) {
    			int j2 = (pixels[i3] >> 16 & 0xff) * j1;
    			int k2 = (pixels[i3] >> 8 & 0xff) * j1;
    			int l2 = (pixels[i3] & 0xff) * j1;
    			int k3 = ((k1 + j2 >> 8) << 16) + ((l1 + k2 >> 8) << 8) + (i2 + l2 >> 8);
    			pixels[i3++] = k3;
    		}
    	}
    
    	public static void drawVerticalLine(int yPos, int lineColor, int lineHeight, int xPos) {//method341
    		if(xPos < startX || xPos >= endX)
    			return;
    		if(yPos < topY) {
    			lineHeight -= topY - yPos;
    			yPos = topY;
    		}
    		if(yPos + lineHeight > bottomY)
    			lineHeight = bottomY - yPos;
    		int j1 = xPos + yPos * width;
    		for(int k1 = 0; k1 < lineHeight; k1++)
    			pixels[j1 + k1 * width] = lineColor;
    	}
    
    	private static void drawVerticalLineWithOpacity(int color, int xPos, int opacityLevel, int yPos, int lineHeight) {//method342
    		if(xPos < startX || xPos >= endX)
    			return;
    		if(yPos < topY) {
    			lineHeight -= topY - yPos;
    			yPos = topY;
    		}
    		if(yPos + lineHeight > bottomY)
    			lineHeight = bottomY - yPos;
    		int j1 = 256 - opacityLevel;
    		int k1 = (color >> 16 & 0xff) * opacityLevel;
    		int l1 = (color >> 8 & 0xff) * opacityLevel;
    		int i2 = (color & 0xff) * opacityLevel;
    		int i3 = xPos + yPos * width;
    		for(int j3 = 0; j3 < lineHeight; j3++) {
    			int j2 = (pixels[i3] >> 16 & 0xff) * j1;
    			int k2 = (pixels[i3] >> 8 & 0xff) * j1;
    			int l2 = (pixels[i3] & 0xff) * j1;
    			int k3 = ((k1 + j2 >> 8) << 16) + ((l1 + k2 >> 8) << 8) + (i2 + l2 >> 8);
    			pixels[i3] = k3;
    			i3 += width;
    		}
    	}
    
    	DrawingArea() {
    	}
    
    	public static int pixels[];
    	public static int width;
    	public static int height;
    	public static int topY;
    	public static int bottomY;
    	public static int startX;
    	public static int endX;
    	public static int lastColumnX;
    	public static int centerX;
    	public static int centerY;
    }
    NOTE: lastColumnX was a guess at the name. That variable is used for the last pixel on the x-axis minus one(from the right). So thanks to Cory(K_2da_O) it is now named that. It was originally anInt1385.
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Member Market Banned Market Banned

    Robin Spud's Avatar
    Join Date
    Aug 2008
    Age
    28
    Posts
    2,338
    Thanks given
    46
    Thanks received
    73
    Rep Power
    1068
    put (K_2da_O) next to cory lol.

    and v.nice
    ILY Stewie.
    Reply With Quote  
     

  4. #3  
    Registered Member
    wizzyt21's Avatar
    Join Date
    Aug 2007
    Posts
    1,167
    Thanks given
    49
    Thanks received
    12
    Rep Power
    156
    100% done by me 2008 Jan 8th.. you're not the only one
    YOU JUST GOT KNOCKED THE F*CK UP.
    Reply With Quote  
     

  5. #4  
    Retired. Stop PMing me.

    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    14
    Posts
    7,528
    Thanks given
    1,783
    Thanks received
    2,822
    Discord
    View profile
    Rep Power
    5000
    Quote Originally Posted by 64base string View Post
    100% done by me 2008 Jan 8th.. you're not the only one
    This I did not know. . Was I correct about anInt1385?
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  6. #5  
    Registered Member
    Its paris's Avatar
    Join Date
    Apr 2009
    Posts
    1,141
    Thanks given
    56
    Thanks received
    234
    Rep Power
    689
    Thanks for this, I only needed the names of the transparent/opaque methods.
    I had a clue about this but wasn't sure.
    Reply With Quote  
     

  7. #6  
    Registered Member
    Join Date
    Jul 2008
    Posts
    3,167
    Thanks given
    235
    Thanks received
    74
    Rep Power
    209
    mr galkon what i have to change in this to work with ur base?
    Reply With Quote  
     

  8. #7  
    Retired. Stop PMing me.

    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    14
    Posts
    7,528
    Thanks given
    1,783
    Thanks received
    2,822
    Discord
    View profile
    Rep Power
    5000
    Quote Originally Posted by dani_gonzales View Post
    mr galkon what i have to change in this to work with ur base?
    You have to rename variables in TextDrawingArea, ItemDef, Sprite, Texture, WorldController, and client classes. Just because the original refactoring(not by me) was done incorrectly.
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  9. #8  
    Valar Morghulis

    Laxika's Avatar
    Join Date
    Sep 2006
    Age
    29
    Posts
    2,813
    Thanks given
    1,804
    Thanks received
    274
    Rep Power
    2128
    Looks nice Galkon, thanks again! (and again and again lol...)
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  10. #9  
    Retired. Stop PMing me.

    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    14
    Posts
    7,528
    Thanks given
    1,783
    Thanks received
    2,822
    Discord
    View profile
    Rep Power
    5000
    Quote Originally Posted by Laxika View Post
    Looks nice Galkon, thanks again! (and again and again lol...)
    Haha you're welcome.
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  11. #10  
    Registered Member
    Its paris's Avatar
    Join Date
    Apr 2009
    Posts
    1,141
    Thanks given
    56
    Thanks received
    234
    Rep Power
    689
    We should start a series of these refactored classes threads.
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •