Mercurial > otakunoraifu
comparison window/button.cc @ 65:4416cfac86ae
Convert EUC-JP files to UTF8
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Fri, 26 Nov 2010 10:53:15 +0100 |
parents | 15a18fbe6f21 |
children |
comparison
equal
deleted
inserted
replaced
64:045ca45f9610 | 65:4416cfac86ae |
---|---|
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 /* r,g,b の基本色で number (0:left 1:right 2:up 3:down)の矢印のビットマップを作成する | 28 /* r,g,b 堺蚊 number (0:left 1:right 2:up 3:down)√違篏 |
29 ** width/heightのどちらかを-1にすると、それにあわせてスケール | 29 ** width/height<-1鴻宴若 |
30 */ | 30 */ |
31 #include <stdlib.h> | 31 #include <stdlib.h> |
32 extern char* create_button(int number, int& width, int& height, int r, int g, int b); | 32 extern char* create_button(int number, int& width, int& height, int r, int g, int b); |
33 extern char* create_box(int& width, int& height, int r, int g, int b); | 33 extern char* create_box(int& width, int& height, int r, int g, int b); |
34 | 34 |
35 // ボタンのbitmap | 35 // 帥潟bitmap |
36 // ランレングスで簡易圧縮 | 36 // 潟潟違鴻х亜х軒 |
37 static int buttonleft_cnt = 990; | 37 static int buttonleft_cnt = 990; |
38 static char buttonleft[991] = { | 38 static char buttonleft[991] = { |
39 0x00,0x10,0x04,0x7e,0x39,0x00,0x22,0x04,0x7f,0x59,0x00,0x1e,0x04,0x81,0x79,0x00, | 39 0x00,0x10,0x04,0x7e,0x39,0x00,0x22,0x04,0x7f,0x59,0x00,0x1e,0x04,0x81,0x79,0x00, |
40 0x1a,0x04,0x83,0x99,0x00,0x17,0x04,0x84,0xb9,0x00,0x14,0x04,0x85,0xc9,0x00,0x11, | 40 0x1a,0x04,0x83,0x99,0x00,0x17,0x04,0x84,0xb9,0x00,0x14,0x04,0x85,0xc9,0x00,0x11, |
41 0x04,0x87,0xd9,0xf8,0x04,0x88,0xe9,0xd8,0x04,0x89,0xf9,0xc8,0x04,0x89,0x01,0x10, | 41 0x04,0x87,0xd9,0xf8,0x04,0x88,0xe9,0xd8,0x04,0x89,0xf9,0xc8,0x04,0x89,0x01,0x10, |
377 } | 377 } |
378 | 378 |
379 char* out = new char[width*height]; | 379 char* out = new char[width*height]; |
380 int outc = 0; | 380 int outc = 0; |
381 int i; | 381 int i; |
382 // ランレングスの展開 | 382 // 潟潟違鴻絮 |
383 for (i=0; i<size; i++) { | 383 for (i=0; i<size; i++) { |
384 int c = *(unsigned char*)(data+i); | 384 int c = *(unsigned char*)(data+i); |
385 int s = 0; | 385 int s = 0; |
386 if (c == 0xff) break; | 386 if (c == 0xff) break; |
387 if (c&0x08) { | 387 if (c&0x08) { |
394 int j; for (j=0; j<s; j++) out[outc++] = c; | 394 int j; for (j=0; j<s; j++) out[outc++] = c; |
395 } | 395 } |
396 return out; | 396 return out; |
397 } | 397 } |
398 | 398 |
399 // R,G,B の指定色を基底色に、明るさを変えた色を RGB -> HLS -> RGB 変換で作成する | 399 // R,G,B 絎蚊阪蚊紊蚊 RGB -> HLS -> RGB 紊т |
400 struct ButtonColor { | 400 struct ButtonColor { |
401 int rs[8]; | 401 int rs[8]; |
402 int gs[8]; | 402 int gs[8]; |
403 int bs[8]; | 403 int bs[8]; |
404 int as[8]; | 404 int as[8]; |
405 int* c_min, *c_mid, *c_max; // rgb->hls->rgb変換用。r,g,b を高い順にmax,mid,minに割り当てる | 405 int* c_min, *c_mid, *c_max; // rgb->hls->rgb紊r,g,b 蕭max,mid,min蚊綵 |
406 bool is_gray; | 406 bool is_gray; |
407 int hc, hd, l, s; // h,l,s 系。h 要素は上の c_min|mid|maxにも入る | 407 int hc, hd, l, s; // h,l,s 膤祉h 荀膣筝 c_min|mid|maxャ |
408 ButtonColor(int _r, int _g, int _b); | 408 ButtonColor(int _r, int _g, int _b); |
409 void SetBrightness1(int n, int c1); | 409 void SetBrightness1(int n, int c1); |
410 void SetBrightness(int c1, int c2, int c3, int c4, int c5); | 410 void SetBrightness(int c1, int c2, int c3, int c4, int c5); |
411 }; | 411 }; |
412 | 412 |
417 l = r; | 417 l = r; |
418 return; | 418 return; |
419 } | 419 } |
420 *rs = r; *bs = b; *gs = g; | 420 *rs = r; *bs = b; *gs = g; |
421 | 421 |
422 // r,g,b の昇順にmax,mid,minをrs,gs,bsに割り当てる | 422 // r,g,b max,mid,minrs,gs,bs蚊綵 |
423 if (r > g) { | 423 if (r > g) { |
424 if (r > b) { // r = max | 424 if (r > b) { // r = max |
425 c_max = rs; | 425 c_max = rs; |
426 if (b > g) { // r>b>g | 426 if (b > g) { // r>b>g |
427 c_mid = bs; | 427 c_mid = bs; |
509 int x = 0, y = 0; | 509 int x = 0, y = 0; |
510 int x2 = 0, y2 = 0; | 510 int x2 = 0, y2 = 0; |
511 int xadd = width*65536/bwidth; | 511 int xadd = width*65536/bwidth; |
512 int yadd = height*65536/bheight; | 512 int yadd = height*65536/bheight; |
513 | 513 |
514 // 元のビットマップに着色しながら縮小する | 514 // 蚊膰絨 |
515 for (by=0; by<bheight; by++) { | 515 for (by=0; by<bheight; by++) { |
516 ScaleData* d = data + y*width; | 516 ScaleData* d = data + y*width; |
517 char* s = bdata + by*bwidth; | 517 char* s = bdata + by*bwidth; |
518 x = 0; x2 = 0; | 518 x = 0; x2 = 0; |
519 for (bx=0; bx<bwidth; bx++) { | 519 for (bx=0; bx<bwidth; bx++) { |
548 | 548 |
549 char* create_button(int number, int& width, int& height, int r, int g, int b) { | 549 char* create_button(int number, int& width, int& height, int r, int g, int b) { |
550 int bwidth, bheight; | 550 int bwidth, bheight; |
551 char* bdata = extract_button(number, bwidth, bheight); | 551 char* bdata = extract_button(number, bwidth, bheight); |
552 if (bdata == NULL) return NULL; | 552 if (bdata == NULL) return NULL; |
553 // 拡大率に合わせてwidth,heightをセット | 553 // ≦ぇwidth,height祉 |
554 if (width == -1 && height == -1) width = bwidth, height = bheight; | 554 if (width == -1 && height == -1) width = bwidth, height = bheight; |
555 else if (width == -1) width = bwidth * height / bheight; | 555 else if (width == -1) width = bwidth * height / bheight; |
556 else if (height == -1) height = bheight * width / bwidth; | 556 else if (height == -1) height = bheight * width / bwidth; |
557 if (width > bwidth) width = bwidth; | 557 if (width > bwidth) width = bwidth; |
558 if (height > bheight) height = bheight; | 558 if (height > bheight) height = bheight; |
559 | 559 |
560 // 色を設定する | 560 // 蚊荐絎 |
561 ButtonColor color(r,g,b); | 561 ButtonColor color(r,g,b); |
562 // 描画 | 562 // |
563 char* rdata = (char*)malloc(width*height*4*3); | 563 char* rdata = (char*)malloc(width*height*4*3); |
564 color.SetBrightness(0x60, 0xa0, 0xc0, 0xe0, 0xe0); | 564 color.SetBrightness(0x60, 0xa0, 0xc0, 0xe0, 0xe0); |
565 draw_button(rdata, width, height, bdata, bwidth, bheight, color); | 565 draw_button(rdata, width, height, bdata, bwidth, bheight, color); |
566 color.SetBrightness(0x60, 0xa0, 0xe0, 0xe0, 0xe0); | 566 color.SetBrightness(0x60, 0xa0, 0xe0, 0xe0, 0xe0); |
567 draw_button(rdata+width*height*4, width, height, bdata, bwidth, bheight, color); | 567 draw_button(rdata+width*height*4, width, height, bdata, bwidth, bheight, color); |
589 static void draw_box(char* buf, int width, int height, int kage_w1, int kage_w2, const ButtonColor& color) { | 589 static void draw_box(char* buf, int width, int height, int kage_w1, int kage_w2, const ButtonColor& color) { |
590 const int* rs = color.rs; | 590 const int* rs = color.rs; |
591 const int* gs = color.gs; | 591 const int* gs = color.gs; |
592 const int* bs = color.bs; | 592 const int* bs = color.bs; |
593 const int* as = color.as; | 593 const int* as = color.as; |
594 // まず、豆腐を書く | 594 // 障莟吾 |
595 drawbox(buf, Rect(0,0,width,height), width, rs[3],gs[3],bs[3],as[3]); | 595 drawbox(buf, Rect(0,0,width,height), width, rs[3],gs[3],bs[3],as[3]); |
596 // 影 | 596 // 綵 |
597 if (height > 2) { | 597 if (height > 2) { |
598 drawbox(buf, Rect(0,0,width,kage_w1), width, rs[4], gs[4], bs[4],as[4]); | 598 drawbox(buf, Rect(0,0,width,kage_w1), width, rs[4], gs[4], bs[4],as[4]); |
599 drawbox(buf, Rect(0,height-kage_w1,width,height), width, rs[1], gs[1], bs[1],as[1]); | 599 drawbox(buf, Rect(0,height-kage_w1,width,height), width, rs[1], gs[1], bs[1],as[1]); |
600 } | 600 } |
601 if (width > 2) { | 601 if (width > 2) { |
610 } | 610 } |
611 } | 611 } |
612 | 612 |
613 char* create_box(int& width, int& height, int r, int g, int b) { | 613 char* create_box(int& width, int& height, int r, int g, int b) { |
614 ButtonColor color(r,g,b); | 614 ButtonColor color(r,g,b); |
615 // scale のカーソル | 615 // scale 若純 |
616 if (width == -1 && height == -1) width = 32, height = 48; | 616 if (width == -1 && height == -1) width = 32, height = 48; |
617 else if (width == -1) width = height*3/2; | 617 else if (width == -1) width = height*3/2; |
618 else if (height == -1) height = width * 3/2; | 618 else if (height == -1) height = width * 3/2; |
619 int kage_w1 = (width<height ? width : height)/14; | 619 int kage_w1 = (width<height ? width : height)/14; |
620 int kage_w2 = (width<height ? width : height)*2/14; | 620 int kage_w2 = (width<height ? width : height)*2/14; |
621 if (kage_w1 <= 0) kage_w1 = 1; | 621 if (kage_w1 <= 0) kage_w1 = 1; |
622 if (kage_w2 <= 1) kage_w2 = 2; | 622 if (kage_w2 <= 1) kage_w2 = 2; |
623 | 623 |
624 char* buf = (char*)malloc(width*height*4*3); | 624 char* buf = (char*)malloc(width*height*4*3); |
625 // 描画 | 625 // |
626 color.SetBrightness(0x60, 0xa0, 0xc0, 0xe0, 0xe0); | 626 color.SetBrightness(0x60, 0xa0, 0xc0, 0xe0, 0xe0); |
627 draw_box(buf, width, height, kage_w1, kage_w2, color); | 627 draw_box(buf, width, height, kage_w1, kage_w2, color); |
628 color.SetBrightness(0x60, 0xa0, 0xe0, 0xe0, 0xe0); | 628 color.SetBrightness(0x60, 0xa0, 0xe0, 0xe0, 0xe0); |
629 draw_box(buf+width*height*4, width, height, kage_w1, kage_w2, color); | 629 draw_box(buf+width*height*4, width, height, kage_w1, kage_w2, color); |
630 color.SetBrightness(0xe0, 0xc0, 0xa0, 0x60, 0xa0); | 630 color.SetBrightness(0xe0, 0xc0, 0xa0, 0x60, 0xa0); |