Add wheel event.
parent
058d9f3c5b
commit
0ef318fab7
110
src/editor.c
110
src/editor.c
|
@ -27,6 +27,8 @@
|
||||||
|
|
||||||
#define ED_GL_BACKGROUND_COLOR GLW_BACKGROUND_COLOR
|
#define ED_GL_BACKGROUND_COLOR GLW_BACKGROUND_COLOR
|
||||||
|
|
||||||
|
#define ED_BONE_COLOR 0xffff00
|
||||||
|
|
||||||
typedef struct editor {
|
typedef struct editor {
|
||||||
glwWin *win;
|
glwWin *win;
|
||||||
float cameraAngleX;
|
float cameraAngleX;
|
||||||
|
@ -34,20 +36,37 @@ typedef struct editor {
|
||||||
float cameraDistance;
|
float cameraDistance;
|
||||||
int newImId;
|
int newImId;
|
||||||
int showBoneChecked;
|
int showBoneChecked;
|
||||||
|
int showBallChecked;
|
||||||
|
int showMeshChecked;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
int mode;
|
int mode;
|
||||||
int glLeft;
|
int renderLeft;
|
||||||
int glTop;
|
int renderTop;
|
||||||
int glWidth;
|
int renderWidth;
|
||||||
int glHeight;
|
int renderHeight;
|
||||||
int mouseX;
|
int moveMouseX;
|
||||||
int mouseY;
|
int moveMouseY;
|
||||||
bmesh *bm;
|
bmesh *bm;
|
||||||
} editor;
|
} editor;
|
||||||
|
|
||||||
#include "../data/bmesh_test_2.h"
|
#include "../data/bmesh_test_2.h"
|
||||||
|
|
||||||
|
static int mouseInRenderRect(glwWin *win) {
|
||||||
|
editor *ed = glwGetUserData(win);
|
||||||
|
return glwPointTest(glwMouseX(win), glwMouseY(win),
|
||||||
|
ed->renderLeft, ed->renderTop,
|
||||||
|
ed->renderWidth, ed->renderHeight, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int drawBmeshBone(bmesh *bm, bmeshBone *bone) {
|
||||||
|
glColor3f(glwR(ED_BONE_COLOR), glwG(ED_BONE_COLOR), glwB(ED_BONE_COLOR));
|
||||||
|
bmeshBall *firstBall = bmeshGetBall(bm, bone->firstBallIndex);
|
||||||
|
bmeshBall *secondBall = bmeshGetBall(bm, bone->secondBallIndex);
|
||||||
|
drawCylinder(&firstBall->position, &secondBall->position, 0.1, 36, 24);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void display(glwWin *win) {
|
static void display(glwWin *win) {
|
||||||
editor *ed = glwGetUserData(win);
|
editor *ed = glwGetUserData(win);
|
||||||
|
|
||||||
|
@ -85,15 +104,25 @@ static void display(glwWin *win) {
|
||||||
int glWinY = glwImNextY(win);
|
int glWinY = glwImNextY(win);
|
||||||
int bottomY = y + height - ED_TOOLBAR_HEIGHT;
|
int bottomY = y + height - ED_TOOLBAR_HEIGHT;
|
||||||
glwImBottomBar(win, GEN_ID, x, bottomY, width, ED_TOOLBAR_HEIGHT);
|
glwImBottomBar(win, GEN_ID, x, bottomY, width, ED_TOOLBAR_HEIGHT);
|
||||||
ed->showBoneChecked = glwImCheck(win, GEN_ID, x + ED_SPACING + ED_SPACING,
|
ed->showBallChecked = glwImCheck(win, GEN_ID, x + ED_SPACING + ED_SPACING,
|
||||||
bottomY + (ED_TOOLBAR_HEIGHT - glwImLineHeight(win)) / 2 + 2,
|
bottomY + (ED_TOOLBAR_HEIGHT - glwImLineHeight(win)) / 2 + 2,
|
||||||
"Show Bone",
|
"Ball",
|
||||||
|
ed->showBallChecked);
|
||||||
|
ed->showBoneChecked = glwImCheck(win, GEN_ID,
|
||||||
|
glwImNextX(win) + ED_SPACING,
|
||||||
|
bottomY + (ED_TOOLBAR_HEIGHT - glwImLineHeight(win)) / 2 + 2,
|
||||||
|
"Bone",
|
||||||
ed->showBoneChecked);
|
ed->showBoneChecked);
|
||||||
|
ed->showMeshChecked = glwImCheck(win, GEN_ID,
|
||||||
|
glwImNextX(win) + ED_SPACING,
|
||||||
|
bottomY + (ED_TOOLBAR_HEIGHT - glwImLineHeight(win)) / 2 + 2,
|
||||||
|
"Mesh",
|
||||||
|
ed->showMeshChecked);
|
||||||
|
|
||||||
ed->glLeft = x + 1;
|
ed->renderLeft = x + 1;
|
||||||
ed->glTop = glWinY;
|
ed->renderTop = glWinY;
|
||||||
ed->glWidth = width - 3;
|
ed->renderWidth = width - 3;
|
||||||
ed->glHeight = bottomY - glWinY;
|
ed->renderHeight = bottomY - glWinY;
|
||||||
|
|
||||||
if (0 == ed->bm) {
|
if (0 == ed->bm) {
|
||||||
bmeshBall ball;
|
bmeshBall ball;
|
||||||
|
@ -122,19 +151,19 @@ static void display(glwWin *win) {
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnable(GL_SCISSOR_TEST);
|
glEnable(GL_SCISSOR_TEST);
|
||||||
glScissor(ed->glLeft, ED_SPACING / 2 + ED_TOOLBAR_HEIGHT + 1,
|
glScissor(ed->renderLeft, ED_SPACING / 2 + ED_TOOLBAR_HEIGHT + 1,
|
||||||
ed->glWidth, ed->glHeight);
|
ed->renderWidth, ed->renderHeight);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(x + 1, glWinY, 0);
|
glTranslatef(x + 1, glWinY, 0);
|
||||||
|
|
||||||
glColor3f(glwR(ED_GL_BACKGROUND_COLOR),
|
glColor3f(glwR(ED_GL_BACKGROUND_COLOR),
|
||||||
glwG(ED_GL_BACKGROUND_COLOR),
|
glwG(ED_GL_BACKGROUND_COLOR),
|
||||||
glwB(ED_GL_BACKGROUND_COLOR));
|
glwB(ED_GL_BACKGROUND_COLOR));
|
||||||
glRecti(0, 0, ed->glWidth, ed->glHeight);
|
glRecti(0, 0, ed->renderWidth, ed->renderHeight);
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluPerspective(60.0f, (float)ed->glWidth / ed->glHeight, 1, 1000);
|
gluPerspective(60.0f, (float)ed->renderWidth / ed->renderHeight, 1, 1000);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
@ -146,7 +175,23 @@ static void display(glwWin *win) {
|
||||||
|
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
bmeshDraw(ed->bm);
|
|
||||||
|
if (ed->showBallChecked) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ed->showBoneChecked) {
|
||||||
|
int index;
|
||||||
|
for (index = 0; index < bmeshGetBoneNum(ed->bm); ++index) {
|
||||||
|
bmeshBone *bone = bmeshGetBone(ed->bm, index);
|
||||||
|
drawBmeshBone(ed->bm, bone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ed->showMeshChecked) {
|
||||||
|
bmeshDraw(ed->bm);
|
||||||
|
}
|
||||||
|
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
|
@ -189,41 +234,52 @@ static void reshape(glwWin *win, int width, int height) {
|
||||||
static void mouse(glwWin *win, int button, int state,
|
static void mouse(glwWin *win, int button, int state,
|
||||||
int x, int y){
|
int x, int y){
|
||||||
editor *ed = glwGetUserData(win);
|
editor *ed = glwGetUserData(win);
|
||||||
if (!glwPointTest(x, y, ed->glLeft, ed->glTop,
|
if (!mouseInRenderRect(win)) {
|
||||||
ed->glWidth, ed->glHeight, 0)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (GLW_DOWN == state) {
|
if (GLW_DOWN == state) {
|
||||||
ed->mouseX = x;
|
ed->moveMouseX = x;
|
||||||
ed->mouseY = y;
|
ed->moveMouseY = y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void motion(glwWin *win, int x, int y) {
|
static void motion(glwWin *win, int x, int y) {
|
||||||
editor *ed = glwGetUserData(win);
|
editor *ed = glwGetUserData(win);
|
||||||
if (!glwPointTest(x, y, ed->glLeft, ed->glTop,
|
if (!mouseInRenderRect(win)) {
|
||||||
ed->glWidth, ed->glHeight, 0)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ed->cameraAngleY += (x - ed->mouseX);
|
ed->cameraAngleY += (x - ed->moveMouseX);
|
||||||
ed->cameraAngleX += (y - ed->mouseY);
|
ed->cameraAngleX += (y - ed->moveMouseY);
|
||||||
ed->mouseX = x;
|
ed->moveMouseX = x;
|
||||||
ed->mouseY = y;
|
ed->moveMouseY = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wheel(glwWin *win, float delta) {
|
||||||
|
editor *ed = glwGetUserData(win);
|
||||||
|
if (!mouseInRenderRect(win)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ed->cameraDistance -= delta * 0.01f;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
editor ed;
|
editor ed;
|
||||||
glwInit();
|
glwInit();
|
||||||
|
drawInit();
|
||||||
|
|
||||||
memset(&ed, 0, sizeof(ed));
|
memset(&ed, 0, sizeof(ed));
|
||||||
ed.cameraAngleX = 30;
|
ed.cameraAngleX = 30;
|
||||||
ed.cameraAngleY = -312;
|
ed.cameraAngleY = -312;
|
||||||
ed.cameraDistance = 14.4;
|
ed.cameraDistance = 14.4;
|
||||||
|
ed.showMeshChecked = 1;
|
||||||
|
|
||||||
ed.win = glwCreateWindow(0, 0, 0, 0);
|
ed.win = glwCreateWindow(0, 0, 0, 0);
|
||||||
glwSetUserData(ed.win, &ed);
|
glwSetUserData(ed.win, &ed);
|
||||||
glwReshapeFunc(ed.win, reshape);
|
glwReshapeFunc(ed.win, reshape);
|
||||||
glwDisplayFunc(ed.win, display);
|
glwDisplayFunc(ed.win, display);
|
||||||
glwMouseFunc(ed.win, mouse);
|
glwMouseFunc(ed.win, mouse);
|
||||||
glwMotionFunc(ed.win, motion);
|
glwMotionFunc(ed.win, motion);
|
||||||
|
glwWheelFunc(ed.win, wheel);
|
||||||
glwMainLoop();
|
glwMainLoop();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
54
src/glw.c
54
src/glw.c
|
@ -688,3 +688,57 @@ int glwImLineHeight(glwWin *win) {
|
||||||
glwSystemFontTexture *systemFontTexture = glwGetSystemFontTexture(win);
|
glwSystemFontTexture *systemFontTexture = glwGetSystemFontTexture(win);
|
||||||
return systemFontTexture->originSize.height * (1 + GLW_VER_AUTO_MARGIN * 2);
|
return systemFontTexture->originSize.height * (1 + GLW_VER_AUTO_MARGIN * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void glwSetUserData(glwWin *win, void *userData) {
|
||||||
|
glwWinContext *ctx = glwGetWinContext(win);
|
||||||
|
ctx->userData = userData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *glwGetUserData(glwWin *win) {
|
||||||
|
glwWinContext *ctx = glwGetWinContext(win);
|
||||||
|
return ctx->userData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void glwDisplayFunc(glwWin *win, void (*func)(glwWin *win)) {
|
||||||
|
glwWinContext *ctx = glwGetWinContext(win);
|
||||||
|
ctx->onDisplay = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
void glwReshapeFunc(glwWin *win, void (*func)(glwWin *win, int width,
|
||||||
|
int height)) {
|
||||||
|
glwWinContext *ctx = glwGetWinContext(win);
|
||||||
|
ctx->onReshape = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
void glwMouseFunc(glwWin *win, void (*func)(glwWin *win, int button, int state,
|
||||||
|
int x, int y)) {
|
||||||
|
glwWinContext *ctx = glwGetWinContext(win);
|
||||||
|
ctx->onMouse = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
void glwMotionFunc(glwWin *win,
|
||||||
|
void (*func)(glwWin *win, int x, int y)) {
|
||||||
|
glwWinContext *ctx = glwGetWinContext(win);
|
||||||
|
ctx->onMotion = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
void glwPassiveMotionFunc(glwWin *win,
|
||||||
|
void (*func)(glwWin *win, int x, int y)) {
|
||||||
|
glwWinContext *ctx = glwGetWinContext(win);
|
||||||
|
ctx->onPassiveMotion = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
void glwWheelFunc(glwWin *win, void(*func)(glwWin *win, float delta)) {
|
||||||
|
glwWinContext *ctx = glwGetWinContext(win);
|
||||||
|
ctx->onWheel = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
int glwMouseX(glwWin *win) {
|
||||||
|
glwWinContext *ctx = glwGetWinContext(win);
|
||||||
|
return ctx->x;
|
||||||
|
}
|
||||||
|
|
||||||
|
int glwMouseY(glwWin *win) {
|
||||||
|
glwWinContext *ctx = glwGetWinContext(win);
|
||||||
|
return ctx->y;
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ void glwMouseFunc(glwWin *win, void (*func)(glwWin *win, int button, int state,
|
||||||
int x, int y));
|
int x, int y));
|
||||||
void glwMotionFunc(glwWin *win, void (*func)(glwWin *win, int x, int y));
|
void glwMotionFunc(glwWin *win, void (*func)(glwWin *win, int x, int y));
|
||||||
void glwPassiveMotionFunc(glwWin *win, void (*func)(glwWin *win, int x, int y));
|
void glwPassiveMotionFunc(glwWin *win, void (*func)(glwWin *win, int x, int y));
|
||||||
|
void glwWheelFunc(glwWin *win, void(*func)(glwWin *win, float delta));
|
||||||
#define glwR(rgb) ((float)(((rgb) >> 16) & 0xff) / 255)
|
#define glwR(rgb) ((float)(((rgb) >> 16) & 0xff) / 255)
|
||||||
#define glwG(rgb) ((float)(((rgb) >> 8) & 0xff) / 255)
|
#define glwG(rgb) ((float)(((rgb) >> 8) & 0xff) / 255)
|
||||||
#define glwB(rgb) ((float)(((rgb)) & 0xff) / 255)
|
#define glwB(rgb) ((float)(((rgb)) & 0xff) / 255)
|
||||||
|
@ -62,6 +63,8 @@ int glwImNextY(glwWin *win);
|
||||||
int glwImLineHeight(glwWin *win);
|
int glwImLineHeight(glwWin *win);
|
||||||
int glwPointTest(int x, int y, int left, int top, int width, int height,
|
int glwPointTest(int x, int y, int left, int top, int width, int height,
|
||||||
int allowOffset);
|
int allowOffset);
|
||||||
|
int glwMouseX(glwWin *win);
|
||||||
|
int glwMouseY(glwWin *win);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,22 @@ typedef enum glwCtrlState {
|
||||||
GLW_CTRL_STATE_PRESS,
|
GLW_CTRL_STATE_PRESS,
|
||||||
} glwCtrlState;
|
} glwCtrlState;
|
||||||
|
|
||||||
|
typedef struct glwWinContext {
|
||||||
|
void (*onReshape)(glwWin *win, int width, int height);
|
||||||
|
void (*onDisplay)(glwWin *win);
|
||||||
|
void (*onMouse)(glwWin *win, int button, int state, int x, int y);
|
||||||
|
void (*onMotion)(glwWin *win, int x, int y);
|
||||||
|
void (*onPassiveMotion)(glwWin *win, int x, int y);
|
||||||
|
void(*onWheel)(glwWin *win, float delta);
|
||||||
|
int viewWidth;
|
||||||
|
int viewHeight;
|
||||||
|
float scaleX;
|
||||||
|
float scaleY;
|
||||||
|
void *userData;
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
} glwWinContext;
|
||||||
|
|
||||||
typedef struct glwSystemFontTexture {
|
typedef struct glwSystemFontTexture {
|
||||||
int texId;
|
int texId;
|
||||||
glwSize size;
|
glwSize size;
|
||||||
|
@ -50,5 +66,6 @@ void glwDrawButtonBackground(float x, float y, float width, float height,
|
||||||
glwCtrlState state);
|
glwCtrlState state);
|
||||||
void glwMouseEvent(glwWin *win, int button, int state, int x, int y);
|
void glwMouseEvent(glwWin *win, int button, int state, int x, int y);
|
||||||
glwImGui *glwGetImGUI(glwWin *win);
|
glwImGui *glwGetImGUI(glwWin *win);
|
||||||
|
glwWinContext *glwGetWinContext(glwWin *win);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
168
src/glw_osx.m
168
src/glw_osx.m
|
@ -6,17 +6,8 @@
|
||||||
@interface GLView : NSOpenGLView <NSWindowDelegate> {
|
@interface GLView : NSOpenGLView <NSWindowDelegate> {
|
||||||
CVDisplayLinkRef displayLink;
|
CVDisplayLinkRef displayLink;
|
||||||
@public
|
@public
|
||||||
void (*onReshape)(glwWin *win, int width, int height);
|
|
||||||
void (*onDisplay)(glwWin *win);
|
|
||||||
void (*onMouse)(glwWin *win, int button, int state, int x, int y);
|
|
||||||
void (*onMotion)(glwWin *win, int x, int y);
|
|
||||||
void (*onPassiveMotion)(glwWin *win, int x, int y);
|
|
||||||
void *userData;
|
|
||||||
int pendingReshape;
|
int pendingReshape;
|
||||||
int viewWidth;
|
glwWinContext context;
|
||||||
int viewHeight;
|
|
||||||
float scaleX;
|
|
||||||
float scaleY;
|
|
||||||
glwSystemFontTexture systemFontTexture;
|
glwSystemFontTexture systemFontTexture;
|
||||||
glwImGui imGUI;
|
glwImGui imGUI;
|
||||||
}
|
}
|
||||||
|
@ -38,6 +29,11 @@ glwSystemFontTexture *glwGetSystemFontTexture(glwWin *win) {
|
||||||
return &view->systemFontTexture;
|
return &view->systemFontTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glwWinContext *glwGetWinContext(glwWin *win) {
|
||||||
|
GLView *view = ((NSWindow *)win).contentView;
|
||||||
|
return &view->context;
|
||||||
|
}
|
||||||
|
|
||||||
@implementation GLView
|
@implementation GLView
|
||||||
- (id)initWithFrame:(NSRect)frameRect {
|
- (id)initWithFrame:(NSRect)frameRect {
|
||||||
NSOpenGLPixelFormatAttribute attribs[] = {NSOpenGLPFAMultisample,
|
NSOpenGLPixelFormatAttribute attribs[] = {NSOpenGLPFAMultisample,
|
||||||
|
@ -82,17 +78,17 @@ glwSystemFontTexture *glwGetSystemFontTexture(glwWin *win) {
|
||||||
[currentContext makeCurrentContext];
|
[currentContext makeCurrentContext];
|
||||||
CGLLockContext([currentContext CGLContextObj]);
|
CGLLockContext([currentContext CGLContextObj]);
|
||||||
if (self->pendingReshape) {
|
if (self->pendingReshape) {
|
||||||
if (self->onReshape) {
|
if (self->context.onReshape) {
|
||||||
self->pendingReshape = 0;
|
self->pendingReshape = 0;
|
||||||
if (!self->systemFontTexture.texId) {
|
if (!self->systemFontTexture.texId) {
|
||||||
glwInitSystemFontTexture((glwWin *)self.window);
|
glwInitSystemFontTexture((glwWin *)self.window);
|
||||||
}
|
}
|
||||||
self->onReshape((glwWin *)self.window, self->viewWidth,
|
self->context.onReshape((glwWin *)self.window, self->context.viewWidth,
|
||||||
self->viewHeight);
|
self->context.viewHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (self->onDisplay) {
|
if (self->context.onDisplay) {
|
||||||
self->onDisplay((glwWin *)self.window);
|
self->context.onDisplay((glwWin *)self.window);
|
||||||
}
|
}
|
||||||
CGLFlushDrawable([[self openGLContext] CGLContextObj]);
|
CGLFlushDrawable([[self openGLContext] CGLContextObj]);
|
||||||
CGLUnlockContext([currentContext CGLContextObj]);
|
CGLUnlockContext([currentContext CGLContextObj]);
|
||||||
|
@ -116,10 +112,10 @@ glwSystemFontTexture *glwGetSystemFontTexture(glwWin *win) {
|
||||||
- (void)reshape {
|
- (void)reshape {
|
||||||
NSRect bounds = [self bounds];
|
NSRect bounds = [self bounds];
|
||||||
NSRect backingBounds = [self convertRectToBacking:[self bounds]];
|
NSRect backingBounds = [self convertRectToBacking:[self bounds]];
|
||||||
viewWidth = (int)backingBounds.size.width;
|
self->context.viewWidth = (int)backingBounds.size.width;
|
||||||
viewHeight = (int)backingBounds.size.height;
|
self->context.viewHeight = (int)backingBounds.size.height;
|
||||||
self->scaleX = (float)viewWidth / bounds.size.width;
|
self->context.scaleX = (float)self->context.viewWidth / bounds.size.width;
|
||||||
self->scaleY = (float)viewHeight / bounds.size.height;
|
self->context.scaleY = (float)self->context.viewHeight / bounds.size.height;
|
||||||
self->pendingReshape = 1;
|
self->pendingReshape = 1;
|
||||||
[self drawFrame];
|
[self drawFrame];
|
||||||
}
|
}
|
||||||
|
@ -140,49 +136,66 @@ glwSystemFontTexture *glwGetSystemFontTexture(glwWin *win) {
|
||||||
CGLUnlockContext([currentContext CGLContextObj]);
|
CGLUnlockContext([currentContext CGLContextObj]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseMoved:(NSEvent*)event {
|
- (void)saveMousePosFromEvent:(NSEvent*)event {
|
||||||
NSPoint loc = [self convertPoint:[event locationInWindow] fromView:nil];
|
NSPoint loc = [self convertPoint:[event locationInWindow] fromView:nil];
|
||||||
int x = loc.x * self->scaleX;
|
self->context.x = loc.x * self->context.scaleX;
|
||||||
int y = loc.y * self->scaleY;
|
self->context.y = loc.y * self->context.scaleY;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)mouseMoved:(NSEvent*)event {
|
||||||
|
[self saveMousePosFromEvent:event];
|
||||||
if (GLW_DOWN == self->imGUI.mouseState) {
|
if (GLW_DOWN == self->imGUI.mouseState) {
|
||||||
if (self->onMotion) {
|
if (self->context.onMotion) {
|
||||||
self->onMotion((glwWin *)self.window, x, y);
|
self->context.onMotion((glwWin *)self.window,
|
||||||
|
self->context.x, self->context.y);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (self->onPassiveMotion) {
|
if (self->context.onPassiveMotion) {
|
||||||
self->onPassiveMotion((glwWin *)self.window, x, y);
|
self->context.onPassiveMotion((glwWin *)self.window,
|
||||||
|
self->context.x, self->context.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseDown:(NSEvent*)event {
|
- (void)mouseDown:(NSEvent*)event {
|
||||||
NSPoint loc = [self convertPoint:[event locationInWindow] fromView:nil];
|
[self saveMousePosFromEvent:event];
|
||||||
int x = loc.x * self->scaleX;
|
glwMouseEvent((glwWin *)self.window, GLW_LEFT_BUTTON, GLW_DOWN,
|
||||||
int y = loc.y * self->scaleY;
|
self->context.x, self->context.y);
|
||||||
glwMouseEvent((glwWin *)self.window, GLW_LEFT_BUTTON, GLW_DOWN, x, y);
|
if (self->context.onMouse) {
|
||||||
if (self->onMouse) {
|
self->context.onMouse((glwWin *)self.window,
|
||||||
self->onMouse((glwWin *)self.window, GLW_LEFT_BUTTON, GLW_DOWN, x, y);
|
GLW_LEFT_BUTTON, GLW_DOWN,
|
||||||
|
self->context.x, self->context.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)scrollWheel:(NSEvent *)event {
|
||||||
|
[self saveMousePosFromEvent:event];
|
||||||
|
if (self->context.onWheel) {
|
||||||
|
self->context.onWheel((glwWin *)self.window, [event deltaY] * 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseDragged:(NSEvent *)event {
|
- (void)mouseDragged:(NSEvent *)event {
|
||||||
NSPoint loc = [self convertPoint:[event locationInWindow] fromView:nil];
|
[self saveMousePosFromEvent:event];
|
||||||
int x = loc.x * self->scaleX;
|
|
||||||
int y = loc.y * self->scaleY;
|
|
||||||
if (GLW_DOWN == self->imGUI.mouseState) {
|
if (GLW_DOWN == self->imGUI.mouseState) {
|
||||||
if (GLW_DOWN == self->imGUI.mouseState) {
|
if (GLW_DOWN == self->imGUI.mouseState) {
|
||||||
if (self->onMotion) {
|
if (self->context.onMotion) {
|
||||||
self->onMotion((glwWin *)self.window, x, y);
|
self->context.onMotion((glwWin *)self.window,
|
||||||
|
self->context.x, self->context.y);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (self->onPassiveMotion) {
|
if (self->context.onPassiveMotion) {
|
||||||
self->onPassiveMotion((glwWin *)self.window, x, y);
|
self->context.onPassiveMotion((glwWin *)self.window,
|
||||||
|
self->context.x, self->context.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
glwMouseEvent((glwWin *)self.window, GLW_LEFT_BUTTON, GLW_DOWN, x, y);
|
glwMouseEvent((glwWin *)self.window, GLW_LEFT_BUTTON, GLW_DOWN,
|
||||||
if (self->onMouse) {
|
self->context.x, self->context.y);
|
||||||
self->onMouse((glwWin *)self.window, GLW_LEFT_BUTTON, GLW_DOWN, x, y);
|
if (self->context.onMouse) {
|
||||||
|
self->context.onMouse((glwWin *)self.window,
|
||||||
|
GLW_LEFT_BUTTON, GLW_DOWN,
|
||||||
|
self->context.x, self->context.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,12 +205,12 @@ glwSystemFontTexture *glwGetSystemFontTexture(glwWin *win) {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseUp:(NSEvent*)event {
|
- (void)mouseUp:(NSEvent*)event {
|
||||||
NSPoint loc = [self convertPoint:[event locationInWindow] fromView:nil];
|
[self saveMousePosFromEvent:event];
|
||||||
int x = loc.x * self->scaleX;
|
glwMouseEvent((glwWin *)self.window, GLW_LEFT_BUTTON, GLW_UP,
|
||||||
int y = loc.y * self->scaleY;
|
self->context.x, self->context.y);
|
||||||
glwMouseEvent((glwWin *)self.window, GLW_LEFT_BUTTON, GLW_UP, x, y);
|
if (self->context.onMouse) {
|
||||||
if (self->onMouse) {
|
self->context.onMouse((glwWin *)self.window, GLW_LEFT_BUTTON, GLW_UP,
|
||||||
self->onMouse((glwWin *)self.window, GLW_LEFT_BUTTON, GLW_UP, x, y);
|
self->context.x, self->context.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
@ -235,16 +248,6 @@ void glwMainLoop(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void glwSetUserData(glwWin *win, void *userData) {
|
|
||||||
GLView *view = ((NSWindow *)win).contentView;
|
|
||||||
view->userData = userData;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *glwGetUserData(glwWin *win) {
|
|
||||||
GLView *view = ((NSWindow *)win).contentView;
|
|
||||||
return view->userData;
|
|
||||||
}
|
|
||||||
|
|
||||||
glwWin *glwCreateWindow(int x, int y, int width, int height) {
|
glwWin *glwCreateWindow(int x, int y, int width, int height) {
|
||||||
NSUInteger windowStyle = NSTitledWindowMask | NSClosableWindowMask |
|
NSUInteger windowStyle = NSTitledWindowMask | NSClosableWindowMask |
|
||||||
NSResizableWindowMask | NSMiniaturizableWindowMask;
|
NSResizableWindowMask | NSMiniaturizableWindowMask;
|
||||||
|
@ -264,19 +267,15 @@ glwWin *glwCreateWindow(int x, int y, int width, int height) {
|
||||||
defer:NO];
|
defer:NO];
|
||||||
|
|
||||||
GLView *view = [[GLView alloc] initWithFrame:viewRect];
|
GLView *view = [[GLView alloc] initWithFrame:viewRect];
|
||||||
view->onReshape = 0;
|
memset(&view->context, 0, sizeof(view->context));
|
||||||
view->onDisplay = 0;
|
memset(&view->systemFontTexture, 0, sizeof(view->systemFontTexture));
|
||||||
view->onMouse = 0;
|
|
||||||
view->userData = 0;
|
|
||||||
view->pendingReshape = 0;
|
|
||||||
view->viewWidth = width;
|
|
||||||
view->viewHeight = height;
|
|
||||||
view->systemFontTexture.texId = 0;
|
|
||||||
memset(&view->imGUI, 0, sizeof(view->imGUI));
|
memset(&view->imGUI, 0, sizeof(view->imGUI));
|
||||||
view->scaleX = 1;
|
view->pendingReshape = 0;
|
||||||
view->scaleY = 1;
|
view->context.viewWidth = width;
|
||||||
view->onPassiveMotion = 0;
|
view->context.viewHeight = height;
|
||||||
view->onMotion = 0;
|
view->systemFontTexture.texId = 0;
|
||||||
|
view->context.scaleX = 1;
|
||||||
|
view->context.scaleY = 1;
|
||||||
|
|
||||||
[window setAcceptsMouseMovedEvents:YES];
|
[window setAcceptsMouseMovedEvents:YES];
|
||||||
[window setContentView:view];
|
[window setContentView:view];
|
||||||
|
@ -287,35 +286,6 @@ glwWin *glwCreateWindow(int x, int y, int width, int height) {
|
||||||
return (glwWin *)window;
|
return (glwWin *)window;
|
||||||
}
|
}
|
||||||
|
|
||||||
void glwDisplayFunc(glwWin *win, void (*func)(glwWin *win)) {
|
|
||||||
GLView *view = ((NSWindow *)win).contentView;
|
|
||||||
view->onDisplay = func;
|
|
||||||
}
|
|
||||||
|
|
||||||
void glwReshapeFunc(glwWin *win, void (*func)(glwWin *win, int width,
|
|
||||||
int height)) {
|
|
||||||
GLView *view = ((NSWindow *)win).contentView;
|
|
||||||
view->onReshape = func;
|
|
||||||
}
|
|
||||||
|
|
||||||
void glwMouseFunc(glwWin *win, void (*func)(glwWin *win, int button, int state,
|
|
||||||
int x, int y)) {
|
|
||||||
GLView *view = ((NSWindow *)win).contentView;
|
|
||||||
view->onMouse = func;
|
|
||||||
}
|
|
||||||
|
|
||||||
void glwMotionFunc(glwWin *win,
|
|
||||||
void (*func)(glwWin *win, int x, int y)) {
|
|
||||||
GLView *view = ((NSWindow *)win).contentView;
|
|
||||||
view->onMotion = func;
|
|
||||||
}
|
|
||||||
|
|
||||||
void glwPassiveMotionFunc(glwWin *win,
|
|
||||||
void (*func)(glwWin *win, int x, int y)) {
|
|
||||||
GLView *view = ((NSWindow *)win).contentView;
|
|
||||||
view->onPassiveMotion = func;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char *glwRenderTextToRGBA(char *text, glwFont *font, glwSize size,
|
unsigned char *glwRenderTextToRGBA(char *text, glwFont *font, glwSize size,
|
||||||
int *pixelsWide, int *pixelsHigh) {
|
int *pixelsWide, int *pixelsHigh) {
|
||||||
NSString *aString = [NSString stringWithCString:text encoding:NSMacOSRomanStringEncoding];
|
NSString *aString = [NSString stringWithCString:text encoding:NSMacOSRomanStringEncoding];
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#define GLW_SYSTEM_FONT_NAME "Helvetica"
|
#define GLW_SYSTEM_FONT_NAME "Helvetica"
|
||||||
#define GLW_SYSTEM_FONT_WEIGHT 5
|
#define GLW_SYSTEM_FONT_WEIGHT 5
|
||||||
#define GLW_SYSTEM_FONT_SIZE 20
|
#define GLW_SYSTEM_FONT_SIZE 21
|
||||||
|
|
||||||
#define GLW_SMALL_ROUNDED_CORNER_SLICES 5
|
#define GLW_SMALL_ROUNDED_CORNER_SLICES 5
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue