void TSC_source::cmd_selectblock() { sel1_linenr=cursor_linenr;sel1_colnr=cursor_colnr;sel2_linenr=cursor_linenr;sel2_colnr=cursor_colnr; while ((sel1_colnr>0)&&(Qisalphanumerical(G_line(cursor_linenr)->G_char(sel1_colnr-1)))) sel1_colnr--; while ((sel2_colnr<=G_line(cursor_linenr)->G_length()-1)&&(Qisalphanumerical(G_line(cursor_linenr)->G_char(sel2_colnr)))) sel2_colnr++; cursor_colnr=sel2_colnr; }
void TSC_source::cmd_cutselblock(bool backup) { int selline1,selcol1,selline2,selcol2; if (!G_sel(selline1,selcol1,selline2,selcol2)) return; if (backup) undo_begin(); if (selline1==selline2) { cursor_linenr=selline1;cursor_colnr=selcol1; cmd_del(selcol2-selcol1+1); } else { cursor_linenr=selline1;cursor_colnr=selcol1; if (cursor_colnr<G_line(selline1)->G_length()) cmd_del(G_line(selline1)->G_length()-cursor_colnr,backup); while (selline2>selline1+1) { cmd_mergeline(backup); if (cursor_colnr<G_line(selline1)->G_length()) cmd_del(G_line(selline1)->G_length()-cursor_colnr,backup); selline2--; } cursor_linenr=selline2;cursor_colnr=0; if (selcol2>=0) cmd_del(selcol2+1,backup); Set_cursor(selline1,selcol1); cmd_mergeline(backup); } Set_sel(cursor_linenr,cursor_colnr,cursor_linenr,cursor_colnr); if (backup) undo_end(); }
int main() { double swidth, sheight ; double i,x,y ; double z[2] ; swidth = 600 ; sheight = 600 ; G_init_graphics(swidth, sheight); i = 0; while(i<600){ G_rgb(0,0,1) ; G_line (i, 0, i, 599) ; G_line(0,i,599,i) ; i=i+10 ; } i=0; while(i<10){ G_wait_click(z) ; x = z[0] ; y = z[1] ; x=x-fmod(x,10); y=y-fmod(y,10); G_fill_rectangle(x, y ,10,10); i++; } G_wait_key(); }
void TSC_source::cmd_insertline(bool autoindent, bool backup) { if (!G_canmodify()) return; if ((cursor_linenr<0)||(cursor_linenr>=G_linecount())) return; if (autoindent&&backup) undo_begin(); if (backup) addundo(new TSC_source_undoaction_insertline(this)); QString strl=*lines[cursor_linenr]; strl.substring(0,cursor_colnr-1); QString strr=*lines[cursor_linenr]; strr.substring(cursor_colnr,strr.G_length()); *lines[cursor_linenr]=strl; lines.insertbefore(cursor_linenr+1,new QString(strr)); cursor_linenr++;cursor_colnr=0; if (autoindent) { QString indent; for (int i=0; (i<G_line(cursor_linenr-1)->G_length())&&(G_line(cursor_linenr-1)->G_char(i)==' '); i++) indent+=' '; if (indent.G_length()>0) insertstring(indent,backup); } if (autoindent&&backup) undo_end(); modified=true; }
my_fill_polygon(double x[], double y[], int length){ int i,j,k; // printf("length %d \n", length); if(length ==2){ G_line(x[1], y[1], x[0], y[0]); }else{ for(i=0;i<WINDOW; i++){ double points[length]; int pcount=0; for(j=0; j<length; j++){ if((y[j] > i && y[(j+1)%length] > i) || (y[j] <= i && y[(j+1)%length] <= i)){} else{ double rise, run, b, slope, xcord; rise = y[j] - y[(j+1)%length]; run = x[j] - x[(j+1)%length]; slope = rise/run; xcord = (i - y[j])/slope + x[j]; //printf("xcord: %lf , slope %lf , y[j] : %lf , x[j]: %lf , y: %d \n ", xcord, slope, y[j], x[j], i); points[pcount] = xcord; pcount++; } } int k; sort(points, pcount); for(k=0; k < pcount; k+=2){ //printf("line x1 %lf, x2 %lf pcount: %d , y: %d \n", points[k], points[k+1], pcount, i); G_line(points[k], i, points[k+1], i); } } } }
void TSC_source::Set_cursor(int linenr, int colnr, bool resetsel) { if (linenr<0) linenr=0; if (colnr<0) colnr=0; if (G_line(linenr)!=NULL) if (colnr>G_line(linenr)->G_length()) colnr=G_line(linenr)->G_length(); cursor_linenr=linenr; cursor_colnr=colnr; if (resetsel) Set_sel(linenr,colnr,linenr,colnr); else Set_sel(sel1_linenr,sel1_colnr,linenr,colnr); }
void TSC_source::jumpcursorpos(int tpe, bool resetsel) { if (G_linecount()<=0) return; if (G_line(cursor_linenr)!=NULL) { if (tpe==-1) Set_cursor(cursor_linenr,0,resetsel); if (tpe==+1) Set_cursor(cursor_linenr,G_line(cursor_linenr)->G_length(),resetsel); if (tpe==-2) Set_cursor(0,0,resetsel); if (tpe==+2) Set_cursor(G_linecount()-1,G_line(G_linecount()-1)->G_length(),resetsel); } }
void mypolygon(double x[], double y[], int length ){ int i; G_rgb(1,1,1); for(i = 0; i< length; i++){ if(i+1 < length){ G_line(x[i], y[i], x[i+1], y[i+1]); } else{ G_line(x[i], y[i], x[0], y[0]); } } }
void display(int pnum){ int i, j, k; G_rgb(0,0,0); G_clear(); G_clear(1,1,1); // printf("enter disp\n"); for(i=0;i<numpolys[pnum];i++){ double xtemp[1000], ytemp[1000]; // printf("New display\n"); for(j=0; j<poly_sizes[pnum][i];j++){ xtemp[j] = x[pnum][polygons[pnum][i][j]]; ytemp[j] = y[pnum][polygons[pnum][i][j]]; // printf("X = %lf Y = %lf \n",xtemp[j],ytemp[j] ); } int tsize = clip(xtemp,ytemp,poly_sizes[pnum][i]); G_rgb(colors[pnum][i][0],colors[pnum][i][1],colors[pnum][i][2]); G_fill_polygon(xtemp, ytemp ,tsize); } double a[3][3], b[3][3]; D2d_make_identity(a); D2d_make_identity(b); D2d_translate(a, b, -WINDOW_WIDTH/2, -WINDOW_WIDTH/2); D2d_rotate(a,b, ROTATE_SPEED); D2d_translate(a, b, WINDOW_WIDTH/2, WINDOW_WIDTH/2); D2d_mat_mult_points(x[pnum], y[pnum], a, x[pnum], y[pnum],numpoints[pnum]); for(i=0; i<cSize;i++){//show clipping box G_rgb(255,255,255); G_line(cx[i], cy[i], cx[(i+1)%cSize], cy[(i+1)%cSize]); } }
void TSC_source::changecursorpos(int incrline, int incrcol, bool resetsel) { if (G_linecount()<=0) return; if ((incrline<0)&&(cursor_linenr>0)) Set_cursor(max(0,cursor_linenr+incrline),cursor_colnr,resetsel); if ((incrline>0)&&(cursor_linenr<G_linecount()-1)) Set_cursor(min(cursor_linenr+incrline,G_linecount()-1),cursor_colnr,resetsel); if (G_line(cursor_linenr)!=NULL) { if (incrcol>0) { if (cursor_colnr<G_line(cursor_linenr)->G_length()) Set_cursor(cursor_linenr,cursor_colnr+1,resetsel); else if (cursor_linenr<G_linecount()-1) Set_cursor(cursor_linenr+1,0,resetsel); } if (incrcol<0) { if (cursor_colnr>0) Set_cursor(cursor_linenr,cursor_colnr-1,resetsel); else if (cursor_linenr>0) Set_cursor(cursor_linenr-1,G_line(cursor_linenr-1)->G_length(),resetsel); } } }
void TSC_source::cmd_del(int cnt, bool backup) { if (!G_canmodify()) return; if ((cursor_linenr<0)||(cursor_linenr>=G_linecount())) return; if (cursor_colnr<lines[cursor_linenr]->G_length()) {//delete character if (cursor_colnr+cnt>G_line(cursor_linenr)->G_length()) cnt=G_line(cursor_linenr)->G_length()-cursor_colnr; if (cnt<=0) return; if (backup) addundo(new TSC_source_undoaction_del(this,cnt)); QString strl=*lines[cursor_linenr]; strl.substring(0,cursor_colnr-1); QString strr=*lines[cursor_linenr]; strr.substring(cursor_colnr+cnt,strr.G_length()); strl+=strr; *lines[cursor_linenr]=strl; } else cmd_mergeline(backup); modified=true; }
void TSC_source::cmd_tab(bool invert, bool backup) { QString str; int selline1,selcol1,selline2,selcol2; if (!G_sel(selline1,selcol1,selline2,selcol2)) { //try to indent int linenr=G_cursor_linenr(); if ((linenr<0)||(linenr>=G_linecount())) return; int colnr=G_cursor_colnr(); if ((colnr<G_line(linenr)->G_length())) return; if (backup) undo_begin(); (*lines[linenr])+=_qstr(" "); if (backup) addundo(new TSC_source_undoaction_insertstring(this,_qstr(" "))); cursor_colnr+=3; if (backup) undo_end(); modified=true; return; } //shift group block if (backup) undo_begin(); int ct1=selline1; int ct2=selline2; if (selcol2<0) ct2=selline2-1; for (int i=ct1; i<=ct2; i++) { if (!invert) { cursor_linenr=i;cursor_colnr=0; str=_qstr(" "); str+=*lines[cursor_linenr]; if (backup) addundo(new TSC_source_undoaction_insertstring(this,_qstr(" "))); *lines[cursor_linenr]=str; } else { cursor_linenr=i;cursor_colnr=0; str=*lines[cursor_linenr]; if (str.G_char(0)==' ') { str.substring(1,str.G_length()-1); if (backup) addundo(new TSC_source_undoaction_del(this,1)); *lines[cursor_linenr]=str; } } } if (backup) undo_end(); modified=true; }
int main() { double swidth, sheight ; swidth = 601 ; sheight = 601 ; G_init_graphics (swidth, sheight); int r, i; r = 300; i = 0; double x, y, p; p = M_PI / 18; while (i < 36) { x = 300 * cos(i * p); y = 300 * sin(i * p); G_line(300, 300, 300 + x, 300 + y); i++; } while (r > 0) { // if (fmod(r, 20) == 0) { // G_rgb(0, 0, 0); // } else { // G_rgb(1, 0, 0); // } G_circle(300, 300, r); r -= 10; } r = G_wait_key(); }
void TSC_source::cmd_copy() { int line1,col1,line2,col2; if (!G_sel(line1,col1,line2,col2)) return; QString str,st0; while ( (line1<line2) || ((line1==line2)&&(col1<=col2)) ) { if (col1<G_line(line1)->G_length()) { st0.clear();st0+=G_line(line1)->G_char(col1); str+=st0; } col1++; if (col1>=G_line(line1)->G_length()) { line1++;col1=0; if (line1<=line2) str+=_qstr("\n"); } } copyclipboard(str); }
int click_and_save (double *x, double *y) { int n ; double P[2] ; G_rgb(0,1,0.5) ; G_fill_rectangle(0,0,swidth,20) ; G_rgb(1,0,0) ; G_wait_click(P); n = 0 ; while (P[1] > 20) { x[n] = P[0] ; y[n] = P[1] ; G_circle(x[n],y[n],2) ; if (n > 0) { G_line(x[n-1],y[n-1], x[n],y[n]) ;} n++ ; G_wait_click(P) ; } return n ; }
int main() { G_init_graphics(600,600) ; G_rgb(0,0,0) ; G_clear() ; G_rgb(0,0,1) ; G_fill_polygon(jx,jy,5) ; G_wait_key(); double rot45[3][3]; double useless[3][3]; D2d_make_identity(rot45); D2d_rotate(rot45, useless, M_PI/4.0); D2d_mat_mult_points(jx, jy, rot45, jx, jy, 5); G_fill_polygon(jx, jy, 5); double upandover[3][3]; D2d_make_identity(upandover); D2d_translate(upandover, useless, 1, 1); int count = 0; while (G_wait_key()) { count = (count+1)%200; D2d_mat_mult_points(jx, jy, upandover, jx, jy, 5); G_rgb(0, 0, 0); G_clear(); G_rgb(0, 0, 1); if (count < 100) { G_fill_polygon(jx, jy, 5); } else { G_fill_polygon(jy, jx, 5); } G_rgb(1, 0, 0); G_line(0, 0, 600, 600); } }
int main() { double pwidth, pheight, bwidth ; double angle,hx,hy,mx,my,sx,sy ; double hours,minutes,seconds ; double x,y,nx,ny,digit ; int theta ; //INTERESTING that this MUST be int to avoid flicker-WHY? double oldhourtheta,oldminutetheta,oldsecondtheta ; char text[3] ; double hms[3] ; // hours,minutes,seconds G_init_graphics(600,600) ; G_rgb (1,1,1) ; G_fill_rectangle (0,0, 600,600) ; // outer circle of the clock face G_rgb (1,0,0) ; // red theta = 0 ; // degrees x = 225*cos(theta*M_PI/180) + 300 ; y = 225*sin(theta*M_PI/180) + 300 ; while (theta <= 360) { theta = theta + 1 ; nx = 225*cos(theta*M_PI/180) + 300 ; ny = 225*sin(theta*M_PI/180) + 300 ; G_line(x,y,nx,ny) ; x = nx ; y = ny ; } G_display_image() ; // digits on the clock face G_rgb (0,0,0) ; // black theta = 90 ; // degrees digit = 0 ; while (theta > -270) { theta = theta - 30 ; digit = digit + 1 ; nx = 200*cos(theta*M_PI/180) + 300 ; ny = 200*sin(theta*M_PI/180) + 300 ; if (digit >= 10) { text[0] = '1' ; text[1] = '0' + digit - 10 ; text[2] = '\0' ; } else { text[0] = '0' + digit ; text[1] = '\0' ; } G_draw_string(text,nx-5,ny-5) ; } G_display_image() ; oldsecondtheta = oldminutetheta = oldhourtheta = -10000000 ; sx = sy = mx = my = hx = hy = 300 ; while (0 < 1) { /* watch out for SLIGHT FLAW : if one of the hands overlays another, then if it is erased, you'll erase the other as well...this should fix that...we erase them all and redraw them all */ get_timeD (hms) ; hours = hms[0] ; minutes = hms[1] ; seconds = hms[2] ; // set the second hand theta = 90 - 6*seconds ; if (theta != oldsecondtheta) { G_rgb (1,1,1) ; // white G_line(300,300,sx,sy) ; G_line(300,300,mx,my) ; G_line(300,300,hx,hy) ; angle = theta*M_PI/180 ; sx = 175*cos(angle) + 300 ; sy = 175*sin(angle) + 300 ; G_rgb (1,0,0) ; // red G_line(300,300,sx,sy) ; G_line(300,300,mx,my) ; G_line(300,300,hx,hy) ; G_display_image() ; oldsecondtheta = theta ; } // set the minute hand theta = 90 - 6*(minutes + seconds/60.0) ; if (theta != oldminutetheta) { G_rgb (1,1,1) ; // white G_line(300,300,sx,sy) ; G_line(300,300,mx,my) ; G_line(300,300,hx,hy) ; angle = theta*M_PI/180 ; mx = 140*cos(angle) + 300 ; my = 140*sin(angle) + 300 ; G_rgb (1,0,0) ; // red G_line(300,300,sx,sy) ; G_line(300,300,mx,my) ; G_line(300,300,hx,hy) ; G_display_image() ; oldminutetheta = theta ; } // set the hour hand theta = 90 - 30*(hours + minutes/60.0 + seconds/3600.0) ; if (theta != oldhourtheta) { G_rgb (1,1,1) ; // white G_line(300,300,sx,sy) ; G_line(300,300,mx,my) ; G_line(300,300,hx,hy) ; angle = theta*M_PI/180 ; hx = 75*cos(angle) + 300 ; hy = 75*sin(angle) + 300 ; G_rgb (1,0,0) ; // red G_line(300,300,sx,sy) ; G_line(300,300,mx,my) ; G_line(300,300,hx,hy) ; G_display_image() ; oldhourtheta = theta ; } } // end while (0 < 1) }
int main() { int swidth, sheight ; double lowleftx, lowlefty, width, height ; double x[10],y[10] ; double numpoints,q, x0,y0,x1,y1 ; double p[2] ; int i ; // must do this before you do 'almost' any other // graphical tasks swidth = 400 ; sheight = 500 ; G_init_graphics (swidth, sheight) ; // draw a point, a line, some rectangles, some triangles G_rgb(1, 0, 0) ; // red G_point(200, 380) ; G_fill_rectangle (300,400, 50, 20) ; G_rgb(0, 1, 0) ; // green // G_line (0, 0, 400, 400) ; // won't show if part is off screen G_line (0, 0, 399, 399) ; G_fill_triangle(50, 400, 100,400, 150,475) ; G_rgb(0, 0, 1) ; // blue lowleftx = 200 ; lowlefty = 50 ; width = 10 ; height = 30 ; G_rectangle (lowleftx, lowlefty, width, height) ; lowleftx = 250 ; G_fill_rectangle (lowleftx, lowlefty, width, height) ; G_rgb(1, 1, 0) ; // yellow G_triangle (10, 300, 40,300, 60,250) ; G_fill_triangle (10,100, 40,100, 60,150) ; G_rgb(1, 0.5, 0) ; // orange G_circle (100, 300, 75) ; G_fill_circle (370, 200, 50) ; // prints text in your graphics window G_rgb(0, 0, 0) ; // black G_draw_string ("hello",300,100) ; // draw a polygon x[0] = 100 ; y[0] = 100 ; x[1] = 100 ; y[1] = 300 ; x[2] = 300 ; y[2] = 300 ; x[3] = 300 ; y[3] = 100 ; x[4] = 200 ; y[4] = 175 ; numpoints = 5 ; G_polygon (x,y,numpoints) ; G_rgb (0.4, 0.2, 0.1) ; // brown G_fill_polygon (x,y,numpoints) ; G_rgb (0.5, 0.8, 0.4) ;// what color is this? int xc,yc ; int pixel ; int rgbI[3] ; double rgb[3] ; G_wait_click(p) ; xc = p[0] ; yc = p[1] ; while (yc > 20) { printf("%d %d\n",xc,yc) ; pixel = G_get_pixel(xc,yc) ; G_convert_pixel_to_rgbI(pixel, rgbI) ; G_convert_rgbI_to_rgb(rgbI, rgb) ; printf("pixel = %x\n",pixel) ; printf("%3d %3d %3d\n",rgbI[0],rgbI[1],rgbI[2]) ; printf("%lf %lf %lf\n",rgb[0],rgb[1],rgb[2]) ; printf("\n") ; G_wait_click(p) ; xc = p[0] ; yc = p[1] ; } }
int main() { double swidth, sheight ; double lowleftx, lowlefty, width, height ; double x[10],y[10] ; double numpoints,q, x0,y0,x1,y1 ; double p[2] ; // must do this before you do 'almost' any other // graphical tasks swidth = 400 ; sheight = 400 ; G_init_graphics (swidth, sheight) ; // draw a point, a line, some rectangles, some triangles G_rgb(1, 0, 0) ; // red G_point(200, 380) ; G_rgb(0, 1, 0) ; // green // G_line (0, 0, 400, 400) ; // won't show if part is off screen G_line (0, 0, 399, 399) ; G_rgb(0, 0, 1) ; // blue lowleftx = 200 ; lowlefty = 50 ; width = 10 ; height = 30 ; G_rectangle (lowleftx, lowlefty, width, height) ; lowleftx = 250 ; G_fill_rectangle (lowleftx, lowlefty, width, height) ; G_rgb(1, 1, 0) ; // yellow G_triangle (10, 300, 40,300, 60,250) ; G_fill_triangle (10,100, 40,100, 60,150) ; G_rgb(1, 0.5, 0) ; // orange G_circle (100, 300, 75) ; G_fill_circle (370, 200, 50) ; // prints text in your graphics window G_rgb(0, 0, 0) ; // black G_draw_string ("hello",300,100) ; // draw a polygon x[0] = 100 ; y[0] = 100 ; x[1] = 100 ; y[1] = 300 ; x[2] = 300 ; y[2] = 300 ; x[3] = 300 ; y[3] = 100 ; x[4] = 200 ; y[4] = 175 ; numpoints = 5 ; G_polygon (x,y,numpoints) ; q = G_wait_key() ; // pause to look ...any key to continue G_rgb (0.4, 0.2, 0.1) ; // brown G_fill_polygon (x,y,numpoints) ; G_rgb (0.5, 0.8, 0.4) ;// what color is this? G_wait_click(p) ; // wait for a mouse click x0 = p[0] ; y0 = p[1] ; // extract coordinates G_fill_rectangle (x0-2, y0-2, 4,4) ;// mark the clicked point G_wait_click(p) ; x1 = p[0] ; y1 = p[1] ; G_fill_rectangle (x1-2, y1-2, 4,4) ; G_rgb (0.5, 0.5, 0.5) ; // a grey G_line (x0,y0, x1,y1) ; q = G_wait_key() ; // pause again before exit G_save_image_to_file ("t01c.xwd") ; G_close() ; // terminate graphics...probably not fatal if forgotten }