Changeset 679
- Timestamp:
- May 19, 2011, 1:45:43 AM (12 years ago)
- Location:
- abuse/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/TODO
r674 r679 58 58 - move to vec2i: 59 59 - scale_put, scale_put_trans 60 - tint_area, darken_area61 60 - fg_width, etc. 62 61 -
abuse/trunk/src/menu.cpp
r676 r679 45 45 46 46 //percent is 0..256 47 void tint_area(int x1, int y1, int x2, int y2, int r_to, int g_to, int b_to, int percent) 48 { 49 vec2i caa, cbb; 50 main_screen->GetClip(caa, cbb); 51 if (x1 < caa.x) x1 = caa.x; 52 if (y1 < caa.y) y1 = caa.y; 53 if (x2 > cbb.x - 1) x2 = cbb.x - 1; 54 if (y2 > cbb.y - 1) y2 = cbb.y - 1; 55 if (x2 < x1 || y2 < y1) return; 56 57 percent=256-percent; 58 59 main_screen->Lock(); 60 for (int y=y1; y<=y2; y++) 61 { 62 uint8_t *sl=main_screen->scan_line(y)+x1; 63 for (int x=x1; x<=x2; x++,sl++) 64 { 65 uint8_t *paddr=(uint8_t *)pal->addr()+(*sl)*3; 66 uint8_t r=((*(paddr++))-r_to)*percent/256+r_to; 67 uint8_t g=((*(paddr++))-g_to)*percent/256+g_to; 68 uint8_t b=((*(paddr++))-b_to)*percent/256+b_to; 69 *sl=color_table->Lookup((r)>>3,(g)>>3,(b)>>3); 47 static void TintArea(vec2i aa, vec2i bb, 48 int r_to, int g_to, int b_to, int percent) 49 { 50 vec2i caa, cbb; 51 main_screen->GetClip(caa, cbb); 52 aa = Max(aa, caa); 53 bb = Min(bb, cbb); 54 55 if (!(aa < bb)) 56 return; 57 58 percent = 256 - percent; 59 60 main_screen->Lock(); 61 for (int y = aa.y; y < bb.y; y++) 62 { 63 uint8_t *sl = main_screen->scan_line(y) + aa.x; 64 for (int x = aa.x; x < bb.x; x++, sl++) 65 { 66 uint8_t *paddr = (uint8_t *)pal->addr() + (*sl) * 3; 67 uint8_t r = (((paddr[0] - r_to) * percent) >> 8) + r_to; 68 uint8_t g = (((paddr[1] - g_to) * percent) >> 8) + g_to; 69 uint8_t b = (((paddr[2] - b_to) * percent) >> 8) + b_to; 70 *sl = color_table->Lookup((r) >> 3, (g) >> 3, (b) >> 3); 71 } 70 72 } 71 } 72 main_screen->AddDirty(vec2i(x1, y1), vec2i(x2 + 1, y2 + 1)); 73 main_screen->Unlock(); 74 } 75 76 void darken_area(int x1, int y1, int x2, int y2, int amount) 77 { 78 vec2i caa, cbb; 79 main_screen->GetClip(caa, cbb); 80 if (x1 < caa.x) x1 = caa.x; 81 if (y1 < caa.y) y1 = caa.y; 82 if (x2 > cbb.x - 1) x2 = cbb.x - 1; 83 if (y2 > cbb.y - 1) y2 = cbb.y - 1; 84 if (x2 < x1 || y2 < y1) return; 85 86 main_screen->Lock(); 87 for (int y=y1; y<=y2; y++) 88 { 89 uint8_t *sl=main_screen->scan_line(y)+x1; 90 for (int x=x1; x<=x2; x++,sl++) 91 { 92 uint8_t *paddr=(uint8_t *)pal->addr()+(*sl)*3; 93 uint8_t r=(*(paddr++))*amount/256; 94 uint8_t g=(*(paddr++))*amount/256; 95 uint8_t b=(*(paddr++))*amount/256; 96 *sl=color_table->Lookup((r)>>3,(g)>>3,(b)>>3); 97 } 98 } 99 main_screen->AddDirty(vec2i(x1, y1), vec2i(x2 + 1, y2 + 1)); 100 main_screen->Unlock(); 101 } 102 103 void dark_widget(int x1, int y1, int x2, int y2, int br, int dr, int amount) 104 { 105 main_screen->AddDirty(vec2i(x1, y1), vec2i(x2 + 1, y2 + 1)); 106 main_screen->Line(vec2i(x1, y1), vec2i(x1, y2), br); 107 main_screen->Line(vec2i(x1 + 1, y1), vec2i(x2, y1), br); 108 main_screen->Line(vec2i(x2, y1 + 1), vec2i(x2, y2), dr); 109 main_screen->Line(vec2i(x1 + 1, y2), vec2i(x2, y2), dr); 110 darken_area(x1 + 1, y1 + 1, x2 - 1, y2 - 1, amount); 73 main_screen->AddDirty(aa, bb); 74 main_screen->Unlock(); 75 } 76 77 void DarkWidget(vec2i aa, vec2i bb, int br, int dr, int amount) 78 { 79 main_screen->AddDirty(aa, bb); 80 main_screen->Line(aa, vec2i(aa.x, bb.y - 1), br); 81 main_screen->Line(aa, vec2i(bb.x - 1, aa.y), br); 82 main_screen->Line(vec2i(bb.x - 1, aa.y + 1), bb - vec2i(1), dr); 83 main_screen->Line(vec2i(aa.x + 1, bb.y - 1), bb - vec2i(1), dr); 84 TintArea(aa + vec2i(1), bb, 0, 0, 0, amount); 111 85 } 112 86 … … 129 103 } 130 104 105 // 106 // This method is only used by the (menu) Lisp method, which was 107 // never tested. 108 // 131 109 int menu(void *args, JCFont *font) // reurns -1 on esc 132 110 { … … 159 137 int tl=strlen(title)*font->Size().x; 160 138 int tx=main_screen->Size().x/2-tl/2; 161 dark_widget(tx-2,my-font->Size().y-4,tx+tl+2,my-2,wm->medium_color(),wm->dark_color(),180); 162 font->PutString(main_screen, vec2i(tx + 1, my-font->Size().y - 2), title,wm->bright_color()); 163 } 164 165 dark_widget(mx,my,mx+mw-1,my+mh-1,wm->medium_color(),wm->dark_color(),200); 139 DarkWidget(vec2i(tx - 2, my-font->Size().y - 4), vec2i(tx + tl + 3, my - 1), wm->medium_color(),wm->dark_color(),180); 140 font->PutString(main_screen, vec2i(tx + 1, my-font->Size().y - 2), title, wm->bright_color()); 141 } 142 143 DarkWidget(vec2i(mx, my), vec2i(mx + mw, my + mh), 144 wm->medium_color(), wm->dark_color(), 200); 166 145 167 146 … … 236 215 237 216 save->PutPart(main_screen, vec2i(0, 0), vec2i(mx + 1, by1), vec2i(mx + mw - 1, by2 + 1)); 238 tint_area(mx+1,by1,mx+mw-2,by2,63,63,63,color); 217 TintArea(vec2i(mx + 1, by1), vec2i(mx + mw - 1, by2 + 1), 218 63, 63, 63, color); 239 219 240 220 char *cur=men_str(nth(choice,args));
Note: See TracChangeset
for help on using the changeset viewer.