*/}}
Browse Source

Better pressure handling

Yiming Wu 2 years ago
parent
commit
a1ba0318fe
3 changed files with 48 additions and 14 deletions
  1. 1 1
      la_interface.h
  2. 19 5
      la_kernel.c
  3. 28 8
      resources/la_widgets.c

+ 1 - 1
la_interface.h

@@ -277,7 +277,7 @@ STRUCTURE(LA){
     int xi_opcode;
     int WacomDeviceStylus; real StylusPressure, StylusAngleX, StylusAngleY;
     int WacomDeviceEraser; real EraserPressure, EraserAngleX, EraserAngleY;
-    int PointerIsEraser;
+    int PointerIsEraser,IsPen;
 
     laWindow *CurrentWindow;
     laPanel *CurrentPanel;

+ 19 - 5
la_kernel.c

@@ -672,7 +672,7 @@ void la_SaveEvent(Window hwnd, laEvent *e, int use_last_pos){
             e->x = rx; e->y = ry;
         }
     }
-    e->Pressure=MAIN.PointerIsEraser?MAIN.EraserPressure:MAIN.StylusPressure;
+    e->Pressure=MAIN.IsPen?(MAIN.PointerIsEraser?MAIN.EraserPressure:MAIN.StylusPressure):0.5f;
     e->AngleX=MAIN.PointerIsEraser?MAIN.EraserAngleX:MAIN.StylusAngleX;
     e->AngleY=MAIN.PointerIsEraser?MAIN.EraserAngleY:MAIN.StylusAngleY;
 
