Mercurial > otakunoraifu
diff window/button.cc @ 52:15a18fbe6f21
* Known bugs added to the README
* Code cleaning (0 -> NULL when needed, indentation, spaces, ...)
author | thib |
---|---|
date | Sat, 18 Apr 2009 18:35:39 +0000 |
parents | 4d7486cb20a9 |
children | 4416cfac86ae |
line wrap: on
line diff
--- a/window/button.cc +++ b/window/button.cc @@ -348,11 +348,32 @@ static char* extract_button(int number, char* data; switch(number) { - case 0: data = buttonleft; size = buttonleft_cnt; width = 164; height = 110; break; - case 1: data = buttonright; size = buttonright_cnt; width = 164; height = 110; break; - case 2: data = buttonup; size = buttonup_cnt; width = 110; height = 164; break; - case 3: data = buttondown; size = buttondown_cnt; width = 110; height = 164; break; - default: return 0; + case 0: + data = buttonleft; + size = buttonleft_cnt; + width = 164; + height = 110; + break; + case 1: + data = buttonright; + size = buttonright_cnt; + width = 164; + height = 110; + break; + case 2: + data = buttonup; + size = buttonup_cnt; + width = 110; + height = 164; + break; + case 3: + data = buttondown; + size = buttondown_cnt; + width = 110; + height = 164; + break; + default: + return NULL; } char* out = new char[width*height]; @@ -388,6 +409,7 @@ struct ButtonColor { void SetBrightness1(int n, int c1); void SetBrightness(int c1, int c2, int c3, int c4, int c5); }; + ButtonColor::ButtonColor(int r, int g, int b) { is_gray = false; if (r == g && r == b) { @@ -436,6 +458,7 @@ ButtonColor::ButtonColor(int r, int g, i if (l < 128) s = (hd*255)/(max+min); else s = (hd*255) / (510-(max+min)); } + void ButtonColor::SetBrightness1(int n, int c1) { if (n < 1 || n > 7) return; as[n] = 255; @@ -457,9 +480,8 @@ void ButtonColor::SetBrightness1(int n, c_max[n] = m2; c_mid[n] = (hc*m2 + (hd-hc)*m1) / hd; c_min[n] = m1; +} - return; -} void ButtonColor::SetBrightness(int c1, int c2, int c3, int c4, int c5) { rs[0] = bs[0] = gs[0] = as[0] = 0; SetBrightness1(1, c1); @@ -469,9 +491,9 @@ void ButtonColor::SetBrightness(int c1, SetBrightness1(5, c5); } -#include"rect.h" -#include<stdlib.h> -#include<string.h> +#include "rect.h" +#include <stdlib.h> +#include <string.h> static void draw_button(char* rdata, int width, int height, char* bdata, int bwidth, int bheight, const ButtonColor& color) { const int* rs = color.rs; @@ -483,8 +505,8 @@ static void draw_button(char* rdata, int ScaleData* data = new ScaleData[width*height]; memset(data, 0, sizeof(ScaleData)*width*height); - int bx,by; - int x=0, y=0; + int bx, by; + int x = 0, y = 0; int x2 = 0, y2 = 0; int xadd = width*65536/bwidth; int yadd = height*65536/bheight; @@ -522,12 +544,12 @@ static void draw_button(char* rdata, int } } delete[] data; - return; } + char* create_button(int number, int& width, int& height, int r, int g, int b) { int bwidth, bheight; char* bdata = extract_button(number, bwidth, bheight); - if (bdata == 0) return 0; + if (bdata == NULL) return NULL; // 拡大率に合わせてwidth,heightをセット if (width == -1 && height == -1) width = bwidth, height = bheight; else if (width == -1) width = bwidth * height / bheight; @@ -550,7 +572,7 @@ char* create_button(int number, int& wid static void drawbox(char* buf, const Rect& region, int width, int r, int g, int b, int a) { buf += region.ty*width*4 + region.lx*4; - int i,j; + int i, j; int h = region.height(); int w = region.width(); int col = (b&0xff) | ((g&0xff)<<8)| ((r&0xff)<<16)| ((a&0xff)<<24); @@ -562,8 +584,8 @@ static void drawbox(char* buf, const Rec } buf += width*4; } - return; } + static void draw_box(char* buf, int width, int height, int kage_w1, int kage_w2, const ButtonColor& color) { const int* rs = color.rs; const int* gs = color.gs; @@ -587,6 +609,7 @@ static void draw_box(char* buf, int widt drawbox(buf, Rect(width-kage_w2, kage_w2, width-kage_w1, height-kage_w1), width, rs[2], gs[2], bs[2], as[2]); } } + char* create_box(int& width, int& height, int r, int g, int b) { ButtonColor color(r,g,b); // scale のカーソル