@@ -376,6 +376,169 @@ window_set_title_bar(PyObject* self, PyObject* args, PyObject* kwargs)
376376 return PyBool_FromLong (gptWindow -> set_title_bar (ptWindow , & tDesc ));
377377}
378378
379+ // window attribute values by type:
380+ // SIZE -> (width, height) (uint)
381+ // POSITION -> (x, y) (int)
382+ // SIZE_LIMITS -> (minWidth, minHeight, maxWidth, maxHeight) (uint)
383+ // others -> bool
384+ static PyObject *
385+ window_set_attribute (PyObject * self , PyObject * args , PyObject * kwargs )
386+ {
387+ static const char * apcKeywords [] = {"window" , "attribute" , "value" , NULL };
388+ PyObject * ptPyWindow = NULL ;
389+ int iAttribute = 0 ;
390+ PyObject * ptValue = NULL ;
391+ if (!pl_parse_args ("OiO" , (const char * * )apcKeywords , args , kwargs , __FUNCTION__ , & ptPyWindow , & iAttribute , & ptValue ))
392+ return NULL ;
393+ plWindow * ptWindow = PyCapsule_GetPointer (ptPyWindow , "plWindow" );
394+ if (ptWindow == NULL )
395+ return NULL ;
396+
397+ plWindowAttributeValue tValue = {0 };
398+ switch (iAttribute )
399+ {
400+ case PL_WINDOW_ATTRIBUTE_SIZE :
401+ if (!PyArg_ParseTuple (ptValue , "II;SIZE expects (width, height)" , & tValue .tuVec2 .x , & tValue .tuVec2 .y ))
402+ return NULL ;
403+ break ;
404+ case PL_WINDOW_ATTRIBUTE_POSITION :
405+ if (!PyArg_ParseTuple (ptValue , "ii;POSITION expects (x, y)" , & tValue .tiVec2 .x , & tValue .tiVec2 .y ))
406+ return NULL ;
407+ break ;
408+ case PL_WINDOW_ATTRIBUTE_SIZE_LIMITS :
409+ if (!PyArg_ParseTuple (ptValue , "IIII;SIZE_LIMITS expects (minWidth, minHeight, maxWidth, maxHeight)" ,
410+ & tValue .tuVec4 .x , & tValue .tuVec4 .y , & tValue .tuVec4 .z , & tValue .tuVec4 .w ))
411+ return NULL ;
412+ break ;
413+ default :
414+ {
415+ if (iAttribute < 0 || iAttribute >= PL_WINDOW_ATTRIBUTE_COUNT )
416+ {
417+ PyErr_Format (PyExc_ValueError , "unknown window attribute %d" , iAttribute );
418+ return NULL ;
419+ }
420+ const int iTruth = PyObject_IsTrue (ptValue );
421+ if (iTruth < 0 )
422+ return NULL ;
423+ tValue .bValue = iTruth != 0 ;
424+ break ;
425+ }
426+ }
427+ return PyBool_FromLong (gptWindow -> set_attribute (ptWindow , iAttribute , & tValue ));
428+ }
429+
430+ // returns the value (see window_set_attribute) or None if unsupported
431+ static PyObject *
432+ window_get_attribute (PyObject * self , PyObject * args , PyObject * kwargs )
433+ {
434+ static const char * apcKeywords [] = {"window" , "attribute" , NULL };
435+ PyObject * ptPyWindow = NULL ;
436+ int iAttribute = 0 ;
437+ if (!pl_parse_args ("Oi" , (const char * * )apcKeywords , args , kwargs , __FUNCTION__ , & ptPyWindow , & iAttribute ))
438+ return NULL ;
439+ plWindow * ptWindow = PyCapsule_GetPointer (ptPyWindow , "plWindow" );
440+ if (ptWindow == NULL )
441+ return NULL ;
442+ if (iAttribute < 0 || iAttribute >= PL_WINDOW_ATTRIBUTE_COUNT )
443+ {
444+ PyErr_Format (PyExc_ValueError , "unknown window attribute %d" , iAttribute );
445+ return NULL ;
446+ }
447+
448+ plWindowAttributeValue tValue = {0 };
449+ if (!gptWindow -> get_attribute (ptWindow , iAttribute , & tValue ))
450+ Py_RETURN_NONE ;
451+ switch (iAttribute )
452+ {
453+ case PL_WINDOW_ATTRIBUTE_SIZE : return Py_BuildValue ("(II)" , tValue .tuVec2 .x , tValue .tuVec2 .y );
454+ case PL_WINDOW_ATTRIBUTE_POSITION : return Py_BuildValue ("(ii)" , tValue .tiVec2 .x , tValue .tiVec2 .y );
455+ case PL_WINDOW_ATTRIBUTE_SIZE_LIMITS : return Py_BuildValue ("(IIII)" , tValue .tuVec4 .x , tValue .tuVec4 .y , tValue .tuVec4 .z , tValue .tuVec4 .w );
456+ default : return PyBool_FromLong (tValue .bValue );
457+ }
458+ }
459+
460+ static PyObject *
461+ window_set_cursor_mode (PyObject * self , PyObject * args , PyObject * kwargs )
462+ {
463+ static const char * apcKeywords [] = {"window" , "mode" , NULL };
464+ PyObject * ptPyWindow = NULL ;
465+ int iMode = 0 ;
466+ if (!pl_parse_args ("Oi" , (const char * * )apcKeywords , args , kwargs , __FUNCTION__ , & ptPyWindow , & iMode ))
467+ return NULL ;
468+ plWindow * ptWindow = PyCapsule_GetPointer (ptPyWindow , "plWindow" );
469+ if (ptWindow == NULL )
470+ return NULL ;
471+ return PyBool_FromLong (gptWindow -> set_cursor_mode (ptWindow , iMode ));
472+ }
473+
474+ static PyObject *
475+ window_get_cursor_mode (PyObject * self , PyObject * arg )
476+ {
477+ plWindow * ptWindow = PyCapsule_GetPointer (arg , "plWindow" );
478+ if (ptWindow == NULL )
479+ return NULL ;
480+ return PyLong_FromLong ((long )gptWindow -> get_cursor_mode (ptWindow ));
481+ }
482+
483+ static PyObject *
484+ window_set_raw_mouse_input (PyObject * self , PyObject * args , PyObject * kwargs )
485+ {
486+ static const char * apcKeywords [] = {"window" , "enabled" , NULL };
487+ PyObject * ptPyWindow = NULL ;
488+ int iEnabled = 0 ;
489+ if (!pl_parse_args ("Op" , (const char * * )apcKeywords , args , kwargs , __FUNCTION__ , & ptPyWindow , & iEnabled ))
490+ return NULL ;
491+ plWindow * ptWindow = PyCapsule_GetPointer (ptPyWindow , "plWindow" );
492+ if (ptWindow == NULL )
493+ return NULL ;
494+ return PyBool_FromLong (gptWindow -> set_raw_mouse_input (ptWindow , iEnabled != 0 ));
495+ }
496+
497+ // desc: plFullScreenDesc (tMode, iMonitor; -1 = automatic)
498+ static PyObject *
499+ window_set_fullscreen (PyObject * self , PyObject * args , PyObject * kwargs )
500+ {
501+ static const char * apcKeywords [] = {"window" , "desc" , NULL };
502+ PyObject * ptPyWindow = NULL ;
503+ PyObject * ptPyDesc = NULL ;
504+ if (!pl_parse_args ("OO" , (const char * * )apcKeywords , args , kwargs , __FUNCTION__ , & ptPyWindow , & ptPyDesc ))
505+ return NULL ;
506+ plWindow * ptWindow = PyCapsule_GetPointer (ptPyWindow , "plWindow" );
507+ if (ptWindow == NULL )
508+ return NULL ;
509+ uint32_t uMode = 0 ;
510+ if (!pl__get_u32_attr (ptPyDesc , "tMode" , & uMode ))
511+ return NULL ;
512+ plFullScreenDesc tDesc = {.tMode = (plFullScreenMode )uMode , .iMonitor = -1 };
513+ if (PyObject_HasAttrString (ptPyDesc , "iMonitor" ))
514+ {
515+ PyObject * ptMonitor = PyObject_GetAttrString (ptPyDesc , "iMonitor" );
516+ if (ptMonitor == NULL )
517+ return NULL ;
518+ tDesc .iMonitor = (int )PyLong_AsLong (ptMonitor );
519+ Py_DECREF (ptMonitor );
520+ if (PyErr_Occurred ())
521+ return NULL ;
522+ }
523+ return PyBool_FromLong (gptWindow -> set_fullscreen (ptWindow , & tDesc ));
524+ }
525+
526+ //-----------------------------------------------------------------------------
527+ // [SECTION] timer api
528+ //-----------------------------------------------------------------------------
529+
530+ static PyObject *
531+ timer_get_time (PyObject * self , PyObject * unused )
532+ {
533+ return PyFloat_FromDouble (gptTimer -> get_time ());
534+ }
535+
536+ static PyObject *
537+ timer_get_raw_time (PyObject * self , PyObject * unused )
538+ {
539+ return PyFloat_FromDouble (gptTimer -> get_raw_time ());
540+ }
541+
379542//-----------------------------------------------------------------------------
380543// [SECTION] file api
381544//-----------------------------------------------------------------------------
@@ -495,11 +658,25 @@ static PyMethodDef gatCommandsplWindowI[] =
495658 {"get_capabilities" , (PyCFunction )window_get_capabilities , METH_NOARGS | METH_STATIC , NULL },
496659 {"set_icon" , (PyCFunction )window_set_icon , METH_VARARGS | METH_KEYWORDS | METH_STATIC , NULL },
497660 {"set_title_bar" , (PyCFunction )window_set_title_bar , METH_VARARGS | METH_KEYWORDS | METH_STATIC , NULL },
661+ {"set_attribute" , (PyCFunction )window_set_attribute , METH_VARARGS | METH_KEYWORDS | METH_STATIC , NULL },
662+ {"get_attribute" , (PyCFunction )window_get_attribute , METH_VARARGS | METH_KEYWORDS | METH_STATIC , NULL },
663+ {"set_cursor_mode" , (PyCFunction )window_set_cursor_mode , METH_VARARGS | METH_KEYWORDS | METH_STATIC , NULL },
664+ {"get_cursor_mode" , (PyCFunction )window_get_cursor_mode , METH_O | METH_STATIC , NULL },
665+ {"set_raw_mouse_input" , (PyCFunction )window_set_raw_mouse_input , METH_VARARGS | METH_KEYWORDS | METH_STATIC , NULL },
666+ {"set_fullscreen" , (PyCFunction )window_set_fullscreen , METH_VARARGS | METH_KEYWORDS | METH_STATIC , NULL },
667+ {NULL , NULL , 0 , NULL }
668+ };
669+
670+ static PyMethodDef gatCommandsplTimerI [] =
671+ {
672+ {"get_time" , (PyCFunction )timer_get_time , METH_NOARGS | METH_STATIC , NULL },
673+ {"get_raw_time" , (PyCFunction )timer_get_raw_time , METH_NOARGS | METH_STATIC , NULL },
498674 {NULL , NULL , 0 , NULL }
499675};
500676
501677PL_NEW_PYTHON_API (plWindowI )
502678PL_NEW_PYTHON_API (plFileI )
679+ PL_NEW_PYTHON_API (plTimerI )
503680
504681//-----------------------------------------------------------------------------
505682// [SECTION] constants
@@ -520,4 +697,22 @@ plPythonIntConstantPair gatPlatformIntPairs[] = {
520697 PL_ADD_INT_CONSTANT (PL_WINDOW_CAPABILITY_FLAGS_APP_ICON ),
521698 PL_ADD_INT_CONSTANT (PL_WINDOW_CAPABILITY_FLAGS_CUSTOM_TITLE_BAR ),
522699 PL_ADD_INT_CONSTANT (PL_WINDOW_CAPABILITY_FLAGS_TITLE_BAR_TEXT ),
700+ PL_ADD_INT_CONSTANT (PL_WINDOW_ATTRIBUTE_SIZE ),
701+ PL_ADD_INT_CONSTANT (PL_WINDOW_ATTRIBUTE_POSITION ),
702+ PL_ADD_INT_CONSTANT (PL_WINDOW_ATTRIBUTE_RESIZABLE ),
703+ PL_ADD_INT_CONSTANT (PL_WINDOW_ATTRIBUTE_DECORATED ),
704+ PL_ADD_INT_CONSTANT (PL_WINDOW_ATTRIBUTE_TOP_MOST ),
705+ PL_ADD_INT_CONSTANT (PL_WINDOW_ATTRIBUTE_MINIMIZED ),
706+ PL_ADD_INT_CONSTANT (PL_WINDOW_ATTRIBUTE_MAXIMIZED ),
707+ PL_ADD_INT_CONSTANT (PL_WINDOW_ATTRIBUTE_VISIBLE ),
708+ PL_ADD_INT_CONSTANT (PL_WINDOW_ATTRIBUTE_FOCUSED ),
709+ PL_ADD_INT_CONSTANT (PL_WINDOW_ATTRIBUTE_HOVERED ),
710+ PL_ADD_INT_CONSTANT (PL_WINDOW_ATTRIBUTE_SIZE_LIMITS ),
711+ PL_ADD_INT_CONSTANT (PL_CURSOR_MODE_NORMAL ),
712+ PL_ADD_INT_CONSTANT (PL_CURSOR_MODE_HIDDEN ),
713+ PL_ADD_INT_CONSTANT (PL_CURSOR_MODE_CAPTURED ),
714+ PL_ADD_INT_CONSTANT (PL_CURSOR_MODE_DISABLED ),
715+ PL_ADD_INT_CONSTANT (PL_FULLSCREEN_MODE_NONE ),
716+ PL_ADD_INT_CONSTANT (PL_FULLSCREEN_MODE_EXCLUSIVE ),
717+ PL_ADD_INT_CONSTANT (PL_FULLSCREEN_MODE_BORDERLESS ),
523718};
0 commit comments