Skip to content
Myr

colorpicker;

Before adoption: this commit came in with the history the project adopted, so no landing records it.

new color scheme

authored by Sean Barrett · committed by Sean Barrett · parent 3ab22d3 · Browse files · 1 file+359 added−138 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+359 added−138 removed

  • other:+359 added−138 removed

1 file+359 added−138 removed

modified:stb_tilemap_editor.h+359 added-138 removed
1// stb_tilemap_editor.h - v0.10 - Sean Barrett - http://nothings.org/stb1// stb_tilemap_editor.h - v0.20 - Sean Barrett - http://nothings.org/stb2// placed in the public domain - not copyrighted - first released 2014-093//4// Embeddable tilemap editor for C/C++5//
63 unmodified lines
69// objects and switch between them. The latter has the advantage that each70// stbte_tilemap keeps its own undo state. (The clipboard is global, so71// either approach allows cut&pasting between levels.)72//73// REVISION HISTORY74//75// 0.20 - 2014-09-27 - eraser tool, bugfixes, new colorscheme76// 0.10 - 2014-09-23 - initial release77//78// TODO79//75// Eraser!!!80// Separate scroll state for each category81// Implement paint bucket82// Support STBTE_HITTEST_TILE above83// Support STBTE_HITTEST_ICON above
182 unmodified lines
266#if STBTE_UNDO_BUFFER_COUNT & (STBTE_UNDO_BUFFER_COUNT-1)267#error "Undo buffer size must be a power of 2"268#endif269266#define STBTE_COLOR_TOOLBAR_BACKGROUND 0x606060 // stbte__color[STBTE__ctoolbar][STBTE__base][STBTE__idle]267#define STBTE_COLOR_TILEMAP_BACKGROUND 0x000000268#define STBTE_COLOR_TILEMAP_BORDER 0x203060269#define STBTE_COLOR_TILEMAP_HIGHLIGHT 0xffffff270#define STBTE_COLOR_PANEL_BACKGROUND 0x403010271#define STBTE_COLOR_PANEL_OUTLINE 0xc08040272#define STBTE_COLOR_PANEL_TEXT 0xffffff273#define STBTE_COLOR_BUTTON_BACKGROUND 0x703870274#define STBTE_COLOR_BUTTON_OUTLINE 0xc060c0275#define STBTE_COLOR_BUTTON_TEXT 0xffffff276#define STBTE_COLOR_BUTTON_DOWN 0xe080e0277#define STBTE_COLOR_BUTTON_OVER 0xffc0ff278#define STBTE_COLOR_BUTTON_TEXT_SELECTED 0x000000279#define STBTE_COLOR_MICROBUTTON 0x40c040280#define STBTE_COLOR_MICROBUTTON_DOWN 0xc0ffc0281#define STBTE_COLOR_MICROBUTTON_FRAME 0x00ff00282#define STBTE_COLOR_MICROBUTTON_OVER 0x80ff80283#define STBTE_COLOR_TILEPALETTE_OUTLINE 0xffffff284#define STBTE_COLOR_TILEPALETTE_BACKGROUND 0x000000285#define STBTE_COLOR_MINIBUTTON_ICON 0xffffff286#define STBTE_COLOR_SELECTION_OUTLINE1 0xdfdfdf287#define STBTE_COLOR_SELECTION_OUTLINE2 0x303030288#define STBTE_COLOR_GRID 0x404040270static int *stbte__colors;271290#define STBTE_COLOR_LAYERCONTROL 0x6f6f6f291#define STBTE_COLOR_LAYERCONTROL_OVER 0xcfcfcf292#define STBTE_COLOR_LAYERCONTROL_DOWN 0xffffff293#define STBTE_COLOR_LAYERCONTROL_TOGGLED 0xbfbfbf294#define STBTE_COLOR_LAYERCONTROL_DISABLED 0x404040295#define STBTE_COLOR_LAYERCONTROL_OUTLINE 0xffffff296#define STBTE_COLOR_LAYERCONTROL_OUTLINE_DISABLED 0x202020297#define STBTE_COLOR_LAYERCONTROL_TEXT 0xffffff298#define STBTE_COLOR_LAYERCONTROL_TEXT_DOWN 0x5f5f5f299#define STBTE_COLOR_LAYERCONTROL_TEXT_TOGGLED 0x000000300#define STBTE_COLOR_LAYERCONTROL_TEXT_DISABLED 0x606060272enum273{274 STBTE__base,275 STBTE__outline,276 STBTE__text,277302#define STBTE_COLOR_LAYERMASK_HIDE 0xffff55303#define STBTE_COLOR_LAYERMASK_LOCK 0x5f55ff304#define STBTE_COLOR_LAYERMASK_SOLO 0xff5f55278 STBTE__num_color_aspects,279};280281enum282{283 STBTE__idle,284 STBTE__over,285 STBTE__down,286 STBTE__over_down,287 STBTE__selected,288 STBTE__selected_over,289 STBTE__disabled,290 STBTE__num_color_states,291};292293enum294{295 STBTE__cexpander,296 STBTE__ctoolbar,297 STBTE__ctoolbar_button,298 STBTE__cpanel,299 STBTE__cpanel_sider,300 STBTE__cpanel_sizer,301 STBTE__cscrollbar,302 STBTE__cmapsize,303 STBTE__clayer_button,304 STBTE__clayer_hide,305 STBTE__clayer_lock,306 STBTE__clayer_solo,307 STBTE__ccategory_button,308309 STBTE__num_color_modes,310};311312#ifdef STBTE__COLORPICKER313static char *stbte__color_names[] =314{315 "expander", "toolbar", "tool button", "panel",316 "panel c1", "panel c2", "scollbar", "map button",317 "layer", "hide", "lock", "solo",318 "category",319};320#endif // STBTE__COLORPICKER321322 // idle, over, down, over&down, selected, sel&over, disabled323static int stbte__color_table[STBTE__num_color_modes][STBTE__num_color_aspects][STBTE__num_color_states] =324{325 {326 { 0x000000, 0x84987c, 0xdcdca8, 0xdcdca8, 0x40c040, 0x60d060, 0x505050, },327 { 0xa4b090, 0xe0ec80, 0xffffc0, 0xffffc0, 0x80ff80, 0x80ff80, 0x606060, },328 { 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x909090, },329 }, {330 { 0x808890, 0x606060, 0x606060, 0x606060, 0x606060, 0x606060, 0x606060, },331 { 0x605860, 0x606060, 0x606060, 0x606060, 0x606060, 0x606060, 0x606060, },332 { 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, },333 }, {334 { 0x3c5068, 0x7088a8, 0x647488, 0x94b4dc, 0x8890c4, 0x9caccc, 0x404040, },335 { 0x889cb8, 0x889cb8, 0x889cb8, 0x889cb8, 0x84c4e8, 0xacc8ff, 0x0c0c08, },336 { 0xbcc4cc, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x707074, },337 }, {338 { 0x403848, 0x403010, 0x403010, 0x403010, 0x403010, 0x403010, 0x303024, },339 { 0x68546c, 0xc08040, 0xc08040, 0xc08040, 0xc08040, 0xc08040, 0x605030, },340 { 0xf4e4ff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x909090, },341 }, {342 { 0xb4b04c, 0xacac60, 0xc0ffc0, 0xc0ffc0, 0x40c040, 0x60d060, 0x505050, },343 { 0xa0a04c, 0xd0d04c, 0xffff80, 0xffff80, 0x80ff80, 0x80ff80, 0x606060, },344 { 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x909090, },345 }, {346 { 0x40c440, 0x60d060, 0xc0ffc0, 0xc0ffc0, 0x40c040, 0x60d060, 0x505050, },347 { 0x40c040, 0x80ff80, 0x80ff80, 0x80ff80, 0x80ff80, 0x80ff80, 0x606060, },348 { 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x909090, },349 }, {350 { 0x9090ac, 0xa0a0b8, 0xbcb8cc, 0xbcb8cc, 0x909040, 0x909040, 0x909040, },351 { 0xa0a0b8, 0xb0b4d0, 0xa0a0b8, 0xa0a0b8, 0xa0a050, 0xa0a050, 0xa0a050, },352 { 0x808088, 0x808030, 0x808030, 0x808030, 0x808030, 0x808030, 0x808030, },353 }, {354 { 0x704c70, 0x885c8c, 0x9c68a4, 0xb870bc, 0xb490bc, 0xb490bc, 0x302828, },355 { 0x646064, 0xcca8d4, 0xc060c0, 0xa07898, 0xe0b8e0, 0xe0b8e0, 0x403838, },356 { 0xdccce4, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x909090, },357 }, {358 { 0x704c70, 0x885c8c, 0x9c68a4, 0xb870bc, 0xb490bc, 0xb490bc, 0x302828, },359 { 0xb09cb4, 0xcca8d4, 0xc060c0, 0xa07898, 0xe0b8e0, 0xe0b8e0, 0x403838, },360 { 0xdccce4, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0x909090, },361 }, {362 { 0x646494, 0x888cb8, 0xb0b0b0, 0xb0b0cc, 0x9c9cf4, 0x8888b0, 0x50506c, },363 { 0x9090a4, 0xb0b4d4, 0xb0b0dc, 0xb0b0cc, 0xd0d0fc, 0xd0d4f0, 0x606060, },364 { 0xb4b4d4, 0xe4e4ff, 0xffffff, 0xffffff, 0xe0e4ff, 0xececff, 0x909090, },365 }, {366 { 0x646444, 0x888c64, 0xb0b0b0, 0xb0b088, 0xaca858, 0x88886c, 0x505050, },367 { 0x88886c, 0xb0b490, 0xb0b0b0, 0xb0b088, 0xd8d898, 0xd0d4b0, 0x606060, },368 { 0xb4b49c, 0xffffd8, 0xffffff, 0xffffd4, 0xffffdc, 0xffffcc, 0x909090, },369 }, {370 { 0x906464, 0xb48c8c, 0xd4b0b0, 0xdcb0b0, 0xff9c9c, 0xc88888, 0x505050, },371 { 0xb47c80, 0xd4b4b8, 0xc4a8a8, 0xdcb0b0, 0xffc0c0, 0xfce8ec, 0x606060, },372 { 0xe0b4b4, 0xffdcd8, 0xffd8d4, 0xffe0e4, 0xffece8, 0xffffff, 0x909090, },373 }, {374 { 0x403848, 0x403848, 0x403848, 0x886894, 0x7c80c8, 0x7c80c8, 0x302828, },375 { 0x403848, 0x403848, 0x403848, 0x403848, 0x7c80c8, 0x7c80c8, 0x403838, },376 { 0xc8c4c8, 0xffffff, 0xffffff, 0xffffff, 0xe8e8ec, 0xffffff, 0x909090, },377 },378};379380#define STBTE_COLOR_TILEMAP_BACKGROUND 0x000000381#define STBTE_COLOR_TILEMAP_BORDER 0x203060382#define STBTE_COLOR_TILEMAP_HIGHLIGHT 0xffffff383#define STBTE_COLOR_GRID 0x404040384#define STBTE_COLOR_SELECTION_OUTLINE1 0xdfdfdf385#define STBTE_COLOR_SELECTION_OUTLINE2 0x303030386#define STBTE_COLOR_TILEPALETTE_OUTLINE 0xffffff387#define STBTE_COLOR_TILEPALETTE_BACKGROUND 0x000000388389// disabled, selected, down, over390static unsigned char stbte__state_to_index[2][2][2][2] =391{392 {393 { { STBTE__idle , STBTE__over }, { STBTE__down , STBTE__over_down }, },394 { { STBTE__selected, STBTE__selected_over }, { STBTE__down , STBTE__over_down }, },395 },{396 { { STBTE__disabled, STBTE__disabled }, { STBTE__disabled, STBTE__disabled }, },397 { { STBTE__selected, STBTE__selected_over }, { STBTE__disabled, STBTE__disabled }, },398 }399};400#define STBTE__INDEX_FOR_STATE(disable,select,down,over) stbte__state_to_index[disable][select][down][over]401#define STBTE__INDEX_FOR_ID(id,disable,select) STBTE__INDEX_FOR_STATE(disable,select,STBTE__IS_ACTIVE(id),STBTE__IS_HOT(id))402403#define STBTE__FONT_HEIGHT 9404static short stbte__font_offset[95+16];405static short stbte__fontdata[762] =406{
47 unmodified lines
454455enum456{457 STBTE__panel_toolbar,458 STBTE__panel_colorpick,459 STBTE__panel_info,460 STBTE__panel_layers,461 STBTE__panel_categories,462 STBTE__panel_tiles,
149 unmodified lines
612 stbte__ui.panel[i].expanded = 1; // visible if not autohidden613 stbte__ui.panel[i].delta_height = 0;614 stbte__ui.panel[i].side = STBTE__side_left;615 }518 stbte__ui.panel[STBTE__panel_toolbar].side = STBTE__side_top;616 stbte__ui.panel[STBTE__panel_toolbar ].side = STBTE__side_top;617 stbte__ui.panel[STBTE__panel_colorpick].side = STBTE__side_right;618619 if (stbte__ui.left_width == 0)620 stbte__ui.left_width = 80;621 if (stbte__ui.right_width == 0)
546 unmodified lines
1168 }1169 return 0;1170}11711073static int stbte__button(char *label, int x, int y, int textoff, int width, int id, int toggled)1172static void stbte__draw_box(int x0, int y0, int x1, int y1, int colormode, int colorindex)1173{1174 stbte__draw_rect (x0,y0,x1,y1, stbte__color_table[colormode][STBTE__base ][colorindex]);1175 stbte__draw_frame(x0,y0,x1,y1, stbte__color_table[colormode][STBTE__outline][colorindex]);1176}11771178static void stbte__draw_textbox(int x0, int y0, int x1, int y1, char *text, int xoff, int yoff, int colormode, int colorindex)1179{1180 stbte__draw_box(x0,y0,x1,y1,colormode,colorindex);1181 stbte__draw_text(x0+xoff,y0+yoff, text, x1-x0-xoff-1, stbte__color_table[colormode][STBTE__text][colorindex]);1182}11831184static int stbte__button(int colormode, char *label, int x, int y, int textoff, int width, int id, int toggled, int disabled)1185{1186 int x0=x,y0=y, x1=x+width,y1=y+STBTE__BUTTON_HEIGHT;1187 int s = STBTE__BUTTON_INTERNAL_SPACING;11881078 int over = stbte__hittest(x0,y0,x1,y1,id);1189 int over = !disabled && stbte__hittest(x0,y0,x1,y1,id);1190 1080 if (stbte__ui.event == STBTE__paint) {1081 stbte__draw_rect (x0, y0, x1, y1, STBTE__IS_ACTIVE(id) || toggled ? STBTE_COLOR_BUTTON_DOWN : STBTE_COLOR_BUTTON_BACKGROUND);1082 stbte__draw_frame(x0, y0, x1, y1, STBTE__IS_HOT(id) || toggled ? STBTE_COLOR_BUTTON_OVER : STBTE_COLOR_BUTTON_OUTLINE);1083 stbte__draw_text (x0+s+textoff, y0+s, label ,width-s*2, toggled ? STBTE_COLOR_BUTTON_TEXT : STBTE_COLOR_BUTTON_TEXT_SELECTED);1084 }1191 if (stbte__ui.event == STBTE__paint)1192 stbte__draw_textbox(x0,y0,x1,y1, label,s+textoff,s, colormode, STBTE__INDEX_FOR_ID(id,disabled,toggled));1193 if (disabled)1194 return 0;1195 return (stbte__button_core(id) == 1);1196}11971088static int stbte__button_icon(char ch, int x, int y, int width, int id, int toggled)1198static int stbte__button_icon(int colormode, char ch, int x, int y, int width, int id, int toggled)1199{1200 int x0=x,y0=y, x1=x+width,y1=y+STBTE__BUTTON_HEIGHT;1091 int s = STBTE__BUTTON_INTERNAL_SPACING, pad;1092 char label[2] = { ch, 0 };1201 int s = STBTE__BUTTON_INTERNAL_SPACING;12021203 int over = stbte__hittest(x0,y0,x1,y1,id);1204 1205 if (stbte__ui.event == STBTE__paint) {1097 stbte__draw_rect (x0, y0, x1, y1, STBTE__IS_ACTIVE(id) || toggled ? STBTE_COLOR_BUTTON_DOWN : STBTE_COLOR_BUTTON_BACKGROUND);1098 stbte__draw_frame(x0, y0, x1, y1, STBTE__IS_HOT(id) || toggled ? STBTE_COLOR_BUTTON_OVER : STBTE_COLOR_BUTTON_OUTLINE);1099 pad = (9 - stbte__get_char_width(ch))/2;1100 stbte__draw_text (x0+s+pad, y0+s, label ,9, toggled ? STBTE_COLOR_BUTTON_TEXT : STBTE_COLOR_BUTTON_TEXT_SELECTED);1206 char label[2] = { ch, 0 };1207 int pad = (9 - stbte__get_char_width(ch))/2;1208 stbte__draw_textbox(x0,y0,x1,y1, label,s+pad,s, colormode, STBTE__INDEX_FOR_ID(id,0,toggled));1209 }1210 return (stbte__button_core(id) == 1);1211}12121105static int stbte__minibutton(int x, int y, int ch, int id)1213static int stbte__minibutton(int colormode, int x, int y, int ch, int id)1214{1215 int x0 = x, y0 = y, x1 = x+8, y1 = y+7;1216 int over = stbte__hittest(x0,y0,x1,y1,id);1217 if (stbte__ui.event == STBTE__paint) {1218 char str[2] = { ch,0 };1111 stbte__draw_rect (x0,y0,x1,y1, STBTE__IS_ACTIVE(id) ? STBTE_COLOR_MICROBUTTON_DOWN : STBTE_COLOR_MICROBUTTON);1112 stbte__draw_frame(x0,y0,x1,y1, STBTE__IS_HOT(id) ? STBTE_COLOR_MICROBUTTON_OVER : STBTE_COLOR_MICROBUTTON_FRAME);1113 stbte__draw_text (x0+1,y0,str,99, STBTE_COLOR_MINIBUTTON_ICON);1219 stbte__draw_textbox(x0,y0,x1,y1, str,1,0,colormode, STBTE__INDEX_FOR_ID(id,0,0));1220 }1221 return stbte__button_core(id);1222}12231118static int stbte__layerbutton(int x, int y, int ch, int id, int toggled, int disabled, int color)1224static int stbte__layerbutton(int x, int y, int ch, int id, int toggled, int disabled, int colormode)1225{1226 int x0 = x, y0 = y, x1 = x+10, y1 = y+11;1121 int over = stbte__hittest(x0,y0,x1,y1,id);1227 int over = !disabled && stbte__hittest(x0,y0,x1,y1,id);1228 if (stbte__ui.event == STBTE__paint) {1123 int rc = STBTE_COLOR_LAYERCONTROL;1124 int rf = STBTE_COLOR_LAYERCONTROL_OUTLINE;1125 int rt = STBTE_COLOR_LAYERCONTROL_TEXT;1126 if (toggled) {1127 rc = STBTE_COLOR_LAYERCONTROL_TOGGLED;1128 rt = STBTE_COLOR_LAYERCONTROL_TEXT_TOGGLED;1129 }1130 if (STBTE__IS_HOT(id)) {1131 rc = STBTE_COLOR_LAYERCONTROL_OVER;1132 }1133 if (STBTE__IS_ACTIVE(id)) {1134 rc = STBTE_COLOR_LAYERCONTROL_DOWN;1135 rt = STBTE_COLOR_LAYERCONTROL_TEXT_DOWN;1136 }1137 rc &= color;1138 rf &= color;1139 rt &= color;1140 if (disabled) {1141 rc = STBTE_COLOR_LAYERCONTROL_DISABLED;1142 rf = STBTE_COLOR_LAYERCONTROL_OUTLINE_DISABLED;1143 rt = STBTE_COLOR_LAYERCONTROL_TEXT_DISABLED;1144 }11451146 stbte__draw_rect (x0,y0,x1,y1, rc);1147 stbte__draw_frame(x0,y0,x1,y1, rf);1148 {1149 char str[2] = { ch,0 };1150 int off = (9-stbte__get_char_width(ch))/2;1151 stbte__draw_text (x0+1+off,y0+2,str,99, rt);1229 char str[2] = { ch,0 };1230 int off = (9-stbte__get_char_width(ch))/2;1231 stbte__draw_textbox(x0,y0,x1,y1, str, off+1,2, colormode, STBTE__INDEX_FOR_ID(id,disabled,toggled));1152 }1232 }1233 if (disabled)1234 return 0;1235 return stbte__button_core(id);1236}123711591160static int stbte__microbutton(int x, int y, int size, int id, int c1, int c2, int toggled)1238static int stbte__microbutton(int x, int y, int size, int id, int colormode)1239{1240 int x0 = x, y0 = y, x1 = x+size, y1 = y+size;1241 int over = stbte__hittest(x0,y0,x1,y1,id);1242 if (stbte__ui.event == STBTE__paint) {1165 stbte__draw_rect (x0,y0,x1,y1, STBTE__IS_ACTIVE(id) || toggled ? c2 : c1 );1166 stbte__draw_frame(x0,y0,x1,y1, STBTE__IS_HOT(id) ? STBTE_COLOR_MICROBUTTON_OVER : STBTE_COLOR_MICROBUTTON_FRAME);1243 stbte__draw_box(x0,y0,x1,y1, colormode, STBTE__INDEX_FOR_ID(id,0,0));1244 }1245 return stbte__button_core(id);1246}12471171static int stbte__microbutton_dragger(int x, int y, int size, int id, int c1, int c2, int toggled, int *pos)1248static int stbte__microbutton_dragger(int x, int y, int size, int id, int *pos)1249{1250 int x0 = x, y0 = y, x1 = x+size, y1 = y+size;1251 int over = stbte__hittest(x0,y0,x1,y1,id);1252 switch (stbte__ui.event) {1253 case STBTE__paint:1177 stbte__draw_rect (x0,y0,x1,y1, STBTE__IS_ACTIVE(id) || toggled ? c2 : c1 );1178 stbte__draw_frame(x0,y0,x1,y1, STBTE__IS_HOT(id) ? STBTE_COLOR_MICROBUTTON_OVER : STBTE_COLOR_MICROBUTTON_FRAME);1254 stbte__draw_box(x0,y0,x1,y1, STBTE__cexpander, STBTE__INDEX_FOR_ID(id,0,0));1255 break;1256 case STBTE__leftdown:1257 if (STBTE__IS_HOT(id) && STBTE__INACTIVE()) {1258 stbte__activate(id);
21 unmodified lines
1280 int s = STBTE__BUTTON_INTERNAL_SPACING;12811282 int over = stbte__hittest(x0,y0,x1,y1,id);1283 1208 if (stbte__ui.event == STBTE__paint) {1209 stbte__draw_rect (x0, y0, x1, y1, toggled ? STBTE_COLOR_BUTTON_DOWN : STBTE_COLOR_BUTTON_BACKGROUND);1210 stbte__draw_text (x0+s, y0+s, label ,width-s*2, STBTE__IS_HOT(id) ? STBTE_COLOR_BUTTON_TEXT : STBTE_COLOR_BUTTON_TEXT_SELECTED);1211 }1284 if (stbte__ui.event == STBTE__paint)1285 stbte__draw_textbox(x0,y0,x1,y1, label, s,s, STBTE__ccategory_button, STBTE__INDEX_FOR_ID(id,0,toggled));12861287 return (stbte__button_core(id) == 1);1288}12891216#define STBTE_COLOR_SCROLLBAR_TRACK 0x8080301217#define STBTE_COLOR_SCROLLBAR_THUMB 0x90904012181290static void stbte__scrollbar(int x, int y0, int y1, int *val, int v0, int v1, int num_vis, int id)1291{1292 int over;1293 int thumbpos;
6 unmodified lines
1300 if (thumbpos >= y1) thumbpos = y1;1301 over = stbte__hittest(x-1,y0,x+2,y1,id);1302 switch (stbte__ui.event) {1303 case STBTE__paint:1233 stbte__draw_rect(x,y0,x+1,y1, STBTE_COLOR_SCROLLBAR_TRACK);1234 stbte__draw_rect(x-1,thumbpos-3,x+2,thumbpos+4, STBTE_COLOR_SCROLLBAR_THUMB);1304 stbte__draw_rect(x,y0,x+1,y1, stbte__color_table[STBTE__cscrollbar][STBTE__text][STBTE__idle]);1305 stbte__draw_box(x-1,thumbpos-3,x+2,thumbpos+4, STBTE__cscrollbar, STBTE__INDEX_FOR_ID(id,0,0));1306 break;1307 case STBTE__leftdown:1308 if (STBTE__IS_HOT(id) && STBTE__INACTIVE()) {1309 // check if it's over the thumb
49 unmodified lines
1359{1360 int i, limit, w, k;1361 int window_width = stbte__ui.x1 - stbte__ui.x0;1362 int window_height = stbte__ui.y1 - stbte__ui.y0;1292 int min_width[STBTE__num_panel]={0,0,0,0,0};1293 int height[STBTE__num_panel]={0,0,0,0,0};1294 int panel_active[STBTE__num_panel]={1,1,1,1,1};1363 int min_width[STBTE__num_panel]={0,0,0,0,0,0};1364 int height[STBTE__num_panel]={0,0,0,0,0,0};1365 int panel_active[STBTE__num_panel]={1,0,1,1,1,1};1366 int vpos[4] = { 0,0,0,0 };1367 stbte__panel *p = stbte__ui.panel;1368 stbte__panel *pt = &p[STBTE__panel_toolbar];1369
8 unmodified lines
13781379 // determine which panels are active1380 panel_active[STBTE__panel_categories] = tm->num_categories != 0;1381 panel_active[STBTE__panel_layers ] = tm->num_layers > 1;1382#ifdef STBTE__COLORPICKER1383 panel_active[STBTE__panel_colorpick ] = 1;1384#endif13851386 // compute minimum widths for each panel (assuming they're on sides not top)1387 min_width[STBTE__panel_info ] = 8 + 11 + 7*tm->digits+17+7; // estimate min width of "w:0000"1388 min_width[STBTE__panel_colorpick ] = 120;1389 min_width[STBTE__panel_tiles ] = 4 + tm->palette_spacing_x + 5; // 5 for scrollbar1390 min_width[STBTE__panel_categories] = 4 + 42 + 5; // 42 is enough to show ~7 chars; 5 for scrollbar1391 min_width[STBTE__panel_layers ] = 4 + 54 + 30*tm->has_layer_names; // 2 digits plus 3 buttons plus scrollbar1392 min_width[STBTE__panel_toolbar ] = 4 + STBTE__TOOLBAR_PASTE_SIZE; // wide enough for 'Paste' button
33 unmodified lines
1426 int anim = (int) (stbte__region[i].width * stbte__region[i].retracted);1427 stbte__region[i].x = (i == STBTE__side_left) ? stbte__ui.x0 - anim : stbte__ui.x1 - stbte__region[i].width + anim;1428 }14291430 // color picker1431 height[STBTE__panel_colorpick] = 300;14321433 // info panel1434 w = stbte__region[p[STBTE__panel_info].side].width;1435 p[STBTE__panel_info].mode = (w >= 8 + (11+7*tm->digits+17)*2 + 4);1436 if (p[STBTE__panel_info].mode)
58 unmodified lines
1495 STBTE__scrollbar, // param is panel ID1496 STBTE__panel_mover, // p1 is panel ID, p2 is destination side1497 STBTE__panel_sizer, // param panel ID1498 STBTE__scrollbar_id,1499 STBTE__colorpick_id,1500};15011502// id is: [ 24-bit data : 7-bit identifer ]1503// map id is: [ 12-bit y : 12 bit x : 7-bit identifier ]
328 unmodified lines
1832 }18331834 for (i=0; i < tm->num_layers; ++i) {1835 result[i] = dest[i];1757 if (src[i] != STBTE__NO_TILE) {1836 if (src[i] != STBTE__NO_TILE)1837 if (!tm->layerinfo[i].hidden && tm->layerinfo[i].locked != STBTE__locked)1838 if (tm->layerinfo[i].locked == STBTE__unlocked || (!dragging && dest[i] == STBTE__BG(tm,i)))1839 result[i] = src[i];1761 }1840 }1841}18421843// compute the result of dragging away from a tile
3 unmodified lines
1847 // special case single-layer1848 i = tm->cur_layer;1849 if (tm->solo_layer >= 0)1850 i = tm->solo_layer;1773 if (i >= 0) {1774 result[i] = (i == 0 ? tm->background_tile : STBTE__NO_TILE);1775 } else {1776 for (i=0; i < tm->num_layers; ++i) {1851 if (i >= 0)1852 result[i] = STBTE__BG(tm,i);1853 else1854 for (i=0; i < tm->num_layers; ++i)1855 if (!tm->layerinfo[i].hidden && tm->layerinfo[i].locked == STBTE__unlocked)1778 result[i] = (i == 0 ? tm->background_tile : STBTE__NO_TILE);1779 }1780 }1856 result[i] = STBTE__BG(tm,i);1857}18581859// check if some map square is active1860#define STBTE__IS_MAP_ACTIVE() ((stbte__ui.active_id & 127) == STBTE__map)
489 unmodified lines
2350 if (i == STBTE__tool_grid && stbte__ui.show_grid)2351 highlight=1;2352 if (i == STBTE__tool_fill)2353 continue;2278 if (stbte__button_icon(toolchar[i], x, y, 13, STBTE__ID(STBTE__toolbarA, i), highlight)) {2354 if (stbte__button_icon(STBTE__ctoolbar_button, toolchar[i], x, y, 13, STBTE__ID(STBTE__toolbarA, i), highlight)) {2355 switch (i) {2356 case STBTE__tool_eyedrop:2357 stbte__ui.eyedrop_last_layer = tm->num_layers; // flush eyedropper state2358 // fallthrough
15 unmodified lines
2374 x += 13;2375 }23762377 x += 8;2302 if (stbte__button("cut" , x, y,10, 40, STBTE__ID(STBTE__toolbarB,0), 0)) {2378 if (stbte__button(STBTE__ctoolbar_button, "cut" , x, y,10, 40, STBTE__ID(STBTE__toolbarB,0), 0, !stbte__ui.has_selection)) {2379 if (stbte__ui.has_selection)2380 stbte__copy_cut(tm, 1);2381 }2382 x += 42;2307 if (stbte__button("copy" , x, y, 5, 40, STBTE__ID(STBTE__toolbarB,1), 0)) {2383 if (stbte__button(STBTE__ctoolbar_button, "copy" , x, y, 5, 40, STBTE__ID(STBTE__toolbarB,1), 0, !stbte__ui.has_selection)) {2384 if (stbte__ui.has_selection)2385 stbte__copy_cut(tm, 0);2386 }2387 x += 42;2312 if (stbte__button("paste", x, y, 0, 40, STBTE__ID(STBTE__toolbarB,2), stbte__ui.pasting)) {2388 if (stbte__button(STBTE__ctoolbar_button, "paste", x, y, 0, 40, STBTE__ID(STBTE__toolbarB,2), stbte__ui.pasting, !stbte__ui.has_copy)) {2389 if (stbte__ui.has_copy) {2390 stbte__ui.pasting = 1;2391 stbte__activate(STBTE__ID(STBTE__toolbarB,3));2392 }2393 }2394}23952396#define STBTE__TEXTCOLOR(n) stbte__color_table[n][STBTE__text][STBTE__idle]23972398static int stbte__info_value(char *label, int x, int y, int val, int digits, int id)2399{2400 if (stbte__ui.event == STBTE__paint) {2401 int off = 9-stbte__get_char_width(label[0]);2402 char text[16];2403 sprintf(text, label, digits, val);2326 stbte__draw_text_core(x+off,y, text, 999, STBTE_COLOR_PANEL_TEXT,1);2404 stbte__draw_text_core(x+off,y, text, 999, STBTE__TEXTCOLOR(STBTE__cpanel),1);2405 }2406 if (id) {2407 x += 9+7*digits+4;2330 if (stbte__minibutton(x,y, '+', id + (0<<19)))2408 if (stbte__minibutton(STBTE__cmapsize, x,y, '+', STBTE__ID2(id,1,0)))2409 val += (stbte__ui.shift ? 10 : 1);2410 x += 9;2333 if (stbte__minibutton(x,y, '-', id + (1<<19)))2411 if (stbte__minibutton(STBTE__cmapsize, x,y, '-', STBTE__ID2(id,2,0)))2412 val -= (stbte__ui.shift ? 10 : 1);2413 if (val < 1) val = 1; else if (val > 4096) val = 4096;2414 }2415 return val;
24 unmodified lines
2440 y += 11;2441 stbte__info_value(in_region ? "y:%*d" : "y:",x,y, (stbte__ui.hot_id>> 7)&4095, tm->digits, 0);2442 y += 15;2443 x = x0+2;2366 stbte__draw_text(x,y,"brush:",40,STBTE_COLOR_PANEL_TEXT);2444 stbte__draw_text(x,y,"brush:",40,STBTE__TEXTCOLOR(STBTE__cpanel));2445 if (tm->cur_tile >= 0)2446 STBTE_DRAW_TILE(x+43,y-3,tm->tiles[tm->cur_tile].id,1);2447}2448
7 unmodified lines
2456 x0 += 2;2457 y0 += 5;2458 if (!tm->has_layer_names) {2459 if (stbte__ui.event == STBTE__paint) {2382 stbte__draw_text(x0,y0, "Layers", w-4, STBTE_COLOR_PANEL_TEXT);2460 stbte__draw_text(x0,y0, "Layers", w-4, STBTE__TEXTCOLOR(STBTE__cpanel));2461 }2462 y0 += 11;2463 }2464 num_rows = (y1-y0)/15;
5 unmodified lines
2470 int disabled = (tm->solo_layer >= 0 && tm->solo_layer != i);2471 if (i-tm->layer_scroll >= 0 && i-tm->layer_scroll < num_rows) {2472 if (str == NULL)2473 sprintf(str=text, "%2d", i+1);2396 if (stbte__button(str, x0,y,(i+1<10)*2,xoff-2, STBTE__ID(STBTE__layer,i), tm->cur_layer==i))2474 if (stbte__button(STBTE__clayer_button, str, x0,y,(i+1<10)*2,xoff-2, STBTE__ID(STBTE__layer,i), tm->cur_layer==i,0))2475 tm->cur_layer = (tm->cur_layer == i ? -1 : i);2398 if (stbte__layerbutton(x0+xoff + 0,y+1,'H',STBTE__ID(STBTE__hide,i), tm->layerinfo[i].hidden,disabled,STBTE_COLOR_LAYERMASK_HIDE))2476 if (stbte__layerbutton(x0+xoff + 0,y+1,'H',STBTE__ID(STBTE__hide,i), tm->layerinfo[i].hidden,disabled,STBTE__clayer_hide))2477 tm->layerinfo[i].hidden = !tm->layerinfo[i].hidden;2400 if (stbte__layerbutton(x0+xoff + 12,y+1,lockedchar[locked],STBTE__ID(STBTE__lock,i), locked!=0,disabled,STBTE_COLOR_LAYERMASK_LOCK))2478 if (stbte__layerbutton(x0+xoff + 12,y+1,lockedchar[locked],STBTE__ID(STBTE__lock,i), locked!=0,disabled,STBTE__clayer_lock))2479 tm->layerinfo[i].locked = (locked+1)%3;2402 if (stbte__layerbutton(x0+xoff + 24,y+1,'S',STBTE__ID(STBTE__solo,i), tm->solo_layer==i,0,STBTE_COLOR_LAYERMASK_SOLO))2480 if (stbte__layerbutton(x0+xoff + 24,y+1,'S',STBTE__ID(STBTE__solo,i), tm->solo_layer==i,0,STBTE__clayer_solo))2481 tm->solo_layer = (tm->solo_layer == i ? -1 : i);2482 y += 15;2483 }2484 }
88 unmodified lines
2573 stbte__flush_delay();2574 stbte__scrollbar(x1-4, y0+6, y1-2, &tm->palette_scroll, 0, num_total_rows, num_vis_rows, STBTE__ID(STBTE__scrollbar_id, STBTE__palette));2575}25762577static int stbte__cp_mode, stbte__cp_aspect, stbte__cp_state, stbte__cp_index, stbte__save, stbte__cp_altered, stbte__color_copy;25782579#ifdef STBTE__COLORPICKER2580static void stbte__dump_colorstate(void)2581{2582 int i,j,k;2583 printf("static int stbte__color_table[STBTE__num_color_modes][STBTE__num_color_aspects][STBTE__num_color_states] =\n");2584 printf("{\n");2585 printf(" {\n");2586 for (k=0; k < STBTE__num_color_modes; ++k) {2587 for (j=0; j < STBTE__num_color_aspects; ++j) {2588 printf(" { ");2589 for (i=0; i < STBTE__num_color_states; ++i) {2590 printf("0x%06x, ", stbte__color_table[k][j][i]);2591 }2592 printf("},\n");2593 }2594 if (k+1 < STBTE__num_color_modes)2595 printf(" }, {\n");2596 else2597 printf(" },\n");2598 }2599 printf("};\n");2600}26012602static void stbte__slider(int x0, int w, int y, int *value, int id)2603{2604 int x1 = x0+w;2605 int pos = *value * w / 256;2606 int over = stbte__hittest(x0,y-2,x1,y+3,id);2607 switch (stbte__ui.event) {2608 case STBTE__paint:2609 stbte__draw_rect(x0,y,x1,y+1, 0x808080);2610 stbte__draw_rect(x0+pos-1,y-1,x0+pos+2,y+2, 0xffffff);2611 break;2612 case STBTE__leftdown:2613 if (STBTE__IS_HOT(id) && STBTE__INACTIVE())2614 stbte__activate(id);2615 // fall through2616 case STBTE__mousemove:2617 if (STBTE__IS_ACTIVE(id)) {2618 int v = (stbte__ui.mx-x0)*256/w;2619 if (v < 0) v = 0; else if (v > 255) v = 255;2620 *value = v;2621 }2622 break;2623 case STBTE__leftup:2624 if (STBTE__IS_ACTIVE(id)) {2625 stbte__activate(0);2626 stbte__dump_colorstate();2627 }2628 break;2629 }2630}26312632static void stbte__colorpicker(int x0, int y0, int w, int h)2633{2634 int x1 = x0+w, y1 = y0+h, x,y, i;26352636 x = x0+2; y = y0+6;26372638 y += 5;2639 x += 8;2640 2641 2642 {2643 int color = stbte__color_table[stbte__cp_mode][stbte__cp_aspect][stbte__cp_index];2644 int rgb[3];2645 if (stbte__cp_altered && stbte__cp_index == STBTE__idle)2646 color = stbte__save;26472648 if (stbte__minibutton(STBTE__cmapsize, x1-20,y+ 5, 'C', STBTE__ID2(STBTE__colorpick_id,4,0)))2649 stbte__color_copy = color;2650 if (stbte__minibutton(STBTE__cmapsize, x1-20,y+15, 'P', STBTE__ID2(STBTE__colorpick_id,4,1)))2651 color = stbte__color_copy;26522653 rgb[0] = color >> 16; rgb[1] = (color>>8)&255; rgb[2] = color & 255;2654 for (i=0; i < 3; ++i) {2655 stbte__slider(x+8,64, y, rgb+i, STBTE__ID2(STBTE__colorpick_id,3,i));2656 y += 15;2657 }2658 if (stbte__ui.event != STBTE__paint && stbte__ui.event != STBTE__tick)2659 stbte__color_table[stbte__cp_mode][stbte__cp_aspect][stbte__cp_index] = (rgb[0]<<16)|(rgb[1]<<8)|(rgb[2]);2660 }26612662 y += 5;26632664 // states2665 x = x0+2+35;2666 if (stbte__ui.event == STBTE__paint) {2667 static char *states[] = { "idle", "over", "down", "down&over", "selected", "selected&over", "disabled" };2668 stbte__draw_text(x, y+1, states[stbte__cp_index], x1-x-1, 0xffffff);2669 }26702671 x = x0+24; y += 12;26722673 for (i=3; i >= 0; --i) {2674 int state = 0 != (stbte__cp_state & (1 << i));2675 if (stbte__layerbutton(x,y, "OASD"[i], STBTE__ID2(STBTE__colorpick_id, 0,i), state,0, STBTE__clayer_button)) {2676 stbte__cp_state ^= (1 << i);2677 stbte__cp_index = stbte__state_to_index[0][0][0][stbte__cp_state];2678 }2679 x += 16;2680 }2681 x = x0+2; y += 18;26822683 for (i=0; i < 3; ++i) {2684 static char *labels[] = { "Base", "Edge", "Text" };2685 if (stbte__button(STBTE__ctoolbar_button, labels[i], x,y,0,36, STBTE__ID2(STBTE__colorpick_id,1,i), stbte__cp_aspect==i,0))2686 stbte__cp_aspect = i;2687 x += 40;2688 }26892690 y += 18;2691 x = x0+2;26922693 for (i=0; i < STBTE__num_color_modes; ++i) {2694 if (stbte__button(STBTE__ctoolbar_button, stbte__color_names[i], x, y, 0,80, STBTE__ID2(STBTE__colorpick_id,2,i), stbte__cp_mode == i,0))2695 stbte__cp_mode = i;2696 y += 12;2697 }26982699 // make the currently selected aspect flash, unless we're actively dragging color slider etc2700 if (stbte__ui.event == STBTE__tick) {2701 stbte__save = stbte__color_table[stbte__cp_mode][stbte__cp_aspect][STBTE__idle];2702 if ((stbte__ui.active_id & 127) != STBTE__colorpick_id) {2703 if ((stbte__ui.ms_time & 2047) < 200) {2704 stbte__color_table[stbte__cp_mode][stbte__cp_aspect][STBTE__idle] ^= 0x1f1f1f;2705 stbte__cp_altered = 1;2706 }2707 }2708 }2709}2710#endif27112712static void stbte__editor_traverse(stbte_tilemap *tm)2713{2714 int i,j;2715
55 unmodified lines
2771 // step 2: traverse the panels2772 for (i=0; i < STBTE__num_panel; ++i) {2773 stbte__panel *p = &stbte__ui.panel[i];2774 if (stbte__ui.event == STBTE__paint) {2563 stbte__draw_rect (p->x0,p->y0,p->x0+p->width,p->y0+p->height, STBTE_COLOR_PANEL_BACKGROUND);2564 stbte__draw_frame(p->x0,p->y0,p->x0+p->width,p->y0+p->height, STBTE_COLOR_PANEL_OUTLINE);2775 stbte__draw_box(p->x0,p->y0,p->x0+p->width,p->y0+p->height, STBTE__cpanel, STBTE__idle);2776 }2777 // obscure tilemap data underneath panel2778 stbte__hittest(p->x0,p->y0,p->x0+p->width,p->y0+p->height, STBTE__ID2(STBTE__panel, i, 0));2779 switch (i) {2780 case STBTE__panel_toolbar:2781 if (stbte__ui.event == STBTE__paint)2571 stbte__draw_rect(p->x0,p->y0,p->x0+p->width,p->y0+p->height, STBTE_COLOR_TOOLBAR_BACKGROUND);2782 stbte__draw_rect(p->x0,p->y0,p->x0+p->width,p->y0+p->height, stbte__color_table[STBTE__ctoolbar][STBTE__base][STBTE__idle]);2783 stbte__toolbar(tm,p->x0,p->y0,p->width,p->height);2784 break;2785 case STBTE__panel_info:2786 stbte__info(tm,p->x0,p->y0,p->width,p->height);
3 unmodified lines
2790 break;2791 case STBTE__panel_categories:2792 stbte__categories(tm,p->x0,p->y0,p->width,p->height);2793 break;2794 case STBTE__panel_colorpick:2795#ifdef STBTE__COLORPICKER2796 stbte__colorpicker(p->x0,p->y0,p->width,p->height);2797#endif2798 break;2799 case STBTE__panel_tiles:2800 // erase boundary between categories and tiles if they're on same side2801 if (stbte__ui.event == STBTE__paint && p->side == stbte__ui.panel[STBTE__panel_categories].side)2586 stbte__draw_rect(p->x0+1,p->y0-1,p->x0+p->width-1,p->y0+1, STBTE_COLOR_PANEL_BACKGROUND);2802 stbte__draw_rect(p->x0+1,p->y0-1,p->x0+p->width-1,p->y0+1, stbte__color_table[STBTE__cpanel][STBTE__base][STBTE__idle]);2803 stbte__palette_of_tiles(tm,p->x0,p->y0,p->width,p->height);2804 break;2805 }2806 // draw the panel side selectors2807 for (j=0; j < 2; ++j) {2808 int result;2809 if (i == STBTE__panel_toolbar) continue;2594 result = stbte__microbutton(p->x0+p->width - 1 - 2*4 + 4*j,p->y0+2,3, STBTE__ID2(STBTE__panel, i, j+1), 0x808080,0xc0c0c0, 0);2810 result = stbte__microbutton(p->x0+p->width - 1 - 2*4 + 4*j,p->y0+2,3, STBTE__ID2(STBTE__panel, i, j+1), STBTE__cpanel_sider+j);2811 if (result) {2812 switch (j) {2813 case 0: p->side = result > 0 ? STBTE__side_left : STBTE__side_right; break;2814 case 1: p->delta_height += result; break;
14 unmodified lines
2829 if (i == STBTE__side_left)2830 width = stbte__ui.left_width , x += stbte__region[i].width + 1;2831 else2832 width = -stbte__ui.right_width, x -= 6;2617 if (stbte__microbutton_dragger(x, stbte__region[i].y+2, 5, STBTE__ID(STBTE__region,i), 0x206020,0xffffff, 0, &width)) {2833 if (stbte__microbutton_dragger(x, stbte__region[i].y+2, 5, STBTE__ID(STBTE__region,i), &width)) {2834 // if non-0, it is expanding, so retract it2835 if (stbte__region[i].retracted == 0.0)2836 stbte__region[i].retracted = 0.01f;2837 else
15 unmodified lines
28532854 if (stbte__ui.event == STBTE__paint && stbte__ui.alert_msg) {2855 int w = stbte__text_width(stbte__ui.alert_msg);2856 int x = (stbte__ui.x0+stbte__ui.x1)/2;2641 int y = (stbte__ui.y0+stbte__ui.y1)/2;2857 int y = (stbte__ui.y0+stbte__ui.y1)*5/6;2858 stbte__draw_rect (x-w/2-4,y-8, x+w/2+4,y+8, 0x604020);2859 stbte__draw_frame(x-w/2-4,y-8, x+w/2+4,y+8, 0x906030);2860 stbte__draw_text (x-w/2,y-4, stbte__ui.alert_msg, w+1, 0xff8040);2861 }
4 unmodified lines
2866 stbte__ui.alert_timer = 0;2867 stbte__ui.alert_msg = 0;2868 }2869 }28702871 if (stbte__ui.event == STBTE__paint) {2872 stbte__color_table[stbte__cp_mode][stbte__cp_aspect][STBTE__idle] = stbte__save;2873 stbte__cp_altered = 0;2874 }2875}28762877static void stbte__do_event(stbte_tilemap *tm)2878{
113 unmodified lines