Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gtk fix style issue and vid.red #4

Merged
merged 3 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions modules/view/backends/gtk3/font.reds
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,19 @@ make-font: func [
hFont [handle!]
][
; no more deal with different styles but only font via pango_font_description (excluding color, underline, strike)
;; DEBUG: print ["make-font face " face " " font lf]
hFont: font-description font

;; DEBUG: print ["make-font font-description: " hFont lf]
set-font-handle font hFont

;; DEBUG: print ["make-font set-font-handle: " font " " hFont lf]
values: object/get-values font

if face <> null [
blk: block/make-at as red-block! values + FONT_OBJ_PARENT 4
block/rs-append blk as red-value! face
]

;; DEBUG: print ["font-description: " hFont lf]
;; DEBUG: print ["make-font end font-description: " hFont lf]

hFont
]
Expand All @@ -110,7 +111,9 @@ get-font-handle: func [
free-font-handle: func [
hFont [handle!]
][
;; DEBUG: print ["free-font-handle " hFont lf]
pango_font_description_free hFont
;; DEBUG: print ["free-font-handle end " hFont lf]
]

free-font: func [
Expand All @@ -120,11 +123,11 @@ free-font: func [
hFont [handle!]
][
hFont: get-font-handle font 0
if hFont <> null [
unless null? hFont [
state: as red-block! (object/get-values font) + FONT_OBJ_STATE
state/header: TYPE_NONE
free-font-handle hFont
]
free-font-handle hFont
]

set-font-handle: func [
Expand All @@ -138,7 +141,9 @@ set-font-handle: func [
hFontP [handle!]
][
; release previous hFont first
;; DEBUG: print ["set-font-handle " font " " hFont lf]
hFontP: get-font-handle font 0
;; DEBUG: print ["set-font-handle get " hFontP lf]
unless null? hFontP [
free-font-handle hFontP
]
Expand All @@ -161,13 +166,13 @@ update-font: func [
font [red-object!]
flag [integer!]
][
;; DEBUG: print ["update-font " font lf]
switch flag [
FONT_OBJ_NAME
FONT_OBJ_SIZE
FONT_OBJ_STYLE
FONT_OBJ_ANGLE
FONT_OBJ_ANTI-ALIAS? [
free-font font
make-font null font
]
default [0]
Expand Down Expand Up @@ -254,6 +259,10 @@ font-description: func [
pango_font_description_set_stretch fd PANGO_STRETCH_NORMAL
pango_font_description_set_variant fd PANGO_VARIANT_NORMAL

;; DOES NOT WORK AS EXPECTED:
;; css: pango_font_description_to_string fd
;; print ["font description css: " css lf]

fd
]

Expand Down
21 changes: 13 additions & 8 deletions modules/view/backends/gtk3/gui.reds
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,23 @@ get-text-size: func [

;;; get pango_context
; from widget first
widget: face-handle? face
pc: gtk_widget_get_pango_context widget
pl: pango_layout_new pc ;seems more natural than pango-context
; widget: face-handle? face
; pc: as handle! 0 pl: as handle! 0
; unless null? widget [
; pc: gtk_widget_get_pango_context widget
; unless null? pc [pl: pango_layout_new pc ];seems more natural than pango-context
; ]
; globally otherwise
if null? pl [pl: pango_layout_new pango-context]
;if null? pl [
pl: pango_layout_new pango-context
;]


pango_layout_set_text pl text -1
pango_layout_set_font_description pl hFont
pango_layout_get_pixel_size pl :width :height
g_object_unref pl
; unless null? pc [g_object_unref pc]

size/width: width
size/height: height
Expand Down Expand Up @@ -1595,10 +1601,9 @@ OS-make-view: func [
gtk_container_add widget gtk_fixed_new
gtk_window_move widget offset/x offset/y
gobj_signal_connect(widget "delete-event" :window-delete-event null)
;gobj_signal_connect(widget "destroy" :window-destroy null)
gtk_widget_add_events widget GDK_STRUCTURE_MASK
gobj_signal_connect(widget "configure-event" :window-configure-event null)
;gobj_signal_connect(widget "size-allocate" :window-size-allocate null)
;BUG (make `vid.red` failing):gtk_widget_add_events widget GDK_STRUCTURE_MASK
;gobj_signal_connect(widget "configure-event" :window-configure-event null)
gobj_signal_connect(widget "size-allocate" :window-size-allocate null)
]
sym = slider [
vertical?: size/y > size/x
Expand Down
57 changes: 29 additions & 28 deletions modules/view/backends/gtk3/handlers.reds
Original file line number Diff line number Diff line change
Expand Up @@ -259,29 +259,28 @@ window-removed-event: func [
count/value: count/value - 1
]

window-configure-event: func [
[cdecl]
widget [handle!]
event [GdkEventConfigure!]
/local
sz [red-pair!]
][


;;DEBUG: print [ "window-resizing " event/x "x" event/y " " event/width "x" event/height lf]
sz: (as red-pair! get-face-values widget) + FACE_OBJ_SIZE ;-- update face/size
either any [event/width <> sz/x event/height <> sz/y] [
;if 0 = (motion/cpt % motion/sensitiv) [
motion/x_new: event/width
motion/y_new: event/height
motion/x_root: as float! event/x
motion/y_root: as float! event/y
make-event widget 0 EVT_SIZING
;]
;motion/cpt: motion/cpt + 1
yes
][no]
]
;; BUG: `vid.red` fails... back with window-size-allocate handler for resizing
; window-configure-event: func [
; [cdecl]
; widget [handle!]
; event [GdkEventConfigure!]
; /local
; sz [red-pair!]
; ][
; ;;DEBUG: print [ "window-resizing " event/x "x" event/y " " event/width "x" event/height lf]
; sz: (as red-pair! get-face-values widget) + FACE_OBJ_SIZE ;-- update face/size
; either any [event/width <> sz/x event/height <> sz/y] [
; ;if 0 = (motion/cpt % motion/sensitiv) [
; motion/x_new: event/width
; motion/y_new: event/height
; motion/x_root: as float! event/x
; motion/y_root: as float! event/y
; make-event widget 0 EVT_SIZING
; ;]
; ;motion/cpt: motion/cpt + 1
; yes
; ][no]
; ]


window-size-allocate: func [
Expand All @@ -291,12 +290,14 @@ window-size-allocate: func [
/local
sz [red-pair!]
][
;;DEBUG: print [ "window-size-allocate " rect/width "x" rect/height lf]
make-event widget 0 EVT_SIZING
sz: (as red-pair! get-face-values widget) + FACE_OBJ_SIZE ;-- update face/size
sz/x: rect/width
sz/y: rect/height
;; DEBUG: print [ "window-size-allocate end " sz lf]
if any [rect/width <> sz/x rect/height <> sz/y] [
motion/x_new: rect/width
motion/y_new: rect/height
motion/x_root: as float! rect/x
motion/y_root: as float! rect/y
make-event widget 0 EVT_SIZING
]
]

range-value-changed: func [
Expand Down