*/}}
Browse Source

Now basic brush is paintable.

Yiming Wu 2 years ago
parent
commit
c8beb8141d
3 changed files with 36 additions and 27 deletions
  1. 2 2
      source/lagui/la_interface.h
  2. 1 1
      source/lagui/la_resource.c
  3. 33 24
      source/lagui/resources/la_widgets.c

+ 2 - 2
source/lagui/la_interface.h

@@ -939,7 +939,7 @@ extern laWidget* LA_WIDGET_VALUE_METER_2D;
 extern laWidget* LA_WIDGET_FLOAT;
 extern laWidget* LA_WIDGET_FLOAT_PLAIN;
 extern laWidget* LA_WIDGET_FLOAT_COLOR;
-extern laWidget* LA_WIDGET_FLOAT_HCY;
+extern laWidget* LA_WIDGET_FLOAT_COLOR_HCY;
 extern laWidget* LA_WIDGET_ENUM_SELECTOR;
 extern laWidget* LA_WIDGET_ENUM_SELECTOR_ICON;
 extern laWidget* LA_WIDGET_ENUM_CYCLE;
@@ -1845,7 +1845,7 @@ extern laUiType *_LA_UI_VALUE_METER;
 extern laUiType *_LA_UI_VALUE_METER_2D;
 extern laUiType *_LA_UI_FLOAT;
 extern laUiType *_LA_UI_FLOAT_COLOR;
-extern laUiType *_LA_UI_FLOAT_HCY;
+extern laUiType *_LA_UI_FLOAT_COLOR_HCY;
 extern laUiType *_LA_UI_ENUM_SELECTOR;
 extern laUiType *_LA_UI_MENU_ROOT;
 extern laUiType *_LA_UI_CONDITION_TOGGLE;

+ 1 - 1
source/lagui/la_resource.c

@@ -22,7 +22,7 @@ laUiType *_LA_UI_VALUE_METER;
 laUiType *_LA_UI_VALUE_METER_2D;
 laUiType *_LA_UI_FLOAT;
 laUiType *_LA_UI_FLOAT_COLOR;
-laUiType *_LA_UI_FLOAT_HCY;
+laUiType *_LA_UI_FLOAT_COLOR_HCY;
 laUiType *_LA_UI_ENUM_SELECTOR;
 laUiType *_LA_UI_MENU_ROOT;
 laUiType *_LA_UI_CONDITION_TOGGLE;

+ 33 - 24
source/lagui/resources/la_widgets.c

@@ -22,7 +22,7 @@ laWidget _LA_WIDGET_VALUE_METER_2D={0,LA_TEXT_ALIGN_CENTER};
 laWidget _LA_WIDGET_FLOAT={0};
 laWidget _LA_WIDGET_FLOAT_PLAIN={0, LA_UI_FLAGS_PLAIN};
 laWidget _LA_WIDGET_FLOAT_COLOR={0};
-laWidget _LA_WIDGET_FLOAT_HCY={0};
+laWidget _LA_WIDGET_FLOAT_COLOR_HCY={0};
 laWidget _LA_WIDGET_ENUM_SELECTOR={0};
 laWidget _LA_WIDGET_ENUM_SELECTOR_ICON={0, LA_UI_FLAGS_ICON};
 laWidget _LA_WIDGET_ENUM_CYCLE={0, LA_UI_FLAGS_CYCLE};
@@ -62,7 +62,7 @@ laWidget *LA_WIDGET_VALUE_METER_2D=&_LA_WIDGET_VALUE_METER_2D;
 laWidget *LA_WIDGET_FLOAT=&_LA_WIDGET_FLOAT;
 laWidget *LA_WIDGET_FLOAT_PLAIN=&_LA_WIDGET_FLOAT_PLAIN;
 laWidget *LA_WIDGET_FLOAT_COLOR=&_LA_WIDGET_FLOAT_COLOR;
