Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c03a89a
commit dbc435e
Showing
4 changed files
with
61 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
#import <Monet/MOApplication.h> | ||
#import <Monet/MORect.h> | ||
#import <Monet/MOView.h> | ||
|
||
// @interface MOButton : MOView | ||
// { | ||
// struct MOButtonData *buttonData; | ||
// } | ||
// | ||
// - (void)clicked; | ||
// | ||
// @end | ||
typedef void (*MOButtonClickedCallback)(MOView *self); | ||
|
||
MOView *MOButtonCreate(MORect aFrame, MOApplication *aApplication); | ||
|
||
void MOButtonSetClickedCallback(MOView *self, MOButtonClickedCallback aCallback); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,70 @@ | ||
#import <Monet/MOButton.h> | ||
|
||
#import <cobject/cobject.h> | ||
|
||
#import <Monet/MOApplication.h> | ||
#import <Monet/MOPoint.h> | ||
#import <Monet/MORect.h> | ||
#import <Monet/MOView.h> | ||
|
||
/* | ||
struct MOButtonData | ||
struct _MOButtonExtra | ||
{ | ||
BOOL isMouseDown; | ||
BOOL isMouseInside; | ||
}; | ||
COGuts *guts; | ||
|
||
@implementation MOButton : MOView | ||
bool isMouseDown; | ||
bool isMouseInside; | ||
|
||
MOButtonClickedCallback clickedCallback; | ||
}; | ||
typedef struct _MOButtonExtra MOButtonExtra; | ||
|
||
- (id)initWithFrame: (MORect)aFrame app: (MOApplication *)aApp; | ||
bool _MOButtonIsMousePressed(MOView *self) | ||
{ | ||
if ((self = [super initWithFrame: aFrame app: aApp])) | ||
{ | ||
buttonData = calloc(1, sizeof (struct MOButtonData)); | ||
buttonData->isMouseDown = NO; | ||
buttonData->isMouseInside = NO; | ||
} | ||
return self; | ||
} | ||
MOButtonExtra *extra = MOViewGetExtra(self); | ||
|
||
#pragma mark - | ||
MORect bounds = MOViewGetBounds(self); | ||
MOPoint untranslatedPoint = MOApplicationGetMouseLocation(MOViewGetApplication(self)); | ||
MOPoint point = MOViewConvertPointFromScreen(self, untranslatedPoint); | ||
return extra->isMouseDown && MORectContainsPoint(bounds, point); | ||
} | ||
|
||
- (BOOL)isPressed | ||
bool _MOButtonMouseButtonPressed(MOView *self, MOEvent *aEvent) | ||
{ | ||
return buttonData->isMouseDown && MORectContainsPoint( | ||
[self bounds], | ||
[self convertPointFromScreen: MOApplicationGetMouseLocation([self app])]); | ||
} | ||
MOButtonExtra *extra = MOViewGetExtra(self); | ||
|
||
#pragma mark - | ||
extra->isMouseDown = YES; | ||
|
||
- (void)mouseDown: (MOEvent *)aEvent | ||
{ | ||
buttonData->isMouseDown = YES; | ||
return true; | ||
} | ||
|
||
- (void)mouseUp: (MOEvent *)aEvent | ||
bool _MOButtonMouseButtonReleased(MOView *self, MOEvent *aEvent) | ||
{ | ||
if ([self isPressed]) | ||
[self clicked]; | ||
MOButtonExtra *extra = MOViewGetExtra(self); | ||
|
||
buttonData->isMouseDown = NO; | ||
} | ||
if (_MOButtonIsMousePressed(self)) | ||
extra->clickedCallback(self); | ||
|
||
#pragma mark - | ||
extra->isMouseDown = NO; | ||
|
||
- (void)clicked | ||
{ | ||
; | ||
return true; | ||
} | ||
|
||
@end | ||
MOView *MOButtonCreate(MORect aFrame, MOApplication *aApplication) | ||
{ | ||
MOView *view = MOViewCreate(aFrame, aApplication); | ||
|
||
MOButtonExtra *extra = calloc(1, sizeof (MOButtonExtra)); | ||
COInitialize(extra); | ||
MOViewSetExtra(view, extra); | ||
|
||
MOViewSetMouseButtonPressedCallback(view, &_MOButtonMouseButtonPressed); | ||
MOViewSetMouseButtonReleasedCallback(view, &_MOButtonMouseButtonReleased); | ||
|
||
*/ | ||
return view; | ||
} | ||
|
||
void MOButtonSetClickedCallback(MOView *self, MOButtonClickedCallback aCallback) | ||
{ | ||
MOButtonExtra *extra = MOViewGetExtra(self); | ||
extra->clickedCallback = aCallback; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#import <Monet/MOView.h> | ||
|
||
#import <cobject/cobject.h> | ||
#import <OpenGL/gl.h> | ||
#import <OpenGL/glu.h> | ||
|
||
|