diff --git a/examples/gldemos/cube.c b/examples/gldemos/cube.c index 2d1954c..de0b840 100644 --- a/examples/gldemos/cube.c +++ b/examples/gldemos/cube.c @@ -12,78 +12,82 @@ static double deg = 0; static void draw(void) { - int i; - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + int i; + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glPushMatrix(); - glRotatef(deg, 1, 0, 0); - glRotatef(deg, 0, 1, 0); - glRotatef(deg, 0, 0, 1); + glPushMatrix(); + glRotatef(deg, 1, 0, 0); + glRotatef(deg, 0, 1, 0); + glRotatef(deg, 0, 0, 1); - for (i = 0; i < 6; i++) { - if (i == 0) - glColor3f(1, 0, 0); - if (i == 1) - glColor3f(0, 1, 0); - if (i == 2) - glColor3f(1, 1, 0); - if (i == 3) - glColor3f(0, 0, 1); - if (i == 4) - glColor3f(1, 0, 1); - if (i == 5) - glColor3f(0, 1, 1); + for(i = 0; i < 6; i++) { + if(i == 0) + glColor3f(1, 0, 0); + if(i == 1) + glColor3f(0, 1, 0); + if(i == 2) + glColor3f(1, 1, 0); + if(i == 3) + glColor3f(0, 0, 1); + if(i == 4) + glColor3f(1, 0, 1); + if(i == 5) + glColor3f(0, 1, 1); - glBegin(GL_QUADS); - glNormal3f(0, 1, 0); - glVertex3f(-1, 1, -1); - glVertex3f(-1, 1, 1); - glVertex3f(1, 1, 1); - glVertex3f(1, 1, -1); - glEnd(); + glBegin(GL_QUADS); + glNormal3f(0, 1, 0); + glVertex3f(-1, 1, -1); + glVertex3f(-1, 1, 1); + glVertex3f(1, 1, 1); + glVertex3f(1, 1, -1); + glEnd(); - if (i < 3) - glRotatef(90, 0, 0, 1); - if (i == 3) - glRotatef(90, 1, 0, 0); - if (i == 4) - glRotatef(180, 0, 0, 1); - } - glPopMatrix(); + if(i < 3) + glRotatef(90, 0, 0, 1); + if(i == 3) + glRotatef(90, 1, 0, 0); + if(i == 4) + glRotatef(180, 0, 0, 1); + } + glPopMatrix(); } -static void idle(void) { deg += 1.0; } +static void idle(void) { + deg += 1.0; +} static void reshape(int width, int height) { - GLfloat lpos[4]; + GLfloat lpos[4]; - lpos[0] = 1; - lpos[1] = 1; - lpos[2] = 1; - lpos[3] = 0; + lpos[0] = 1; + lpos[1] = 1; + lpos[2] = 1; + lpos[3] = 0; - glViewport(0, 0, width, height); + glViewport(0, 0, width, height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(60, (double)width / height, 1, 100); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60, (double)width / height, 1, 100); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - gluLookAt(2, 2, 2, 0, 0, 0, 0, 1, 0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + gluLookAt(2, 2, 2, 0, 0, 0, 0, 1, 0); - glLightfv(GL_LIGHT0, GL_POSITION, lpos); + glLightfv(GL_LIGHT0, GL_POSITION, lpos); } static void init(void) { - glEnable(GL_DEPTH_TEST); - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glEnable(GL_COLOR_MATERIAL); - glEnable(GL_CULL_FACE); - glEnable(GL_NORMALIZE); + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_COLOR_MATERIAL); + glEnable(GL_CULL_FACE); + glEnable(GL_NORMALIZE); - glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); + glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); } -static void key(int k) { (void)k; } +static void key(int k) { + (void)k; +} diff --git a/include/Mw/LowLevel/Cocoa.h b/include/Mw/LowLevel/Cocoa.h index 19e0bc3..7d1b217 100644 --- a/include/Mw/LowLevel/Cocoa.h +++ b/include/Mw/LowLevel/Cocoa.h @@ -23,9 +23,9 @@ // Note: implements NSApplicationDelegate @interface MilskoCocoaApplicationDelegate : NSObject { - NSApplication *appl; + NSApplication* appl; } -- (MilskoCocoaApplicationDelegate *)initWithAppl:(NSApplication *)appl; +- (MilskoCocoaApplicationDelegate*)initWithAppl:(NSApplication*)appl; @end @interface MilskoCocoaWindow : NSWindow { @@ -34,9 +34,9 @@ // Note: implements NSWindowDelegate @interface MilskoCocoaWindowDelegate : NSObject { - MilskoCocoaWindow *w; + MilskoCocoaWindow* w; } -- (MilskoCocoaWindowDelegate *)initWithWin:(MilskoCocoaWindow *)win; +- (MilskoCocoaWindowDelegate*)initWithWin:(MilskoCocoaWindow*)win; @end /* @@ -52,139 +52,138 @@ retrieved appropriately. */ @interface MilskoFakePointer : NSView { - void *ptr; + void* ptr; } -- (void)setPointer:(void *)ptr; -- (void *)pointer; +- (void)setPointer:(void*)ptr; +- (void*)pointer; @end @interface MilskoCocoaPixmap : NSObject { - MwBool valid; - int width; - int height; - unsigned char *buf; - NSImage *image; - NSBitmapImageRep *rep; + MwBool valid; + int width; + int height; + unsigned char* buf; + NSImage* image; + NSBitmapImageRep* rep; } -+ (MilskoCocoaPixmap *)newWithWidth:(int)width height:(int)height; -- (void)updateWithData:(unsigned char *)data; ++ (MilskoCocoaPixmap*)newWithWidth:(int)width height:(int)height; +- (void)updateWithData:(unsigned char*)data; - (void)destroy; /* using @property to create instance variables fucks up 10.4 gcc for some * reason? */ -- (NSImage *)image; +- (NSImage*)image; @end @interface MilskoCocoaView : NSView { - NSBitmapImageRep *rep; - NSGraphicsContext *context; - MwBool valid; - CGColorSpaceRef space; - CGDataProviderRef provider; - float width; - float height; + NSBitmapImageRep* rep; + NSGraphicsContext* context; + MwBool valid; + CGColorSpaceRef space; + CGDataProviderRef provider; + float width; + float height; } - (void)initRepAndContextWithWidth:(float)w Height:(float)h; -- (NSGraphicsContext *)context; +- (NSGraphicsContext*)context; - (void)destroy; -- (NSBitmapImageRep *)getRep; +- (NSBitmapImageRep*)getRep; @end @interface MilskoCocoa : NSObject { - NSApplication *application; - MwBool _forceRender; - MilskoCocoaWindow *window; - NSRect rect; - MilskoCocoaView *view; - MwLL parent; - MilskoFakePointer *handle; - unsigned int strHash; - NSEvent *lastEvent; + NSApplication* application; + MwBool _forceRender; + MilskoCocoaWindow* window; + NSRect rect; + MilskoCocoaView* view; + MwLL parent; + MilskoFakePointer* handle; + unsigned int strHash; + NSEvent* lastEvent; - MilskoCocoaPixmap *cursorPixmap; - NSCursor *cursor; - NSModalSession modalSession; - - MwBool pointerLocked; - MwBool mouseMoved; + MilskoCocoaPixmap* cursorPixmap; + NSCursor* cursor; + NSModalSession modalSession; + MwBool pointerLocked; + MwBool mouseMoved; } -+ (MilskoCocoa *)newWithParent:(MwLL)parent - x:(int)x - y:(int)y - width:(int)width - height:(int)height - handle:(MwLL)handle; -- (void)polygonWithPoints:(MwPoint *)points - points_count:(int)points_count - color:(MwLLColor)color; -- (void)lineWithPoints:(MwPoint *)points color:(MwLLColor)color; -- (void)getX:(int *)x Y:(int *)y W:(unsigned int *)w H:(unsigned int *)h; ++ (MilskoCocoa*)newWithParent:(MwLL)parent + x:(int)x + y:(int)y + width:(int)width + height:(int)height + handle:(MwLL)handle; +- (void)polygonWithPoints:(MwPoint*)points + points_count:(int)points_count + color:(MwLLColor)color; +- (void)lineWithPoints:(MwPoint*)points color:(MwLLColor)color; +- (void)getX:(int*)x Y:(int*)y W:(unsigned int*)w H:(unsigned int*)h; - (void)setX:(int)x Y:(int)y; - (void)setW:(int)w H:(int)h; - (int)pending; -- (void)eventProcess:(NSEvent *)ev; -- (void)handleKeyEvent:(NSEvent *)ev ll:(MwLL)ll; -- (void)handleMouseEvent:(NSEvent *)ev ll:(MwLL)ll; +- (void)eventProcess:(NSEvent*)ev; +- (void)handleKeyEvent:(NSEvent*)ev ll:(MwLL)ll; +- (void)handleMouseEvent:(NSEvent*)ev ll:(MwLL)ll; - (void)getNextEvent; -- (void)setTitle:(const char *)title; -- (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect *)rect; +- (void)setTitle:(const char*)title; +- (void)drawPixmap:(MwLLPixmap)pixmap rect:(MwRect*)rect; - (void)setIcon:(MwLLPixmap)pixmap; - (void)forceRender; -- (void)setCursor:(MwCursor *)image mask:(MwCursor *)mask; -- (void)detachWithPoint:(MwPoint *)point; +- (void)setCursor:(MwCursor*)image mask:(MwCursor*)mask; +- (void)detachWithPoint:(MwPoint*)point; - (void)show:(int)show; - (void)makePopupWithParent:(MwLL)parent; - (void)setSizeHintsWithMinX:(int)minx - MinY:(int)miny - MaxX:(int)maxx - MaxY:(int)maxy; + MinY:(int)miny + MaxX:(int)maxx + MaxY:(int)maxy; - (void)makeBorderless:(int)toggle; - (void)focus; - (void)grabPointer:(int)toggle; -- (void)setClipboard:(const char *)text; +- (void)setClipboard:(const char*)text; - (void)makeToolWindow; -- (void)getCursorCoord:(MwPoint *)point; -- (void)getScreenSize:(MwRect *)rect; +- (void)getCursorCoord:(MwPoint*)point; +- (void)getScreenSize:(MwRect*)rect; - (void)destroy; - (void)sendClipboardEvent; - (MwLL)getParent; -- (NSView *)getView; -- (MilskoCocoaWindow *)getWindow; +- (NSView*)getView; +- (MilskoCocoaWindow*)getWindow; -- (MilskoFakePointer *)getHandle; -+ (void)eventCanceller:(MilskoCocoa *)this; +- (MilskoFakePointer*)getHandle; ++ (void)eventCanceller:(MilskoCocoa*)this; @end #define OBJC(x) x #else -#define OBJC(x) void * +#define OBJC(x) void* #endif MWDECL int MwLLCocoaCallInit(void); struct _MwLLCocoa { - struct _MwLLCommon common; - OBJC(MilskoCocoa *) - real; + struct _MwLLCommon common; + OBJC(MilskoCocoa*) + real; }; struct _MwLLCocoaColor { - struct _MwLLCommonColor common; + struct _MwLLCommonColor common; }; struct _MwLLCocoaPixmap { - struct _MwLLCommonPixmap common; - OBJC(MilskoCocoaPixmap *) - real; + struct _MwLLCommonPixmap common; + OBJC(MilskoCocoaPixmap*) + real; }; #endif diff --git a/include/Mw/Widget/OpenGL.h b/include/Mw/Widget/OpenGL.h index c3fab76..3f7a0c4 100644 --- a/include/Mw/Widget/OpenGL.h +++ b/include/Mw/Widget/OpenGL.h @@ -43,7 +43,7 @@ MWDECL MwClass MwOpenGLClass; * @param handle Widget */ MwInline void MwOpenGLMakeCurrent(MwWidget handle) { - MwVaWidgetExecute(handle, "mwOpenGLMakeCurrent", NULL); + MwVaWidgetExecute(handle, "mwOpenGLMakeCurrent", NULL); } /*! @@ -52,10 +52,10 @@ MwInline void MwOpenGLMakeCurrent(MwWidget handle) { * @param name Name * @return Procedure */ -MwInline void *MwOpenGLGetProcAddress(MwWidget handle, const char *name) { - void *out; - MwVaWidgetExecute(handle, "mwOpenGLGetProcAddress", &out, name); - return out; +MwInline void* MwOpenGLGetProcAddress(MwWidget handle, const char* name) { + void* out; + MwVaWidgetExecute(handle, "mwOpenGLGetProcAddress", &out, name); + return out; } /*! @@ -63,7 +63,7 @@ MwInline void *MwOpenGLGetProcAddress(MwWidget handle, const char *name) { * @param handle Widget */ MwInline void MwOpenGLSwapBuffer(MwWidget handle) { - MwVaWidgetExecute(handle, "mwOpenGLSwapBuffer", NULL); + MwVaWidgetExecute(handle, "mwOpenGLSwapBuffer", NULL); } #ifdef __cplusplus diff --git a/pl/rules.pl b/pl/rules.pl index a35a6c3..a4ba7bf 100644 --- a/pl/rules.pl +++ b/pl/rules.pl @@ -37,7 +37,7 @@ if (grep(/^wayland$/, @backends)) { } scan_wayland_protocol("stable", "xdg-shell", ""); - scan_wayland_protocol("stable", "viewporter", ""); + scan_wayland_protocol("stable", "viewporter", ""); scan_wayland_protocol("stable", "tablet", "-v2"); scan_wayland_protocol("staging", "xdg-toplevel-icon", "-v1"); scan_wayland_protocol("staging", "cursor-shape", "-v1"); @@ -55,7 +55,7 @@ if (grep(/^cocoa$/, @backends)) { new_object("src/widget/opengl_cocoa.m"); } - # tim cook my man literally everybody and their mother who knows what opengl is knows its deprecated on macos and i'm not having you spam the console with this +# tim cook my man literally everybody and their mother who knows what opengl is knows its deprecated on macos and i'm not having you spam the console with this add_cflags("-DGL_SILENCE_DEPRECATION"); $gl_libs = "-framework OpenGL"; diff --git a/src/backend/gdi.c b/src/backend/gdi.c index 4601b79..d6ad07a 100644 --- a/src/backend/gdi.c +++ b/src/backend/gdi.c @@ -621,7 +621,7 @@ HCURSOR MwLLGDICreateCursor(MwCursor* image, MwCursor* mask) { } } - cursor = CreateCursor(GetModuleHandle(NULL), xs, ys, MwCursorDataHeight, MwCursorDataHeight, dmask, dimage); + cursor = CreateCursor(GetModuleHandle(NULL), xs - image->x, ys + (MwCursorDataHeight + image->y), MwCursorDataHeight, MwCursorDataHeight, dmask, dimage); free(dimage); free(dmask); diff --git a/src/backend/x11.c b/src/backend/x11.c index f7c6fe4..cd9e882 100644 --- a/src/backend/x11.c +++ b/src/backend/x11.c @@ -849,7 +849,7 @@ Cursor MwLLX11CreateCursor(Display* display, MwCursor* image, MwCursor* mask) { XPutImage(display, pimage, imagegc, cimage, 0, 0, 0, 0, MwCursorDataHeight, MwCursorDataHeight); XPutImage(display, pmask, maskgc, cmask, 0, 0, 0, 0, MwCursorDataHeight, MwCursorDataHeight); - cur = XCreatePixmapCursor(display, pimage, pmask, &cfg, &cbg, xs, ys); + cur = XCreatePixmapCursor(display, pimage, pmask, &cfg, &cbg, xs - image->x, ys + (MwCursorDataHeight + image->y)); XFreePixmap(display, pimage); XFreePixmap(display, pmask); diff --git a/src/widget/opengl_cocoa.m b/src/widget/opengl_cocoa.m index 503fe5e..2397a84 100644 --- a/src/widget/opengl_cocoa.m +++ b/src/widget/opengl_cocoa.m @@ -7,124 +7,125 @@ #import @interface MacOpenGLWidget : NSObject { - NSOpenGLPixelFormat *pixelFormat; - NSOpenGLContext *glc; - MilskoCocoa *_win; + NSOpenGLPixelFormat* pixelFormat; + NSOpenGLContext* glc; + MilskoCocoa* _win; } -- (MacOpenGLWidget *)initWithWindow:(MilskoCocoa *)w; +- (MacOpenGLWidget*)initWithWindow:(MilskoCocoa*)w; - (void)destroy; - (void)makeCurrent; - (void)swapBuffer; -- (void *)getProcAddressWithName:(const char *)name; +- (void*)getProcAddressWithName:(const char*)name; @end static int create(MwWidget handle) { - void *r = NULL; - MwWidget w = handle; + void* r = NULL; + MwWidget w = handle; - int x = MwGetInteger(w, MwNx); - int y = MwGetInteger(w, MwNy); - int width = MwGetInteger(w, MwNwidth); - int height = MwGetInteger(w, MwNheight); + int x = MwGetInteger(w, MwNx); + int y = MwGetInteger(w, MwNy); + int width = MwGetInteger(w, MwNwidth); + int height = MwGetInteger(w, MwNheight); - printf("%d %d\n", width, height); + printf("%d %d\n", width, height); - handle->internal = - [[MacOpenGLWidget alloc] initWithWindow:handle->lowlevel->cocoa.real]; - handle->lowlevel->common.copy_buffer = 0; + handle->internal = + [[MacOpenGLWidget alloc] initWithWindow:handle->lowlevel->cocoa.real]; + handle->lowlevel->common.copy_buffer = 0; - MwSetDefault(handle); + MwSetDefault(handle); - while (w->parent != NULL) - w = w->parent; + while(w->parent != NULL) + w = w->parent; - w->berserk++; + w->berserk++; - return 0; + return 0; } static void destroy(MwWidget handle) { - [(MacOpenGLWidget *)handle->internal destroy]; + [(MacOpenGLWidget*)handle->internal destroy]; } static void mwOpenGLMakeCurrentImpl(MwWidget handle) { - [(MacOpenGLWidget *)handle->internal makeCurrent]; + [(MacOpenGLWidget*)handle->internal makeCurrent]; } static void mwOpenGLSwapBufferImpl(MwWidget handle) { - [(MacOpenGLWidget *)handle->internal swapBuffer]; + [(MacOpenGLWidget*)handle->internal swapBuffer]; } -static void *mwOpenGLGetProcAddressImpl(MwWidget handle, const char *name) { - return [(MacOpenGLWidget *)handle->internal getProcAddressWithName:name]; +static void* mwOpenGLGetProcAddressImpl(MwWidget handle, const char* name) { + return [(MacOpenGLWidget*)handle->internal getProcAddressWithName:name]; } -static void func_handler(MwWidget handle, const char *name, void *out, - va_list va) { - if (strcmp(name, "mwOpenGLMakeCurrent") == 0) { - mwOpenGLMakeCurrentImpl(handle); - } - if (strcmp(name, "mwOpenGLSwapBuffer") == 0) { - mwOpenGLSwapBufferImpl(handle); - } - if (strcmp(name, "mwOpenGLGetProcAddress") == 0) { - const char *_name = va_arg(va, const char *); - *(void **)out = mwOpenGLGetProcAddressImpl(handle, _name); - } +static void func_handler(MwWidget handle, const char* name, void* out, + va_list va) { + if(strcmp(name, "mwOpenGLMakeCurrent") == 0) { + mwOpenGLMakeCurrentImpl(handle); + } + if(strcmp(name, "mwOpenGLSwapBuffer") == 0) { + mwOpenGLSwapBufferImpl(handle); + } + if(strcmp(name, "mwOpenGLGetProcAddress") == 0) { + const char* _name = va_arg(va, const char*); + *(void**)out = mwOpenGLGetProcAddressImpl(handle, _name); + } } @implementation MacOpenGLWidget -- (MacOpenGLWidget *)initWithWindow:(MilskoCocoa *)w { - NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = { - NSOpenGLPFAColorSize, 24, - NSOpenGLPFAStencilSize, 8, - NSOpenGLPFAAlphaSize, 8, - NSOpenGLPFADoubleBuffer, NSOpenGLPFAAccelerated, - NSOpenGLPFANoRecovery, 0}; - self->pixelFormat = - [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes]; - self->glc = - [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil]; - [self->glc setView:[w getView]]; - self->_win = w; - return self; +- (MacOpenGLWidget*)initWithWindow:(MilskoCocoa*)w { + NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = { + NSOpenGLPFAColorSize, 24, + NSOpenGLPFAStencilSize, 8, + NSOpenGLPFAAlphaSize, 8, + NSOpenGLPFADoubleBuffer, NSOpenGLPFAAccelerated, + NSOpenGLPFANoRecovery, 0}; + self->pixelFormat = + [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes]; + self->glc = + [[NSOpenGLContext alloc] initWithFormat:pixelFormat + shareContext:nil]; + [self->glc setView:[w getView]]; + self->_win = w; + return self; }; - (void)destroy { }; - (void)makeCurrent { - [self->glc makeCurrentContext]; + [self->glc makeCurrentContext]; }; - (void)swapBuffer { - [self->glc flushBuffer]; + [self->glc flushBuffer]; }; -- (void *)getProcAddressWithName:(const char *)name { - if (NSIsSymbolNameDefined(name)) { - return NSAddressOfSymbol(NSLookupAndBindSymbol(name)); - } else { - return NULL; - } +- (void*)getProcAddressWithName:(const char*)name { + if(NSIsSymbolNameDefined(name)) { + return NSAddressOfSymbol(NSLookupAndBindSymbol(name)); + } else { + return NULL; + } }; @end -MwClassRec MwOpenGLClassRec = {create, /* create */ - destroy, /* destroy */ - NULL, /* draw */ - NULL, /* click */ - NULL, /* parent_resize */ - NULL, /* prop_change */ - NULL, /* mouse_move */ - NULL, /* mouse_up */ - NULL, /* mouse_down */ - NULL, /* key */ - func_handler, /* execute */ - NULL, /* tick */ - NULL, /* resize */ - NULL, /* children_update */ - NULL, /* children_prop_change */ - NULL, /* clipboard */ - NULL, NULL, NULL, NULL}; -MwClass MwOpenGLClass = &MwOpenGLClassRec; \ No newline at end of file +MwClassRec MwOpenGLClassRec = {create, /* create */ + destroy, /* destroy */ + NULL, /* draw */ + NULL, /* click */ + NULL, /* parent_resize */ + NULL, /* prop_change */ + NULL, /* mouse_move */ + NULL, /* mouse_up */ + NULL, /* mouse_down */ + NULL, /* key */ + func_handler, /* execute */ + NULL, /* tick */ + NULL, /* resize */ + NULL, /* children_update */ + NULL, /* children_prop_change */ + NULL, /* clipboard */ + NULL, NULL, NULL, NULL}; +MwClass MwOpenGLClass = &MwOpenGLClassRec; \ No newline at end of file diff --git a/tools/readme.pl b/tools/readme.pl index 7070312..653184c 100755 --- a/tools/readme.pl +++ b/tools/readme.pl @@ -58,8 +58,7 @@ l( l(""); c("Requirements"); l(""); -l( -" Milsko requires either"); +l(" Milsko requires either"); l(" * A Windows environment with GDI (so anything NT or 9x)"); l(" * A MacOS environment with Cocoa (10.4 or above supported)"); l(" * A Unix-like environment with X11 for runtime.");