@@ -6031,15 +6031,29 @@ void laFinalizeOperators(){
 //=================
 
 
-static void la_RegisterRawMotions(XIRawEvent *event)
+static void la_RecordWacomMotions(XIRawEvent *event)
 {
     double *valuator = event->valuators.values;
     int IsStylus=event->deviceid==MAIN.WacomDeviceStylus;
     if(!IsStylus) MAIN.PointerIsEraser = 1; else MAIN.PointerIsEraser = 0;
+    
+
+    //Window root_return, child_return;
+    //int root_x_return, root_y_return;
+    //int win_x_return, win_y_return;
+    //unsigned int mask_return;
+    //int retval = XQueryPointer(MAIN.dpy, RootWindow(MAIN.dpy,0), &root_return, &child_return,
+    //                            &root_x_return, &root_y_return,
+    //                            &win_x_return, &win_y_return,
+    //                            &mask_return);
+    //
+    //printf("root: x %d y %d\n", win_x_return, win_y_return);
 
     if(XIMaskIsSet(event->valuators.mask, 2)){ if(IsStylus) MAIN.StylusPressure=valuator[2]/65536; else MAIN.EraserPressure=valuator[2]/65536; }
     if(XIMaskIsSet(event->valuators.mask, 3)){ if(IsStylus) MAIN.StylusAngleX=valuator[3]; else MAIN.EraserAngleX=valuator[3]; }
     if(XIMaskIsSet(event->valuators.mask, 4)){ if(IsStylus) MAIN.StylusAngleY=valuator[4]; else MAIN.EraserAngleY=valuator[4]; }
+
+    MAIN.IsPen=1;
 }
 
 
@@ -6218,7 +6232,8 @@ int la_ProcessSysMessage(){
         SendIdle=0; MAIN.IdleStart=MAIN.TimeAccum; MAIN.IdleTriggered=0;
 
         if (cookie->type == GenericEvent && cookie->extension == MAIN.xi_opcode && XGetEventData(MAIN.dpy, cookie)){
-            if (cookie->evtype == XI_RawMotion) la_RegisterRawMotions(cookie->data);
+            if (cookie->evtype == XI_RawMotion) la_RecordWacomMotions(cookie->data);
+            XFreeEventData(MAIN.dpy, cookie); continue;
         }
             
         switch(e.type){
@@ -6234,7 +6249,6 @@ int la_ProcessSysMessage(){
             break;
         case ButtonPress:
             type=LA_MOUSEDOWN;
-            printf("down\n");
             if(e.xbutton.button==1){type|=LA_KEY_MOUSE_LEFT;}
             elif(e.xbutton.button==2){type|=LA_KEY_MOUSE_MIDDLE;}
             elif(e.xbutton.button==3){type|=LA_KEY_MOUSE_RIGHT;}
@@ -6310,7 +6324,7 @@ int la_ProcessSysMessage(){
         default:
             break;
         }
-        XFreeEventData(MAIN.dpy, cookie);
+        MAIN.IsPen=0;
     }
 
     for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){

+ 28 - 8
resources/la_widgets.c

@@ -162,6 +162,9 @@ int la_SocketGetHeight(laUiItem *ui){
     if(ui->Flags&(LA_UI_SOCKET_LABEL_N|LA_UI_SOCKET_LABEL_S))return 2; return 1;
 }
 
+int la_ColorSelectorGetMinWidth(laUiItem *ui){
+    return 5*LA_RH;
+}
 int la_ValueGetMinWidth(laUiItem *ui){
     int ExtraW=0;
     if(ui->Flags&LA_UI_FLAGS_EXPAND){ ExtraW+=tnsStringGetWidth(ui->PP.LastPs->p->Name,0,0);  }
@@ -197,15 +200,24 @@ int la_EnumGetMinWidth(laUiItem *ui){
     if(!IsIcon){
         SharedWidth = bt->LM + bt->RM + ((IsCycle||IsExpand)?0:LA_RH); int HasIcon=0;
         if(Highlight){
-            tW = tnsStringGetWidth(ep->Base.Name, 0, ui->Flags&LA_TEXT_MONO) + SharedWidth;
-            if (tW > W) W = tW;
-        }
-        for (i = ep->Items.pFirst; i; i = i->Item.pNext){
-            tW = tnsStringGetWidth(i->Name, 0, ui->Flags&LA_TEXT_MONO) + SharedWidth;
-            if (i->IconID){ HasIcon=1; }
+            if (ui->ExtraInstructions){
+                if (ui->Type->OperatorType->ParseArgs){
+                    int ico; char buf[256]; buf[0]=0;
+                    ui->Type->OperatorType->ParseArgs(ui->Instructions, &ico, buf);
+                    tW = tnsStringGetWidth(buf, 0, ui->Flags&LA_TEXT_MONO) + SharedWidth;
+                }
+            }else{
+                tW = tnsStringGetWidth(ep->Base.Name, 0, ui->Flags&LA_TEXT_MONO) + SharedWidth;
+            }
             if (tW > W) W = tW;
+        }else{
+            for (i = ep->Items.pFirst; i; i = i->Item.pNext){
+                tW = tnsStringGetWidth(i->Name, 0, ui->Flags&LA_TEXT_MONO) + SharedWidth;
+                if (i->IconID){ HasIcon=1; }
+                if (tW > W) W = tW;
+            }
+            if(HasIcon) W+=bt->LM+LA_RH;
         }
-        if(HasIcon) W+=bt->LM+LA_RH;
     }else{
         W = LA_RH;
     }
@@ -747,7 +759,14 @@ void la_EnumSelectorDraw(laUiItem *ui, int h){
                 tnsPackAs(GL_LINE_LOOP);
             }
 
-            if(!Highlight){ strcpy(buf, transLate(use_ei->Name)); }
+            if(!Highlight){ 
+                if (ui->ExtraInstructions){
+                    if (ui->Type->OperatorType->ParseArgs){
+                        int ico; buf[0]=0; ui->Type->OperatorType->ParseArgs(ui->Instructions, &ico, buf);
+                    }
+                }
+                if(!buf[0]) strcpy(buf, transLate(use_ei->Name)); 
+            }
             else{ if(ArrLen==1) strcpy(buf, transLate(ui->PP.LastPs->p->Name)); else{ if(i<8)strcat(buf, &prefix[i]); } }
             int iconR; if(IconOnly)iconR=TNS_MAX2(_L+LA_RH,_R);else{ iconR=TNS_MIN2(_L+LA_RH,_R); }
             if (use_ei->IconID) tnsDrawIcon(use_ei->IconID, laThemeColor(bt, LA_BT_TEXT|ExtraState), _L,iconR, _U, LA_TEXT_ALIGN_CENTER);
@@ -1432,6 +1451,7 @@ void la_RegisterUiTypesBasic(){
     LA_WIDGET_FLOAT_COLOR->Type=
     _LA_UI_FLOAT_COLOR = la_RegisterUiType("LA_real_color", LA_PROP_FLOAT | LA_PROP_ARRAY, "LA_real_color_operator",
                         &_LA_THEME_VALUATOR, la_FloatArrayColorDraw, 0, la_GeneralUiInit, la_GeneralUiDestroy);
+    _LA_UI_FLOAT_COLOR->GetMinWidth=la_ColorSelectorGetMinWidth;
 
     LA_WIDGET_FLOAT_COLOR_HCY->Type=
     _LA_UI_FLOAT_COLOR_HCY = la_RegisterUiType("LA_real_hcy", LA_PROP_FLOAT | LA_PROP_ARRAY, "LA_real_hcy_operator",