From: equilet <2237372+equilet@users.noreply.github.com> Date: Tue, 23 Jan 2024 05:48:25 +0000 (-0800) Subject: set shapewriter functions to private, updated letter drawing code to new filewriter X-Git-Tag: v0.1~4 X-Git-Url: https://git.dabkitsch.com/?a=commitdiff_plain;h=20499877bd3e863a5512c1aa4cd6c6396d63ced3;p=morphograph.git set shapewriter functions to private, updated letter drawing code to new filewriter --- diff --git a/source/morphograph.cpp b/source/morphograph.cpp index 9503403..db3462f 100644 --- a/source/morphograph.cpp +++ b/source/morphograph.cpp @@ -128,43 +128,11 @@ public: //could be a memory leak here } - void eval_drawstyle(){ - switch(drawstyle){ - case 0: //stroke; consider stroke width - linestr.append("stroke=\"rgb(0,0,0)\" stroke-width=\"" + lws + "\" "); - linestr.append("fill=\"transparent\" "); - break; - case 1: //fill - linestr.append("fill=\"rgb(" + bs + "," + bs + "," + bs + ")\" "); - break; - case 2: //both - linestr.append("stroke=\"rgb(0,0,0)\" stroke-width=\"0.2\" "); //should be [linewidth] - linestr.append("fill=\"rgb(" + bs + "," + bs + "," + bs + ")\" "); - break; - } - } - - void calc_position_info(float tx, float ty){ - - float baseline_scalar = 15; - float aw = baseline_scalar * elem_width * size; //actual width - float hwn = -1. * (aw / 2.); //half width negative - float ah = baseline_scalar * elem_height * size; //actual height - float hhn = -1. * (ah / 2.); //half height negative - - ws = std::to_string(aw); - offset_x = std::to_string(hwn); - hs = std::to_string(ah); - offset_y = std::to_string(hhn); - xs = std::to_string(tx); - ys = std::to_string(ty); - - } - void draw_init(){ //any drawing initialization should happen here + - if(shape==std::string("linegraph")){ + if(shape == std::string("linegraph")){ linestr = "<"; //open //default strings for filewriter float tx = (x / float(vecsize)) * float(params->width); @@ -178,10 +146,9 @@ public: } void draw(){ - lws = std::to_string(linewidth); bs = std::to_string(bright); - + float tx = (x / float(vecsize)) * float(params->width); float ty = (1.0 - y) * params->height; @@ -292,6 +259,38 @@ public: private: + void eval_drawstyle(){ + switch(drawstyle){ + case 0: //stroke; consider stroke width + linestr.append("stroke=\"rgb(0,0,0)\" stroke-width=\"" + lws + "\""); + linestr.append("fill=\"transparent\" "); + break; + case 1: //fill + linestr.append("fill=\"rgb(" + bs + "," + bs + "," + bs + ")\""); + break; + case 2: //both + linestr.append("stroke=\"rgb(0,0,0)\" stroke-width=\"0.2\" "); //should be [linewidth] + linestr.append("fill=\"rgb(" + bs + "," + bs + "," + bs + ")\""); + break; + } + } + + void calc_position_info(float tx, float ty){ + + float baseline_scalar = 15; + float aw = baseline_scalar * elem_width * size; //actual width + float hwn = -1. * (aw / 2.); //half width negative + float ah = baseline_scalar * elem_height * size; //actual height + float hhn = -1. * (ah / 2.); //half height negative + + ws = std::to_string(aw); + offset_x = std::to_string(hwn); + hs = std::to_string(ah); + offset_y = std::to_string(hhn); + xs = std::to_string(tx); + ys = std::to_string(ty); + + } void set_transform(std::string ox, std::string oy){ //transform characteristics std::string rstr = std::to_string(rotation); @@ -332,54 +331,16 @@ private: void draw_letter(){ int l = rand() % 26; char ls = 'a'; - char the_char = (char)(ls + l); + std::string letter{(char)(ls + l)}; linestr.append( "text x=\"" + xs + "\" y=\"" + ys + "\" " + "font-family=\"Arial\" font-size=\"" + - std::to_string(int((size * params->height) / 16)) + "\"" + std::to_string(int((size * params->height) / 16)) + "px\" " ); - // set_transform(offset_x, offset_y); - - linestr.append( - ">" + - std::to_string(the_char) + "\n" - ); + eval_drawstyle(); - switch(drawstyle){ - case 0://stroke - - -// (*doc) << Text( -// pPoint(x / vecsize * params->width, y * params->height), -// lss.str(), Fill(), -// Font((size * params->height) / 16, "Verdana"), -// Stroke(linewidth, Color(0, 0, 0)) -// ); - break; - case 1://fill -// (*doc) << Text( -// pPoint(x / vecsize * params->width, y * params->height), -// lss.str(), Color(bright, bright, bright), -// Font((size * params->height) / 16, "Verdana") -// ); - break; - case 2://both -// (*doc) << Text( -// pPoint(x / vecsize * params->width, y * params->height), -// lss.str(), Color(bright, bright, bright), -// Font((size * params->height) / 16, "Verdana"), -// Stroke(linewidth, Color(0, 0, 0)) -// ); - break; - default: -// (*doc) << Text( -// pPoint(x / vecsize * params->width, y * params->height), -// lss.str(), Color(bright, bright, bright), -// Font((size * params->height) / 16, "Verdana") -// ); - break; - } + linestr.append(">" + letter + "\n"); } }; @@ -473,7 +434,7 @@ public: //swrite.set_idx(j); //i is layer, j is analysis frame swrite.set_x(float(j)); - object_post((t_object *)x, "x location: %d", j); + //object_post((t_object *)x, "x location: %d", j); double sc_freq = (layers[i].desc.speccentr[j] / (max_freq - min_freq)) + min_freq; double sc_nrg = (layers[i].desc.energy[j] / (max_nrg - min_nrg)) + min_nrg; @@ -550,9 +511,8 @@ public: swrite.set_size(curr_feature_datum); } break; case PARAM_YLOC: { - object_post((t_object *)x, "detected yloc; curr feature data: %f", curr_feature_datum); - swrite.set_y(curr_feature_datum); + //object_post((t_object *)x, "detected ylocation: curr feature data: %f", curr_feature_datum); } break; // case PARAM_XDEV: { // //unimplemented