void draw_terrain() { short q,r,x,i,small_i; location which_pt,where_draw; RECT draw_rect,clipping_rect = {8,8,260,332}; unsigned char t_to_draw; RECT tiny_to,tiny_to_base = {29,37,36,44},tiny_from,from_rect,to_rect; HBITMAP store_bmp; COLORREF gray = RGB(128,128,128); COLORREF red = RGB(255,0,0); COLORREF white = RGB(255,255,255); HBRUSH new_brush; HDC hdc; HPEN old_pen; if (overall_mode >= 60) return; if (cur_viewing_mode == 0) { paint_pattern(ter_draw_gworld,0,terrain_rect,1); } hdc = CreateCompatibleDC(main_dc); SetBkMode(hdc,TRANSPARENT); SelectObject(hdc,small_bold_font); store_bmp = (HBITMAP)SelectObject(hdc,ter_draw_gworld); new_brush = CreateSolidBrush(gray); FrameRect(hdc,&terrain_rect,new_brush); DeleteObject(new_brush); old_pen = (HPEN)SelectObject(hdc,GetStockObject(NULL_PEN)); SelectObject(hdc,store_bmp); if (cur_viewing_mode == 0) { for (q = 0; q < 9; q++) for (r = 0; r < 9; r++) { where_draw.x = q; where_draw.y = r; if (editing_town == TRUE) { t_to_draw = t_d.terrain[cen_x + q - 4][cen_y + r - 4]; } else { if (cen_x + q - 4 == -1) t_to_draw = borders[3][cen_y + r - 4]; else if (cen_x + q - 4 == 48) t_to_draw = borders[1][cen_y + r - 4]; else if (cen_y + r - 4 == -1) t_to_draw = borders[0][cen_x + q - 4]; else if (cen_y + r - 4 == 48) t_to_draw = borders[2][cen_x + q - 4]; else t_to_draw = current_terrain.terrain[cen_x + q - 4][cen_y + r - 4]; } draw_one_terrain_spot(q,r,t_to_draw); which_pt.x = cen_x + q - 4; which_pt.y =cen_y + r - 4; tiny_to = tiny_to_base; OffsetRect(&tiny_to,28 * q, 36 * r); // draw start icon, if starting point if ((editing_town == TRUE) && (cur_town == scenario.which_town_start) && (scenario.where_start.x == cen_x + q - 4) && (scenario.where_start.y == cen_y + r - 4)) { from_rect = start_button_from; to_rect = tiny_to; to_rect.left -= 14; rect_draw_some_item(editor_mixed,from_rect,ter_draw_gworld,to_rect,0,0); OffsetRect(&tiny_to,0,-7); } if ((editing_town == FALSE) && (scenario.out_sec_start.x == cur_out.x) && (scenario.out_sec_start.y == cur_out.y) && (scenario.out_start.x == cen_x + q - 4) && (scenario.out_start.y == cen_y + r - 4)) { from_rect = start_button_from; to_rect = tiny_to; to_rect.left -= 14; rect_draw_some_item(editor_mixed,from_rect,ter_draw_gworld,to_rect,0,0); OffsetRect(&tiny_to,0,-7); } small_i = small_icons[scenario.ter_types[t_to_draw].special]; if ((small_i == 30) && (scenario.ter_types[t_to_draw].flag2 >= 5)) small_i = 31; if ((small_i == 31) && (scenario.ter_types[t_to_draw].flag2 == 10)) small_i = 32; tiny_from = base_small_button_from; OffsetRect(&tiny_from,7 * (small_i % 10),7 * (small_i / 10)); if (small_i > 0) { rect_draw_some_item(editor_mixed,tiny_from,ter_draw_gworld,tiny_to,0,0); OffsetRect(&tiny_to,0,-7); } if (is_special(cen_x + q - 4,cen_y + r - 4) == TRUE) { tiny_from = base_small_button_from; OffsetRect(&tiny_from,7 * (7),7 * (0)); rect_draw_some_item(editor_mixed,tiny_from,ter_draw_gworld,tiny_to,0,0); OffsetRect(&tiny_to,0,-7); } if ((t_to_draw == 7) || (t_to_draw == 10) || (t_to_draw == 13) || (t_to_draw == 16)) { tiny_from = base_small_button_from; OffsetRect(&tiny_from,7 * (3),7 * (2)); rect_draw_some_item(editor_mixed,tiny_from,ter_draw_gworld,tiny_to,0,0); OffsetRect(&tiny_to,0,-7); } if (editing_town == FALSE) { for (i = 0; i < 4; i++) if ((cen_x + q - 4 == current_terrain.wandering_locs[i].x) && (cen_y + r - 4 == current_terrain.wandering_locs[i].y)) { tiny_from = base_small_button_from; OffsetRect(&tiny_from,7 * (2),7 * (1)); rect_draw_some_item(editor_mixed,tiny_from,ter_draw_gworld,tiny_to,0,0); OffsetRect(&tiny_to,0,-7); i = 4; } } if (editing_town == TRUE) { for (i = 0; i < 4; i++) if ((cen_x + q - 4 == town.start_locs[i].x) && (cen_y + r - 4 == town.start_locs[i].y)) { tiny_from = base_small_button_from; OffsetRect(&tiny_from,7 * (6 + i),7 * (1)); rect_draw_some_item(editor_mixed,tiny_from,ter_draw_gworld,tiny_to,0,0); OffsetRect(&tiny_to,0,-7); } for (i = 0; i < 4; i++) if ((cen_x + q - 4 == town.wandering_locs[i].x) && (cen_y + r - 4 == town.wandering_locs[i].y)) { tiny_from = base_small_button_from; OffsetRect(&tiny_from,7 * (2),7 * (1)); rect_draw_some_item(editor_mixed,tiny_from,ter_draw_gworld,tiny_to,0,0); OffsetRect(&tiny_to,0,-7); i = 4; } if (is_web(cen_x + q - 4,cen_y + r - 4) == TRUE) { from_rect = calc_rect(5,0); Draw_Some_Item(field_gworld,from_rect,ter_draw_gworld,where_draw,1,0); } if (is_crate(cen_x + q - 4,cen_y + r - 4) == TRUE) { from_rect = calc_rect(6,0); Draw_Some_Item(field_gworld,from_rect,ter_draw_gworld,where_draw,1,0); } if (is_barrel(cen_x + q - 4,cen_y + r - 4) == TRUE) { from_rect = calc_rect(7,0); Draw_Some_Item(field_gworld,from_rect,ter_draw_gworld,where_draw,1,0); } if (is_fire_barrier(cen_x + q - 4,cen_y + r - 4) == TRUE) { from_rect = calc_rect(0,2); Draw_Some_Item(field_gworld,from_rect,ter_draw_gworld,where_draw,1,0); } if (is_quickfire(cen_x + q - 4,cen_y + r - 4) == TRUE) { from_rect = calc_rect(7,1); Draw_Some_Item(field_gworld,from_rect,ter_draw_gworld,where_draw,1,0); } if (is_force_barrier(cen_x + q - 4,cen_y + r - 4) == TRUE) { from_rect = calc_rect(2,2); Draw_Some_Item(field_gworld,from_rect,ter_draw_gworld,where_draw,1,0); } for (i = 0; i < 8; i++) if (is_sfx(cen_x + q - 4,cen_y + r - 4,i)) { from_rect = calc_rect(i,3); Draw_Some_Item(field_gworld,from_rect,ter_draw_gworld,where_draw,1,0); } for (x = 0; x < 64; x++) if ((cen_x + q - 4 == town.preset_items[x].item_loc.x) && (cen_y + r - 4 == town.preset_items[x].item_loc.y) && (town.preset_items[x].item_code >= 0)) { } for (x = 0; x < 60; x++) if ((cen_x + q - 4 == t_d.creatures[x].start_loc.x) && (cen_y + r - 4 == t_d.creatures[x].start_loc.y) && (t_d.creatures[x].number != 0)) { } } } if (editing_town == TRUE) { draw_monsts(hdc); draw_items(hdc); } store_bmp = (HBITMAP)SelectObject(hdc,ter_draw_gworld); ClipRect(hdc,&clipping_rect); if (editing_town == TRUE) { // draw info rects for (i = 0; i < 16; i++) if (t_d.room_rect[i].left > -1) { draw_rect.left = 22 + 28 * (t_d.room_rect[i].left - cen_x + 4); draw_rect.right = 22 + 28 * (t_d.room_rect[i].right - cen_x + 4); draw_rect.top = 24 + 36 * (t_d.room_rect[i].top - cen_y + 4); draw_rect.bottom = 24 + 36 * (t_d.room_rect[i].bottom - cen_y + 4); //c = GetNearestPaletteIndex(hpal,red); new_brush = CreateSolidBrush(red); FrameRect(hdc,&draw_rect,new_brush); DeleteObject(new_brush); } // draw border rect draw_rect.left = 21 + 28 * (town.in_town_rect.left - cen_x + 4); draw_rect.right = 21 + 28 * (town.in_town_rect.right - cen_x + 4); draw_rect.top = 25 + 36 * (town.in_town_rect.top - cen_y + 4); draw_rect.bottom = 25 + 36 * (town.in_town_rect.bottom - cen_y + 4); // c = GetNearestPaletteIndex(hpal,white); new_brush = CreateSolidBrush(white); FrameRect(hdc,&draw_rect,new_brush); DeleteObject(new_brush); } if (editing_town == FALSE) { // draw info rects for (i = 0; i < 8; i++) if (current_terrain.info_rect[i].left > -1) { draw_rect.left = 22 + 28 * (current_terrain.info_rect[i].left - cen_x + 4); draw_rect.right = 22 + 28 * (current_terrain.info_rect[i].right - cen_x + 4); draw_rect.top = 24 + 36 * (current_terrain.info_rect[i].top - cen_y + 4); draw_rect.bottom = 24 + 36 * (current_terrain.info_rect[i].bottom - cen_y + 4); //c = GetNearestPaletteIndex(hpal,red); new_brush = CreateSolidBrush(red); FrameRect(hdc,&draw_rect,new_brush); DeleteObject(new_brush); } } undo_clip(hdc); SelectObject(hdc,store_bmp); small_any_drawn = FALSE; } if (cur_viewing_mode == 1) { if (small_any_drawn == FALSE) { InsetRect(&terrain_rect,1,1); paint_pattern(ter_draw_gworld,0,terrain_rect,1); InsetRect(&terrain_rect,-1,-1); //FrameRect(&terrain_rect); } for (q = 0; q < ((editing_town == TRUE) ? max_dim[town_type] : 48); q++) for (r = 0; r < ((editing_town == TRUE) ? max_dim[town_type] : 48); r++) { t_to_draw = (editing_town == TRUE) ? t_d.terrain[q][r] : current_terrain.terrain[q][r]; if ((small_what_drawn[q][r] != t_to_draw) || (small_any_drawn == FALSE)) { draw_one_tiny_terrain_spot(q,r,t_to_draw,hdc); small_what_drawn[q][r] = t_to_draw; } } small_any_drawn = TRUE; } SelectObject(hdc,old_pen); DeleteObject(hdc); //draw_cur_string(); place_location(); rect_draw_some_item(ter_draw_gworld,terrain_rect,ter_draw_gworld,world_screen,0,1); }
void cTextField::draw(){ if(!visible) return; static const sf::Color hiliteClr = {127,127,127}, ipClr = {92, 92, 92}; inWindow->setActive(); rectangle outline = frame; outline.inset(-2,-2); fill_rect(*inWindow, outline, sf::Color::White); frame_rect(*inWindow, outline, sf::Color::Black); std::string contents = getText(); TextStyle style; style.font = FONT_PLAIN; style.pointSize = 12; style.colour = sf::Color::Black; style.lineHeight = 16; size_t ip_offset = 0; hilite_t hilite = {insertionPoint, selectionPoint}; if(selectionPoint < insertionPoint) std::swap(hilite.first,hilite.second); if(haveFocus && contents.length() >= 1 && changeMade) { text_rect = frame; text_rect.inset(2,2); // Determine which line the insertion and selection points are on clip_rect(*inWindow, {0,0,0,0}); // To prevent drawing hilite_t tmp_hilite = hilite; // Manipulate this to ensure that there is a hilited area std::string dummy_str = contents + " "; if(tmp_hilite.first >= tmp_hilite.second) tmp_hilite.second = tmp_hilite.first + 1; std::vector<rectangle> rects = draw_string_hilite(*inWindow, text_rect, dummy_str, style, {tmp_hilite}, {0,0,0}); if(!rects.empty()) { // We only care about the first and last rects. Furthermore, we only really need one point location ip_pos = rects[0].centre(), sp_pos = rects[rects.size() - 1].centre(); if(selectionPoint < insertionPoint) std::swap(ip_pos, sp_pos); // Prioritize selection point being visible. If possible, also keep insertion point visible. // We do this by first ensuring the insertion point is visible, then doing the same // for the selection point. while(!ip_pos.in(frame)) { text_rect.offset(0,-14); ip_pos.y -= 14; sp_pos.y -= 14; } while(!sp_pos.in(frame)) { int shift = selectionPoint < insertionPoint ? 14 : -14; text_rect.offset(0,shift); ip_pos.y += shift; sp_pos.y += shift; } } undo_clip(*inWindow); changeMade = false; } clip_rect(*inWindow, frame); ip_col = ip_row = -1; if(haveFocus) { snippets = draw_string_sel(*inWindow, text_rect, contents, style, {hilite}, hiliteClr); int iSnippet = -1, sum = 0; ip_offset = insertionPoint; for(size_t i = 0; i < snippets.size(); i++) { size_t snippet_len = snippets[i].text.length(); sum += snippet_len; if(sum >= insertionPoint) { iSnippet = i; break; } ip_offset -= snippet_len; } std::string pre_ip = iSnippet >= 0 ? snippets[iSnippet].text.substr(0, ip_offset) : ""; ip_offset = string_length(pre_ip, style); if(ip_timer.getElapsedTime().asMilliseconds() < 500) { // printf("Blink on (%d); ", ip_timer.getElapsedTime().asMilliseconds()); rectangle ipRect = {0, 0, 15, 1}; if(iSnippet >= 0) ipRect.offset(snippets[iSnippet].at.x + ip_offset, snippets[iSnippet].at.y + 1); else ipRect.offset(frame.topLeft()), ipRect.offset(3,2); fill_rect(*inWindow, ipRect, ipClr); } else if(ip_timer.getElapsedTime().asMilliseconds() > 1000) { // printf("Blink off (%d); ", ip_timer.getElapsedTime().asMilliseconds()); ip_timer.restart(); } // Record it so that we can calculate up/down arrow key results ip_col = ip_offset; ip_row = iSnippet; } else { rectangle text_rect = frame; text_rect.inset(2,2); win_draw_string(*inWindow, text_rect, contents, eTextMode::WRAP, style); } undo_clip(*inWindow); }