int BC_Pan::button_press_event() { // there are two modes of operation... if (popup) { if (popup->is_event_win() && get_button_down() && get_buttonpress() == 1) { active = 1; x_origin = popup->get_cursor_x(); y_origin = popup->get_cursor_y(); stick_x_origin = stick_x; stick_y_origin = stick_y; return 1; } else { deactivate(); return 0; } } if(is_event_win() && get_button_down() && get_buttonpress() == 1) { hide_tooltip(); activate(); active = 1; x_origin = get_cursor_x(); y_origin = get_cursor_y(); stick_x_origin = stick_x; stick_y_origin = stick_y; draw_popup(); return 1; } return 0; }
int CreateDVD_Cancel::button_press_event() { if(get_buttonpress() == 1 && is_event_win() && cursor_inside()) { gui->set_done(1); return 1; } return 0; }
int BC_Pan::cursor_enter_event() { if(is_event_win() && !highlighted) { tooltip_done = 0; highlighted = 1; draw(1, 1); } return 0; }
int TimeBar::button_press_event() { if(is_event_win() && cursor_inside() && get_buttonpress() == 1) { // Change time format if(ctrl_down()) { if(get_buttonpress() == 1) mwindow->next_time_format(); else if(get_buttonpress() == 2) mwindow->prev_time_format(); return 1; } else // if(test_preview(1)) // { // } // else { stop_playback(); // Select region between two labels if(get_double_click()) { double position = pixel_to_position(get_cursor_x()); // Test labels select_region(position); return 1; } else // Reposition highlight cursor if(is_event_win() && cursor_inside()) { update_cursor(); current_operation = TIMEBAR_DRAG; activate_timeline(); return 1; } } } return 0; }
int TimeBar::cursor_motion_event() { int result = 0; int redraw = 0; //printf("TimeBar::cursor_motion_event %d %p %d\n", __LINE__, this, current_operation); switch(current_operation) { case TIMEBAR_DRAG: { update_cursor(); handle_mwindow_drag(); result = 1; //printf("TimeBar::cursor_motion_event %d %d\n", __LINE__, current_operation); break; } // case TIMEBAR_DRAG_LEFT: // case TIMEBAR_DRAG_RIGHT: // case TIMEBAR_DRAG_CENTER: // result = move_preview(redraw); // break; default: if(cursor_inside() && is_event_win()) { highlighted = 1; redraw = 1; result = 1; } //printf("TimeBar::cursor_motion_event 20\n"); // result = test_preview(0); //printf("TimeBar::cursor_motion_event 30\n"); break; } //printf("TimeBar::cursor_motion_event %d %d\n", __LINE__, current_operation); if(redraw) { update(1); } //printf("TimeBar::cursor_motion_event %d %p %d\n", __LINE__, this, current_operation); return result; }
int ScopePanel::button_press_event() { if(is_event_win() && cursor_inside()) { gui->clear_points(1); is_dragging = 1; int x = get_cursor_x(); int y = get_cursor_y(); CLAMP(x, 0, get_w() - 1); CLAMP(y, 0, get_h() - 1); update_point(x, y); return 1; } return 0; }
int CompressorCanvas::cursor_motion_event() { if(current_operation == DRAG) { int x = get_cursor_x(); int y = get_cursor_y(); CLAMP(x, 0, get_w()); CLAMP(y, 0, get_h()); double x_db = (double)(1 - (double)x / get_w()) * plugin->config.min_db; double y_db = (double)y / get_h() * plugin->config.min_db; plugin->config.levels.values[current_point].x = x_db; plugin->config.levels.values[current_point].y = y_db; ((CompressorWindow*)plugin->thread->window)->update(); plugin->send_configure_change(); return 1; //plugin->config.dump(); } else // Change cursor over points if(is_event_win() && cursor_inside()) { int new_cursor = CROSS_CURSOR; for(int i = 0; i < plugin->config.levels.total; i++) { double x_db = plugin->config.get_x(i); double y_db = plugin->config.get_y(i); int x = (int)(((double)1 - x_db / plugin->config.min_db) * get_w()); int y = (int)(y_db / plugin->config.min_db * get_h()); if(get_cursor_x() < x + POINT_W / 2 && get_cursor_x() >= x - POINT_W / 2 && get_cursor_y() < y + POINT_W / 2 && get_cursor_y() >= y - POINT_W / 2) { new_cursor = UPRIGHT_ARROW_CURSOR; break; } } if(new_cursor != get_cursor()) { set_cursor(new_cursor, 0, 1); } } return 0; }
int CompressorTrigger::button_press_event() { if(is_event_win()) { if(get_buttonpress() < 4) return BC_TextBox::button_press_event(); if(get_buttonpress() == 4) { plugin->config.trigger++; } else if(get_buttonpress() == 5) { plugin->config.trigger--; } update((int64_t)plugin->config.trigger); plugin->send_configure_change(); return 1; } return 0; }
int CompressorDecay::button_press_event() { if(is_event_win()) { if(get_buttonpress() < 4) return BC_TextBox::button_press_event(); if(get_buttonpress() == 4) { plugin->config.decay_len += 0.1; } else if(get_buttonpress() == 5) { plugin->config.decay_len -= 0.1; } update((float)plugin->config.decay_len); plugin->send_configure_change(); return 1; } return 0; }
int CompressorCanvas::button_press_event() { // Check existing points if(is_event_win() && cursor_inside()) { for(int i = 0; i < plugin->config.levels.total; i++) { double x_db = plugin->config.get_x(i); double y_db = plugin->config.get_y(i); int x = (int)(((double)1 - x_db / plugin->config.min_db) * get_w()); int y = (int)(y_db / plugin->config.min_db * get_h()); if(get_cursor_x() < x + POINT_W / 2 && get_cursor_x() >= x - POINT_W / 2 && get_cursor_y() < y + POINT_W / 2 && get_cursor_y() >= y - POINT_W / 2) { current_operation = DRAG; current_point = i; return 1; } } // Create new point double x_db = (double)(1 - (double)get_cursor_x() / get_w()) * plugin->config.min_db; double y_db = (double)get_cursor_y() / get_h() * plugin->config.min_db; current_point = plugin->config.set_point(x_db, y_db); current_operation = DRAG; ((CompressorWindow*)plugin->thread->window)->update(); plugin->send_configure_change(); return 1; } return 0; //plugin->config.dump(); }
void GraphicCanvas::process(int buttonpress, int motion, int draw) { int got_button = 0; int center_y = get_h() / 2; int out_of_order = 0; ArrayList<GraphicPoint*> *points; double *envelope; const int debug = 0; if(state == GraphicCanvas::NONE) { points = &plugin->config.points; envelope = plugin->envelope; } else { points = &temp_points; envelope = temp_envelope; } plugin->calculate_envelope(points, envelope); // spectrogram if(draw) { clear_box(0, 0, get_w(), get_h()); int niquist = plugin->PluginAClient::project_sample_rate / 2; int total_frames = plugin->get_gui_update_frames(); GraphicGUIFrame *frame = (GraphicGUIFrame*)plugin->get_gui_frame(); if(frame) { delete plugin->last_frame; plugin->last_frame = frame; } else { frame = plugin->last_frame; } // Draw most recent frame if(frame) { set_color(MEGREY); int y1 = 0; int y2 = 0; for(int i = 0; i < get_w(); i++) { int freq = Freq::tofreq(i * TOTALFREQS / get_w()); int index = (int64_t)freq * (int64_t)frame->window_size / 2 / niquist; if(index < frame->window_size / 2) { double magnitude = frame->data[index] / frame->freq_max * frame->time_max; y2 = (int)(get_h() - (DB::todb(magnitude) - INFINITYGAIN) * get_h() / -INFINITYGAIN); CLAMP(y2, 0, get_h() - 1); if(i > 0) { draw_line(i - 1, y1, i, y2); //printf(" %.0f", frame->data[index]); } y1 = y2; } } //printf( "\n"); total_frames--; } // Delete remaining frames while(total_frames > 0) { PluginClientFrame *frame = plugin->get_gui_frame(); if(frame) delete frame; total_frames--; } } // Determine if active point is out of order if(plugin->active_point_exists()) { GraphicPoint *active_point = points->get(plugin->active_point); for(int i = 0; i < points->size(); i++) { if(i == plugin->active_point) { if(i < points->size() - 1 && active_point->freq >= points->get(i + 1)->freq || i > 0 && active_point->freq <= points->get(i - 1)->freq) { out_of_order = 1; } break; } } } if(motion) { if(state == GraphicCanvas::DRAG_POINT) { int point_x = get_cursor_x() + x_diff; int point_y = get_cursor_y() + y_diff; CLAMP(point_x, 0, get_w()); CLAMP(point_y, 0, get_h()); int frequency = Freq::tofreq(point_x * TOTALFREQS / get_w()); double magnitude_db = (double)(center_y - point_y) * MAXMAGNITUDE / center_y; int minfreq = Freq::tofreq(0); int maxfreq = Freq::tofreq(TOTALFREQS - 1); CLAMP(frequency, minfreq, maxfreq); CLAMP(magnitude_db, -MAXMAGNITUDE, MAXMAGNITUDE); if(plugin->active_point >= 0) { GraphicPoint *active_point = points->get(plugin->active_point); active_point->freq = frequency; active_point->value = magnitude_db; } // Redraw with new value process(0, 0, 1); save_temps(); plugin->send_configure_change(); gui->update_textboxes(); return; } } // Magnitude bars if(draw) { set_color(GREEN); set_line_dashes(1); for(int i = 1; i < MAJOR_DIVISIONS; i++) { int y = i * get_h() / (MAJOR_DIVISIONS - 1); draw_line(0, y, get_w(), y); } set_line_dashes(0); } int y1 = 0; if(draw) set_color(WHITE); // Control points, cursor change and control point selection int new_cursor = CROSS_CURSOR; for(int i = 0; i < points->size(); i++) { GraphicPoint *point = points->get(i); int x = Freq::fromfreq(point->freq) * get_w() / TOTALFREQS; int y = freq_to_y(point->freq, points, envelope); if(draw) { y1 = y; // Draw point under cursor if out of order if(i == plugin->active_point && out_of_order) y1 = get_cursor_y() + y_diff; if(i == plugin->active_point) draw_box(x - BOX_SIZE / 2, y1 - BOX_SIZE / 2, BOX_SIZE, BOX_SIZE); else draw_rectangle(x - BOX_SIZE / 2, y1 - BOX_SIZE / 2, BOX_SIZE, BOX_SIZE); } if(motion && state == GraphicCanvas::NONE && is_event_win() && cursor_inside()) { if(get_cursor_x() >= x - BOX_SIZE / 2 && get_cursor_y() >= y - BOX_SIZE / 2 && get_cursor_x() < x + BOX_SIZE / 2 && get_cursor_y() < y + BOX_SIZE / 2) { new_cursor = UPRIGHT_ARROW_CURSOR; } } if(buttonpress && state == GraphicCanvas::NONE && is_event_win() && cursor_inside() && !got_button) { if(get_cursor_x() >= x - BOX_SIZE / 2 && get_cursor_y() >= y - BOX_SIZE / 2 && get_cursor_x() < x + BOX_SIZE / 2 && get_cursor_y() < y + BOX_SIZE / 2) { plugin->active_point = i; state = GraphicCanvas::DRAG_POINT; new_temps(); points = &temp_points; envelope = temp_envelope; x_diff = x - get_cursor_x(); y_diff = y - get_cursor_y(); got_button = 1; process(0, 0, 1); save_temps(); plugin->send_configure_change(); gui->update_textboxes(); } } } if(motion && new_cursor != get_cursor()) { set_cursor(new_cursor, 0, 1); } // Envelope line; y1 = 0; set_line_width(2); for(int i = 0; i < get_w(); i++) { int y = freq_to_y(Freq::tofreq(i * TOTALFREQS / get_w()), points, envelope); if(draw) { if(i > 0) draw_line(i - 1, y1, i, y); } y1 = y; } set_line_width(1); if(buttonpress && !got_button) { if(is_event_win() && cursor_inside()) { GraphicPoint *new_point = new GraphicPoint; new_point->freq = Freq::tofreq(get_cursor_x() * TOTALFREQS / get_w()); new_point->value = (double)(center_y - get_cursor_y()) * MAXMAGNITUDE / center_y; state = GraphicCanvas::DRAG_POINT; new_temps(); points = &temp_points; envelope = temp_envelope; insert_point(new_point); plugin->active_point = points->number_of(new_point); x_diff = 0; y_diff = 0; // Redraw with new point process(0, 0, 1); save_temps(); plugin->send_configure_change(); gui->update_textboxes(); } } if(draw) { flash(); } }
int PerspectiveCanvas::button_press_event() { if(is_event_win() && cursor_inside()) { // Set current point int x1, y1, x2, y2, x3, y3, x4, y4; int cursor_x = get_cursor_x(); int cursor_y = get_cursor_y(); plugin->thread->window->calculate_canvas_coords(x1, y1, x2, y2, x3, y3, x4, y4); float distance1 = DISTANCE(cursor_x, cursor_y, x1, y1); float distance2 = DISTANCE(cursor_x, cursor_y, x2, y2); float distance3 = DISTANCE(cursor_x, cursor_y, x3, y3); float distance4 = DISTANCE(cursor_x, cursor_y, x4, y4); // printf("PerspectiveCanvas::button_press_event %f %d %d %d %d\n", // distance3, // cursor_x, // cursor_y, // x3, // y3); float min = distance1; plugin->config.current_point = 0; if(distance2 < min) { min = distance2; plugin->config.current_point = 1; } if(distance3 < min) { min = distance3; plugin->config.current_point = 2; } if(distance4 < min) { min = distance4; plugin->config.current_point = 3; } if(plugin->config.mode == AffineEngine::SHEER) { if(plugin->config.current_point == 1) plugin->config.current_point = 0; else if(plugin->config.current_point == 2) plugin->config.current_point = 3; } start_cursor_x = cursor_x; start_cursor_y = cursor_y; if(alt_down() || shift_down()) { if(alt_down()) state = PerspectiveCanvas::DRAG_FULL; else state = PerspectiveCanvas::ZOOM; // Get starting positions start_x1 = plugin->config.x1; start_y1 = plugin->config.y1; start_x2 = plugin->config.x2; start_y2 = plugin->config.y2; start_x3 = plugin->config.x3; start_y3 = plugin->config.y3; start_x4 = plugin->config.x4; start_y4 = plugin->config.y4; } else { state = PerspectiveCanvas::DRAG; // Get starting positions start_x1 = plugin->get_current_x(); start_y1 = plugin->get_current_y(); } plugin->thread->window->update_coord(); plugin->thread->window->update_canvas(); return 1; } return 0; }