-laWidget *LA_WIDGET_FLOAT_HCY=&_LA_WIDGET_FLOAT_HCY;
+laWidget *LA_WIDGET_FLOAT_COLOR_HCY=&_LA_WIDGET_FLOAT_COLOR_HCY;
 laWidget *LA_WIDGET_ENUM_SELECTOR=&_LA_WIDGET_ENUM_SELECTOR;
 laWidget *LA_WIDGET_ENUM_SELECTOR_ICON=&_LA_WIDGET_ENUM_SELECTOR_ICON;
 laWidget *LA_WIDGET_ENUM_CYCLE=&_LA_WIDGET_ENUM_CYCLE;
@@ -125,7 +125,8 @@ int la_EnumGetHeight(laUiItem *ui){
     }
 }
 int la_ColorPickerGetHeight(laUiItem *ui){
-    return 7;
+    if(!ui->Extra->HeightCoeff) ui->Extra->HeightCoeff=7;
+    return ui->Extra->HeightCoeff;
 }
 int la_SymbolGetHeight(laUiItem *ui){
     //if (!ui->State)
@@ -1119,6 +1120,9 @@ void la_ColorCircleDrawHCY(laUiItem *ui, int h){
     tnsVertexArray2d(verts, 2);
     tnsPackAs(GL_LINES);
 
+    if(ui->Extra->HeightCoeff>=0)
+        tnsDrawStringAuto("◿",laThemeColor(bt,LA_BT_BORDER),ui->R-LA_RH, ui->R, ui->B-bt->BM-LA_RH, LA_TEXT_ALIGN_CENTER);
+
     tnsFlush();
 }
 void la_MenuItemDraw(laUiItem *ui, int h){
@@ -1428,10 +1432,10 @@ void la_RegisterUiTypesBasic(){
     _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_WIDGET_FLOAT_HCY->Type=
-    _LA_UI_FLOAT_HCY = la_RegisterUiType("LA_real_hcy", LA_PROP_FLOAT | LA_PROP_ARRAY, "LA_real_hcy_operator",
+    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",
                         &_LA_THEME_VALUATOR, la_ColorCircleDrawHCY, la_ColorPickerGetHeight, la_GeneralUiInit, la_GeneralUiDestroy);
-    _LA_UI_FLOAT_HCY->GetMinWidth = la_ColorPickerGetMinWidth;
+    _LA_UI_FLOAT_COLOR_HCY->GetMinWidth = la_ColorPickerGetMinWidth;
 
     LA_WIDGET_ENUM_SELECTOR->Type=LA_WIDGET_ENUM_SELECTOR_ICON->Type=LA_WIDGET_ENUM_CYCLE->Type=LA_WIDGET_ENUM_HIGHLIGHT->Type=
     _LA_UI_ENUM_SELECTOR = la_RegisterUiType("LA_enum_selector", LA_PROP_ENUM, "LA_enum_selector_operator",
@@ -1940,7 +1944,7 @@ int OPMOD_FloatColor(laOperator *a, laEvent *e){
         p = laEnableEmptyPropertyPanel(a->ToPanel, a, GX, GX + 150, GY, 500, e);{
             uil = &p->UI;
             col = laFirstColumn(uil);
-            laShowItemFull(uil, col, &ui->PP, 0, LA_WIDGET_FLOAT_HCY, 0, 0, 0);
+            laShowItemFull(uil, col, &ui->PP, 0, LA_WIDGET_FLOAT_COLOR_HCY, 0, 0, 0);
             laShowItemFull(uil, col, &ui->PP, 0, LA_WIDGET_FLOAT, 0, 0, 0)->Flags=LA_UI_FLAGS_TRANSPOSE;
             laEnclosePanelContent(p, uil);
         }
@@ -1958,38 +1962,43 @@ int OPMOD_FloatColor(laOperator *a, laEvent *e){
 int OPMOD_ColorHCY(laOperator *a, laEvent *e){
     laUiItem *ui = a->Instance;
     laBoxedTheme *bt = (*ui->Type->Theme);
-    laGeneralUiExtraData *uit = a->CustomData;
+    laGeneralUiExtraData *es = a->CustomData;
     int Away = 0;
-    real c = (real)((ui->R + ui->L) / 2) - LA_RH / 2; /*- bt->RM;*/
-    real r = (ui->B - ui->U - bt->TP - bt->BP) / 2;
     int i = 0;
     real hcy[3] = {0};
     real Color[4] = {0};
     real PickerPos[2];
     real abso;
-    real dx = e->x - c, dy = e->y - (ui->U + r + bt->TP);
-    real dist = sqrt(dx * dx + dy * dy);
 
-    if (!laIsInUiItem(ui, e->x, e->y)){
+    if (!laIsInUiItem(ui, e->x, e->y) && !es->Dragging){
         return LA_FINISHED_PASS;
     }
 
-    if (e->Type == LA_L_MOUSE_DOWN){
-        ui->State = LA_UI_ACTIVE;
-        laRedrawCurrentPanel();
-        //return LA_RUNNING;
+    if(e->Type == LA_L_MOUSE_DOWN && es->HeightCoeff>=0 && e->x>ui->R-bt->RM-LA_RH && e->y>ui->B-bt->BM-LA_RH){
+        es->Dragging=3; es->LastX=e->x; es->LastY=e->y; es->TargetIndexVali=es->HeightCoeff; return LA_RUNNING;
     }
-    if (e->Type == LA_L_MOUSE_UP){
-        ui->State = LA_UI_NORMAL;
-        laRedrawCurrentPanel();
+    if(es->Dragging==3){
+        if(e->Type==LA_MOUSEMOVE){ es->HeightCoeff=es->TargetIndexVali+((real)e->y-es->LastY+0.5)/LA_RH;
+            if(es->HeightCoeff<1)es->HeightCoeff=1; laRecalcCurrentPanel();}
+        elif(e->Type==LA_L_MOUSE_UP){ es->Dragging=0; }
+        elif(e->Type==LA_R_MOUSE_DOWN){
+            es->Dragging=0; es->HeightCoeff=es->TargetIndexVali; laRecalcCurrentPanel(); }
         return LA_RUNNING;
     }
 
-    if (e->Type & LA_MOUSE_EVENT && LA_UI_NORMAL != ui->State){
+    real c = (real)((ui->R + ui->L) / 2) - LA_RH / 2; /*- bt->RM;*/
+    real r = (ui->B - ui->U - bt->TP - bt->BP) / 2;
+    real dx = e->x - c, dy = e->y - (ui->U + r + bt->TP);
+    real dist = sqrt(dx * dx + dy * dy);
+
+    if (e->Type == LA_L_MOUSE_DOWN){ ui->State = LA_UI_ACTIVE; laRedrawCurrentPanel(); es->Dragging=(dist<=r)?1:2; }
+    if (e->Type == LA_L_MOUSE_UP){ ui->State = LA_UI_NORMAL; es->Dragging=0; laRedrawCurrentPanel(); return LA_RUNNING_PASS; }
+
+    if (e->Type & LA_MOUSE_EVENT && es->Dragging){
         laGetFloatArray(&ui->PP, Color);
         tnsLogToLinear(Color, MAIN.Gamma);
         tnsRGBtoHCY(Color, hcy);
-        if (dist < r){
+        if (es->Dragging==1){
             abso = fabs(atan((real)dy / (real)dx));
             hcy[0] = abso / TNS_PI / 2;
             if (dx > 0){
@@ -2001,7 +2010,7 @@ int OPMOD_ColorHCY(laOperator *a, laEvent *e){
                     hcy[0] += 0.5;
                 }
             }
-            hcy[1] = dist / r;
+            hcy[1] = dist / r; TNS_CLAMP(hcy[1],0,1);
             //printf("hcy[1] = %d -> ",hcy[1]);
             //if (MAIN.ColorAccessCorrectGamma) {
             //tnsSingleLogToLinear(&hcy[1], 2.2);
@@ -2009,7 +2018,7 @@ int OPMOD_ColorHCY(laOperator *a, laEvent *e){
             //printf("%d\n", hcy[1]);
         }else if (dist < r + LA_RH * 2 && dx > 0){
             abso = -atan((real)dy / (real)dx) / TNS_PI * 2 + 0.5;
-            hcy[2] = abso;
+            hcy[2] = abso; TNS_CLAMP(hcy[2],0,1);
             //if (MAIN.ColorAccessCorrectGamma) {
             //    tnsSingleLogToLinear(&hcy[2], MAIN.Gamma);
             //}