Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / util / ed_util.c
index 278b8e34311dfcd76da99d6eadebf202e05ad6ba..d0f29abc62f2e1f6d7634dba6ba2fbd76f5e3c3d 100644 (file)
@@ -70,6 +70,8 @@
 #include "ED_space_api.h"
 #include "ED_util.h"
 
+#include "GPU_immediate.h"
+
 #include "UI_interface.h"
 #include "UI_resources.h"
 
@@ -86,7 +88,8 @@ void ED_editors_init(bContext *C)
        wmWindowManager *wm = CTX_wm_manager(C);
        Main *bmain = CTX_data_main(C);
        Scene *sce = CTX_data_scene(C);
-       Object *ob, *obact = (sce && sce->basact) ? sce->basact->object : NULL;
+       SceneLayer *sl = CTX_data_scene_layer(C);
+       Object *ob, *obact = (sl && sl->basact) ? sl->basact->object : NULL;
        ID *data;
 
        /* This is called during initialization, so we don't want to store any reports */
@@ -101,12 +104,15 @@ void ED_editors_init(bContext *C)
        for (ob = bmain->object.first; ob; ob = ob->id.next) {
                int mode = ob->mode;
 
-               if (!ELEM(mode, OB_MODE_OBJECT, OB_MODE_POSE)) {
-                       ob->mode = OB_MODE_OBJECT;
+               if (mode == OB_MODE_OBJECT) {
+                       /* pass */
+               }
+               else {
                        data = ob->data;
-
-                       if (ob == obact && !ID_IS_LINKED(ob) && !(data && ID_IS_LINKED(data)))
+                       ob->mode = OB_MODE_OBJECT;
+                       if ((ob == obact) && !ID_IS_LINKED(ob) && !(data && ID_IS_LINKED(data))) {
                                ED_object_toggle_modes(C, mode);
+                       }
                }
        }
 
@@ -313,16 +319,28 @@ void ED_region_draw_mouse_line_cb(const bContext *C, ARegion *ar, void *arg_info
 {
        wmWindow *win = CTX_wm_window(C);
        const float *mval_src = (float *)arg_info;
-       const int mval_dst[2] = {win->eventstate->x - ar->winrct.xmin,
-                                win->eventstate->y - ar->winrct.ymin};
-
-       UI_ThemeColor(TH_VIEW_OVERLAY);
-       setlinestyle(3);
-       glBegin(GL_LINES);
-       glVertex2iv(mval_dst);
-       glVertex2fv(mval_src);
-       glEnd();
-       setlinestyle(0);
+       const float mval_dst[2] = {win->eventstate->x - ar->winrct.xmin,
+                                  win->eventstate->y - ar->winrct.ymin};
+
+       const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+       immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+       float viewport_size[4];
+       glGetFloatv(GL_VIEWPORT, viewport_size);
+       immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
+
+       immUniform1i("num_colors", 0);  /* "simple" mode */
+       immUniformThemeColor(TH_VIEW_OVERLAY);
+       immUniform1f("dash_width", 6.0f);
+       immUniform1f("dash_factor", 0.5f);
+
+       immBegin(GWN_PRIM_LINES, 2);
+       immVertex2fv(shdr_pos, mval_src);
+       immVertex2fv(shdr_pos, mval_dst);
+       immEnd();
+
+       immUnbindProgram();
 }
 
 /**