mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Rainbow: SDL20GL SDL Color cursor support
git-svn-id: svn://ultimatepp.org/upp/trunk@6505 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
b9740ac60d
commit
a67030a4bc
10 changed files with 121 additions and 48 deletions
|
|
@ -68,6 +68,8 @@ public:
|
|||
|
||||
static void PaintScene(SystemDraw& draw);
|
||||
static void PaintCaretCursor(SystemDraw& draw);
|
||||
|
||||
static bool SystemCursor;
|
||||
|
||||
enum { DRAWDRAGRECT_SCREEN = 0x8000 };
|
||||
|
||||
|
|
|
|||
75
rainbow/SDL20GL/Cursor.cpp
Normal file
75
rainbow/SDL20GL/Cursor.cpp
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
#include "Local.h"
|
||||
|
||||
#ifdef GUI_SDL20GL
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
#define LLOG(x) LOG(x)
|
||||
#define LDUMP(x) //DDUMP(x)
|
||||
|
||||
struct RectSDL {
|
||||
SDL_Rect sr;
|
||||
|
||||
operator SDL_Rect *() { return &sr; }
|
||||
|
||||
RectSDL(const Rect& r)
|
||||
{
|
||||
sr.x = r.left;
|
||||
sr.y = r.top;
|
||||
sr.w = r.GetWidth();
|
||||
sr.h = r.GetHeight();
|
||||
}
|
||||
};
|
||||
|
||||
SDL_Texture *SDLTextureFromImage(SDL_Renderer *renderer, const Image& m)
|
||||
{
|
||||
Size isz = m.GetSize();
|
||||
SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STATIC, isz.cx, isz.cy);
|
||||
if(texture) {
|
||||
SDL_UpdateTexture(texture, RectSDL(isz), ~m, isz.cx * sizeof(RGBA));
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
return texture;
|
||||
}
|
||||
|
||||
SDL_Cursor *sdl_cursor;
|
||||
SDL_Surface *sdl_cursor_surface;
|
||||
Buffer<RGBA> data;
|
||||
|
||||
void Ctrl::SetMouseCursor(const Image& image)
|
||||
{
|
||||
GuiLock __;
|
||||
if(image.GetSerialId() != fbCursorImage.GetSerialId()) {
|
||||
fbCursorImage = image;
|
||||
fbCursorPos = Null;
|
||||
SDL_ShowCursor(SystemCursor);
|
||||
if(SystemCursor) {
|
||||
if(sdl_cursor)
|
||||
SDL_FreeCursor(sdl_cursor);
|
||||
if(sdl_cursor_surface)
|
||||
SDL_FreeSurface(sdl_cursor_surface);
|
||||
|
||||
int a = image.GetAuxData();
|
||||
if(a)
|
||||
sdl_cursor = SDL_CreateSystemCursor(SDL_SystemCursor(a - 1));
|
||||
else {
|
||||
sdl_cursor = NULL;
|
||||
data.Alloc(image.GetLength());
|
||||
Copy(data, image, image.GetLength());
|
||||
sdl_cursor_surface = SDL_CreateRGBSurfaceFrom(~data, image.GetWidth(), image.GetHeight(),
|
||||
32, sizeof(RGBA) * image.GetWidth(),
|
||||
0xff0000, 0xff00, 0xff, 0xff000000);
|
||||
Point h = image.GetHotSpot();
|
||||
if(sdl_cursor_surface)
|
||||
sdl_cursor = SDL_CreateColorCursor(sdl_cursor_surface, h.x, h.y);
|
||||
}
|
||||
if(sdl_cursor)
|
||||
SDL_SetCursor(sdl_cursor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
#endif
|
||||
|
|
@ -324,22 +324,13 @@ void Ctrl::CursorSync()
|
|||
if(focusCtrl && (((GetTickCount() - fbCaretTm) / 500) & 1) == 0)
|
||||
cr = (RectC(focusCtrl->caretx, focusCtrl->carety, focusCtrl->caretcx, focusCtrl->caretcy)
|
||||
+ focusCtrl->GetScreenView().TopLeft()) & focusCtrl->GetScreenView();
|
||||
if(fbCursorPos != p || cr != fbCaretRect) {
|
||||
if(fbCursorPos != p && !SystemCursor || cr != fbCaretRect) {
|
||||
fbCaretRect = cr;
|
||||
fbCursorPos = p;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void Ctrl::SetMouseCursor(const Image& image)
|
||||
{
|
||||
GuiLock __;
|
||||
if(image.GetSerialId() != fbCursorImage.GetSerialId()) {
|
||||
fbCursorImage = image;
|
||||
fbCursorPos = Null;
|
||||
}
|
||||
}
|
||||
|
||||
bool Ctrl::ProcessEvent(bool *quit)
|
||||
{
|
||||
LLOG("@ ProcessEvent");
|
||||
|
|
|
|||
|
|
@ -1,26 +1,26 @@
|
|||
PREMULTIPLIED
|
||||
IMAGE_ID(arrow)
|
||||
IMAGE_ID(ibeam)
|
||||
IMAGE_ID(wait)
|
||||
IMAGE_ID(no)
|
||||
IMAGE_ID(sizeall)
|
||||
IMAGE_ID(sizehorz)
|
||||
IMAGE_ID(sizeright)
|
||||
IMAGE_ID(sizeleft)
|
||||
IMAGE_ID(sizevert)
|
||||
IMAGE_ID(sizetopleft)
|
||||
IMAGE_ID(sizetop)
|
||||
IMAGE_ID(sizetopright)
|
||||
IMAGE_ID(sizebottomleft)
|
||||
IMAGE_ID(sizebottom)
|
||||
IMAGE_ID(sizebottomright)
|
||||
IMAGE_ID(Arrow)
|
||||
IMAGE_ID(IBeam)
|
||||
IMAGE_ID(Wait)
|
||||
IMAGE_ID(No)
|
||||
IMAGE_ID(SizeAll)
|
||||
IMAGE_ID(SizeHorz)
|
||||
IMAGE_ID(SizeRight)
|
||||
IMAGE_ID(SizeLeft)
|
||||
IMAGE_ID(SizeVert)
|
||||
IMAGE_ID(SizeTopLeft)
|
||||
IMAGE_ID(SizeTop)
|
||||
IMAGE_ID(SizeTopRight)
|
||||
IMAGE_ID(SizeBottomLeft)
|
||||
IMAGE_ID(SizeBottom)
|
||||
IMAGE_ID(SizeBottomRight)
|
||||
IMAGE_ID(overlap)
|
||||
IMAGE_ID(maximize)
|
||||
IMAGE_ID(close)
|
||||
IMAGE_ID(bgtitle)
|
||||
IMAGE_ID(title)
|
||||
IMAGE_ID(border)
|
||||
IMAGE_ID(hand)
|
||||
IMAGE_ID(Hand)
|
||||
|
||||
IMAGE_BEGIN_DATA
|
||||
IMAGE_DATA(120,156,237,90,61,104,20,65,20,30,77,162,9,92,144,248,135,160,133,117,42,177,18,21,4,171,84,65,76,22,4,149)
|
||||
|
|
|
|||
|
|
@ -19,25 +19,28 @@ void SetSurface(SystemDraw& w, const Rect& dest, const RGBA *pixels, Size psz, P
|
|||
}
|
||||
|
||||
#define IMAGECLASS FBImg
|
||||
#define IMAGEFILE <Framebuffer/FB.iml>
|
||||
#define IMAGEFILE <SDL20GL/FB.iml>
|
||||
#include <Draw/iml_source.h>
|
||||
|
||||
Image Image::Arrow() { return FBImg::arrow(); }
|
||||
Image Image::Wait() { return FBImg::wait(); }
|
||||
Image Image::IBeam() { return FBImg::ibeam(); }
|
||||
Image Image::No() { return FBImg::no(); }
|
||||
Image Image::SizeAll() { return FBImg::sizeall(); }
|
||||
Image Image::SizeHorz() { return FBImg::sizehorz(); }
|
||||
Image Image::SizeVert() { return FBImg::sizevert(); }
|
||||
Image Image::SizeTopLeft() { return FBImg::sizetopleft(); }
|
||||
Image Image::SizeTop() { return FBImg::sizetop(); }
|
||||
Image Image::SizeTopRight() { return FBImg::sizetopright(); }
|
||||
Image Image::SizeLeft() { return FBImg::sizeleft(); }
|
||||
Image Image::SizeRight() { return FBImg::sizeright(); }
|
||||
Image Image::SizeBottomLeft() { return FBImg::sizebottomleft(); }
|
||||
Image Image::SizeBottom() { return FBImg::sizebottom(); }
|
||||
Image Image::SizeBottomRight() { return FBImg::sizebottomright(); }
|
||||
Image Image::Hand() { return FBImg::hand(); }
|
||||
#define STD_CURSOR(name, sdl) \
|
||||
Image Image::name() { static Image img; ONCELOCK { img = FBImg::name(); img.SetAuxData(sdl + 1); } return img; }
|
||||
|
||||
STD_CURSOR(Arrow, SDL_SYSTEM_CURSOR_ARROW)
|
||||
STD_CURSOR(Wait, SDL_SYSTEM_CURSOR_WAIT)
|
||||
STD_CURSOR(IBeam, SDL_SYSTEM_CURSOR_IBEAM)
|
||||
STD_CURSOR(No, SDL_SYSTEM_CURSOR_NO)
|
||||
STD_CURSOR(SizeAll, SDL_SYSTEM_CURSOR_SIZEALL)
|
||||
STD_CURSOR(SizeHorz, SDL_SYSTEM_CURSOR_SIZEWE)
|
||||
STD_CURSOR(SizeVert, SDL_SYSTEM_CURSOR_SIZENS)
|
||||
STD_CURSOR(SizeTopLeft, SDL_SYSTEM_CURSOR_SIZENWSE)
|
||||
STD_CURSOR(SizeTop, SDL_SYSTEM_CURSOR_SIZENS)
|
||||
STD_CURSOR(SizeTopRight, SDL_SYSTEM_CURSOR_SIZENESW)
|
||||
STD_CURSOR(SizeLeft, SDL_SYSTEM_CURSOR_SIZEWE)
|
||||
STD_CURSOR(SizeRight, SDL_SYSTEM_CURSOR_SIZEWE)
|
||||
STD_CURSOR(SizeBottomLeft, SDL_SYSTEM_CURSOR_SIZENWSE)
|
||||
STD_CURSOR(SizeBottom, SDL_SYSTEM_CURSOR_SIZENS)
|
||||
STD_CURSOR(SizeBottomRight, SDL_SYSTEM_CURSOR_SIZENESW)
|
||||
STD_CURSOR(Hand, SDL_SYSTEM_CURSOR_HAND)
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -62,9 +62,6 @@ void FBInit()
|
|||
//FIXME adjustable
|
||||
videoflags = SDL_HWSURFACE | SDL_HWACCEL | SDL_DOUBLEBUF | SDL_RESIZABLE;// | SDL_NOFRAME | SDL_FULLSCREEN;
|
||||
#endif
|
||||
|
||||
SDL_ShowCursor(0);
|
||||
|
||||
screen_size = Size(1500, 900);
|
||||
screen.Create(screen_size, "First test");
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
NAMESPACE_UPP
|
||||
|
||||
#define IMAGECLASS FBImg
|
||||
#define IMAGEFILE <Framebuffer/FB.iml>
|
||||
#define IMAGEFILE <SDL20GL/FB.iml>
|
||||
#include <Draw/iml_header.h>
|
||||
|
||||
struct SDLWindow {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ file
|
|||
DrawDragRect.cpp,
|
||||
Ctrl.cpp,
|
||||
Wnd.cpp,
|
||||
Cursor.cpp,
|
||||
Event.cpp,
|
||||
Top.h,
|
||||
TopFrame.cpp,
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ int Ctrl::fbCaretTm;
|
|||
bool Ctrl::fbEndSession;
|
||||
int Ctrl::PaintLock;
|
||||
|
||||
bool Ctrl::SystemCursor;
|
||||
|
||||
void Ctrl::SetDesktop(Ctrl& q)
|
||||
{
|
||||
desktop = &q;
|
||||
|
|
@ -235,7 +237,7 @@ void Ctrl::PaintCaretCursor(SystemDraw& draw)
|
|||
{
|
||||
if(!IsNull(fbCaretRect))
|
||||
draw.DrawRect(fbCaretRect, InvertColor);
|
||||
if(sdlMouseIsIn)
|
||||
if(sdlMouseIsIn && !SystemCursor)
|
||||
draw.DrawImage(fbCursorPos.x, fbCursorPos.y, fbCursorImage);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -242,6 +242,8 @@ void UWord::SerializeApp(Stream& s)
|
|||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
Ctrl::SystemCursor = true;
|
||||
|
||||
SetLanguage(LNG_ENGLISH);
|
||||
SetDefaultCharset(CHARSET_UTF8);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue