1 36 37 40 41 49 class RoundButtonFilter extends ButtonFilter { 50 int Xcenter; 51 int Ycenter; 52 int Yradsq; 53 int innerW; 54 int innerH; 55 int Yrad2sq; 56 57 public RoundButtonFilter(boolean press, int p, int b, int w, int h) { 58 super(press, p, b, w, h); 59 Xcenter = w/2; 60 Ycenter = h/2; 61 Yradsq = h * h / 4; 62 innerW = w - border * 2; 63 innerH = h - border * 2; 64 Yrad2sq = innerH * innerH / 4; 65 } 66 67 public boolean inside(int x, int y) { 68 int yrel = Math.abs(Ycenter - y); 69 int xrel = (int) (Math.sqrt(Yradsq - yrel * yrel) * width / height); 70 return (x >= Xcenter - xrel && x < Xcenter + xrel); 71 } 72 73 public void buttonRanges(int y, int ranges[]) { 74 int yrel = Math.abs(Ycenter - y); 75 int xrel = (int) (Math.sqrt(Yradsq - yrel * yrel) * width / height); 76 ranges[0] = 0; 77 ranges[1] = Xcenter - xrel; 78 ranges[6] = Xcenter + xrel; 79 ranges[7] = width; 80 ranges[8] = ranges[9] = y; 81 if (y < border) { 82 ranges[2] = ranges[3] = ranges[4] = Xcenter; 83 ranges[5] = ranges[6]; 84 } else if (y + border >= height) { 85 ranges[2] = ranges[1]; 86 ranges[3] = ranges[4] = ranges[5] = Xcenter; 87 } else { 88 int xrel2 = (int) (Math.sqrt(Yrad2sq - yrel * yrel) 89 * innerW / innerH); 90 ranges[3] = Xcenter - xrel2; 91 ranges[4] = Xcenter + xrel2; 92 if (y < Ycenter) { 93 ranges[2] = ranges[3]; 94 ranges[5] = ranges[6]; 95 } else { 96 ranges[2] = ranges[1]; 97 ranges[5] = ranges[4]; 98 } 99 } 100 } 101 102 public int filterRGB(int x, int y, int rgb) { 103 boolean brighter; 104 int percent; 105 int i; 106 int xrel, yrel; 107 int ranges[] = getRanges(y); 108 for (i = 0; i < 7; i++) { 109 if (x >= ranges[i] && x < ranges[i+1]) { 110 break; 111 } 112 } 113 switch (i) { 114 default: 115 case 0: 116 case 6: 117 return rgb & 0x00ffffff; 118 case 1: 119 brighter = !pressed; 120 percent = defpercent; 121 break; 122 case 5: 123 brighter = pressed; 124 percent = defpercent; 125 break; 126 case 2: 127 yrel = y - Ycenter; 128 xrel = Xcenter - x; 129 percent = (int) (yrel * defpercent * 2 / 130 Math.sqrt(yrel * yrel + xrel * xrel)) 131 - defpercent; 132 if (!pressed) { 133 percent = -percent; 134 } 135 if (percent == 0) { 136 return rgb; 137 } else if (percent < 0) { 138 percent = -percent; 139 brighter = false; 140 } else { 141 brighter = true; 142 } 143 break; 144 case 4: 145 yrel = Ycenter - y; 146 xrel = x - Xcenter; 147 percent = (int) (yrel * defpercent * 2 / 148 Math.sqrt(yrel * yrel + xrel * xrel)) 149 - defpercent; 150 if (pressed) { 151 percent = -percent; 152 } 153 if (percent == 0) { 154 return rgb; 155 } else if (percent < 0) { 156 percent = -percent; 157 brighter = false; 158 } else { 159 brighter = true; 160 } 161 break; 162 case 3: 163 if (!pressed) { 164 return rgb & 0x00ffffff; 165 } 166 brighter = false; 167 percent = defpercent; 168 break; 169 } 170 return filterRGB(rgb, brighter, percent); 171 } 172 } 173 | Popular Tags |