22 #if defined(DEVEL_RALF)
26 #if defined(TRACE_MODEL_VIEW_UPDATES)
30 tm *tms = localtime(&t);
32 strftime(atime, 255,
"%k:%M:%S", tms);
33 fprintf(stderr,
"[MVU] %s: %s\n", atime, action);
35 #else // !TRACE_MODEL_VIEW_UPDATES
63 int maxpos =
int(worldsize.r-rect.r)-1;
64 if (pos>maxpos) pos = maxpos;
66 aww->set_horizontal_scrollbar_position(pos);
70 int maxpos =
int(worldsize.b-rect.b)-1;
71 if (pos>maxpos) pos = maxpos;
73 aww->set_vertical_scrollbar_position(pos);
77 AW_pos width = this->worldinfo.r - this->worldinfo.l;
78 AW_pos height = this->worldinfo.b - this->worldinfo.t;
83 AW::Vector zv = gfx->exports.zoomVector(trans_to_fit);
85 worldsize.r = width *zv.
x() + gfx->exports.get_x_padding();
86 worldsize.b = height*zv.
y() + gfx->exports.get_y_padding();
88 aww->tell_scrolled_picture_size(worldsize);
90 aww->calculate_scrollbars();
92 this->old_hor_scroll_pos = (
int)((-this->worldinfo.l -
93 this->shift_x_to_fit)*
95 gfx->exports.get_left_padding());
96 this->set_horizontal_scrollbar_position(this->aww, old_hor_scroll_pos);
98 this->old_vert_scroll_pos = (
int)((-this->worldinfo.t -
99 this->shift_y_to_fit)*
101 gfx->exports.get_top_padding());
103 this->set_vertical_scrollbar_position(this->aww, old_vert_scroll_pos);
109 device->
zoom(this->trans_to_fit);
117 AW_pos old_width = worldinfo.r - worldinfo.l;
118 AW_pos old_height = worldinfo.b - worldinfo.t;
124 size_device->
reset();
126 gfx->show(size_device);
128 if (consider_text_for_size) {
135 if (adjust_scrollbars) {
137 if (shift_x_to_fit<0) {
138 AW_pos new_width = worldinfo.
r - worldinfo.l;
139 shift_x_to_fit *= new_width/old_width;
143 if (shift_y_to_fit<0) {
144 AW_pos new_height = worldinfo.b - worldinfo.t;
145 shift_y_to_fit *= new_height/old_height;
152 gfx->exports.clear_resize_request();
153 gfx->exports.request_refresh();
157 instant_resize(
false);
160 AW_pos width = this->worldinfo.r - this->worldinfo.l;
161 AW_pos height = this->worldinfo.b - this->worldinfo.t;
163 AW_pos net_window_width = rect.r - rect.l - gfx->exports.get_x_padding();
164 AW_pos net_window_height = rect.b - rect.t - gfx->exports.get_y_padding();
169 if (width <
EPS) width =
EPS;
170 if (height <
EPS) height =
EPS;
172 AW_pos x_scale = net_window_width/width;
173 AW_pos y_scale = net_window_height/height;
176 switch (gfx->exports.fit_mode) {
178 case AWT_FIT_X: trans_to_fit = x_scale;
break;
179 case AWT_FIT_Y: trans_to_fit = y_scale;
break;
185 AW_pos center_shift_x = 0;
186 AW_pos center_shift_y = 0;
188 if (gfx->exports.zoom_mode&
AWT_ZOOM_X) center_shift_x = (net_window_width /trans_to_fit - width)/2;
189 if (gfx->exports.zoom_mode&
AWT_ZOOM_Y) center_shift_y = (net_window_height/trans_to_fit - height)/2;
192 this->shift_x_to_fit = - this->worldinfo.l + gfx->exports.get_left_padding()/trans_to_fit + center_shift_x;
193 this->shift_y_to_fit = - this->worldinfo.t + gfx->exports.get_top_padding()/trans_to_fit + center_shift_y;
195 this->old_hor_scroll_pos = 0;
196 this->old_vert_scroll_pos = 0;
200 this->set_scrollbars();
202 gfx->exports.clear_zoom_reset_request();
222 AW_pos width = worldinfo.r-worldinfo.l;
223 AW_pos height = worldinfo.b-worldinfo.t;
225 if (width<
EPS) width =
EPS;
226 if (height<
EPS) height =
EPS;
230 aw_message(
"Zoom does not work in this mode");
237 bool isClick =
false;
250 Vector click2UpperLeft = current.upper_left_corner()-clickPos;
251 Vector click2LowerRight = current.lower_right_corner()-clickPos;
253 double scale = (100-percent)/100.0;
255 wanted =
Rectangle(clickPos+scale*click2UpperLeft, clickPos+scale*click2LowerRight);
265 double factor = current.
diagonal().
length()/wanted.diagonal().length();
266 Vector curr2wanted(current.upper_left_corner(), wanted.upper_left_corner());
267 Rectangle big(current.upper_left_corner()+(curr2wanted*-factor), current.diagonal()*factor);
274 factor = current.
width()/wanted.width();
278 factor = current.height()/wanted.height();
280 Vector curr2wanted_start(current.upper_left_corner(), wanted.upper_left_corner());
281 Vector curr2wanted_end(current.lower_right_corner(), wanted.lower_right_corner());
282 Rectangle big(current.upper_left_corner()+(curr2wanted_start*-factor),
283 current.lower_right_corner()+(curr2wanted_end*-factor));
290 shift_x_to_fit = (zoom_mode&
AWT_ZOOM_X) ? -wanted.start().xpos() : (shift_x_to_fit+worldinfo.l)*trans_to_fit;
291 shift_y_to_fit = (zoom_mode&
AWT_ZOOM_Y) ? -wanted.start().ypos() : (shift_y_to_fit+worldinfo.t)*trans_to_fit;
294 if ((rect.r-rect.l)<
EPS) rect.r = rect.l+1;
295 if ((rect.b-rect.t)<
EPS) rect.b = rect.t+1;
297 AW_pos max_trans_to_fit = 0;
301 trans_to_fit =
max((rect.r-rect.l)/wanted.width(), (rect.b-rect.t)/wanted.height());
302 max_trans_to_fit = 32000.0/
max(width, height);
306 trans_to_fit = (rect.r-rect.l)/wanted.width();
307 max_trans_to_fit = 32000.0/width;
311 trans_to_fit = (rect.b-rect.t)/wanted.height();
312 max_trans_to_fit = 32000.0/height;
317 trans_to_fit =
std::min(trans_to_fit, max_trans_to_fit);
320 if (zoom_mode ==
AWT_ZOOM_Y) shift_x_to_fit = (shift_x_to_fit/trans_to_fit)-worldinfo.l;
321 if (zoom_mode ==
AWT_ZOOM_X) shift_y_to_fit = (shift_y_to_fit/trans_to_fit)-worldinfo.t;
337 int left_border,
int right_border,
338 int top_border,
int bottom_border,
339 int hor_overlap,
int ver_overlap)
350 device->
clear_part(left_border, top_border, right_border-left_border,
351 bottom_border-top_border, -1);
357 if (hor_overlap> 0.0) {
360 if (hor_overlap< 0.0) {
363 if (ver_overlap> 0.0) {
366 if (ver_overlap< 0.0) {
379 clip_expose(this->aww,
this, this->rect.l, this->rect.r,
380 this->rect.t, this->rect.b, 0, 0);
382 gfx->exports.clear_refresh_request();
398 switch (whatChanged) {
423 bool handled =
false;
443 scr->
zoom(device, zoomIn, drag, screen, percent);
472 int viewport_size = horizontal ? (rect.r-rect.l+1) : (rect.b-rect.t+1);
473 int gfx_size = horizontal ? (worldsize.r-worldsize.l) : (worldsize.b-worldsize.t);
476 int dist =
std::min(viewport_size / 20, gfx_size / 30);
477 int direction =
event.button ==
AW_WHEEL_UP ? -dist : dist;
479 int dx = horizontal ? direction : 0;
480 int dy = horizontal ? 0 : direction;
488 void AWT_graphic::update_DB_and_model_as_requested(
GBDATA *
gb_main) {
492 if (exports.needs_save()) {
497 load_from_DB(gb_main,
NULp);
499 exports.clear_save_request();
501 exports.request_structure_update();
504 if (exports.needs_structure_update()) {
507 exports.clear_structure_update_request();
509 exports.request_resize();
510 awt_assert(!exports.needs_structure_update());
512 if (gb_main) notify_synchronized(gb_main);
526 gfx->update_DB_and_model_as_requested(gb_main);
530 gfx->exports.update_display_as_requested(
this, perform_refresh);
549 bool event_handled =
false;
552 event_handled =
true;
558 if (!event_handled) {
562 if (!event_handled) {
590 switch (gfx->exports.zoom_mode) {
596 zoom_drag_sy = rect.t;
597 zoom_drag_ey = rect.b-1;
598 zoom_drag_ex = dragx;
602 zoom_drag_sx = rect.l;
603 zoom_drag_ex = rect.r-1;
604 zoom_drag_ey = dragy;
608 zoom_drag_ex = dragx;
609 zoom_drag_ey = dragy;
611 int drag_sx = zoom_drag_ex-zoom_drag_sx;
612 int drag_sy = zoom_drag_ey-zoom_drag_sy;
614 bool correct_x =
false;
615 bool correct_y =
false;
618 int scr_sx = rect.r-rect.l;
619 int scr_sy = rect.b-rect.t;
622 if (drag_sy != 0) { factor = double(drag_sy)/scr_sy; correct_x =
true; }
625 if (drag_sy == 0) { factor = double(drag_sx)/scr_sx; correct_y =
true; }
627 double facx = double(drag_sx)/scr_sx;
628 double facy = double(drag_sy)/scr_sy;
630 if (fabs(facx)>fabs(facy)) { factor = facx; correct_y =
true; }
631 else { factor = facy; correct_x =
true; }
636 int width =
int(scr_sx*factor) * ((drag_sx*drag_sy) < 0 ? -1 : 1);
637 zoom_drag_ex = zoom_drag_sx+width;
639 else if (correct_y) {
640 int height =
int(scr_sy*factor) * ((drag_sx*drag_sy) < 0 ? -1 : 1);
641 zoom_drag_ey = zoom_drag_sy+height;
670 scr->
scroll(-dx*3, -dy*3);
682 AW_device_click *click_device =
NULp;
704 int csx, cdx, cwidth, csy, cdy, cheight;
706 if (!dont_update_scrollbars) {
707 this->old_hor_scroll_pos += dx;
708 this->set_horizontal_scrollbar_position(aww, this->old_hor_scroll_pos);
709 this->old_vert_scroll_pos += dy;
710 this->set_vertical_scrollbar_position(aww, this->old_vert_scroll_pos);
715 int screenwidth = this->rect.r-this->rect.l;
716 int screenheight = this->rect.b-this->rect.t;
723 cwidth = screenwidth-dx;
728 cwidth = screenwidth+dx;
733 cheight = screenheight-dy;
738 cheight = screenheight+dy;
742 if (!gfx->exports.dont_scroll) {
743 device->
move_region(csx, csy, cwidth, cheight, cdx, cdy);
745 this->shift_x_to_fit -= dx/this->trans_to_fit;
746 this->shift_y_to_fit -= dy/this->trans_to_fit;
751 screenwidth-dx, screenwidth, 0, screenheight,
756 0, -dx, 0, screenheight,
763 0, screenwidth, screenheight-dy, screenheight,
768 0, screenwidth, 0, -dy,
774 this->shift_x_to_fit -= dx/this->trans_to_fit;
775 this->shift_y_to_fit -= dy/this->trans_to_fit;
778 this->request_refresh();
785 scr->
scroll(0, delta_screen_y,
true);
793 scr->
scroll(delta_screen_x, 0,
true);
799 consider_text_for_size(
true),
801 announce_update_cb(
NULp),
807 awr(aww->get_root()),
809 gc_manager(gfx->init_devices(aww, aww->get_device(
AW_MIDDLE_AREA), this)),
830 return "AWT_nonDB_graphic cannot be loaded";
834 return "AWT_nonDB_graphic cannot be saved";
839 printf(
"AWT_nonDB_graphic can't check_for_DB_update\n");
844 printf(
"AWT_nonDB_graphic can't notify_synchronized\n");
void zoom(AW_device *device, bool zoomIn, const AW::Rectangle &wanted_part, const AW::Rectangle ¤t_part, int percent)
virtual void clear(AW_bitset filteri)
void push_transaction() const
void set_resize_callback(AW_area area, const WindowCallback &wcb)
const AW_bitset AW_SCREEN
void request_zoom_reset()
void set_horizontal_scrollbar_position(AW_window *aww, int pos)
AW_device * get_device(AW_area area)
const AW_screen_area & get_area_size() const
Position centroid() const
void set_left_clip_border(int left, bool allow_oversize=false)
void shift(const AW::Vector &doff)
virtual void clear_part(const AW::Rectangle &rect, AW_bitset filteri)
char * ARB_strdup(const char *str)
void set_top_clip_border(int top, bool allow_oversize=false)
const int ZOOM_SPEED_WHEEL
void sync_DB_model_and_view(bool perform_refresh)
void announce_screen_update()
static void input_event(AW_window *aww, AWT_canvas *scr)
void instant_zoom_reset()
int slider_pos_horizontal
current position of the vertical slider
AWT_canvas(GBDATA *gb_main_, AW_window *aww_, const char *gc_base_name_, AWT_graphic *gfx_)
GB_ERROR GB_push_transaction(GBDATA *gbd)
void set_motion_callback(AW_area area, const WindowCallback &wcb)
void nt_draw_zoom_box(AW_device *device, int gc, AW_pos x1, AW_pos y1, AW_pos x2, AW_pos y2)
struct Unfixed_cb_parameter * UNFIXED
int AW_get_drag_gc(AW_gc_manager *gcman)
void drag_target_detection(bool detect)
void get_event(AW_event *eventi) const
GB_ERROR save_to_DB(GBDATA *gb_main, const char *name) OVERRIDE __ATTR__USERESULT
static bool handleZoomEvent(AWT_canvas *scr, AW_device *device, const AW_event &event, int percent)
void set_bottom_clip_border(int bottom, bool allow_oversize=false)
AW_device_click * get_click_device(AW_area area, int mousex, int mousey, int max_distance)
void set_dragEndpoint(int x, int y)
void set_expose_callback(AW_area area, const WindowCallback &wcb)
AW::Vector rtransform(const AW::Vector &vec) const
static void error(const char *msg)
const AW_bitset AW_CLICK_DROP
void set_vertical_scrollbar_position(AW_window *aww, int pos)
static void clip_expose(AW_window *aww, AWT_canvas *scr, int left_border, int right_border, int top_border, int bottom_border, int hor_overlap, int ver_overlap)
GB_write_int const char GB_write_autoconv_string WRITE_SKELETON(write_pointer, GBDATA *,"%p", GB_write_pointer) char *AW_awa if)(!gb_var) return strdup("")
void check_for_DB_update(GBDATA *gb_main) OVERRIDE
GB_ERROR GB_pop_transaction(GBDATA *gbd)
GB_ERROR load_from_DB(GBDATA *gb_main, const char *name) OVERRIDE __ATTR__USERESULT
AW_borders get_unscaleable_overlap() const
const Vector & diagonal() const
static void motion_event(AW_window *aww, AWT_canvas *scr)
const Vector & line_vector() const
virtual void handle_command(AW_device *device, AWT_graphic_event &event)=0
void set_right_clip_border(int right, bool allow_oversize=false)
static void scroll_vert_cb(AW_window *aww, AWT_canvas *scr)
const int ZOOM_SPEED_CLICK
bool wants_drag_target() const
const double & length() const
void scroll(int delta_x, int delta_y, bool dont_update_scrollbars=false)
void AWT_expose_cb(UNFIXED, AWT_canvas *scr)
void set_focus_callback(const WindowCallback &wcb)
void get_size_information(AW_world *ptr) const __ATTR__DEPRECATED_TODO("whole AW_world is deprecated")
AW_gc_manager * gc_manager
bool handleWheelEvent(AW_device *device, const AW_event &event)
AWT_graphic_exports exports
void init_device(AW_device *device)
#define assert_no_auto_refresh_for(CANVAS)
const AW_bitset AW_SIZE_UNSCALED
void aw_message(const char *msg)
static void canvas_resize_cb(UNFIXED, AWT_canvas *scr)
void set_filter(AW_bitset filteri)
static void scroll_hor_cb(AW_window *aww, AWT_canvas *scr)
virtual void move_region(AW_pos src_x, AW_pos src_y, AW_pos width, AW_pos height, AW_pos dest_x, AW_pos dest_y)
void pop_transaction() const
void instant_resize(bool adjust_scrollbars)
GB_transaction ta(gb_var)
void set_horizontal_change_callback(const WindowCallback &wcb)
bool box(int gc, AW::FillStyle filled, const AW::Rectangle &rect, AW_bitset filteri=AW_ALL_DEVICES_SCALED)
void set_vertical_change_callback(const WindowCallback &wcb)
void TRACE_UPDATE(const char *)
int slider_pos_vertical
window id
static void canvas_focus_cb(AW_window *, AWT_canvas *scr)
void set_input_callback(AW_area area, const WindowCallback &wcb)
void notify_synchronized(GBDATA *gb_main) OVERRIDE
void AWT_GC_changed_cb(GcChange whatChanged, AWT_canvas *scr)
virtual void show(AW_device *device)=0