zoomedit: Added scales to drawing area.
This commit is contained in:
parent
0698046e50
commit
7f879850b5
3 changed files with 19 additions and 31 deletions
23
Drawer.cpp
23
Drawer.cpp
|
@ -106,11 +106,15 @@ void Drawer::updateScrolling() {
|
||||||
else
|
else
|
||||||
xCenter = gtk_adjustment_get_value(hAdjustment);
|
xCenter = gtk_adjustment_get_value(hAdjustment);
|
||||||
|
|
||||||
|
g_object_set(G_OBJECT(hRuler), "lower", xCenter-getWidth()/scale/2, "upper", xCenter+getWidth()/scale/2, NULL);
|
||||||
|
|
||||||
if((getImageHeight())*scale < getHeight())
|
if((getImageHeight())*scale < getHeight())
|
||||||
yCenter = 0;
|
yCenter = 0;
|
||||||
else
|
else
|
||||||
yCenter = gtk_adjustment_get_value(vAdjustment);
|
yCenter = gtk_adjustment_get_value(vAdjustment);
|
||||||
|
|
||||||
|
g_object_set(G_OBJECT(vRuler), "lower", yCenter-getHeight()/scale/2, "upper", yCenter+getHeight()/scale/2, NULL);
|
||||||
|
|
||||||
gtk_widget_queue_draw(drawingArea);
|
gtk_widget_queue_draw(drawingArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,6 +157,9 @@ void Drawer::updateHoveredPoint(float x, float y) {
|
||||||
Vertex v(x, y);
|
Vertex v(x, y);
|
||||||
viewToImage(&v);
|
viewToImage(&v);
|
||||||
window->getEditManager().setHoveredVertex(&v);
|
window->getEditManager().setHoveredVertex(&v);
|
||||||
|
|
||||||
|
g_object_set(G_OBJECT(hRuler), "position", v.getX(), NULL);
|
||||||
|
g_object_set(G_OBJECT(vRuler), "position", v.getY(), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Drawer::render() {
|
void Drawer::render() {
|
||||||
|
@ -192,7 +199,7 @@ Drawer::Drawer(Window *window, GdkGLConfig *glconfig) : renderer(&window->getEdi
|
||||||
xCenter = 0;
|
xCenter = 0;
|
||||||
yCenter = 0;
|
yCenter = 0;
|
||||||
|
|
||||||
drawer = gtk_table_new(2, 2, FALSE);
|
drawer = gtk_table_new(3, 3, FALSE);
|
||||||
g_object_ref_sink(G_OBJECT(drawer));
|
g_object_ref_sink(G_OBJECT(drawer));
|
||||||
|
|
||||||
drawingArea = gtk_drawing_area_new();
|
drawingArea = gtk_drawing_area_new();
|
||||||
|
@ -207,18 +214,24 @@ Drawer::Drawer(Window *window, GdkGLConfig *glconfig) : renderer(&window->getEdi
|
||||||
g_signal_connect(G_OBJECT(drawingArea), "motion-notify-event", G_CALLBACK(eventHandler), this);
|
g_signal_connect(G_OBJECT(drawingArea), "motion-notify-event", G_CALLBACK(eventHandler), this);
|
||||||
g_signal_connect(G_OBJECT(drawingArea), "scroll-event", G_CALLBACK(eventHandler), this);
|
g_signal_connect(G_OBJECT(drawingArea), "scroll-event", G_CALLBACK(eventHandler), this);
|
||||||
gtk_widget_add_events(drawingArea, GDK_SCROLL_MASK | GDK_POINTER_MOTION_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_RELEASE_MASK);
|
gtk_widget_add_events(drawingArea, GDK_SCROLL_MASK | GDK_POINTER_MOTION_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_RELEASE_MASK);
|
||||||
gtk_table_attach(GTK_TABLE(drawer), drawingArea, 0, 1, 0, 1, (GtkAttachOptions)(GTK_FILL|GTK_EXPAND|GTK_SHRINK), (GtkAttachOptions)(GTK_FILL|GTK_EXPAND|GTK_SHRINK), 0, 0);
|
gtk_table_attach(GTK_TABLE(drawer), drawingArea, 1, 2, 1, 2, (GtkAttachOptions)(GTK_FILL|GTK_EXPAND|GTK_SHRINK), (GtkAttachOptions)(GTK_FILL|GTK_EXPAND|GTK_SHRINK), 0, 0);
|
||||||
|
|
||||||
hAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 0, 10, 100, 100));
|
hAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 0, 10, 100, 100));
|
||||||
GtkWidget *hScroll = gtk_hscrollbar_new(hAdjustment);
|
GtkWidget *hScroll = gtk_hscrollbar_new(hAdjustment);
|
||||||
g_signal_connect(G_OBJECT(hScroll), "value-changed", G_CALLBACK(valueChanged), this);
|
g_signal_connect(G_OBJECT(hScroll), "value-changed", G_CALLBACK(valueChanged), this);
|
||||||
gtk_table_attach(GTK_TABLE(drawer), hScroll, 0, 1, 1, 2, (GtkAttachOptions)(GTK_FILL|GTK_EXPAND|GTK_SHRINK), (GtkAttachOptions)0, 0, 0);
|
gtk_table_attach(GTK_TABLE(drawer), hScroll, 1, 2, 2, 3, (GtkAttachOptions)(GTK_FILL|GTK_EXPAND|GTK_SHRINK), (GtkAttachOptions)0, 0, 0);
|
||||||
|
|
||||||
vAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 0, 10, 100, 100));
|
vAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 0, 10, 100, 100));
|
||||||
GtkWidget *vScroll = gtk_vscrollbar_new(vAdjustment);
|
GtkWidget *vScroll = gtk_vscrollbar_new(vAdjustment);
|
||||||
g_signal_connect(G_OBJECT(vScroll), "value-changed", G_CALLBACK(valueChanged), this);
|
g_signal_connect(G_OBJECT(vScroll), "value-changed", G_CALLBACK(valueChanged), this);
|
||||||
gtk_table_attach(GTK_TABLE(drawer), vScroll, 1, 2, 0, 1, (GtkAttachOptions)0, (GtkAttachOptions)(GTK_FILL|GTK_EXPAND|GTK_SHRINK), 0, 0);
|
gtk_table_attach(GTK_TABLE(drawer), vScroll, 2, 3, 1, 2, (GtkAttachOptions)0, (GtkAttachOptions)(GTK_FILL|GTK_EXPAND|GTK_SHRINK), 0, 0);
|
||||||
|
|
||||||
|
hRuler = gtk_hruler_new();
|
||||||
|
gtk_table_attach(GTK_TABLE(drawer), hRuler, 1, 2, 0, 1, (GtkAttachOptions)(GTK_FILL|GTK_EXPAND|GTK_SHRINK), (GtkAttachOptions)0, 0, 0);
|
||||||
|
|
||||||
|
vRuler = gtk_vruler_new();
|
||||||
|
gtk_table_attach(GTK_TABLE(drawer), vRuler, 0, 1, 1, 2, (GtkAttachOptions)0, (GtkAttachOptions)(GTK_FILL|GTK_EXPAND|GTK_SHRINK), 0, 0);
|
||||||
|
|
||||||
gtk_widget_show_all(drawer);
|
gtk_widget_show_all(drawer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
Drawer.h
1
Drawer.h
|
@ -14,6 +14,7 @@ class Drawer {
|
||||||
GtkWidget *drawer;
|
GtkWidget *drawer;
|
||||||
GtkWidget *drawingArea;
|
GtkWidget *drawingArea;
|
||||||
GtkAdjustment *hAdjustment, *vAdjustment;
|
GtkAdjustment *hAdjustment, *vAdjustment;
|
||||||
|
GtkWidget *hRuler, *vRuler;
|
||||||
int zoomExp;
|
int zoomExp;
|
||||||
|
|
||||||
Window *window;
|
Window *window;
|
||||||
|
|
26
Renderer.cpp
26
Renderer.cpp
|
@ -9,13 +9,11 @@ void Renderer::drawGrid(const Rectangle &rect, float scale) {
|
||||||
float step = powf(0.1f, depth2);
|
float step = powf(0.1f, depth2);
|
||||||
float f;
|
float f;
|
||||||
int i;
|
int i;
|
||||||
//gchar *string;
|
|
||||||
float x1 = rect.getVertex1().getX(), y1 = rect.getVertex1().getY();
|
float x1 = rect.getVertex1().getX(), y1 = rect.getVertex1().getY();
|
||||||
float x2 = rect.getVertex2().getX(), y2 = rect.getVertex2().getY();
|
float x2 = rect.getVertex2().getX(), y2 = rect.getVertex2().getY();
|
||||||
|
|
||||||
|
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
//cairo_set_font_size(cr, 10.0/scale);
|
|
||||||
|
|
||||||
for(i = 0; 0.4f*(depth-depth2+i-1) < 0.5f; i++) {
|
for(i = 0; 0.4f*(depth-depth2+i-1) < 0.5f; i++) {
|
||||||
f = fminf(0.4f*(depth-depth2+i), 0.5f);
|
f = fminf(0.4f*(depth-depth2+i), 0.5f);
|
||||||
|
@ -24,35 +22,11 @@ void Renderer::drawGrid(const Rectangle &rect, float scale) {
|
||||||
for(f = x1 - fmodf(x1, step) - step; f <= x2; f+=step) {
|
for(f = x1 - fmodf(x1, step) - step; f <= x2; f+=step) {
|
||||||
glVertex2f(f, y1);
|
glVertex2f(f, y1);
|
||||||
glVertex2f(f, y2);
|
glVertex2f(f, y2);
|
||||||
|
|
||||||
/*if(step > 0.005) {
|
|
||||||
if(step > 0.5)
|
|
||||||
string = g_strdup_printf("%i", (int)rint(d));
|
|
||||||
else
|
|
||||||
string = g_strdup_printf("%.*f", -(int)floor(log10(step*1.1)), d+step/10);
|
|
||||||
|
|
||||||
cairo_move_to(cr, d+1/scale, y1+11/scale);
|
|
||||||
cairo_show_text(cr, string);
|
|
||||||
|
|
||||||
g_free(string);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(f = y1 - fmodf(y1, step) - step; f <= y2; f+=step) {
|
for(f = y1 - fmodf(y1, step) - step; f <= y2; f+=step) {
|
||||||
glVertex2f(x1, f);
|
glVertex2f(x1, f);
|
||||||
glVertex2f(x2, f);
|
glVertex2f(x2, f);
|
||||||
|
|
||||||
/*if(step > 0.005) {
|
|
||||||
if(step > 0.5)
|
|
||||||
string = g_strdup_printf("%i", (int)rint(d));
|
|
||||||
else
|
|
||||||
string = g_strdup_printf("%.*f", -(int)floor(log10(step*1.1)), d+step/10);
|
|
||||||
|
|
||||||
cairo_move_to(cr, x1+3/scale, d+11/scale);
|
|
||||||
cairo_show_text(cr, string);
|
|
||||||
|
|
||||||
g_free(string);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
step *= 10;
|
step *= 10;
|
||||||
|
|
Reference in a new issue