diff --git a/plugins/Brushes.h b/plugins/Brushes.h index 39f1614bd..7cbc73daa 100644 --- a/plugins/Brushes.h +++ b/plugins/Brushes.h @@ -197,47 +197,72 @@ private: }; command_result parseRectangle(color_ostream & out, + vector & input, int start, int end, int & width, int & height, int & zLevels, - int oldWidth, int oldHeight, int oldZLevels, bool hasConsole = true) { - out << "Parse:" << endl - << "\tW:" << width << " - " << oldWidth << endl - << "\tW:" << height << " - " << oldHeight << endl - << "\tW:" << zLevels << " - " << oldZLevels << endl - << "Console: " << hasConsole << endl; - if (width < 1 || height < 1) { + int newWidth = 0, newHeight = 0, newZLevels = 1; + // z is different so 'range w h' won't ask for it. + + if (end > start + 1) + { + newWidth = atoi(input[start++].c_str()); + newHeight = atoi(input[start++].c_str()); + } + + if (end > start) { + newZLevels = atoi(input[start++].c_str()); + } + + string command = ""; + std::stringstream str; + CommandHistory hist; + + if (newWidth < 1) { if (hasConsole) { - string command = ""; - std::stringstream str; Console &con = static_cast(out); - CommandHistory hist; str.str(""); - str << "Set range width <" << oldWidth << "> "; + str << "Set range width <" << width << "> "; con.lineedit(str.str(), command, hist); hist.add(command); - width = command == "" ? oldWidth : atoi(command.c_str()); + newWidth = command == "" ? width : atoi(command.c_str()); + } else { + return CR_WRONG_USAGE; + } + } + + if (newHeight < 1) { + if (hasConsole) { + Console &con = static_cast(out); str.str(""); - str << "Set range height <" << oldHeight << "> "; + str << "Set range height <" << height << "> "; con.lineedit(str.str(), command, hist); hist.add(command); - height = command == "" ? oldHeight : atoi(command.c_str()); + newHeight = command == "" ? height : atoi(command.c_str()); + } else { + return CR_WRONG_USAGE; + } + } + + if (newZLevels < 1) { + if (hasConsole) { + Console &con = static_cast(out); str.str(""); - str << "Set range z-levels <" << oldZLevels << "> "; + str << "Set range z-levels <" << zLevels << "> "; con.lineedit(str.str(), command, hist); hist.add(command); - zLevels = command == "" ? oldZLevels : atoi(command.c_str()); + newZLevels = command == "" ? zLevels : atoi(command.c_str()); } else { return CR_WRONG_USAGE; } } - width = width < 1? 1 : width; - height = height < 1? 1 : height; - zLevels = zLevels < 1? 1 : zLevels; + width = newWidth < 1? 1 : newWidth; + height = newHeight < 1? 1 : newHeight; + zLevels = newZLevels < 1? 1 : zLevels; return CR_OK; } diff --git a/plugins/liquids.cpp b/plugins/liquids.cpp index ff222126d..1ecf98b1f 100644 --- a/plugins/liquids.cpp +++ b/plugins/liquids.cpp @@ -200,22 +200,8 @@ command_result df_liquids (color_ostream &out_, vector & parameters) } else if(command == "range" || command == "r") { - int oldWidth = width, oldHeight = height, oldZLevels = z_levels; - width = height = z_levels = 0; - - if (commands.size() >= 3) - { - width = atoi(commands[1].c_str()); - height = atoi(commands[2].c_str()); - - if (commands.size() >= 4) { - z_levels = atoi(commands[3].c_str()); - } - } - - command_result res = parseRectangle(out, width, height, z_levels, - oldWidth, oldHeight, oldZLevels); - + command_result res = parseRectangle(out, commands, 1, commands.size(), + width, height, z_levels); if (res != CR_OK) { return res; diff --git a/plugins/tiletypes.cpp b/plugins/tiletypes.cpp index 236ac1fa1..b7914f259 100644 --- a/plugins/tiletypes.cpp +++ b/plugins/tiletypes.cpp @@ -788,7 +788,6 @@ command_result processCommand(color_ostream &out, std::vector &comm return executePaintJob(out); } - std::ostringstream ss_o; int loc = start; std::string command = commands[loc++]; @@ -817,26 +816,17 @@ command_result processCommand(color_ostream &out, std::vector &comm } else if (command == "range" || command == "r") { - int width = 0, height = 0, z_levels = 0; + int width = 1, height = 1, zLevels = 1; - if (commands.size() >= loc) - { - width = toint(commands[loc++]); - height = toint(commands[loc++]); - - if (commands.size() >= loc) { - z_levels = toint(commands[loc++]); - } - } - - command_result res = parseRectangle(out, width, height, z_levels, width, height, z_levels, hasConsole); + command_result res = parseRectangle(out, commands, loc, end, + width, height, zLevels, hasConsole); if (res != CR_OK) { return res; } delete brush; - brush = new RectangleBrush(width, height, z_levels, 0, 0, 0); + brush = new RectangleBrush(width, height, zLevels, 0, 0, 0); } else if (command == "block") {