static void test_two_commands(void) { const char buf[] = "apropos|locate"; assert_int_equal(0, line_pos(buf, buf, ' ', 0)); assert_int_equal(0, line_pos(buf, buf + 1, ' ', 0)); assert_int_equal(0, line_pos(buf, buf + 7, ' ', 0)); }
static void test_skip(void) { const char *buf; buf = "set fusehome=a\\|b"; assert_int_equal(0, line_pos(buf, buf, ' ', 0)); assert_int_equal(0, line_pos(buf, buf + 1, ' ', 0)); assert_int_equal(1, line_pos(buf, buf + 15, ' ', 0)); }
double LevelAABBTree::IntersectRayLine(const DVector2 &ray_start, const DVector2 &ray_end, int line_index, const DVector2 &raydelta, double rayd, double raydist2) { // Check if two line segments intersects (the ray and the line). // The math below does this by first finding the fractional hit for an infinitely long ray line. // If that hit is within the line segment (0 to 1 range) then it calculates the fractional hit for where the ray would hit. // // This algorithm is homemade - I would not be surprised if there's a much faster method out there. const double epsilon = 0.0000001; const AABBTreeLine &line = treelines[line_index]; DVector2 raynormal = DVector2(raydelta.Y, -raydelta.X); DVector2 line_pos(line.x, line.y); DVector2 line_delta(line.dx, line.dy); double den = raynormal | line_delta; if (fabs(den) > epsilon) { double t_line = (rayd - (raynormal | line_pos)) / den; if (t_line >= 0.0 && t_line <= 1.0) { DVector2 linehitdelta = line_pos + line_delta * t_line - ray_start; double t = (raydelta | linehitdelta) / raydist2; return t > 0.0 ? t : 1.0; } } return 1.0; }
// Rotate the grid by rotation, keeping cell contents. // rotation must be a multiple of 90 degrees. // NOTE: due to partial cells, cell coverage in the rotated grid will be // inexact. This is why there is no Rotate for the generic BBGrid. // TODO(rays) investigate fixing this inaccuracy by moving the origin after // rotation. void IntGrid::Rotate(const FCOORD& rotation) { ASSERT_HOST(rotation.x() == 0.0f || rotation.y() == 0.0f); ICOORD old_bleft(bleft()); ICOORD old_tright(tright()); int old_width = gridwidth(); int old_height = gridheight(); TBOX box(bleft(), tright()); box.rotate(rotation); int* old_grid = grid_; grid_ = NULL; Init(gridsize(), box.botleft(), box.topright()); // Iterate over the old grid, copying data to the rotated position in the new. int oldi = 0; FCOORD x_step(rotation); x_step *= gridsize(); for (int oldy = 0; oldy < old_height; ++oldy) { FCOORD line_pos(old_bleft.x(), old_bleft.y() + gridsize() * oldy); line_pos.rotate(rotation); for (int oldx = 0; oldx < old_width; ++oldx, line_pos += x_step, ++oldi) { int grid_x, grid_y; GridCoords(static_cast<int>(line_pos.x() + 0.5), static_cast<int>(line_pos.y() + 0.5), &grid_x, &grid_y); grid_[grid_y * gridwidth() + grid_x] = old_grid[oldi]; } } delete [] old_grid; }
void centre_align_text(int pos, char *charlies){ int index = 0; for(index = 0; charlies[index] != 0; index++); int text_width = index * 10; int xpos = (window_width/2) - (text_width/2); glRasterPos2f(xpos ,line_pos(pos)); printString(charlies); }
void right_align_text(int pos, char *charlies){ int index = 0; for(index = 0; charlies[index] != 0; index++); int text_width = index * 10; int xpos = window_width - text_width; glRasterPos2f(xpos - 6 ,line_pos(pos)); printString(charlies); }
static void test_custom_separator(void) { const char *buf; buf = "s/a|b\\/c/d|e/g|"; assert_int_equal(0, line_pos(buf, buf, '/', 1)); assert_int_equal(0, line_pos(buf, buf + 1, '/', 1)); assert_int_equal(2, line_pos(buf, buf + 2, '/', 1)); assert_int_equal(2, line_pos(buf, buf + 3, '/', 1)); assert_int_equal(2, line_pos(buf, buf + 4, '/', 1)); assert_int_equal(1, line_pos(buf, buf + 6, '/', 1)); assert_int_equal(2, line_pos(buf, buf + 10, '/', 1)); assert_int_equal(0, line_pos(buf, buf + 14, '/', 1)); }
static void test_pipe(void) { const char *buf; buf = "filter /a|b/"; assert_int_equal(0, line_pos(buf, buf, ' ', 1)); assert_int_equal(0, line_pos(buf, buf + 1, ' ', 1)); assert_int_equal(5, line_pos(buf, buf + 9, ' ', 1)); buf = "filter 'a|b'"; assert_int_equal(0, line_pos(buf, buf, ' ', 1)); assert_int_equal(0, line_pos(buf, buf + 1, ' ', 1)); assert_int_equal(3, line_pos(buf, buf + 9, ' ', 1)); buf = "filter \"a|b\""; assert_int_equal(0, line_pos(buf, buf, ' ', 1)); assert_int_equal(0, line_pos(buf, buf + 1, ' ', 1)); assert_int_equal(4, line_pos(buf, buf + 9, ' ', 1)); }
const char * find_last_command(const char cmds[]) { const char *p, *q; p = cmds; q = cmds; while(*cmds != '\0') { if(*p == '\\') { q += (p[1] == '|') ? 1 : 2; p += 2; } else if(*p == '\0' || (*p == '|' && line_pos(cmds, q, ' ', starts_with_lit(cmds, "fil")) == 0)) { if(*p != '\0') { ++p; } cmds = skip_to_cmd_name(cmds); if(*cmds == '!' || starts_with_lit(cmds, "com")) { break; } q = p; if(*q == '\0') { break; } cmds = q; } else { ++q; ++p; } } return cmds; }
CmdLineLocation get_cmdline_location(const char cmd[], const char pos[]) { char separator; int regex_quoting; cmd_info_t info; const int cmd_id = get_cmd_info(cmd, &info); switch(cmd_id) { case COM_FILTER: separator = ' '; regex_quoting = 1; break; case COM_SUBSTITUTE: case COM_TR: separator = info.sep; regex_quoting = 1; break; default: separator = ' '; regex_quoting = 0; break; } switch(line_pos(cmd, pos, separator, regex_quoting)) { case 0: return CLL_OUT_OF_ARG; case 1: /* Fall through. */ case 2: return CLL_NO_QUOTING; case 3: return CLL_S_QUOTING; case 4: return CLL_D_QUOTING; case 5: return CLL_R_QUOTING; default: assert(0 && "Unexpected return code."); return CLL_NO_QUOTING; } }
static void test_set_command(void) { const char *buf; buf = "set fusehome=\"a|b\""; assert_int_equal(0, line_pos(buf, buf, ' ', 0)); assert_int_equal(0, line_pos(buf, buf + 1, ' ', 0)); assert_int_equal(4, line_pos(buf, buf + 16, ' ', 0)); buf = "set fusehome='a|b'"; assert_int_equal(0, line_pos(buf, buf, ' ', 0)); assert_int_equal(0, line_pos(buf, buf + 1, ' ', 0)); assert_int_equal(3, line_pos(buf, buf + 16, ' ', 0)); }
void eos::TextEditor::OnPaint() { ax::GC gc; ax::Rect rect(GetDrawingRect()); gc.SetColor(_info.bg_color); gc.DrawRectangle(ax::Rect(0, 0, rect.size.x, rect.size.y)); // Draw line number background. gc.SetColor(_info.line_number_bg_color); gc.DrawRectangle(ax::Rect(0, 0, 25, rect.size.y)); ax::Point num_pos(4, 2); gc.SetColor(_info.line_number_color); // Draw line number. for(int i = 0; i < _n_line_shown; i++) { int num = i + _file_start_index; std::string num_str = std::to_string(num); if(num < 10) { num_str = " " + num_str; } else if(num < 100) { num_str = " " + num_str; } gc.DrawString(_line_num_font, num_str, num_pos); num_pos += ax::Point(0, 15); } // Text initial position. //ax::Point line_pos(4, 0); ax::Point line_pos(25 + 4, 0); _next_pos_data.clear(); const ax::StringVector& data = _logic.GetFileData(); // Set text color. gc.SetColor(_info.text_color); // Draw text. for(int i = 0, k = _file_start_index; k < data.size() && i < _n_line_shown; i++, k++) { const std::string& text = data[k]; std::vector<int> next_vec(text.size() + 1); // Draw string. if(_font) { int x = line_pos.x; next_vec[0] = x; // //---------------------------------------- // ax::StringVector words = ax::Utils::String::Split(text, " "); // // int index = 0; // // for(auto& w : words) // { // std::string clean_word = RemoveSpecialChar(w); // // ax::Color word_color = _info.text_color; // // if(_key_words_cpp.find(clean_word) != _key_words_cpp.end()) // { // word_color = ax::Color(0.6627451, 0.05098039, 0.5686275); // } // // for (int i = 0; i < w.size(); i++) // { // gc.SetColor(word_color); // // if(text[index] == ' ') // { // i--; // _font.SetChar(' '); // } // else // { // _font.SetChar(w[i]); // // if(is_special(w[i])) // { // gc.SetColor(_info.text_color); // } // else if(std::isdigit(w[i])) // { // gc.SetColor(ax::Color(0.0, 0.0, 1.0)); // } // } // // ax::Point d = _font.GetDelta(); // // ax::Point txtPos(x + d.x, // line_pos.y - d.y + _font.GetFontSize()); // // ax::Rect txtRect(txtPos, _font.GetSize()); // gc.DrawTexture(_font.GetTexture(), txtRect); // // x += _font.GetNextPosition(); // // next_vec[index + 1] = x; // // index++; // // } // } // // _font.SetChar(' '); // ax::Point d = _font.GetDelta(); // // while(index < text.size()) // { // ax::Point txtPos(x + d.x, // line_pos.y - d.y + _font.GetFontSize()); // ax::Rect txtRect(txtPos, _font.GetSize()); // gc.DrawTexture(_font.GetTexture(), txtRect); // x += _font.GetNextPosition(); // next_vec[index + 1] = x; // index++; // } //------------------------ for (int i = 0; i < text.size(); i++) { _font.SetChar(text[i]); ax::Point d = _font.GetDelta(); ax::Point txtPos(x + d.x, line_pos.y - d.y + _font.GetFontSize()); ax::Rect txtRect(txtPos, _font.GetSize()); gc.DrawTexture(_font.GetTexture(), txtRect); x += _font.GetNextPosition(); next_vec[i + 1] = x; } } _next_pos_data.push_back(next_vec); line_pos += ax::Point(0, 15); } // Line cursor. ax::Point cursor_index = FileCursorPosToNextPosIndex(); if(cursor_index.x != -1 && cursor_index.y != -1) { ax::Print("Draw cursor"); int x = _next_pos_data[cursor_index.y][cursor_index.x]; int y = cursor_index.y * _line_height; // gc.SetColor(_info.cursor_color); gc.SetColor(ax::Color(1.0, 0.0, 0.0)); gc.DrawLine(ax::Point(x, y), ax::Point(x, y + _line_height)); } }
void left_align_text(int pos, char *charlies){ glRasterPos2f(6 ,line_pos(pos)); printString(charlies); }