Skip to content

Commit 540a130

Browse files
committed
[[ Bug 12225 ]] Add external coordinate conversion functions
1 parent 35462ab commit 540a130

3 files changed

Lines changed: 108 additions & 0 deletions

File tree

engine/src/externalv0.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
4040
#include "scriptpt.h"
4141
#include "chunk.h"
4242

43+
#include "dispatch.h"
44+
45+
#include "graphics_util.h"
46+
4347
#include "external.h"
4448

4549
////////////////////////////////////////////////////////////////////////////////
@@ -747,6 +751,58 @@ static char *runloop_wait(const char *arg1, const char *arg2,
747751
return NULL;
748752
}
749753

754+
// IM-2014-07-09: [[ Bug 12225 ]] Add external functions to convert stack coordinates based on current transform
755+
756+
// convert stack to logical window coords
757+
static char *stack_to_window_rect(const char *arg1, const char *arg2,
758+
const char *arg3, int *retval)
759+
{
760+
uint32_t t_win_id;
761+
t_win_id = (uint32_t)arg1;
762+
763+
MCStack *t_stack;
764+
t_stack = MCdispatcher->findstackwindowid(t_win_id);
765+
766+
if (t_stack == nil)
767+
{
768+
*retval = xresFail;
769+
return nil;
770+
}
771+
772+
MCRectangle32 *t_rect;
773+
t_rect = (MCRectangle32*)arg2;
774+
775+
*t_rect = MCRectangle32GetTransformedBounds(*t_rect, t_stack->getviewtransform());
776+
777+
*retval = xresSucc;
778+
return nil;
779+
}
780+
781+
// convert logical window to stack coords
782+
static char *window_to_stack_rect(const char *arg1, const char *arg2,
783+
const char *arg3, int *retval)
784+
{
785+
uint32_t t_win_id;
786+
t_win_id = (uint32_t)arg1;
787+
788+
MCStack *t_stack;
789+
t_stack = MCdispatcher->findstackwindowid(t_win_id);
790+
791+
if (t_stack == nil)
792+
{
793+
*retval = xresFail;
794+
return nil;
795+
}
796+
797+
MCRectangle32 *t_rect;
798+
t_rect = (MCRectangle32*)arg2;
799+
800+
*t_rect = MCRectangle32GetTransformedBounds(*t_rect, MCGAffineTransformInvert(t_stack->getviewtransform()));
801+
802+
*retval = xresSucc;
803+
return nil;
804+
}
805+
750806
// IM-2014-03-06: [[ revBrowserCEF ]] Add externals extension to the callback list
751807
XCB MCcbs[] =
752808
{
@@ -780,6 +836,9 @@ XCB MCcbs[] =
780836
remove_runloop_action,
781837
runloop_wait,
782838

839+
stack_to_window_rect,
840+
window_to_stack_rect,
841+
783842
NULL
784843
};
785844

libexternal/include/revolution/external.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ typedef struct _ExternalArray
4444
char **keys;
4545
} ExternalArray;
4646

47+
typedef struct _MCRectangle32
48+
{
49+
int x;
50+
int y;
51+
unsigned int width;
52+
unsigned int height;
53+
} MCRectangle32;
54+
4755
// Function:
4856
// SendCardMessage
4957
// Parameters:
@@ -437,6 +445,11 @@ extern void RemoveRunloopAction(MCRunloopActionRef p_action, int *r_success);
437445
// IM-2014-03-06: [[ revBrowserCEF ]] Run the engine runloop
438446
extern void RunloopWait(int *r_success);
439447

448+
// IM-2014-07-09: [[ Bug 12225 ]] Convert stack coords to logical window coords
449+
extern void StackToWindowRect(unsigned int p_win_id, MCRectangle32 *x_rect, int *r_success);
450+
// IM-2014-07-09: [[ Bug 12225 ]] Convert logical window coords to stack coords
451+
extern void WindowToStackRect(unsigned int p_win_id, MCRectangle32 *x_rect, int *r_success);
452+
440453
//
441454
extern Bool SecurityCanAccessFile(const char *p_file);
442455
extern Bool SecurityCanAccessHost(const char *p_host);

libexternal/src/external.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ enum
4141
OPERATION_ADD_RUNLOOP_ACTION,
4242
OPERATION_REMOVE_RUNLOOP_ACTION,
4343
OPERATION_RUNLOOP_WAIT,
44+
45+
// IM-2014-07-09: [[ Bug 12225 ]] Add coordinate conversion functions
46+
OPERATION_STACK_TO_WINDOW_RECT,
47+
OPERATION_WINDOW_TO_STACK_RECT,
4448
};
4549

4650
enum
@@ -369,6 +373,38 @@ void RunloopWait(int *r_success)
369373
s_delete(t_result);
370374
}
371375

376+
////////////////////////////////////////////////////////////////////////////////
377+
// IM-2014-07-09: [[ Bug 12225 ]] Add coordinate conversion functions
378+
void StackToWindowRect(unsigned int p_win_id, MCRectangle32 *x_rect, int *r_success)
379+
{
380+
char *t_result;
381+
382+
if (s_external_interface_version < 1)
383+
{
384+
*r_success = EXTERNAL_FAILURE;
385+
return;
386+
}
387+
388+
t_result = (s_operations[OPERATION_STACK_TO_WINDOW_RECT])(p_win_id, x_rect, NULL, &r_success);
389+
if (t_result != NULL)
390+
s_delete(t_result);
391+
}
392+
393+
void WindowToStackRect(unsigned int p_win_id, MCRectangle32 *x_rect, int *r_success)
394+
{
395+
char *t_result;
396+
397+
if (s_external_interface_version < 1)
398+
{
399+
*r_success = EXTERNAL_FAILURE;
400+
return;
401+
}
402+
403+
t_result = (s_operations[OPERATION_WINDOW_TO_STACK_RECT])(p_win_id, x_rect, NULL, &r_success);
404+
if (t_result != NULL)
405+
s_delete(t_result);
406+
}
407+
372408
////////////////////////////////////////////////////////////////////////////////
373409

374410
#ifdef TARGET_SUBPLATFORM_IPHONE

0 commit comments

Comments
 (0)