コード例 #1
0
ファイル: particles.c プロジェクト: daniilguit/openbgi
void main(void) {
  int gd = CUSTOM, gm = CUSTOM_MODE(1024,768);
  int page = 0;
  g_mousestate curState;
  g_mousestate oldState;
  int scrolling = 0;
  
  initgraph(&gd, &gm, "");
  
  initParticles(particles);
  
  while(!anykeypressed()) {
    getmousestate(&curState);
    if((curState.buttons & MOUSE_LEFTBUTTON) == 0) {
      scrolling = 0;
    } else {
      if(scrolling == 0) {
        scrolling = 1;
        getmousestate(&oldState);
      } else {
        orgX -= -curState.x + oldState.x;
        orgY += -curState.y + oldState.y;
        oldState = curState;
      }
    }
    updateParticles(particles, particles2);
	setactivepage(1 - page);
    clearviewport();
	drawParticles(particles);
	setvisualpage(1 - page);
    page = 1 - page;
	delay(4);
  }
  closegraph();
}
コード例 #2
0
ファイル: app.c プロジェクト: nashr/Paint-Rohmen
void _app_handle_input( void ) {
	int i;

	g_mousestate state;
	getmousestate( &state );

	if ( state.buttons == 0 && mouse_prev_state == 0 ) { // hover ( no click )
		mouse_prev_state = 0;
		
		mouse_prev_x = state.x;
		mouse_prev_y = state.y;
	} else if ( state.buttons == 1 && mouse_prev_state == 0 ) { // on mouse down ( left clicked )
		int done = false;
		mouse_prev_state = 1;
		
		if ( !done ) {
			for ( i = 0; i < NUM_MENU; i++ ) {
				if ( state.x > menu_panels[ i ].rect.x0 && state.x < menu_panels[ i ].rect.x1 
					&& state.y > menu_panels[ i ].rect.y0 && state.y < menu_panels[ i ].rect.y1 ) {
					if ( i == 0 ) { // Special case for cartesian ( it's independent from others )
						menu_panels[ i ].focus += 1;
						menu_panels[ i ].focus %= 2;
					} else if ( i == 6 ) { // Special case too for color pallete
						for ( i = 0; i < 16; i++ ) {
							if ( i < 8 ) {
								if ( state.x > 384 + 32 * i && state.x < 384 + 32 * ( i + 1 ) && state.y > 0 && state.y < 16 ) {
									chosen_color = i;
									done = true;
								}
							} else {
								if ( state.x > 384 + 32 * ( i - 8 ) && state.x < 384 + 32 * ( i + 1 - 8 ) && state.y > 16 && state.y < 32 ) {
									chosen_color = i;
									done = true;
								}
							}
						}
					} else {
						menu_focus = i;
					}
					
					done = true;
				}
			}
		}
		
		if ( !done ) {
			for ( i = 0; i < NUM_SIDE; i++ ) {
				if ( state.x > side_panels[ i ].rect.x0 && state.x < side_panels[ i ].rect.x1 
					&& state.y > side_panels[ i ].rect.y0 && state.y < side_panels[ i ].rect.y1 ) {
					side_focus = i;
					
					done = true;
				}
			}
		}
		
		if ( !done ) {
			if ( side_focus == 0 ) { // SELECT
				
			} else if ( side_focus == 1 ) { // LINE
				drawing_prepare_line( state.x, state.y, chosen_color );
			} else if ( side_focus == 2 ) { // CURVE
				//drawing_prepare_curve( state.x, state.y, chosen_color );
			} else if ( side_focus == 3 ) { // ELLIPSE
				drawing_prepare_ellipse( state.x, state.y, chosen_color );
			} else if ( side_focus == 4 ) { // POLYGON
				drawing_prepare_polygon( state.x, state.y, chosen_color );
				
			} else if ( side_focus == 5 ) { // FILL
				canvas_fill( state.x, state.y, chosen_color, getpixel( state.x, state.y ) );
			} else if ( side_focus == 6 ) { // CROP
				
			}
		}
		
		mouse_prev_x = state.x;
		mouse_prev_y = state.y;
	} else if ( state.buttons == 1 && mouse_prev_state == 1 ) { // on mouse move ( left pressed )
		mouse_prev_state = 1;
		
		if ( side_focus == 0 ) { // SELECT
			
		} else if ( side_focus == 1 ) { // LINE
			drawing_process_line( state.x, state.y );
		} else if ( side_focus == 2 ) { // CURVE
			//drawing_process_curve (state.x, state.y);
		} else if ( side_focus == 3 ) { // ELLIPSE
			drawing_process_ellipse( state.x, state.y );
		} else if ( side_focus == 4 ) { // POLYGON
			drawing_process_polygon( state.x, state.y );
			
		} else if ( side_focus == 5 ) { // FILL
			
		} else if ( side_focus == 6 ) { // CROP
			
		}
		
		mouse_prev_x = state.x;
		mouse_prev_y = state.y;
	} else if ( state.buttons == 0 && mouse_prev_state == 1 ) { // on mouse up ( left released )
		mouse_prev_state = 0;
		
		if ( side_focus == 0 ) { // SELECT
			
		} else if ( side_focus == 1 ) { // LINE
			drawing_finalize_line( state.x, state.y );
		} else if ( side_focus == 2 ) { // CURVE
			//drawing_finalize_curve( state.x, state.y );
		} else if ( side_focus == 3 ) { // ELLIPSE
			drawing_finalize_ellipse( state.x, state.y );
		} else if ( side_focus == 4 ) { // POLYGON
			drawing_finalize_polygon( state.x, state.y );
			
		} else if ( side_focus == 5 ) { // FILL
			
		} else if ( side_focus == 6 ) { // CROP
			
		}
		
		mouse_prev_x = state.x;
		mouse_prev_y = state.y;
	} else if ( state.buttons == 2 && mouse_prev_state == 0 ) { // on mouse down ( right clicked )
		int done = false;
		mouse_prev_state = 2;

		if ( !done ) {
			if ( menu_focus == 1 ) { // MOVE
				if ( canvas_translate( state.x, state.y ) ) {
					drawing_translate( state.x, state.y );
				}
			} else if ( menu_focus == 2 ) { // ROTATE
				if ( !canvas_change_rotation_center( state.x, state.y ) ) {
					int dx = state.x - mouse_prev_x;
					int dy = state.y - mouse_prev_y;

					if ( state.x < rx ) {
						dy *= -1;
					}

					if ( canvas_rotate( dx, dy ) ) {
						drawing_rotate( dx, dy );
					}
				}
			} else if ( menu_focus == 3 ) { // SKEW
				if ( !canvas_change_shearing_center( state.x, state.y ) ) {
					int dx = state.x - mouse_prev_x;
					int dy = state.y - mouse_prev_y;

					if ( state.x < sx ) {
						dy *= -1;
					}
					
					if ( state.y < sy ) {
						dx *= -1;
					}

					if ( fabs( dx ) < fabs( dy ) ) {
						if ( canvas_shear( 0, dy ) ) {
							drawing_shear( 0, dy );
						}
					} else {
						if ( canvas_shear( dx, 0 ) ) {
							drawing_shear( dx, 0 );
						}
					}
				}
			} else if ( menu_focus == 4 ) { // ZOOM IN
				// do nothing
			} else if ( menu_focus == 5 ) { // ZOOM OUT
				// do nothing
			}
		}
		
		mouse_prev_x = state.x;
		mouse_prev_y = state.y;
	} else if ( state.buttons == 2 && mouse_prev_state == 2 ) { // on mouse move ( right pressed )
		mouse_prev_state = 2;

		if ( menu_focus == 1 ) { // MOVE
			if ( canvas_translate( state.x, state.y ) ) {
				drawing_translate( state.x, state.y );
			}
		} else if ( menu_focus == 2 ) { // ROTATE
			if ( !canvas_change_rotation_center( state.x, state.y ) ) {
				int dx = state.x - mouse_prev_x;
				int dy = state.y - mouse_prev_y;

				if ( state.x < rx ) {
					dy *= -1;
				}

				if ( canvas_rotate( dx, dy ) ) {
					drawing_rotate( dx, dy );
				}	
			}
		} else if ( menu_focus == 3 ) { // SKEW
			if ( !canvas_change_shearing_center( state.x, state.y ) ) {
				int dx = state.x - mouse_prev_x;
				int dy = state.y - mouse_prev_y;

				if ( state.x < sx ) {
					dy *= -1;
				}

				if ( state.y < sy ) {
					dx *= -1;
				}

				if ( fabs( dx ) < fabs( dy ) ) {
					if ( canvas_shear( 0, dy ) ) {
						drawing_shear( 0, dy );
					}
				} else {
					if ( canvas_shear( dx, 0 ) ) {
						drawing_shear( dx, 0 );
					}
				}
			}
		} else if ( menu_focus == 4 ) { // ZOOM IN
			if ( canvas_zoom_in( state.x, state.y ) ) {
				drawing_scale( state.x, state.y, DEFAULT_ZOOM_IN );
			}
		} else if ( menu_focus == 5 ) { // ZOOM OUT
			if ( canvas_zoom_out( state.x, state.y ) ) {
				drawing_scale( state.x, state.y, DEFAULT_ZOOM_OUT );
			}
		}

		mouse_prev_x = state.x;
		mouse_prev_y = state.y;
	} else if ( state.buttons == 0 && mouse_prev_state == 2 ) { // on mouse up ( right released )
		mouse_prev_state = 0;

		if ( menu_focus == 1 ) { // MOVE
			if ( canvas_translate( -1, -1 ) ) {
				drawing_translate( -1, -1 );
			}
		} else if ( menu_focus == 2 ) { // ROTATE
			if ( !canvas_change_rotation_center( 999, 999 ) ) {
				if ( canvas_rotate( 999, 999 ) ) {
					drawing_rotate( 999, 999 );
				}
			}
		} else if ( menu_focus == 3 ) { // SKEW
			if ( !canvas_change_shearing_center( 999, 999 ) ) {
				if ( canvas_shear( 999, 999 ) ) {
					drawing_shear( 999, 999 );
				}
			}
		} else if ( menu_focus == 4 ) { // ZOOM IN
			// do nothing
		} else if ( menu_focus == 5 ) { // ZOOM OUT
			// do nothing
		}

		mouse_prev_x = state.x;
		mouse_prev_y = state.y;
	} else if ( state.buttons == 3 ) { // both click ( not to be confused with double click )
		// do nothing
	}

	return;
}