parent
d5723f0f2c
commit
752076d2cc
@ -1,3 +1,6 @@
|
||||
[submodule "MetalLearning/src/vendor"]
|
||||
[submodule "MetalLearning/vendor/imgui"]
|
||||
path=MetalLearning/vendor/imgui
|
||||
url=https://github.com/TheCherno/imgui.git
|
||||
[submodule "MetalLearning/vendor/spdlog"]
|
||||
path = MetalLearning/vendor/spdlog
|
||||
url = https://github.com/gabime/spdlog.git
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "group:MetalLearning/MetalLearning.xcodeproj">
|
||||
</FileRef>
|
||||
<Group
|
||||
location = "group:MetalLearning/src/MEL/Events"
|
||||
name = "Events">
|
||||
</Group>
|
||||
</Workspace>
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "group:MetalLearning/vendor/imgui/ImGui.xcodeproj">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:MetalLearning/MetalLearning.xcodeproj">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Bucket
|
||||
uuid = "DF66116D-CBEC-417A-B438-C6E6BCF5D426"
|
||||
type = "0"
|
||||
version = "2.0">
|
||||
</Bucket>
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include "Layer/Layer.h"
|
||||
#include "Layer/LayerStack.h"
|
||||
|
||||
namespace MEL{
|
||||
class ImGuiLayer:public Layer{
|
||||
public:
|
||||
ImGuiLayer(NSWindow* window);
|
||||
~ImGuiLayer();
|
||||
|
||||
virtual void OnAttach()override;
|
||||
virtual void OnDetach()override;
|
||||
virtual void OnUpdate()override;
|
||||
virtual void OnImGuiRender()override;
|
||||
virtual void OnEvent(Event& event)override;
|
||||
|
||||
void Begin();
|
||||
void End();
|
||||
|
||||
private:
|
||||
NSWindow* m_NativeWindow;
|
||||
};
|
||||
}
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
#include "ImGuiLayer.h"
|
||||
|
||||
#import "imgui.h"
|
||||
#import "imgui_impl_metal.h"
|
||||
#import "imgui_impl_osx.h"
|
||||
|
||||
namespace MEL{
|
||||
ImGuiLayer::ImGuiLayer(NSWindow* window):m_NativeWindow(window){
|
||||
|
||||
}
|
||||
|
||||
void ImGuiLayer::OnAttach(){
|
||||
|
||||
}
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
#include "Input.h"
|
||||
@ -1 +1,72 @@
|
||||
#pragma once
|
||||
#include "melpch.h"
|
||||
#include <utility>
|
||||
namespace MEL {
|
||||
using Keycode =uint16_t;
|
||||
namespace Key{
|
||||
enum: Keycode{
|
||||
D1 =18,
|
||||
D2 =19,
|
||||
D3 =20,
|
||||
D4 =21,
|
||||
D5 =23,
|
||||
D6 =22,
|
||||
D7 =26,
|
||||
D8 =28,
|
||||
D9 =25,
|
||||
D0 =29,
|
||||
S1 =50,//`
|
||||
S2 =33,//[
|
||||
S3 =30,//]
|
||||
S4 =42,//|
|
||||
S6 =41,//;
|
||||
S7 =39,//'
|
||||
S8 =27,//-
|
||||
S9 =24,//=
|
||||
S10 =43,//,
|
||||
S11 =47,//.
|
||||
S12 =44,//?
|
||||
N =45,
|
||||
M =46,
|
||||
Q =12,
|
||||
W =13,
|
||||
E =14,
|
||||
R =15,
|
||||
T =17,
|
||||
Y =16,
|
||||
U =32,
|
||||
I =34,
|
||||
O =31,
|
||||
P =35,
|
||||
A =0,
|
||||
S =1,
|
||||
D =2,
|
||||
F =3,
|
||||
G =5,
|
||||
H =4,
|
||||
J =38,
|
||||
K =40,
|
||||
L =37,
|
||||
Z =6,
|
||||
X =7,
|
||||
C =8,
|
||||
V =9,
|
||||
B =11,
|
||||
enter =76
|
||||
};
|
||||
}
|
||||
class Input{
|
||||
static bool IsKeypressed(Keycode keycode){return IsKeyPressedImpl(keycode);}
|
||||
static bool IsMouseButtonPressed(int button){return IsMouseButtonPressedImpl(button);}
|
||||
static float GetMouseX(){return GetMouseXImpl();}
|
||||
static float GetMouseY(){return GetMouseYImpl();}
|
||||
static std::pair<float,float> GetMousePosition(){return GetMousePositionImpl();}
|
||||
private:
|
||||
static bool IsKeyPressedImpl(Keycode keycode);
|
||||
static bool IsMouseButtonPressedImpl(int button);
|
||||
static float GetMouseXImpl();
|
||||
static float GetMouseYImpl();
|
||||
static std::pair<float,float> GetMousePositionImpl();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include "Input.h"
|
||||
#include <AppKit/AppKit.h>
|
||||
|
||||
namespace MEL{
|
||||
class MacInput:public Input{
|
||||
public:
|
||||
static void Init();
|
||||
|
||||
static void OnKeyEvent(NSEvent* event,bool pressed);
|
||||
static void OnMouseEvent(NSEvent* event);
|
||||
static void OnMouseMovedEvent(NSEvent* event);
|
||||
|
||||
static bool IsKeyPressedImpl(Keycode keycode);
|
||||
static bool IsMouseButtonPressedImpl(int button);
|
||||
static float GetMouseXImpl(){return MouseX;}
|
||||
static float GetMouseYImpl(){return MouseY;}
|
||||
static std::pair<float,float> GetMousePositionImpl();
|
||||
|
||||
private:
|
||||
static std::unordered_map<Keycode, bool> s_KeyState;
|
||||
static std::unordered_map<int, bool> s_MouseState;
|
||||
static float MouseX,MouseY;
|
||||
|
||||
static std::unordered_map<uint16_t, Keycode> s_KeyMap;
|
||||
|
||||
static int CocoaToEngineMouseButton(NSEvent* event);
|
||||
};
|
||||
}
|
||||
@ -0,0 +1,132 @@
|
||||
#include "MacInput.h"
|
||||
#include "Application.h"
|
||||
namespace MEL{
|
||||
std::unordered_map<uint16_t, Keycode> MacInput::s_KeyMap;
|
||||
std::unordered_map<Keycode, bool> MacInput::s_KeyState;
|
||||
std::unordered_map<int, bool> MacInput::s_MouseState;
|
||||
float MacInput::MouseX=.0f;
|
||||
float MacInput::MouseY=.0f;
|
||||
|
||||
void MacInput::Init(){
|
||||
s_KeyState[Key::D1 ]=false;
|
||||
s_KeyState[Key::D2 ]=false;
|
||||
s_KeyState[Key::D3 ]=false;
|
||||
s_KeyState[Key::D4 ]=false;
|
||||
s_KeyState[Key::D5 ]=false;
|
||||
s_KeyState[Key::D6 ]=false;
|
||||
s_KeyState[Key::D7 ]=false;
|
||||
s_KeyState[Key::D8 ]=false;
|
||||
s_KeyState[Key::D9 ]=false;
|
||||
s_KeyState[Key::D0 ]=false;
|
||||
s_KeyState[Key::S1 ]=false;
|
||||
s_KeyState[Key::S2 ]=false;
|
||||
s_KeyState[Key::S3 ]=false;
|
||||
s_KeyState[Key::S4 ]=false;
|
||||
s_KeyState[Key::S6 ]=false;
|
||||
s_KeyState[Key::S7 ]=false;
|
||||
s_KeyState[Key::S8 ]=false;
|
||||
s_KeyState[Key::S9 ]=false;
|
||||
s_KeyState[Key::S10 ]=false;
|
||||
s_KeyState[Key::S11 ]=false;
|
||||
s_KeyState[Key::S12 ]=false;
|
||||
s_KeyState[Key::N ]=false;
|
||||
s_KeyState[Key::M ]=false;
|
||||
s_KeyState[Key::Q ]=false;
|
||||
s_KeyState[Key::W ]=false;
|
||||
s_KeyState[Key::E ]=false;
|
||||
s_KeyState[Key::R ]=false;
|
||||
s_KeyState[Key::T ]=false;
|
||||
s_KeyState[Key::Y ]=false;
|
||||
s_KeyState[Key::U ]=false;
|
||||
s_KeyState[Key::I ]=false;
|
||||
s_KeyState[Key::O ]=false;
|
||||
s_KeyState[Key::P ]=false;
|
||||
s_KeyState[Key::A ]=false;
|
||||
s_KeyState[Key::S ]=false;
|
||||
s_KeyState[Key::D ]=false;
|
||||
s_KeyState[Key::F ]=false;
|
||||
s_KeyState[Key::G ]=false;
|
||||
s_KeyState[Key::H ]=false;
|
||||
s_KeyState[Key::J ]=false;
|
||||
s_KeyState[Key::K ]=false;
|
||||
s_KeyState[Key::L ]=false;
|
||||
s_KeyState[Key::Z ]=false;
|
||||
s_KeyState[Key::X ]=false;
|
||||
s_KeyState[Key::C ]=false;
|
||||
s_KeyState[Key::V ]=false;
|
||||
s_KeyState[Key::B ]=false;
|
||||
s_KeyState[Key::enter ]=false;
|
||||
|
||||
s_MouseState[0]=false;
|
||||
s_MouseState[1]=false;
|
||||
s_MouseState[2]=false;
|
||||
}
|
||||
|
||||
void MacInput::OnKeyEvent(NSEvent *event, bool pressed){
|
||||
Keycode keycode=[event keyCode];
|
||||
s_KeyState[keycode]=pressed;
|
||||
}
|
||||
|
||||
void MacInput::OnMouseEvent(NSEvent *event){
|
||||
int button=CocoaToEngineMouseButton(event);
|
||||
NSEventType type=[event type];
|
||||
|
||||
switch (type) {
|
||||
case NSEventTypeLeftMouseUp:
|
||||
case NSEventTypeRightMouseUp:
|
||||
case NSEventTypeOtherMouseUp:
|
||||
s_MouseState[button]=false;
|
||||
break;
|
||||
case NSEventTypeLeftMouseDown:
|
||||
case NSEventTypeRightMouseDown:
|
||||
case NSEventTypeOtherMouseDown:
|
||||
s_MouseState[button]=true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MacInput::OnMouseMovedEvent(NSEvent *event){
|
||||
NSPoint location=[event locationInWindow];
|
||||
MouseX=location.x;
|
||||
MouseY=location.y;
|
||||
}
|
||||
|
||||
int MacInput::CocoaToEngineMouseButton(NSEvent *event){
|
||||
switch ([event type]) {
|
||||
case NSEventTypeLeftMouseDown:
|
||||
case NSEventTypeLeftMouseUp:
|
||||
case NSEventTypeLeftMouseDragged:
|
||||
return 0;
|
||||
break;
|
||||
case NSEventTypeRightMouseUp:
|
||||
case NSEventTypeRightMouseDown:
|
||||
case NSEventTypeRightMouseDragged:
|
||||
return 1;
|
||||
break;
|
||||
case NSEventTypeOtherMouseUp:
|
||||
case NSEventTypeOtherMouseDown:
|
||||
case NSEventTypeOtherMouseDragged:
|
||||
return 2;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool MacInput::IsKeyPressedImpl(Keycode keycode){
|
||||
auto it=s_KeyState.find(keycode);
|
||||
return (it != s_KeyState.end())?it->second:false;
|
||||
}
|
||||
|
||||
bool MacInput::IsMouseButtonPressedImpl(int button){
|
||||
auto it=s_MouseState.find(button);
|
||||
return (it != s_MouseState.end())?it->second:false;
|
||||
}
|
||||
|
||||
std::pair<float,float> MacInput::GetMousePositionImpl(){
|
||||
return {MouseX,MouseY};
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,8 @@
|
||||
#include "melpch.h"
|
||||
#include "Layer.h"
|
||||
|
||||
|
||||
namespace MEL {
|
||||
Layer::Layer(const std::string& debugName)
|
||||
:m_DebugName(debugName){}
|
||||
Layer::~Layer(){}
|
||||
}
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
#include "melpch.h"
|
||||
#include "LayerStack.h"
|
||||
|
||||
namespace MEL{
|
||||
LayerStack::LayerStack(){
|
||||
m_LayerInsert=m_Layers.begin();
|
||||
}
|
||||
|
||||
LayerStack::~LayerStack(){
|
||||
for (Layer* layer : m_Layers)
|
||||
delete layer;
|
||||
}
|
||||
|
||||
void LayerStack::PushLayer(Layer *layer){
|
||||
m_LayerInsert=m_Layers.emplace(m_LayerInsert, layer);
|
||||
}
|
||||
|
||||
void LayerStack::PushOverLay(Layer *overlay){
|
||||
m_Layers.emplace_back(overlay);
|
||||
}
|
||||
|
||||
void LayerStack::PopLayer(Layer *layer){
|
||||
auto it=std::find(m_Layers.begin(),m_Layers.end(),layer);
|
||||
if(it != m_Layers.end()){
|
||||
m_Layers.erase(it);
|
||||
m_LayerInsert--;
|
||||
}
|
||||
}
|
||||
|
||||
void LayerStack::PopOverLay(Layer *overlay){
|
||||
auto it=std::find(m_Layers.begin(),m_Layers.end(),overlay);
|
||||
if(it != m_Layers.end())
|
||||
m_Layers.erase(it);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "Core.h"
|
||||
#include "Layer.h"
|
||||
#include<vector>
|
||||
|
||||
namespace MEL{
|
||||
class LayerStack{
|
||||
public:
|
||||
LayerStack();
|
||||
~LayerStack();
|
||||
|
||||
void PushLayer(Layer* layer);
|
||||
void PushOverLay(Layer* overlay);
|
||||
void PopLayer(Layer* layer);
|
||||
void PopOverLay(Layer* overlay);
|
||||
|
||||
std::vector<Layer*>::iterator begin() {return m_Layers.begin();}
|
||||
std::vector<Layer*>::iterator end() {return m_Layers.end();}
|
||||
|
||||
private:
|
||||
std::vector<Layer*>m_Layers;
|
||||
std::vector<Layer*>::iterator m_LayerInsert;
|
||||
};
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
Subproject commit 781a4ffc674d98dfd2b4d42747e1cd27887fac36
|
||||
Loading…
Reference in new issue