; Module/File: Editor_MWheelCtrlZoom3.pb ; Function: Relative zoom/scale on EditorGadget with Pango-Relations - Linux gtk3 ; Author: Omi ; Date: Sep. 09, 2015 ; Version: 0.1 ; Target Compiler: PureBasic 5.22/5.31/5.40 ; Target OS: Linux: (X/K/L)ubuntu, Ascii/Uni, 32/64 ;-------------------------------------------------------------- ;gtk3: The first Mousewheel-scroll-event is ignored !?! Seems to be a gtk3-bug. EnableExplicit ImportC "" gdk_event_get_scroll_deltas(*event, *delta_x, *delta_y); gtk3 pango_context_get_font_description(*context) pango_font_description_set_size (*desc, size) pango_font_description_get_size(*desc) pango_font_description_get_family(*desc) gtk_widget_override_font(*widget.GtkWidget, *font_desc); gtk3 g_signal_connect(*instance, detailed_signal.p-utf8, *c_handler, *pdata, destroy= 0, flags= 0) As "g_signal_connect_data" EndImport ; Object constants #MainWin = 0 #Txt1 = 0 #Edt1 = 1 ; Missing constants ... ; PANGO_SCALE factors #PANGO_SCALE = 1024 #PANGO_SCALE_XX_LARGE = 1.728; (* 1.2^3) #PANGO_SCALE_X_LARGE = 1.44; (* 1.2^2) #PANGO_SCALE_LARGE = 1.2; (* 1.2) #PANGO_SCALE_MEDIUM = 1.0 #PANGO_SCALE_SMALL = 0.8333333333333; (1 / 1.2) #PANGO_SCALE_X_SMALL = 0.6444444444444; (1 / 1.2^2) #PANGO_SCALE_XX_SMALL = 0.5787037037037; (1 / (1.2^3) ; GdkScrollDirection #GDK_SCROLL_SMOOTH = 4 Global Dim PangoScale.d(6) Global.i gEvent, gQuit Global.i gFontSize= 12, gPangoScale= 3 Global.s gS= "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam " + "erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus " + "est Lorem ipsum dolor sit amet." #FontMono= 0 LoadFont(#FontMono, "Monospace", gFontSize) Procedure Editor_CreateFontScaleFactors() PangoScale(0)= #PANGO_SCALE_XX_SMALL PangoScale(1)= #PANGO_SCALE_X_SMALL PangoScale(2)= #PANGO_SCALE_SMALL PangoScale(3)= #PANGO_SCALE_MEDIUM PangoScale(4)= #PANGO_SCALE_LARGE PangoScale(5)= #PANGO_SCALE_X_LARGE PangoScale(6)= #PANGO_SCALE_XX_LARGE EndProcedure Procedure Editor_Zoom(*widget, PangoScale, PangoScalePrev) Protected *context= gtk_widget_get_pango_context_(*widget) Protected *fontdescription = pango_context_get_font_description(*context) pango_font_description_set_size(*fontdescription, gFontSize * #PANGO_SCALE * PangoScale(PangoScale)) gtk_widget_override_font(*widget, *fontdescription); activate with gtk3 gtk_widget_queue_draw_(*widget); Workaround for sporadic diplay errors (mainly 64-Bit) EndProcedure ProcedureC Callback_EditorScroll(*widget, *event.GdkEventScroll, user_data) Protected.d delta_x, delta_y Protected.i Ret= #False, sSteps= ArraySize(PangoScale()) Static PangoScalePrev= -1, SmoothScroll= #False If *event\type = #GDK_SCROLL If *event\direction = #GDK_SCROLL_SMOOTH If gdk_event_get_scroll_deltas(*event, @delta_x, @delta_y) SmoothScroll= #True EndIf EndIf If *event\state & #GDK_CONTROL_MASK = 4; Control-key? If (*event\direction = 1 And Not SmoothScroll) Or delta_y = 1.0; Scroll up gtk2 | gtk3 gPangoScale- 1 If gPangoScale < 0 : gPangoScale = 0 : EndIf ElseIf (*event\direction = 0 And Not SmoothScroll) Or delta_y = -1.0; Scroll down gtk2 | gtk3 gPangoScale+ 1 If gPangoScale > sSteps : gPangoScale = sSteps : EndIf EndIf If PangoScalePrev <> gPangoScale Editor_Zoom(*widget, gPangoScale, PangoScalePrev) EndIf PangoScalePrev= gPangoScale Ret= #True; prevent from scrolling EndIf EndIf ProcedureReturn Ret EndProcedure If OpenWindow(#MainWin, 300, 200, 600, 200, "EditorGadget - relative PangoZoom", #PB_Window_SystemMenu) TextGadget(#Txt1, 5, 5, 590, 22, "Zoom: [Ctrl]+[MouseWheel up/down] over Editor ...") EditorGadget(#Edt1, 5, 25, 590, 170) SetGadgetFont(#Edt1, FontID(#FontMono)) SetGadgetText(#Edt1, gS) gtk_text_view_set_wrap_mode_(GadgetID(#Edt1), #GTK_WRAP_WORD) gtk_widget_add_events_(GadgetID(#Edt1), gtk_widget_get_events_(GadgetID(#Edt1)) | #GDK_SCROLL_MASK) g_signal_connect(GadgetID(#Edt1), "scroll-event", @Callback_EditorScroll(), 0) Editor_CreateFontScaleFactors() Repeat gEvent= WaitWindowEvent() Select gEvent Case #PB_Event_CloseWindow gQuit= #True Case #PB_Event_Gadget Select EventGadget() EndSelect EndSelect Until gQuit EndIf ; IDE Options = PureBasic 5.40 LTS Beta 9 (Linux - x86) ; CursorPosition = 96 ; FirstLine = 10 ; Folding = - ; EnableUnicode ; EnableXP