Skip to content

Commit

Permalink
FEAT: enabled "window" host extension on Windows (without graphics)...
Browse files Browse the repository at this point in the history
... so it's possible to `view gob` or `view image` to open a system window.
Originally the windowing was dependent on `graphics` extension. Now it is independent and the graphics (using AGG ) is not yet ready.
  • Loading branch information
Oldes committed Feb 18, 2019
1 parent 8a96edb commit 04cb592
Show file tree
Hide file tree
Showing 13 changed files with 764 additions and 386 deletions.
2 changes: 1 addition & 1 deletion make/r3.rc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
IDI_APPICON ICON "r3.ico"
101 ICON "r3.ico"

1 VERSIONINFO
FILEVERSION 3,0,0,0
Expand Down
29 changes: 3 additions & 26 deletions src/boot/graphics.r
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
REBOL [
System: "REBOL [R3] Language Interpreter and Run-time Environment"
Title: "REBOL Graphics"
Author: ["Richard Smolak" "Carl Sassenrath"]
Rights: {
Copyright 2012 REBOL Technologies
REBOL is a trademark of REBOL Technologies
Additional code modifications and improvements Copyright 2012 Saphirion AG
}
License: {
Licensed under the Apache License, Version 2.0.
Expand All @@ -16,13 +19,6 @@ REBOL [
]

words: [
;gui-metric
screen-size
border-size
border-fixed
title-size
work-origin
work-size
]

;temp hack - will be removed later
Expand All @@ -32,34 +28,20 @@ init-words: command [

init-words words

init: command [
"Initialize graphics subsystem."
gob [gob!] "The screen gob (root gob)"
]

caret-to-offset: command [
"Returns the xy offset (pair) for a specific string position in a graphics object."
gob [gob!]
element [integer! block!] "The position of the string in the richtext block"
position [integer! string!] "The position within the string"
]

cursor: command [
"Changes the mouse cursor image."
image [integer! image! none!]
]

offset-to-caret: command [ ;returns pair! instead of the block..needs to be fixed
"Returns the richtext block at the string position for an XY offset in the graphics object."
gob [gob!]
position [pair!]
]

show: command [
"Display or update a graphical object or block of them."
gob [gob! none!]
]

size-text: command [
"Returns the size of text rendered by a graphics object."
gob [gob!]
Expand All @@ -71,11 +53,6 @@ draw: command [
commands [block!] "Draw commands"
]

gui-metric: command [
"Returns specific gui related metric setting."
keyword [word!] "Available keywords: SCREEN-SIZE, BORDER-SIZE, BORDER-FIXED, TITLE-SIZE, WORK-ORIGIN and WORK-SIZE."
]

;#not-yet-used [
;
;effect: command [
Expand Down
78 changes: 78 additions & 0 deletions src/boot/window.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
REBOL [
System: "REBOL [R3] Language Interpreter and Run-time Environment"
Title: "REBOL Window"
Author: ["Richard Smolak" "Carl Sassenrath" "Oldes"]
Rights: {
Copyright 2012 REBOL Technologies
REBOL is a trademark of REBOL Technologies
Additional code modifications and improvements Copyright 2012 Saphirion AG
}
License: {
Licensed under the Apache License, Version 2.0.
See: http://www.apache.org/licenses/LICENSE-2.0
}
Name: window
Type: extension
Exports: [] ; added by make-host-ext.r
Note: "Run make-host-ext.r to convert"
]

words: [
;gui-metric
border-fixed
border-size
screen-size
virtual-screen-size
log-size
phys-size
screen-dpi
screen-num
screen-origin
title-size
window-min-size
work-origin
work-size
restore
minimize
maximize
activate
]

;temp hack - will be removed later
init-words: command [
words [block!]
]

init-words words

init-top-window: command [
"Initialize window subsystem."
gob [gob!] "The screen gob (root gob)"
]

cursor: command [
"Changes the mouse cursor image."
image [integer! image! none!]
]

show: command [
"Display or update a graphical object or block of them."
gob [gob! none!]
]

gui-metric: command [
"Returns specific gui related metric setting."
keyword [word!] "Available keywords: BORDER-FIXED, BORDER-SIZE, SCREEN-DPI, LOG-SIZE, PHYS-SIZE, SCREEN-SIZE, VIRTUAL-SCREEN-SIZE, TITLE-SIZE, WINDOW-MIN-SIZE, WORK-ORIGIN and WORK-SIZE."
/set
val "Value used to set specific setting(works only on 'writable' keywords)."
/display
idx [integer!] "Display index, starting with 0"
]

show-soft-keyboard: command [
"Display on-screen keyboard for user input."
/attach
gob [gob!] "GOB which should be visible during the input operation"
]

41 changes: 32 additions & 9 deletions src/include/reb-gob.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
** are accounted for by the standard garbage collector.
**
***********************************************************************/

#ifndef REB_GOB_H
#define REB_GOB_H

#include "host-view.h"

enum GOB_FLAGS { // GOB attribute and option flags
GOBF_TOP = 0, // Top level (window or output image)
GOBF_WINDOW, // Window (parent is OS window reference)
Expand All @@ -50,6 +51,11 @@ enum GOB_FLAGS { // GOB attribute and option flags
GOBF_POPUP, // Window is a popup (with owner window)
GOBF_MODAL, // Modal event filtering
GOBF_ON_TOP, // The window is always on top
GOBF_ACTIVE, // Window is active
GOBF_MINIMIZE, // Window is minimized
GOBF_MAXIMIZE, // Window is maximized
GOBF_RESTORE, // Window is restored
GOBF_FULLSCREEN, // Window is fullscreen
};

enum GOB_STATE { // GOB state flags
Expand Down Expand Up @@ -79,7 +85,6 @@ enum GOB_DTYPES { // Userdata types
GOBD_INTEGER
};


#pragma pack(4)

typedef struct rebol_gob REBGOB;
Expand Down Expand Up @@ -110,16 +115,32 @@ struct rebol_gob { // size: 64 bytes!
};
#pragma pack()

typedef struct gob_window { // Maps gob to window
REBGOB *gob;
void* win;
void* compositor;
} REBGOBWINDOWS;

#define GOB_X(g) ((g)->offset.x)
#define GOB_Y(g) ((g)->offset.y)
#define GOB_W(g) ((g)->size.x)
#define GOB_H(g) ((g)->size.y)

#define GOB_LOG_X(g) (LOG_COORD_X((g)->offset.x))
#define GOB_LOG_Y(g) (LOG_COORD_Y((g)->offset.y))
#define GOB_LOG_W(g) (LOG_COORD_X((g)->size.x))
#define GOB_LOG_H(g) (LOG_COORD_Y((g)->size.y))

#define GOB_X_INT(g) ROUND_TO_INT((g)->offset.x)
#define GOB_Y_INT(g) ROUND_TO_INT((g)->offset.y)
#define GOB_W_INT(g) ROUND_TO_INT((g)->size.x)
#define GOB_H_INT(g) ROUND_TO_INT((g)->size.y)

#define GOB_LOG_X_INT(g) ROUND_TO_INT(LOG_COORD_X((g)->offset.x))
#define GOB_LOG_Y_INT(g) ROUND_TO_INT(LOG_COORD_Y((g)->offset.y))
#define GOB_LOG_W_INT(g) ROUND_TO_INT(LOG_COORD_X((g)->size.x))
#define GOB_LOG_H_INT(g) ROUND_TO_INT(LOG_COORD_Y((g)->size.y))

#define GOB_XO(g) ((g)->old_offset.x)
#define GOB_YO(g) ((g)->old_offset.y)
#define GOB_WO(g) ((g)->old_size.x)
Expand All @@ -131,12 +152,14 @@ struct rebol_gob { // size: 64 bytes!

#define CLEAR_GOB_STATE(g) ((g)->state = 0)

#define SET_GOB_FLAG(g,f) SET_FLAG((g)->flags, f)
#define GET_GOB_FLAG(g,f) GET_FLAG((g)->flags, f)
#define CLR_GOB_FLAG(g,f) CLR_FLAG((g)->flags, f)
#define SET_GOB_STATE(g,f) SET_FLAG((g)->state, f)
#define GET_GOB_STATE(g,f) GET_FLAG((g)->state, f)
#define CLR_GOB_STATE(g,f) CLR_FLAG((g)->state, f)
#define SET_GOB_FLAG(g,f) SET_FLAG((g)->flags, f)
#define GET_GOB_FLAG(g,f) GET_FLAG((g)->flags, f)
#define CLR_GOB_FLAG(g,f) CLR_FLAG((g)->flags, f)
#define CLR_GOB_FLAGS(g,f,h) CLR_FLAGS((g)->flags, f, h)
#define SET_GOB_STATE(g,f) SET_FLAG((g)->state, f)
#define GET_GOB_STATE(g,f) GET_FLAG((g)->state, f)
#define CLR_GOB_STATE(g,f) CLR_FLAG((g)->state, f)
#define CLR_GOB_STATES(g,f,h) CLR_FLAGS((g)->state, f, h)

#define GOB_ALPHA(g) ((g)->alpha)
#define GOB_TYPE(g) ((g)->ctype)
Expand Down Expand Up @@ -192,4 +215,4 @@ enum {

extern REBGOB *Gob_Root; // Top level GOB (the screen)

#endif
#endif
15 changes: 12 additions & 3 deletions src/mezz/view-funcs.r
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ system/standard/para: context [

view: func [
"Displays a window view."
window [gob! block! object!] "Window gob, VID face, or VID layout block"
window [gob! block! object! image!] "Window gob, VID face, or VID layout block"
/options opts [block!] "Window options spec block"
/no-wait "Return immediately. Do not wait and process events."
/as-is "Leave window as is. Do not add a parent gob."
/local screen tmp xy
/local screen tmp xy image
][
if not screen: system/view/screen-gob [return none]

Expand All @@ -54,13 +54,22 @@ view: func [
; options [append opts reduce/no-set opts]
]

if image? window [
image: window
window: make gob! [
size: image/size
image: image
]
]

; GOB based view:
if gob? window [
; Build the window:
unless opts/as-is [
tmp: window
tmp/offset: 0x0
window: make gob! [size: tmp/size]
window/offset: system/view/metrics/title-size
append window tmp
]
; Set optional background:
Expand Down Expand Up @@ -214,7 +223,7 @@ init-view-system: func [
/local ep
][
; The init function called here resides in this module
init system/view/screen-gob: make gob! [text: "Top Gob"]
init-top-window system/view/screen-gob: make gob! [text: "Top Gob"]

;update the metrics object (temp - will become mezz later)
foreach w words-of system/view/metrics [
Expand Down
2 changes: 1 addition & 1 deletion src/os/host-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ int main(int argc, char **argv) {
if (n == 2) Host_Crash("Host-lib wrong version/checksum");

#ifndef REB_CORE
//Init_Windows();
Init_Windows();
//Init_Graphics();
#endif

Expand Down
11 changes: 5 additions & 6 deletions src/os/win32/host-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ const REBCNT Key_To_Event[] = {
extern HCURSOR Cursor;
extern void Done_Device(int handle, int error);
extern void Paint_Window(HWND window);
extern void Close_Window(REBGOB *gob);
extern REBOOL Resize_Window(REBGOB *gob, REBOOL redraw);



/***********************************************************************
Expand Down Expand Up @@ -239,12 +238,12 @@ static Check_Modifiers(REBINT flags)
last_xy = xy;
if (mode) {
//Resize and redraw the window buffer (when resize dragging)
Resize_Window(gob, TRUE);
OS_Resize_Window(gob, TRUE);
mode = EVT_RESIZE;
break;
} else {
//Resize only the window buffer (when win gob size changed by REBOL code or using min/max buttons)
if (!Resize_Window(gob, FALSE)){
if (!OS_Resize_Window(gob, FALSE)){
//size has been changed programatically - return only 'resize event
Add_Event_XY(gob, EVT_RESIZE, xy, flags);
break;
Expand Down Expand Up @@ -383,8 +382,8 @@ static Check_Modifiers(REBINT flags)

case WM_CLOSE:
Add_Event_XY(gob, EVT_CLOSE, xy, flags);
Close_Window(gob); // Needs to be removed - should be done by REBOL event handling
// DestroyWindow(hwnd);// This is done in Close_Window()
OS_Close_Window(gob); // Needs to be removed - should be done by REBOL event handling
// DestroyWindow(hwnd);// This is done in OS_Close_Window()
break;

case WM_DESTROY:
Expand Down
Loading

0 comments on commit 04cb592

Please sign in to comment.