void window_draw_line(struct window *w, int x1, int y1, int x2, int y2, struct graphics_color color) { x1 += w->x_offset; y1 += w->y_offset; x2 += w->x_offset; y2 += w->y_offset; graphics_line(x1, y1, x2, y2, color, 0); }
void blinking_light() { while(BCHK); // debounce graphics_close(); // close any existing window graphics_open(45,45); graphics_fill(WHITE); while(!(BCHK)) { graphics_circle_fill(24, 24, 20, GRAY); graphics_circle_fill(24, 24, 8, YELLOW); graphics_line(6, 24, 42, 24, YELLOW); // horizontal graphics_line(24, 6, 24, 42, YELLOW); // vertical graphics_line(12, 12, 36, 36, YELLOW); // forward slash graphics_line(12, 36, 36, 12, YELLOW); // back slash graphics_update(); msleep(250); if(BCHK) break; graphics_circle_fill(24, 24, 20, GRAY); graphics_update(); msleep(250); } graphics_close(); }
void vseg(int dy, int dx, int l, int r, int g, int b) { graphics_line(dy, dx+1,dy, dx+l-1, r,g,b); // horizontal graphics_line(dy+1, dx, dy+1, dx+l, r,g,b); graphics_line(dy+2, dx+1, dy+2, dx+l-1, r,g,b); }
void frame::on_paint(PAINT_EVT& evt) { HGFX g = evt.surface; unsigned int width = evt.view_w; unsigned int height = evt.view_h; //graphics_gamma( g, 1.0 ); //graphics_blend_mode( g, GBlendContrast ); // dotted test { graphics_state_save(g); graphics_dashes_add(g, 15, 5); { graphics_state_save(g); graphics_line_width(g, 3); graphics_dashes_clear(g); graphics_dashes_add(g, 5, 5); graphics_line(g, 10,10, 100, 100); graphics_state_restore(g); } graphics_line(g, 20,10, 110, 100); graphics_state_restore(g); } // arrow test { graphics_state_save(g); graphics_line_width(g,2); graphics_line( g, 100, 80, 200, 180 ); graphics_arrow_bone(g, 100, 80, 200, 180, 20, (40. / 360.) * 2. * 3.14 ); graphics_line( g, 140, 80, 240, 180 ); graphics_arrow(g, 140, 80, 240, 180, 40, (20. / 360.) * 2. * 3.14, 0.5 ); graphics_line( g, 180, 80, 280, 180 ); graphics_arrow(g, 180, 80, 280, 180, 40, (20. / 360.) * 2. * 3.14, 0.0 ); graphics_arrow(g, 280, 180, 180, 80, 40, (20. / 360.) * 2. * 3.14, 0.0 ); graphics_fill_color(g, graphics_rgbt(255,255,255,0) ); graphics_line( g, 230, 80, 330, 180 ); graphics_arrow(g, 230, 80, 330, 180, 40, (40. / 360.) * 2. * 3.14, 0.5 ); graphics_state_restore(g); } graphics_state_save(g); graphics_scale(g,0.5,0.5); graphics_translate(g,0,0); // first quadrant, basic drawing functions graphics_line(g, 0,0, width,height); graphics_line_color(g,graphics_rgbt(255,0,0,0)); graphics_triangle(g, width/2, 10.5, 10.5, height - 10.5 , width - 10.5, height - 10.5); graphics_line_color(g,graphics_rgbt(0,255,0,0)); graphics_rectangle(g, 20.5, 20.5, width - 20.5, height - 20.5); graphics_line_color(g,graphics_rgbt(0,0,255,0)); graphics_rounded_rectangle(g, 30.5, 30.5, width - 30.5, height - 30.5, 10, 10); graphics_line_color(g,graphics_rgbt(0,127,127,0)); graphics_ellipse(g, width/2, height/2, width/4, height/4); int r = min(width, height); graphics_line_color(g,graphics_rgbt(127,0,127,0)); graphics_arc(g, width/2, height/2, r/8, r/8, 0,6); graphics_line_color(g,graphics_rgbt(127,127,0,0)); graphics_star(g, width/2, height/2, r/5, r/8, 0,5); graphics_state_restore(g); // second quadrant, path operations graphics_state_save(g); graphics_translate(g,width/2,0); graphics_line_width(g,2); graphics_line_color(g, graphics_rgbt(0xAF,0x7F,0x2F)); // brown graphics_fill_linear_gradient(g, 30, 30, (150 + 70) / 2, 150, graphics_rgbt(0xFF,0,0), // red graphics_rgbt(0xFF,0xFF,0), // yellow 0.5); graphics_open_path(g); // stealed from Mozilla <canvas> tests graphics_move_to(g, 30, 30, false); graphics_line_to(g, 150, 150, false); graphics_bezier_curve_to(g, 60, 70, 60, 70, 70, 150, false); graphics_line_to(g,30, 30, false); graphics_close_path(g); graphics_draw_path(g, FILL_AND_STROKE); graphics_fill_radial_gradient(g, 250, 80, 50, graphics_rgbt(0xFF,0,0), // red graphics_rgbt(0xFF,0xFF,0)); // yellow graphics_rounded_rectangle(g, 200, 30, 200 + 100, 30 + 100, 10, 10); graphics_line_color( g, graphics_rgbt(0,200,0,0) ); graphics_fill_color( g, graphics_rgbt(150,230,150,80) ); graphics_ellipse( g, 190, 60, 50, 30 ); graphics_state_restore(g); // Third quadrant, text output graphics_state_save(g); graphics_translate(g,0,height/2); graphics_scale(g,0.5,0.5); graphics_line(g,0,height/2, width, height/2); graphics_line_width(g,3); graphics_line_color(g, graphics_rgbt(0xAF,0x7F,0x2F)); // brown graphics_fill_radial_gradient(g, width/2, height/2, r / 2, graphics_rgbt(0xFF,0xFF,0), // yellow graphics_rgbt(0,0x8F,0)); // green graphics_text_alignment(g, ALIGN_CENTER, ALIGN_BASELINE); graphics_font(g, "Century Gothic", r / 5); graphics_text(g, width/2, height/2, L"graphinius", 10); graphics_state_restore(g); // Fourth quadrant, image output graphics_state_save(g); graphics_translate(g,width/2,height/2); graphics_scale(g,0.5,0.5); static HIMG img = 0; if(!img) { tool::mm_file mf; if( mf.open("../petrov_vodkin_A_Candle_and_a_Decanter.jpg") ) image_load( (BYTE*) mf.data(), mf.size(), &img ); // load png/jpeg/etc. image from stream of bytes } if(img) { DIM w = width - 20; DIM h = height - 20; graphics_draw_image ( g, img, 10, 10, &w, &h ); } // pattern fill test { graphics_fill_color(g, graphics_rgbt(0xFF,0xdd,0) ); graphics_state_save(g); static HIMG pat = 0; if(!pat) { tool::mm_file mf; if( mf.open("../cubes.png") ) image_load( (BYTE*) mf.data(), mf.size(), &pat ); // load png/jpeg/etc. image from stream of bytes } if(pat) { graphics_fill_pattern(g, pat, 255, -width/2, 0); graphics_ellipse( g, 400, 40, 120, 100 ); } graphics_state_restore(g); graphics_ellipse( g, 100, 40, 60, 50 ); } graphics_state_restore(g); }
void kissSimComputerDraw() { int oriX=ksWindow.simWidth, oriY=0, i; static char digitals[]="0 0 0 0 0 0 0 0"; static char buttons[]="0 0 0 0 0 0 0"; static char analogs[11][10]={" "," "," "," "," "," "," "," "," "," "," "}; static char actuators[4][25]={" "," "," "," "}; static char servos[4][25]={" "," "," "," "}; if(!glfwGetWindowParam(GLFW_OPENED)) return; graphics_rectangle_fill(oriX,oriY,oriX+1,ksWindow.height,BLACK); // draw left border draw_bg(oriX+5,oriY+9,0.36); // Botguy NOBOLD g_printString(" CBC SIMULATOR",oriX+25, oriY+10,TEAL,1.0); NOBOLD g_printString(" DIGITALS ",oriX+25, oriY+40,TEAL,1.0); NOBOLD g_printString("0 1 2 3 4 5 6 7",oriX+25, oriY+55,TEAL,1.0); NOBOLD g_printString(" BUTTONS ",oriX+25, oriY+90,TEAL,1.0); //NOBOLD g_printString("< ^ V > A B .",oriX+30, oriY+105,TEAL,1.0); NOBOLD g_printString("\xb \xd \xe \xc A B .",oriX+30, oriY+105,TEAL,1.0); // hex b, c, d, e are left, right, up, and down arrows NOBOLD g_printString(digitals,oriX+25, oriY+70,WHITE,1.0); // erase old digital values NOBOLD g_printString(" ANALOGS ",oriX+25, oriY+140,TEAL,1.0); for(i=0;i<8;i++){ digitals[2*i]=48+digital(i); } NOBOLD g_printString(digitals,oriX+25, oriY+70,BLACK,1.0); // write new digital values NOBOLD g_printString(buttons,oriX+30, oriY+120,WHITE,1.0); // erase old button values buttons[0]=48+!!left_button(); buttons[2]=48+!!up_button(); buttons[4]=48+!!down_button(); buttons[6]=48+!!right_button(); buttons[8]=48+!!a_button(); buttons[10]=48+!!b_button(); _bob.button=!!kiss_get_key('.'); buttons[12]=48+black_button(); NOBOLD g_printString(buttons,oriX+30, oriY+120,BLACK,1.0); // erase old button values for(i=8;i<16;i++){//print out analogs analogs[i-8][1]=(i<10)?48+i:48+i-10; analogs[i-8][0]=(i<10)?32:49; analogs[i-8][2]=':'; analogs[i-8][3]=' '; NOBOLD g_printString(analogs[i-8],oriX+5, oriY+155+(15*(i-8)),WHITE,1.0); convertNumToString(analog10(i),4,*analogs,10,i-8,3); graphics_rectangle_fill(oriX+30,oriY+155+(15*(i-8)),oriX+157, oriY+165+(15*(i-8)),GRAY); graphics_line(oriX+30+analog(i)/2, oriY+155+(15*(i-8)),oriX+30+analog(i)/2,oriY+165+(15*(i-8)),RED); NOBOLD g_printString(analogs[i-8],oriX+5, oriY+155+(15*(i-8)),BLACK,1.0); } analogs[8][1]='X'; analogs[8][0]='A'; analogs[8][2]=':'; analogs[8][3]=' '; NOBOLD g_printString(analogs[8],oriX+5, oriY+155+(15*(8)),WHITE,1.0); convertNumToString(accel_x(),5,*analogs,10,8,3); graphics_rectangle_fill(oriX+30,oriY+155+(15*(8)),oriX+157, oriY+165+(15*(8)),GRAY); graphics_line(oriX+30+(accel_x()+2048)/32, oriY+155+(15*(8)),oriX+30+(accel_x()+2048)/32,oriY+165+(15*(8)),RED); NOBOLD g_printString(analogs[8],oriX+5, oriY+155+(15*(8)),BLACK,1.0); analogs[9][1]='Y'; analogs[9][0]='A'; analogs[9][2]=':'; analogs[9][3]=' '; NOBOLD g_printString(analogs[9],oriX+5, oriY+155+(15*(9)),WHITE,1.0); convertNumToString(accel_y(),5,*analogs,10,9,3); graphics_rectangle_fill(oriX+30,oriY+155+(15*(9)),oriX+157, oriY+165+(15*(9)),GRAY); graphics_line(oriX+30+(accel_y()+2048)/32, oriY+155+(15*(9)),oriX+30+(accel_y()+2048)/32,oriY+165+(15*(9)),RED); NOBOLD g_printString(analogs[9],oriX+5, oriY+155+(15*(9)),BLACK,1.0); analogs[10][1]='Z'; analogs[10][0]='A'; analogs[10][2]=':'; analogs[10][3]=' '; NOBOLD g_printString(analogs[10],oriX+5, oriY+155+(15*(10)),WHITE,1.0); convertNumToString(accel_z(),5,*analogs,10,10,3); graphics_rectangle_fill(oriX+30,oriY+155+(15*(10)),oriX+157, oriY+165+(15*(10)),GRAY); graphics_line(oriX+30+(accel_z()+2048)/32, oriY+155+(15*(10)),oriX+30+(accel_z()+2048)/32,oriY+165+(15*(10)),RED); NOBOLD g_printString(analogs[10],oriX+5, oriY+155+(15*(10)),BLACK,1.0); NOBOLD g_printString("MOT PWM TPS ENCODER VAL",oriX+5, oriY+330,TEAL,1.0); for(i=0;i<4;i++){ actuators[i][0]=48+i; actuators[i][1]=':'; actuators[i][2]=' '; NOBOLD g_printString(actuators[i],oriX+5, oriY+345+(15*(i)),WHITE,1.0); convertNumToString(_bob.motor_pwm[i],4,*actuators,25,i,2); convertNumToString(_bob.motor_tps[i],4,*actuators,25,i,7); convertNumToString(_bob.motor_counter[i],10,*actuators,25,i,12); NOBOLD g_printString(actuators[i],oriX+5, oriY+345+(15*(i)),BLACK,1.0); } if(_bob.enable_servos){ NOBOLD g_printString("SERVO TARGET DISABLED",oriX+5, oriY+410,WHITE,1.0); NOBOLD g_printString("SERVO TARGET ENABLED",oriX+5, oriY+410,TEAL,1.0); } else { NOBOLD g_printString("SERVO TARGET ENABLED",oriX+5, oriY+410,WHITE,1.0); NOBOLD g_printString("SERVO TARGET DISABLED",oriX+5, oriY+410,TEAL,1.0); } for(i=0;i<4;i++){ servos[i][2]=49+i;//servos are 1 indexed!! servos[i][3]=':'; servos[i][4]=' '; NOBOLD g_printString(servos[i],oriX+5, oriY+425+(15*(i)),WHITE,1.0); convertNumToString(_bob.servo_targets[i],4,*servos,25,i,6); NOBOLD g_printString(servos[i],oriX+5, oriY+425+(15*(i)),BLACK,1.0); } }