Created
April 24, 2017 04:46
-
-
Save anonymous/d4c72f16dd1aa431079b88131f8a769f to your computer and use it in GitHub Desktop.
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
import "ecere" | |
import "slider" | |
class MyApp : GuiApplication | |
{ | |
driver = "OpenGL"; | |
}; | |
Camera camera | |
{ | |
fixed, | |
position = Vector3D { 0, 0, -10 }, | |
orientation = Euler { 0, 0, 0 }, | |
fov = 53; | |
}; | |
Light light | |
{ | |
diffuse = lightCoral; | |
orientation = Euler { pitch = 10, yaw = 30 }; | |
}; | |
class Roof : Object | |
{ | |
double split; split = 0.5; | |
void Create(DisplaySystem displaySystem) | |
{ | |
Mesh mesh = InitializeMesh(displaySystem); | |
if(mesh.Allocate({ vertices = true }, 6, displaySystem)) | |
{ | |
Vector3Df vertices[] = | |
{ | |
/* | |
{ -1, 0, 1 }, // 0: left side | |
{ -1, 0, -1 }, // 1: left side | |
{ 0, -1, -1 }, // 2: middle (high point) | |
{ 0, -1, 1 }, // 3: middle (high point) | |
{ 1, 0, 1 }, // 4: right side | |
{ 1, 0, -1 } // 5: right side | |
*/ | |
{ -1, 0, 1 }, // 0: left side | |
{ -1, 0, -1 }, // 1: left side | |
{ -1 + (float)(2*split), -1, -1 }, // 2: middle (high point) | |
{ -1 + (float)(2*split), -1, 1 }, // 3: middle (high point) | |
{ 1, 0, 1 }, // 4: right side | |
{ 1, 0, -1 } // 5: right side | |
}; | |
uint16 indices[] = | |
{ | |
0,1,3, | |
1,2,3, | |
3,2,4, | |
2,5,4 | |
}; | |
PrimitiveGroup group; | |
memcpy(mesh.vertices, vertices, sizeof(vertices)); | |
group = mesh.AddPrimitiveGroup(triangles, 12); | |
if(group) | |
{ | |
memcpy(group.indices, indices, sizeof(indices)); | |
mesh.UnlockPrimitiveGroup(group); | |
mesh.Unlock(0); | |
} | |
} | |
} | |
} | |
class RoofForm : Window | |
{ | |
caption = "3D Roof"; | |
background = black; | |
borderStyle = sizable; | |
hasMaximize = true; | |
hasMinimize = true; | |
hasClose = true; | |
size = { 640, 480 }; | |
state = maximized; | |
Slider slider | |
{ | |
this, direction = horizontal, size.h = 20, anchor = { bottom = 10, left = 10, right = 10 }, | |
foreground = white; | |
percent = 0.5; | |
bool NotifySlide(Slider slider, double percent) | |
{ | |
Transform oldTransform = roof.transform; | |
displaySystem.Lock(); | |
roof.Free(displaySystem); | |
roof.split = percent; | |
roof.Create(displaySystem); | |
roof.transform = oldTransform; | |
roof.UpdateTransform(); | |
displaySystem.Unlock(); | |
Update(null); | |
return true; | |
} | |
}; | |
Roof roof { split = 0.5 }; | |
Point startClick; | |
Euler startAngle; | |
bool dragging; | |
bool OnLeftButtonDown(int x, int y, Modifiers mods) | |
{ | |
//if(y < clientSize.h - 30) | |
{ | |
startClick = { x, y }; | |
startAngle = roof.transform.orientation; | |
dragging = true; | |
Capture(); | |
} | |
return true; | |
} | |
bool OnMouseMove(int x, int y, Modifiers mods) | |
{ | |
if(dragging) | |
{ | |
roof.transform.orientation = | |
Euler | |
{ | |
startAngle.yaw + x - startClick.x, | |
startAngle.pitch + y - startClick.y, | |
0 | |
}; | |
roof.UpdateTransform(); | |
Update(null); | |
} | |
return true; | |
} | |
bool OnLeftButtonUp(int x, int y, Modifiers mods) | |
{ | |
dragging = false; | |
ReleaseCapture(); | |
return true; | |
} | |
bool OnLoadGraphics() | |
{ | |
roof.Create(displaySystem); | |
roof.transform.scaling = { 1, 1, 1 }; | |
//roof.transform.orientation = Euler { 50, 30, 50 }; | |
roof.UpdateTransform(); | |
return true; | |
} | |
void OnResize(int w, int h) | |
{ | |
camera.Setup(w, h, null); | |
camera.Update(); | |
} | |
void OnRedraw(Surface surface) | |
{ | |
surface.Clear(depthBuffer); | |
display.SetLight(0, light); | |
display.SetCamera(surface, camera); | |
display.DrawObject(roof); | |
display.SetCamera(surface, null); | |
} | |
} | |
RoofForm roofForm {}; |
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
{ | |
"Version" : 0.2, | |
"ModuleName" : "roof", | |
"Options" : { | |
"Warnings" : "All", | |
"TargetType" : "Executable", | |
"TargetFileName" : "roof", | |
"Libraries" : [ | |
"ecere" | |
] | |
}, | |
"Configurations" : [ | |
{ | |
"Name" : "Debug", | |
"Options" : { | |
"Debug" : true, | |
"Optimization" : "None", | |
"PreprocessorDefinitions" : [ | |
"_DEBUG", | |
"IMPORT_STATIC=\"\"" | |
], | |
"FastMath" : false | |
} | |
}, | |
{ | |
"Name" : "Release", | |
"Options" : { | |
"Debug" : false, | |
"Optimization" : "Speed", | |
"FastMath" : true | |
} | |
} | |
], | |
"Files" : [ | |
"roof.ec", | |
"slider.ec" | |
], | |
"ResourcesPath" : "", | |
"Resources" : [ | |
] | |
} |
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
public import IMPORT_STATIC "ecere" | |
class Slider : Window | |
{ | |
ScrollDirection direction; | |
opacity = 0; | |
bool dragging; | |
double percent; | |
int offset; | |
void OnRedraw(Surface surface) | |
{ | |
bool disabled = !isEnabled; | |
surface.SetBackground(disabled ? darkGray : foreground); | |
surface.SetForeground(disabled ? darkGray : foreground); | |
if(direction == horizontal) | |
{ | |
int pos = (int)((clientSize.w-7) * percent + 0.5) + 3; | |
surface.Area(0, clientSize.h / 2 - 3, clientSize.w-1, clientSize.h/2 + 3); | |
surface.Rectangle(1, clientSize.h / 2 - 2, clientSize.w-2, clientSize.h/2 + 2); | |
surface.SetBackground(darkGray); | |
surface.Area(pos - 3, 0, pos + 3, clientSize.h-1); | |
surface.SetForeground(white); | |
surface.Rectangle(pos - 3, 0, pos + 3, clientSize.h-1); | |
surface.VLine(2, clientSize.h-3, pos); | |
} | |
else | |
{ | |
int pos = (int)((clientSize.h-7) * (1.0-percent) + 0.5) + 3; | |
surface.Area(clientSize.w / 2 - 3, 0, clientSize.w/2 + 3, clientSize.h-1); | |
surface.Rectangle(clientSize.w / 2 - 2, 1, clientSize.w/2 + 2, clientSize.h-2); | |
surface.SetBackground(darkGray); | |
surface.Area(0, pos - 3, clientSize.w-1, pos + 3); | |
surface.SetForeground(white); | |
surface.Rectangle(0, pos - 3, clientSize.w-1, pos + 3); | |
surface.HLine(2, clientSize.w-3, pos); | |
} | |
} | |
bool OnLeftButtonDown(int x, int y, Modifiers mods) | |
{ | |
dragging = true; | |
Capture(); | |
OnMouseMove(x, y, mods); | |
return true; | |
} | |
bool OnMouseMove(int x, int y, Modifiers mods) | |
{ | |
if(dragging) | |
{ | |
if(direction == horizontal) | |
percent = ((double)x - offset - 3) / (double)(clientSize.w-7); | |
else | |
percent = 1.0-((double)y - offset - 3) / (double)(clientSize.h-7); | |
// TO FIX: Max(Min didn't work with double | |
if(percent < 0) percent = 0; | |
else if(percent > 1) percent = 1; | |
Update(null); | |
NotifySlide(master, this, percent); | |
} | |
return true; | |
} | |
void OnMouseCaptureLost() | |
{ | |
OnLeftButtonUp(0,0,0); | |
} | |
bool OnLeftButtonUp(int x, int y, Modifiers mods) | |
{ | |
if(dragging) | |
{ | |
dragging = false; | |
ReleaseCapture(); | |
NotifySlideUp(master, this, percent); | |
} | |
return true; | |
} | |
public: | |
virtual bool Window::NotifySlide(Slider slider, double percent); | |
virtual bool Window::NotifySlideUp(Slider slider, double percent); | |
property double percent | |
{ | |
get { return percent; } | |
set { if(!dragging) { percent = value; Update(null); } } | |
} | |
property ScrollDirection direction | |
{ | |
set { direction = value; } | |
get { return direction; } | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment